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
|
||||
public String toString() {
|
||||
return "[id=" + getId() + ", name=" + getName() + ", locationId=" + getLocationId()
|
||||
+ ", architecture=" + architecture + ", description=" + description
|
||||
+ ", osDescription=" + osDescription + ", osFamily=" + osFamily + ", version="
|
||||
+ version + "]";
|
||||
+ ", architecture=" + architecture + ", osDescription=" + osDescription
|
||||
+ ", osFamily=" + osFamily + ", version=" + version + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,18 +18,19 @@
|
|||
*/
|
||||
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 java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
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.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
|
@ -47,11 +48,13 @@ import com.google.common.collect.Iterables;
|
|||
public class BlueLockVCloudRestClientModule extends VCloudRestClientModule {
|
||||
|
||||
@Override
|
||||
protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException,
|
||||
protected URI provideDefaultNetwork(VCloudClient client) throws InterruptedException,
|
||||
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(
|
||||
Iterables.filter(client.getDefaultVDC().get(180, TimeUnit.SECONDS)
|
||||
.getAvailableNetworks().values(), new Predicate<NamedResource>() {
|
||||
Iterables.filter(networks.values(), new Predicate<NamedResource>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(NamedResource input) {
|
||||
|
@ -63,6 +66,7 @@ public class BlueLockVCloudRestClientModule extends VCloudRestClientModule {
|
|||
|
||||
@Override
|
||||
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(
|
||||
Iterables.filter(org.getCatalogs().values(), new Predicate<NamedResource>() {
|
||||
|
||||
|
|
|
@ -230,7 +230,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
|
|||
void addVAppToSetRetryingIfNotYetPresent(Set<ComputeMetadata> nodes, NamedResource vdc,
|
||||
NamedResource resource) {
|
||||
NodeMetadata node = null;
|
||||
while (node == null) {
|
||||
int i = 0;
|
||||
while (node == null && i++ < 3) {
|
||||
try {
|
||||
node = getNodeMetadataByIdInVDC(vdc.getId(), resource.getId());
|
||||
} catch (NullPointerException e) {
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
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_ENDPOINT;
|
||||
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.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
@ -51,6 +55,7 @@ import org.jclouds.rest.RestClientFactory;
|
|||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.VCloudToken;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.endpoints.Catalog;
|
||||
|
@ -121,14 +126,16 @@ public class VCloudRestClientModule extends AbstractModule {
|
|||
@VCloudToken
|
||||
@Provides
|
||||
String provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
return cache.get().getVCloudToken();
|
||||
return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Org
|
||||
@Singleton
|
||||
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
|
||||
|
@ -170,7 +177,12 @@ public class VCloudRestClientModule extends AbstractModule {
|
|||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
|
||||
@Named(PROPERTY_VCLOUD_VERSION) String version) throws InterruptedException,
|
||||
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
|
||||
|
@ -238,6 +250,7 @@ public class VCloudRestClientModule extends AbstractModule {
|
|||
@VDC
|
||||
@Singleton
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -245,18 +258,19 @@ public class VCloudRestClientModule extends AbstractModule {
|
|||
@Catalog
|
||||
@Singleton
|
||||
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();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Network
|
||||
@Singleton
|
||||
protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException,
|
||||
protected URI provideDefaultNetwork(VCloudClient client) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
return Iterables
|
||||
.get(
|
||||
client.getDefaultVDC().get(180, TimeUnit.SECONDS).getAvailableNetworks()
|
||||
.values(), 0).getLocation();
|
||||
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.get(networks.values(), 0).getLocation();
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -270,6 +284,7 @@ public class VCloudRestClientModule extends AbstractModule {
|
|||
@TasksList
|
||||
@Singleton
|
||||
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
|
||||
protected URI provideDefaultNetwork(VCloudAsyncClient client) {
|
||||
protected URI provideDefaultNetwork(VCloudClient client) {
|
||||
return URI.create("https://vcloud.safesecureweb.com/network/1990");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue