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;
/**
* Configures the VCloud authentication service connection, including logging
* and http transport.
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/
@ -166,9 +165,19 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected URI provideDefaultVDC(Org org) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName());
return get(org.getVDCs().values(), 0).getHref();
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org %s", org.getName());
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
@ -357,7 +366,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Singleton
@org.jclouds.vcloud.endpoints.VCloudLogin
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);
checkState(versions.size() > 0, "No versions present");
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()));
return network.getHref();
} catch (ConfigurationException e) {
// TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not work well.
// Each VDC will have differnt network subnets. So we cannot assume the default VDC's 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.
// TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not
// work well.
// Each VDC will have differnt network subnets. So we cannot assume the default VDC's
// 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;
//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);
}
} 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(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
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
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> 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>>() {
@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);
}
});

View File

@ -852,10 +852,15 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
@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");
}
@Override
protected String provideDefaultVDCName(@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
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);
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/vAppTemplate/3"), "my-vapp",
processorCount(1).memory(512).disk(1024)
.addNetworkConfig(
new NetworkConfig(null, URI
.create("https://vcloud.safesecureweb.com/network/1990"),
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", processorCount(1)
.memory(512).disk(1024).addNetworkConfig(
new NetworkConfig(null, URI.create("https://vcloud.safesecureweb.com/network/1990"),
FenceMode.BRIDGED)));
assertRequestLineEquals(request,
@ -685,10 +683,16 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
}
@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");
}
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
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.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.VApp;
import org.testng.annotations.Test;
/**
@ -63,6 +64,11 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(node.getType(), ComputeType.NODE);
NodeMetadata allData = client.getNodeMetadata(node.getId());
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.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.compute.util.ComputeUtils;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
@ -69,14 +71,17 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
@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,
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap, NodeMetadataToOrgAndName nodeToOrgAndName) {
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, templateBuilderProvider,
templateOptionsProvider, nodeRunning, nodeTerminated, utils, timeouts, executor);
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
nodeSuspended, utils, timeouts, executor);
this.cleanupOrphanKeys = cleanupOrphanKeys;
}

View File

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

View File

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