Issue 386: fixed find method in vcloud

This commit is contained in:
Adrian Cole 2010-10-31 11:37:44 -07:00
parent a45532f05c
commit ad61d6e071
7 changed files with 259 additions and 210 deletions

View File

@ -95,8 +95,7 @@ import com.google.inject.name.Names;
import domain.VCloudVersionsAsyncClient; import domain.VCloudVersionsAsyncClient;
/** /**
* Configures the VCloud authentication service connection, including logging * Configures the VCloud authentication service connection, including logging and http transport.
* and http transport.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -166,9 +165,19 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Provides @Provides
@org.jclouds.vcloud.endpoints.VDC @org.jclouds.vcloud.endpoints.VDC
@Singleton @Singleton
protected URI provideDefaultVDC(Org org) { protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName()); checkState(org.getVDCs().size() > 0, "No vdcs present in org %s", org.getName());
return get(org.getVDCs().values(), 0).getHref(); return checkNotNull(org.getVDCs().get(defaultVDC), "vdc %s not present in org %s", defaultVDC, org.getName())
.getHref();
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected String provideDefaultVDCName(@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
Map<String, String> vDCtoOrg = vDCtoOrgSupplier.get();
checkState(vDCtoOrg.keySet().size() > 0, "No vdcs present!");
return get(vDCtoOrg.keySet(), 0);
} }
@Provides @Provides
@ -357,7 +366,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Singleton @Singleton
@org.jclouds.vcloud.endpoints.VCloudLogin @org.jclouds.vcloud.endpoints.VCloudLogin
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, TimeoutException { @Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException,
TimeoutException {
SortedMap<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS); SortedMap<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS);
checkState(versions.size() > 0, "No versions present"); checkState(versions.size() > 0, "No versions present");
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions); checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
@ -415,12 +425,17 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
checkState(network != null, String.format("network named %s not in %s", networkName, networks.keySet())); checkState(network != null, String.format("network named %s not in %s", networkName, networks.keySet()));
return network.getHref(); return network.getHref();
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
// TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not work well. // TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not
// Each VDC will have differnt network subnets. So we cannot assume the default VDC's networks will // work well.
// work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK optional. If this property // Each VDC will have differnt network subnets. So we cannot assume the default VDC's
// is not set, they are expected to add NetworkConfig to the options when launching a server. // networks will
// work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK optional. If
// this property
// is not set, they are expected to add NetworkConfig to the options when launching a
// server.
return null; return null;
//throw new IllegalStateException(String.format("you must specify the property %s as one of %s", // throw new
// IllegalStateException(String.format("you must specify the property %s as one of %s",
// PROPERTY_VCLOUD_DEFAULT_NETWORK, networks.keySet()), e); // PROPERTY_VCLOUD_DEFAULT_NETWORK, networks.keySet()), e);
} }
} catch (AuthorizationException e) { } catch (AuthorizationException e) {
@ -469,7 +484,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache( protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) { @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>( return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
authException, seconds, new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() { authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
@Override @Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() { public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return supplier.get(); return supplier.get();
@ -535,7 +551,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() { new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
@Override @Override
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) { public Map<String, ? extends CatalogItem> apply(
org.jclouds.vcloud.domain.Catalog from) {
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name); return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
} }
}); });

View File

@ -852,10 +852,15 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
} }
@Override @Override
protected URI provideDefaultVDC(Org org) { protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"); return URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1");
} }
@Override
protected String provideDefaultVDCName(@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override @Override
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) { protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"); return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990");

View File

@ -120,11 +120,9 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
String.class, InstantiateVAppTemplateOptions[].class); String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", processorCount(1)
processorCount(1).memory(512).disk(1024) .memory(512).disk(1024).addNetworkConfig(
.addNetworkConfig( new NetworkConfig(null, URI.create("https://vcloud.safesecureweb.com/network/1990"),
new NetworkConfig(null, URI
.create("https://vcloud.safesecureweb.com/network/1990"),
FenceMode.BRIDGED))); FenceMode.BRIDGED)));
assertRequestLineEquals(request, assertRequestLineEquals(request,
@ -685,10 +683,16 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
} }
@Override @Override
protected URI provideDefaultVDC(Org org) { protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"); return URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1");
} }
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override @Override
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) { protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
return URI.create("https://vcloud.safesecureweb.com/network/1990"); return URI.create("https://vcloud.safesecureweb.com/network/1990");

View File

@ -30,6 +30,7 @@ import org.jclouds.rest.RestContext;
import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.VApp;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -63,6 +64,11 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(node.getType(), ComputeType.NODE); assertEquals(node.getType(), ComputeType.NODE);
NodeMetadata allData = client.getNodeMetadata(node.getId()); NodeMetadata allData = client.getNodeMetadata(node.getId());
System.out.println(allData.getHardware()); System.out.println(allData.getHardware());
RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory().createContext(
provider, identity, credential).getProviderSpecificContext();
VApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName());
assertEquals(vApp.getName(), allData.getName());
} }
} }
} }

View File

@ -43,7 +43,9 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.compute.util.ComputeUtils; import org.jclouds.compute.util.ComputeUtils;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -69,14 +71,17 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy, @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider, Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning, @Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated, ComputeUtils utils, Timeouts timeouts, @Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated,
@Named("NODE_SUSPENDED") Predicate<NodeMetadata> nodeSuspended, ComputeUtils utils, Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys,
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap, NodeMetadataToOrgAndName nodeToOrgAndName) { ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap, NodeMetadataToOrgAndName nodeToOrgAndName) {
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy, super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, templateBuilderProvider, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
templateOptionsProvider, nodeRunning, nodeTerminated, utils, timeouts, executor); suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
nodeSuspended, utils, timeouts, executor);
this.cleanupOrphanKeys = cleanupOrphanKeys; this.cleanupOrphanKeys = cleanupOrphanKeys;
} }

View File

@ -530,8 +530,9 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
@Override @Override
public ReferenceType apply(ReferenceType from) { public ReferenceType apply(ReferenceType from) {
return new ReferenceTypeImpl(from.getName(), TerremarkECloudMediaType.KEYSLIST_XML, URI return new ReferenceTypeImpl(from.getName(), TerremarkECloudMediaType.KEYSLIST_XML, URI.create(from
.create(from.getHref().toASCIIString() + "/keysList")); .getHref().toASCIIString()
+ "/keysList"));
} }
}); });
} }
@ -551,9 +552,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
.<String, ReferenceType> of("catalog", new ReferenceTypeImpl("catalog", .<String, ReferenceType> of("catalog", new ReferenceTypeImpl("catalog",
TerremarkECloudMediaType.CATALOG_XML, URI TerremarkECloudMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", .<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", TerremarkECloudMediaType.VDC_XML,
TerremarkECloudMediaType.VDC_XML, URI URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, ReferenceType> of(), new ReferenceTypeImpl("tasksList", .<String, ReferenceType> of(), new ReferenceTypeImpl("tasksList",
TerremarkECloudMediaType.TASKSLIST_XML, URI TerremarkECloudMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), new ReferenceTypeImpl( .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), new ReferenceTypeImpl(
@ -593,10 +593,16 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
} }
@Override @Override
protected URI provideDefaultVDC(Org org) { protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vdc/1"); return URI.create("https://vdc/1");
} }
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override @Override
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) { protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
return URI.create("https://vcloud.safesecureweb.com/network/1990"); return URI.create("https://vcloud.safesecureweb.com/network/1990");

View File

@ -729,10 +729,16 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
} }
@Override @Override
protected URI provideDefaultVDC(Org org) { protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vdc/1"); return URI.create("https://vdc/1");
} }
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override @Override
protected String provideCatalogName(Supplier<Map<String, Map<String, ? extends Catalog>>> catalogs) { protected String provideCatalogName(Supplier<Map<String, Map<String, ? extends Catalog>>> catalogs) {
return "catalog"; return "catalog";