mirror of https://github.com/apache/jclouds.git
added better error handling for vcloud
This commit is contained in:
parent
40447696c7
commit
529a0ad075
|
@ -103,9 +103,8 @@ public class ImageImpl extends ComputeMetadataImpl implements Image {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[id=" + getId() + ", name=" + getName() + ", locationId=" + getLocationId()
|
return "[id=" + getId() + ", name=" + getName() + ", locationId=" + getLocationId()
|
||||||
+ ", architecture=" + architecture + ", description=" + description
|
+ ", architecture=" + architecture + ", osDescription=" + osDescription
|
||||||
+ ", osDescription=" + osDescription + ", osFamily=" + osFamily + ", version="
|
+ ", osFamily=" + osFamily + ", version=" + version + "]";
|
||||||
+ version + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,18 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.bluelock.config;
|
package org.jclouds.vcloud.bluelock.config;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
import org.jclouds.vcloud.VCloudClient;
|
||||||
import org.jclouds.vcloud.config.VCloudRestClientModule;
|
import org.jclouds.vcloud.config.VCloudRestClientModule;
|
||||||
import org.jclouds.vcloud.domain.NamedResource;
|
import org.jclouds.vcloud.domain.NamedResource;
|
||||||
import org.jclouds.vcloud.domain.Organization;
|
import org.jclouds.vcloud.domain.Organization;
|
||||||
|
@ -47,11 +48,13 @@ import com.google.common.collect.Iterables;
|
||||||
public class BlueLockVCloudRestClientModule extends VCloudRestClientModule {
|
public class BlueLockVCloudRestClientModule extends VCloudRestClientModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException,
|
protected URI provideDefaultNetwork(VCloudClient client) throws InterruptedException,
|
||||||
ExecutionException, TimeoutException {
|
ExecutionException, TimeoutException {
|
||||||
|
org.jclouds.vcloud.domain.VDC vDC = client.getDefaultVDC();
|
||||||
|
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
|
||||||
|
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
|
||||||
return Iterables.getOnlyElement(
|
return Iterables.getOnlyElement(
|
||||||
Iterables.filter(client.getDefaultVDC().get(180, TimeUnit.SECONDS)
|
Iterables.filter(networks.values(), new Predicate<NamedResource>() {
|
||||||
.getAvailableNetworks().values(), new Predicate<NamedResource>() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(NamedResource input) {
|
public boolean apply(NamedResource input) {
|
||||||
|
@ -63,6 +66,7 @@ public class BlueLockVCloudRestClientModule extends VCloudRestClientModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URI provideCatalog(Organization org, @Named(PROPERTY_VCLOUD_USER) final String user) {
|
protected URI provideCatalog(Organization org, @Named(PROPERTY_VCLOUD_USER) final String user) {
|
||||||
|
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
|
||||||
return Iterables.getOnlyElement(
|
return Iterables.getOnlyElement(
|
||||||
Iterables.filter(org.getCatalogs().values(), new Predicate<NamedResource>() {
|
Iterables.filter(org.getCatalogs().values(), new Predicate<NamedResource>() {
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
|
||||||
void addVAppToSetRetryingIfNotYetPresent(Set<ComputeMetadata> nodes, NamedResource vdc,
|
void addVAppToSetRetryingIfNotYetPresent(Set<ComputeMetadata> nodes, NamedResource vdc,
|
||||||
NamedResource resource) {
|
NamedResource resource) {
|
||||||
NodeMetadata node = null;
|
NodeMetadata node = null;
|
||||||
while (node == null) {
|
int i = 0;
|
||||||
|
while (node == null && i++ < 3) {
|
||||||
try {
|
try {
|
||||||
node = getNodeMetadataByIdInVDC(vdc.getId(), resource.getId());
|
node = getNodeMetadataByIdInVDC(vdc.getId(), resource.getId());
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.config;
|
package org.jclouds.vcloud.config;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
|
||||||
|
@ -29,6 +31,8 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.SortedMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
@ -51,6 +55,7 @@ import org.jclouds.rest.RestClientFactory;
|
||||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||||
import org.jclouds.vcloud.VCloudClient;
|
import org.jclouds.vcloud.VCloudClient;
|
||||||
import org.jclouds.vcloud.VCloudToken;
|
import org.jclouds.vcloud.VCloudToken;
|
||||||
|
import org.jclouds.vcloud.domain.NamedResource;
|
||||||
import org.jclouds.vcloud.domain.Organization;
|
import org.jclouds.vcloud.domain.Organization;
|
||||||
import org.jclouds.vcloud.domain.VApp;
|
import org.jclouds.vcloud.domain.VApp;
|
||||||
import org.jclouds.vcloud.endpoints.Catalog;
|
import org.jclouds.vcloud.endpoints.Catalog;
|
||||||
|
@ -121,14 +126,16 @@ public class VCloudRestClientModule extends AbstractModule {
|
||||||
@VCloudToken
|
@VCloudToken
|
||||||
@Provides
|
@Provides
|
||||||
String provideVCloudToken(Supplier<VCloudSession> cache) {
|
String provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||||
return cache.get().getVCloudToken();
|
return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Org
|
@Org
|
||||||
@Singleton
|
@Singleton
|
||||||
protected URI provideOrg(Supplier<VCloudSession> cache, @Named(PROPERTY_VCLOUD_USER) String user) {
|
protected URI provideOrg(Supplier<VCloudSession> cache, @Named(PROPERTY_VCLOUD_USER) String user) {
|
||||||
return Iterables.getLast(cache.get().getOrgs().values()).getLocation();
|
VCloudSession discovery = cache.get();
|
||||||
|
checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user);
|
||||||
|
return Iterables.getLast(discovery.getOrgs().values()).getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -170,7 +177,12 @@ public class VCloudRestClientModule extends AbstractModule {
|
||||||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
|
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
|
||||||
@Named(PROPERTY_VCLOUD_VERSION) String version) throws InterruptedException,
|
@Named(PROPERTY_VCLOUD_VERSION) String version) throws InterruptedException,
|
||||||
ExecutionException, TimeoutException {
|
ExecutionException, TimeoutException {
|
||||||
return versionService.getSupportedVersions().get(180, TimeUnit.SECONDS).get(version);
|
SortedMap<String, URI> versions = versionService.getSupportedVersions().get(180,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
checkState(versions.size() > 0, "No versions present");
|
||||||
|
checkState(versions.containsKey(version), "version " + version + " not present in: "
|
||||||
|
+ versions);
|
||||||
|
return versions.get(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -238,6 +250,7 @@ public class VCloudRestClientModule extends AbstractModule {
|
||||||
@VDC
|
@VDC
|
||||||
@Singleton
|
@Singleton
|
||||||
protected URI provideDefaultVDC(Organization org) {
|
protected URI provideDefaultVDC(Organization org) {
|
||||||
|
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName());
|
||||||
return Iterables.get(org.getVDCs().values(), 0).getLocation();
|
return Iterables.get(org.getVDCs().values(), 0).getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,18 +258,19 @@ public class VCloudRestClientModule extends AbstractModule {
|
||||||
@Catalog
|
@Catalog
|
||||||
@Singleton
|
@Singleton
|
||||||
protected URI provideCatalog(Organization org, @Named(PROPERTY_VCLOUD_USER) String user) {
|
protected URI provideCatalog(Organization org, @Named(PROPERTY_VCLOUD_USER) String user) {
|
||||||
|
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
|
||||||
return Iterables.get(org.getCatalogs().values(), 0).getLocation();
|
return Iterables.get(org.getCatalogs().values(), 0).getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Network
|
@Network
|
||||||
@Singleton
|
@Singleton
|
||||||
protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException,
|
protected URI provideDefaultNetwork(VCloudClient client) throws InterruptedException,
|
||||||
ExecutionException, TimeoutException {
|
ExecutionException, TimeoutException {
|
||||||
return Iterables
|
org.jclouds.vcloud.domain.VDC vDC = client.getDefaultVDC();
|
||||||
.get(
|
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
|
||||||
client.getDefaultVDC().get(180, TimeUnit.SECONDS).getAvailableNetworks()
|
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
|
||||||
.values(), 0).getLocation();
|
return Iterables.get(networks.values(), 0).getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -270,6 +284,7 @@ public class VCloudRestClientModule extends AbstractModule {
|
||||||
@TasksList
|
@TasksList
|
||||||
@Singleton
|
@Singleton
|
||||||
protected URI provideDefaultTasksList(Organization org) {
|
protected URI provideDefaultTasksList(Organization org) {
|
||||||
return org.getTasksLists().values().iterator().next().getLocation();
|
checkState(org.getTasksLists().size() > 0, "No tasks lists present in org: " + org.getName());
|
||||||
|
return Iterables.get(org.getTasksLists().values(), 0).getLocation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class HostingDotComVCloudRestClientModule extends VCloudRestClientModule
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URI provideDefaultNetwork(VCloudAsyncClient client) {
|
protected URI provideDefaultNetwork(VCloudClient client) {
|
||||||
return URI.create("https://vcloud.safesecureweb.com/network/1990");
|
return URI.create("https://vcloud.safesecureweb.com/network/1990");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue