From 4da03553f10aa825672e5d0a99d05ded6eb59916 Mon Sep 17 00:00:00 2001 From: spasam Date: Mon, 18 Oct 2010 00:43:13 -0400 Subject: [PATCH] a.) When listing all public IPs in ecloud, the URL was incorrect. Was using something like ..../publicIps/publicIps. b.) CommonVCloudRestClientModule#provideDefaultNetwork(...) is rather strict. This does not work in all environments. For eg, we have two test environments. Each has different DMZ/Internet networks. This method is always checking against default VDC. It doesn't make sense to configure jclouds client with one environments network and launch in another. So I kind'a made PROPERTY_VCLOUD_DEFAULT_NETWORK optional. It is a bit of a hack. This whole thing is probably mute anyway. They added functionality to figure out the Network type (DMZ vs Internal). We probably should figure out the network based on the fence mode??? c.) Implement SSH key support for ecloud. --- ...ExpressVAppTemplateParamsToXmlPayload.java | 2 +- .../config/CommonVCloudRestClientModule.java | 9 +- .../terremark/TerremarkECloudAsyncClient.java | 87 ++++++++++++ .../terremark/TerremarkECloudMediaType.java | 9 ++ .../TerremarkECloudPropertiesBuilder.java | 4 +- .../terremark/TerremarkVCloudAsyncClient.java | 4 +- .../terremark/TerremarkVCloudClient.java | 22 +++ .../TerremarkVCloudExpressClient.java | 25 ---- ...antiateVAppTemplateParamsToXmlPayload.java | 3 +- .../config/TerremarkRestClientModule.java | 57 +++++++- ...erremarkVCloudExpressRestClientModule.java | 63 --------- .../terremark/xml/TerremarkOrgHandler.java | 9 +- .../TerremarkECloudAsyncClientTest.java | 127 +++++++++++++++++- 13 files changed, 319 insertions(+), 102 deletions(-) diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java index e8a0f37cfb..4aa7f7d360 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java @@ -97,7 +97,7 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen SortedMap virtualHardwareQuantity = Maps.newTreeMap(); InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); - String network = defaultNetwork.toASCIIString(); + String network = (defaultNetwork != null) ? defaultNetwork.toASCIIString() : null; String fenceMode = defaultFenceMode; String networkName = name; if (options != null) { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java index 68fed093c0..cbd7726d10 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java @@ -415,8 +415,13 @@ public class CommonVCloudRestClientModule getInternetService(@EndpointParam URI internetServiceId); + /** + * @see TerremarkVCloudExpressClient#findKeyPairInOrgNamed + */ + @GET + @Path("") + @XMLResponseParser(KeyPairByNameHandler.class) + @Consumes(KEYSLIST_XML) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findKeyPairInOrg( + @Nullable @EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org, String keyName); + + /** + * @see TerremarkVCloudExpressClient#listKeyPairsInOrgNamed + */ + @GET + @Path("") + @Consumes(KEYSLIST_XML) + @XMLResponseParser(KeyPairsHandler.class) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listKeyPairsInOrg( + @Nullable @EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org); + + /** + * @see TerremarkVCloudExpressClient#listKeyPairs + */ + @GET + @Path("") + @Consumes(KEYSLIST_XML) + @XMLResponseParser(KeyPairsHandler.class) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listKeyPairs(@EndpointParam URI keysList); + + /** + * @see TerremarkVCloudExpressClient#generateKeyPairInOrg + */ + @POST + @Path("") + @Produces(KEYSLIST_XML) + @Consumes(KEYSLIST_XML) + @XMLResponseParser(KeyPairHandler.class) + @MapBinder(BindCreateKeyToXmlPayload.class) + ListenableFuture generateKeyPairInOrg( + @EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org, @MapPayloadParam("name") String name, + @MapPayloadParam("isDefault") boolean makeDefault); + + /** + * @see TerremarkVCloudExpressClient#getKeyPair + */ + @GET + @Path("") + @XMLResponseParser(KeyPairHandler.class) + @Consumes(APPLICATION_XML) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getKeyPair(@EndpointParam URI keyId); + + // TODO + // /** + // * @see TerremarkVCloudClient#configureKeyPair + // */ + // @PUT + // @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + // @Path("/extensions/key/{keyId}") + // @Produces(APPLICATION_XML) + // @Consumes(APPLICATION_XML) + // @XMLResponseParser(KeyPairHandler.class) + // ListenableFuture configureKeyPair( + // @PathParam("keyId") int keyId, + // @BinderParam(BindKeyPairConfigurationToXmlPayload.class) + // KeyPairConfiguration keyConfiguration); + + /** + * @see TerremarkVCloudExpressClient#deleteKeyPair + */ + @DELETE + @Path("") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture deleteKeyPair(@EndpointParam URI keyId); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudMediaType.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudMediaType.java index 6649e9e432..c357f47712 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudMediaType.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudMediaType.java @@ -58,4 +58,13 @@ public interface TerremarkECloudMediaType extends TerremarkVCloudMediaType { public final static MediaType INTERNETSERVICESLIST_XML_TYPE = new MediaType("application", "vnd.tmrk.ecloud.internetServicesList+xml"); + /** + * "application/vnd.tmrk.ecloud.keysList+xml" + */ + public final static String KEYSLIST_XML = "application/vnd.tmrk.ecloud.keysList+xml"; + + /** + * "application/vnd.tmrk.ecloud.keysList+xml" + */ + public final static MediaType KEYSLIST_XML_TYPE = new MediaType("application", "vnd.tmrk.ecloud.keysList+xml"); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudPropertiesBuilder.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudPropertiesBuilder.java index 421a142c5d..9bec07eb52 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudPropertiesBuilder.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudPropertiesBuilder.java @@ -35,10 +35,10 @@ public class TerremarkECloudPropertiesBuilder extends TerremarkVCloudPropertiesB @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "0.8b-ext2.3"); + properties.setProperty(PROPERTY_API_VERSION, "0.8b-ext2.5"); properties.setProperty(PROPERTY_ENDPOINT, "https://services.enterprisecloud.terremark.com/api"); properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "eCloudExtensions"); - properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.3"); + properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.5"); return properties; } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java index 33bf5bfe38..d3a72b0004 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java @@ -258,7 +258,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient { * @see TerremarkVCloudExpressClient#getPublicIpsAssociatedWithVDC */ @GET - @Path("/publicIps") + @Path("") @Consumes(PUBLICIPSLIST_XML) @XMLResponseParser(PublicIpAddressesHandler.class) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @@ -358,4 +358,4 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient { @Consumes(CATALOGITEMCUSTOMIZATIONPARAMETERS_XML) ListenableFuture getCustomizationOptions(@EndpointParam URI customization); -} \ No newline at end of file +} diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java index 7607018f06..bb6d3d5955 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java @@ -31,6 +31,7 @@ import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.KeyPair; import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; @@ -142,4 +143,25 @@ public interface TerremarkVCloudClient extends VCloudExpressClient { */ Task configureVApp(VCloudExpressVApp vApp, VAppConfiguration configuration); + /** + */ + Set listKeyPairsInOrg(URI org); + + /** + * @throws IllegalStateException + * if a key of the same name already exists + */ + KeyPair generateKeyPairInOrg(URI org, String name, boolean makeDefault); + + /** + */ + KeyPair findKeyPairInOrg(URI org, String keyPairName); + + KeyPair getKeyPair(URI keyPair); + + // TODO + // KeyPair configureKeyPair(int keyPairId, KeyPairConfiguration + // keyPairConfiguration); + + void deleteKeyPair(URI keyPair); } \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressClient.java index 2fcf524bb7..62dff8b1cc 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressClient.java @@ -20,12 +20,10 @@ package org.jclouds.vcloud.terremark; import java.net.URI; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.terremark.domain.InternetService; -import org.jclouds.vcloud.terremark.domain.KeyPair; import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; @@ -40,29 +38,6 @@ import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) public interface TerremarkVCloudExpressClient extends TerremarkVCloudClient { - /** - - */ - Set listKeyPairsInOrg(URI org); - - /** - * @throws IllegalStateException - * if a key of the same name already exists - */ - KeyPair generateKeyPairInOrg(URI org, String name, boolean makeDefault); - - /** - */ - KeyPair findKeyPairInOrg(URI org, String keyPairName); - - KeyPair getKeyPair(URI keyPair); - - // TODO - // KeyPair configureKeyPair(int keyPairId, KeyPairConfiguration - // keyPairConfiguration); - - void deleteKeyPair(URI keyPair); - InternetService addInternetServiceToVDC(URI vDCId, String serviceName, Protocol protocol, int port, AddInternetServiceOptions... options); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java index e17459ae20..f5f316ae06 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java @@ -41,6 +41,7 @@ import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; +import com.google.inject.internal.Nullable; import com.jamesmurty.utils.XMLBuilder; /** @@ -55,7 +56,7 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends @Inject public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, - @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network, + @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Nullable @Network URI network, @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) { super(stringBinder, apiVersion, ns, schema, network, fenceMode); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkRestClientModule.java index 1016e7b63c..141e6bf41d 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkRestClientModule.java @@ -19,8 +19,12 @@ package org.jclouds.vcloud.terremark.config; -import java.io.IOException; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import java.io.IOException; +import java.util.Map; + +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -28,12 +32,19 @@ import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; +import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.util.Utils; import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; +import org.jclouds.vcloud.terremark.endpoints.KeysList; import org.jclouds.vcloud.terremark.handlers.ParseTerremarkVCloudErrorFromHttpResponse; +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.Maps; import com.google.inject.Provides; public abstract class TerremarkRestClientModule @@ -69,4 +80,48 @@ public abstract class TerremarkRestClientModule> { + protected final Supplier sessionSupplier; + private final TerremarkVCloudClient client; + + @Inject + protected OrgNameToKeysListSupplier(Supplier sessionSupplier, TerremarkVCloudClient client) { + this.sessionSupplier = sessionSupplier; + this.client = client; + } + + @Override + public Map get() { + return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function() { + + @Override + public ReferenceType apply(ReferenceType from) { + return client.findOrgNamed(from.getName()).getKeysList(); + } + + }); + } + } + + @Provides + @Singleton + @KeysList + protected Supplier> provideOrgToKeysListCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgNameToKeysListSupplier supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, + seconds, new Supplier>() { + @Override + public Map get() { + return supplier.get(); + } + }); + } + + @Singleton + @Provides + @Named("CreateKey") + String provideCreateKey() throws IOException { + return Utils.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateKey.xml")); + } } \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java index 3233f8c22f..450c9381f6 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java @@ -19,32 +19,17 @@ package org.jclouds.vcloud.terremark.config; -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; - -import java.io.IOException; -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; -import org.jclouds.util.Utils; import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.VCloudExpressClient; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient; -import org.jclouds.vcloud.terremark.endpoints.KeysList; -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.collect.Maps; import com.google.inject.Provides; /** @@ -84,52 +69,4 @@ public class TerremarkVCloudExpressRestClientModule extends protected TerremarkVCloudClient provideTerremarkClient(TerremarkVCloudExpressClient in) { return in; } - - @Singleton - public static class OrgNameToKeysListSupplier implements Supplier> { - protected final Supplier sessionSupplier; - private final TerremarkVCloudExpressClient client; - - @Inject - protected OrgNameToKeysListSupplier(Supplier sessionSupplier, TerremarkVCloudExpressClient client) { - this.sessionSupplier = sessionSupplier; - this.client = client; - } - - @Override - public Map get() { - return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function() { - - @Override - public ReferenceType apply(ReferenceType from) { - return client.findOrgNamed(from.getName()).getKeysList(); - } - - }); - } - - } - - @Provides - @Singleton - @KeysList - protected Supplier> provideOrgToKeysListCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgNameToKeysListSupplier supplier) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, - seconds, new Supplier>() { - @Override - public Map get() { - return supplier.get(); - } - - }); - } - - @Singleton - @Provides - @Named("CreateKey") - String provideCreateKey() throws IOException { - return Utils.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateKey.xml")); - } - } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkOrgHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkOrgHandler.java index 4c95f23c93..2143e74785 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkOrgHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkOrgHandler.java @@ -19,7 +19,6 @@ package org.jclouds.vcloud.terremark.xml; -import static org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType.KEYSLIST_XML; import static org.jclouds.vcloud.util.Utils.cleanseAttributes; import static org.jclouds.vcloud.util.Utils.newReferenceType; @@ -28,6 +27,8 @@ import java.util.Map; import javax.inject.Inject; import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.terremark.TerremarkECloudMediaType; +import org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType; import org.jclouds.vcloud.terremark.domain.TerremarkOrg; import org.jclouds.vcloud.terremark.domain.internal.TerremarkOrgImpl; import org.jclouds.vcloud.xml.OrgHandler; @@ -57,8 +58,10 @@ public class TerremarkOrgHandler extends OrgHandler { super.startElement(uri, localName, qName, attrs); if (qName.equals("Link")) { if (attributes.containsKey("type")) { - if (attributes.get("type").equals(KEYSLIST_XML)) { - keysList = newReferenceType(attributes); + String type = attributes.get("type"); + if (type.equals(TerremarkVCloudExpressMediaType.KEYSLIST_XML) + || type.equals(TerremarkECloudMediaType.KEYSLIST_XML)) { + keysList = newReferenceType(attributes); } } } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java index c73e905eb3..167f28a44e 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java @@ -27,15 +27,19 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; +import java.util.Map; import java.util.Properties; +import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Singleton; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; @@ -50,20 +54,23 @@ import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExt import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.VCloudSession; +import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; -import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestOrgNameToKeysListSupplier; -import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestTerremarkOrgMapSupplier; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestTerremarkOrgVDCSupplier; import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule; import org.jclouds.vcloud.terremark.domain.Protocol; +import org.jclouds.vcloud.terremark.domain.internal.TerremarkOrgImpl; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.xml.CustomizationParametersHandler; import org.jclouds.vcloud.terremark.xml.InternetServiceHandler; import org.jclouds.vcloud.terremark.xml.InternetServicesHandler; +import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler; +import org.jclouds.vcloud.terremark.xml.KeyPairHandler; +import org.jclouds.vcloud.terremark.xml.KeyPairsHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler; import org.jclouds.vcloud.terremark.xml.NodesHandler; import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler; @@ -72,7 +79,10 @@ import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.VCloudExpressVAppHandler; import org.testng.annotations.Test; +import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.TypeLiteral; @@ -298,6 +308,22 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest sessionSupplier) { + super(sessionSupplier, null); + } + + @Override + public Map get() { + return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function() { + + @Override + public ReferenceType apply(ReferenceType from) { + return new ReferenceTypeImpl(from.getName(), TerremarkECloudMediaType.KEYSLIST_XML, URI + .create(from.getHref().toASCIIString() + "/keysList")); + } + }); + } + } + + @Singleton + public static class TestTerremarkOrgMapSupplier extends OrgMapSupplier { + @Inject + protected TestTerremarkOrgMapSupplier() { + super(null, null); + } + + @Override + public Map get() { + return ImmutableMap. of("org", new TerremarkOrgImpl("org", null, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), null, ImmutableMap + . of("catalog", new ReferenceTypeImpl("catalog", + TerremarkECloudMediaType.CATALOG_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap + . of("vdc", new ReferenceTypeImpl("vdc", + TerremarkECloudMediaType.VDC_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap + . of(), new ReferenceTypeImpl("tasksList", + TerremarkECloudMediaType.TASKSLIST_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), new ReferenceTypeImpl( + "keysList", TerremarkECloudMediaType.KEYSLIST_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/keysList/1")))); + } + } + @Override protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable orgs) { return URI.create("https://org");