From ee1e4ca59c6b24ce880b2371f8cd89ace404316d Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Sun, 20 Dec 2009 09:10:40 +0000 Subject: [PATCH] Issue 112: Added catalog and template queries. clarified api syntax git-svn-id: http://jclouds.googlecode.com/svn/trunk@2478 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../org/jclouds/vcloud/VCloudAsyncClient.java | 25 +- .../java/org/jclouds/vcloud/VCloudClient.java | 8 +- .../org/jclouds/vcloud/VCloudMediaType.java | 10 + .../vcloud/VCloudPropertiesBuilder.java | 8 +- ...antiateVAppTemplateParamsToXmlPayload.java | 229 +++++++++++++++--- .../vcloud/config/VCloudRestClientModule.java | 14 +- .../jclouds/vcloud/domain/CatalogItem.java | 44 ++++ .../jclouds/vcloud/domain/VAppTemplate.java} | 17 +- .../domain/internal/CatalogItemImpl.java | 122 ++++++++++ .../domain/internal/VAppTemplateImpl.java | 98 ++++++++ .../InstantiateVAppTemplateOptions.java | 78 +++++- .../vcloud/reference/VCloudConstants.java | 18 +- .../jclouds/vcloud/xml/CatalogHandler.java | 24 +- .../vcloud/xml/CatalogItemHandler.java | 86 +++++++ .../vcloud/xml/VAppTemplateHandler.java | 75 ++++++ .../InstantiateVAppTemplateParams.xml | 17 -- .../jclouds/vcloud/VCloudAsyncClientTest.java | 95 +++++++- .../jclouds/vcloud/VCloudClientLiveTest.java | 35 ++- .../jclouds/vcloud/VCloudComputeClient.java | 4 +- ...ateVAppTemplateParamsToXmlPayloadTest.java | 157 +++++------- .../config/VCloudRestClientModuleTest.java | 12 - .../InstantiateVAppTemplateOptionsTest.java | 44 +++- .../vcloud/xml/CatalogHandlerTest.java | 166 ++----------- .../vcloud/xml/CatalogItemHandlerTest.java | 204 ++++++++++++++++ .../vcloud/xml/VAppTemplateHandlerTest.java | 75 ++++++ vcloud/core/src/test/resources/catalog.xml | 2 +- .../src/test/resources/newvapp-hosting.xml | 18 +- .../HostingDotComVCloudAsyncClient.java | 6 +- .../HostingDotComVCloudClient.java | 2 +- .../HostingDotComVCloudComputeClient.java | 17 +- .../HostingDotComVCloudComputeService.java | 3 +- ...tingDotComVCloudComputeClientLiveTest.java | 10 +- vcloud/pom.xml | 5 + .../terremark/TerremarkVCloudAsyncClient.java | 58 +++-- .../terremark/TerremarkVCloudClient.java | 31 +-- .../TerremarkVCloudPropertiesBuilder.java | 27 +-- ...antiateVAppTemplateParamsToXmlPayload.java | 75 +++--- .../compute/TerremarkVCloudComputeClient.java | 27 ++- .../TerremarkVCloudComputeService.java | 16 +- .../TerremarkVCloudRestClientModule.java | 12 +- ...ComputeOption.java => ComputeOptions.java} | 25 +- .../domain/CustomizationParameters.java | 4 +- ...rremarkInstantiateVAppTemplateOptions.java | 71 ++++-- .../terremark/xml/ComputeOptionHandler.java | 8 +- .../terremark/xml/ComputeOptionsHandler.java | 8 +- .../InstantiateVAppTemplateParams.xml | 38 --- .../terremark/InternetServiceLiveTest.java | 17 +- .../TerremarkVCloudAsyncClientTest.java | 141 ++++++----- .../TerremarkVCloudClientLiveTest.java | 80 ++++-- ...ateVAppTemplateParamsToXmlPayloadTest.java | 144 ++++------- .../TerremarkVCloudComputeClientLiveTest.java | 17 +- .../TerremarkVCloudRestClientModuleTest.java | 4 - ...arkInstantiateVAppTemplateOptionsTest.java | 44 ++-- .../xml/ComputeOptionHandlerTest.java | 6 +- .../xml/ComputeOptionsHandlerTest.java | 8 +- ...antiateVAppTemplateParams-options-test.xml | 39 +-- .../InstantiateVAppTemplateParams-test-2.xml | 38 --- .../InstantiateVAppTemplateParams-test.xml | 39 +-- 58 files changed, 1739 insertions(+), 966 deletions(-) create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/domain/CatalogItem.java rename vcloud/{terremark/src/main/java/org/jclouds/vcloud/terremark/reference/TerremarkVCloudConstants.java => core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java} (65%) create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogItemImpl.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogItemHandler.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java delete mode 100644 vcloud/core/src/main/resources/InstantiateVAppTemplateParams.xml create mode 100644 vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogItemHandlerTest.java create mode 100644 vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java rename vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/{ComputeOption.java => ComputeOptions.java} (81%) delete mode 100644 vcloud/terremark/src/main/resources/terremark/InstantiateVAppTemplateParams.xml delete mode 100644 vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-test-2.xml diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index cae55d3d9e..ddb0223ebf 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -23,9 +23,11 @@ */ package org.jclouds.vcloud; +import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; +import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; @@ -47,20 +49,24 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.functions.VAppTemplateIdToUri; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.xml.CatalogHandler; +import org.jclouds.vcloud.xml.CatalogItemHandler; import org.jclouds.vcloud.xml.OrgHandler; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.VAppHandler; +import org.jclouds.vcloud.xml.VAppTemplateHandler; import org.jclouds.vcloud.xml.VDCHandler; /** @@ -85,6 +91,20 @@ public interface VCloudAsyncClient { @XMLResponseParser(CatalogHandler.class) Future getCatalog(); + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/vAppTemplate/{vAppTemplateId}") + @Consumes(VAPPTEMPLATE_XML) + @XMLResponseParser(VAppTemplateHandler.class) + Future getVAppTemplate(@PathParam("vAppTemplateId") String vAppTemplateId); + + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/catalogItem/{catalogItemId}") + @Consumes(CATALOGITEM_XML) + @XMLResponseParser(CatalogItemHandler.class) + Future getCatalogItem(@PathParam("catalogItemId") String catalogItemId); + @GET @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vdc/{vDCId}") @@ -204,7 +224,8 @@ public interface VCloudAsyncClient { @Consumes(VAPP_XML) @XMLResponseParser(VAppHandler.class) @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) - Future instantiateVAppTemplate(@MapPayloadParam("name") String appName, + Future instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId, + @MapPayloadParam("name") String appName, @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, - @PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options); + InstantiateVAppTemplateOptions... options); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java index 3c10c6a817..136479b519 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -27,10 +27,12 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -51,6 +53,10 @@ public interface VCloudClient { Catalog getCatalog(); + CatalogItem getCatalogItem(String catalogItemId); + + VAppTemplate getVAppTemplate(String vAppTemplateId); + VDC getVDC(String vDCId); VDC getDefaultVDC(); @@ -96,6 +102,6 @@ public interface VCloudClient { VApp getVApp(String appId); - VApp instantiateVAppTemplate(String appName, String templateId, String vDCId, + VApp instantiateVAppTemplateInVDC(String vDCId, String appName, String templateId, InstantiateVAppTemplateOptions... options); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java index 92340285f0..22cac0208d 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java @@ -120,5 +120,15 @@ public class VCloudMediaType { */ public final static MediaType VAPP_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vApp+xml"); + + /** + * "application/vnd.vmware.vcloud.vAppTemplate+xml" + */ + public final static String VAPPTEMPLATE_XML = "application/vnd.vmware.vcloud.vAppTemplate+xml"; + /** + * "application/vnd.vmware.vcloud.vAppTemplate+xml" + */ + public final static MediaType VAPPTEMPLATE_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.vAppTemplate+xml"); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java index aab7acdf6c..4300e5c9a8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java @@ -24,13 +24,13 @@ package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY; 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_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; import java.net.URI; import java.util.Properties; @@ -48,8 +48,8 @@ public class VCloudPropertiesBuilder extends HttpPropertiesBuilder { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8"); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 9 * 60 + ""); - properties.setProperty(PROPERTY_VCLOUD_DEFAULTCPUCOUNT, "1"); - properties.setProperty(PROPERTY_VCLOUD_DEFAULTMEMORY, "512"); + properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/0.8"); + properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); return properties; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java index e3e7cd244a..bc5ac9e2b7 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java @@ -26,25 +26,35 @@ package org.jclouds.vcloud.binders; import static com.google.common.base.Preconditions.checkArgument; 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_DEFAULTCPUCOUNT; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DISK; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; -import java.util.HashMap; import java.util.Map; +import java.util.Properties; +import java.util.SortedMap; import java.util.Map.Entry; -import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import javax.xml.parsers.FactoryConfigurationError; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; import org.jclouds.http.HttpRequest; import org.jclouds.rest.MapBinder; import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; +import com.google.inject.Inject; +import com.jamesmurty.utils.XMLBuilder; /** * @@ -54,23 +64,50 @@ import com.google.common.collect.Maps; @Singleton public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder { - private final String xmlTemplate; + protected final String ns; + protected final String schema; private final BindToStringPayload stringBinder; - protected final Map defaultParams; + protected final Map defaultVirtualHardwareQuantity; + protected final Map virtualHardwareToInstanceId = ImmutableMap.of( + ResourceType.PROCESSOR, "1", ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9"); + + private final String defaultNetwork; + + /** + * To allow for optional injection, since guice doesn't allow unresolved constants in + * constructors + */ + protected static class OptionalConstantsHolder { + @Inject(optional = true) + @Named(PROPERTY_VCLOUD_DEFAULT_CPUCOUNT) + String cpuCount; + @Inject(optional = true) + @Named(PROPERTY_VCLOUD_DEFAULT_MEMORY) + String memorySizeMegabytes; + @Inject(optional = true) + @Named(PROPERTY_VCLOUD_DEFAULT_DISK) + String diskSizeKilobytes; + } @Inject - public BindInstantiateVAppTemplateParamsToXmlPayload( - @Named("InstantiateVAppTemplateParams") String xmlTemplate, - BindToStringPayload stringBinder, - @Named(PROPERTY_VCLOUD_DEFAULTNETWORK) String defaultNetwork, - @Named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT) String defaultCpuCount, - @Named(PROPERTY_VCLOUD_DEFAULTMEMORY) String defaultMemory) { - this.xmlTemplate = xmlTemplate; + public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, + @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, + @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, + @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network, + OptionalConstantsHolder defaultsHolder) { + this.ns = ns; + this.schema = schema; this.stringBinder = stringBinder; - this.defaultParams = Maps.newHashMap(); - this.defaultParams.put("network", defaultNetwork); - this.defaultParams.put("count", defaultCpuCount); - this.defaultParams.put("megabytes", defaultMemory); + this.defaultVirtualHardwareQuantity = Maps.newHashMap(); + this.defaultNetwork = network; + if (defaultsHolder.cpuCount != null) + this.defaultVirtualHardwareQuantity.put(ResourceType.PROCESSOR, defaultsHolder.cpuCount); + if (defaultsHolder.memorySizeMegabytes != null) + this.defaultVirtualHardwareQuantity.put(ResourceType.MEMORY, + defaultsHolder.memorySizeMegabytes); + if (defaultsHolder.diskSizeKilobytes != null) + this.defaultVirtualHardwareQuantity.put(ResourceType.DISK_DRIVE, + defaultsHolder.diskSizeKilobytes); } @SuppressWarnings("unchecked") @@ -79,39 +116,153 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder "this binder is only valid for GeneratedHttpRequests!"); GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; checkState(gRequest.getArgs() != null, "args should be initialized at this point"); - postParams = new HashMap(postParams); - postParams.putAll(defaultParams); - addOptionsToMap(postParams, gRequest); + String name = checkNotNull(postParams.remove("name"), "name"); + String template = checkNotNull(postParams.remove("template"), "template"); + String network = postParams.remove("network"); - String payload = xmlTemplate; - for (Entry entry : postParams.entrySet()) { - payload = payload.replaceAll("\\{" + entry.getKey() + "\\}", entry.getValue()); + SortedMap virtualHardwareQuantity = extractVirtualQuantityFromPostParams(postParams); + + InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); + Map properties = Maps.newTreeMap(); + if (options != null) { + String networkFromOptions = addQuantityOrReturnNetwork(options, virtualHardwareQuantity, + network); + network = networkFromOptions != null ? networkFromOptions : network; + properties.putAll(options.getProperties()); } - stringBinder.bindToRequest(request, payload); + network = network == null ? defaultNetwork : network; + try { + stringBinder.bindToRequest(request, generateXml(name, template, properties, + virtualHardwareQuantity, network)); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } catch (FactoryConfigurationError e) { + throw new RuntimeException(e); + } catch (TransformerException e) { + throw new RuntimeException(e); + } + } - protected void addOptionsToMap(Map postParams, GeneratedHttpRequest gRequest) { - for (Object arg : gRequest.getArgs()) { - if (arg instanceof InstantiateVAppTemplateOptions) { - InstantiateVAppTemplateOptions options = (InstantiateVAppTemplateOptions) arg; - if (options.getCpuCount() != null) { - postParams.put("count", options.getCpuCount()); - } - if (options.getMegabytes() != null) { - postParams.put("megabytes", options.getMegabytes()); - } - if (options.getNetwork() != null) { - postParams.put("network", options.getNetwork()); - } + protected SortedMap extractVirtualQuantityFromPostParams( + Map postParams) { + SortedMap virtualHardwareQuantity = Maps.newTreeMap(); + virtualHardwareQuantity.putAll(defaultVirtualHardwareQuantity); + for (Entry entry : postParams.entrySet()) { + virtualHardwareQuantity.put(ResourceType.fromValue(entry.getKey()), entry.getValue()); + } + return virtualHardwareQuantity; + } + + protected String generateXml(String name, String template, Map properties, + SortedMap virtualHardwareQuantity, String network) + throws ParserConfigurationException, FactoryConfigurationError, TransformerException { + XMLBuilder rootBuilder = buildRoot(name); + + rootBuilder.e("VAppTemplate").a("href", template); + + XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams"); + addPropertiesifPresent(instantiationParamsBuilder, properties); + addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity); + addNetworkConfig(instantiationParamsBuilder, name, network); + Properties outputProperties = new Properties(); + outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); + return rootBuilder.asString(outputProperties); + } + + protected void addPropertiesifPresent(XMLBuilder instantiationParamsBuilder, + Map properties) { + if (properties.size() > 0) { + XMLBuilder productSectionBuilder = instantiationParamsBuilder.e("ProductSection").a( + "xmlns:q1", "http://www.vmware.com/vcloud/v1").a("xmlns:ovf", + "http://schemas.dmtf.org/ovf/envelope/1"); + for (Entry entry : properties.entrySet()) { + productSectionBuilder.e("Property") + .a("xmlns", "http://schemas.dmtf.org/ovf/envelope/1").a("ovf:key", + entry.getKey()).a("ovf:value", entry.getValue()); } } } + protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, + String network) { + XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e( + "NetworkConfig").a("name", name); + XMLBuilder featuresBuilder = networkConfigBuilder.e("Features"); + featuresBuilder.e("FenceMode").t("allowInOut"); + featuresBuilder.e("Dhcp").t("false"); + networkConfigBuilder.e("NetworkAssociation").a("href", network); + } + + protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder, + SortedMap virtualHardwareQuantity) { + if (virtualHardwareQuantity.size() > 0) { + XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder.e( + "VirtualHardwareSection").a("xmlns:q1", "http://www.vmware.com/vcloud/v1"); + for (Entry entry : virtualHardwareQuantity.entrySet()) { + XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a("xmlns", + "http://schemas.dmtf.org/ovf/envelope/1"); + itemBuilder + .e("InstanceID") + .a("xmlns", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData") + .t(virtualHardwareToInstanceId.get(entry.getKey())); + itemBuilder + .e("ResourceType") + .a("xmlns", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData") + .t(entry.getKey().value()); + itemBuilder + .e("VirtualQuantity") + .a("xmlns", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData") + .t(entry.getValue()); + } + } + } + + protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, + FactoryConfigurationError { + XMLBuilder rootBuilder = XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name) + .a("xmlns", ns).a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a( + "xsi:schemaLocation", ns + " " + schema); + return rootBuilder; + } + + protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest gRequest) { + for (Object arg : gRequest.getArgs()) { + if (arg instanceof InstantiateVAppTemplateOptions) { + return (InstantiateVAppTemplateOptions) arg; + } else if (arg instanceof InstantiateVAppTemplateOptions[]) { + InstantiateVAppTemplateOptions[] options = (InstantiateVAppTemplateOptions[]) arg; + return (options.length > 0) ? options[0] : null; + } + } + return null; + } + + private String addQuantityOrReturnNetwork(InstantiateVAppTemplateOptions options, + Map virtualHardwareQuantity, String network) { + if (options.getCpuCount() != null) { + virtualHardwareQuantity.put(ResourceType.PROCESSOR, options.getCpuCount()); + } + if (options.getMemorySizeMegabytes() != null) { + virtualHardwareQuantity.put(ResourceType.MEMORY, options.getMemorySizeMegabytes()); + } + if (options.getDiskSizeKilobytes() != null) { + virtualHardwareQuantity.put(ResourceType.DISK_DRIVE, options.getDiskSizeKilobytes()); + } + if (options.getNetwork() != null) { + return options.getNetwork(); + } + return network; + } + public void bindToRequest(HttpRequest request, Object input) { throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters"); } - String ifNullDefaultTo(String value, String defaultValue) { + protected String ifNullDefaultTo(String value, String defaultValue) { return value != null ? value : checkNotNull(defaultValue, "defaultValue"); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index 78db4b7c4b..7bce52334b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -23,15 +23,13 @@ */ package org.jclouds.vcloud.config; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK; +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; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; -import java.io.IOException; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URI; import java.util.concurrent.ExecutionException; @@ -216,14 +214,6 @@ public class VCloudRestClientModule extends AbstractModule { return org.getCatalog().getLocation(); } - @Singleton - @Provides - @Named("InstantiateVAppTemplateParams") - protected String provideInstantiateVAppTemplateParams() throws IOException { - InputStream is = getClass().getResourceAsStream("/InstantiateVAppTemplateParams.xml"); - return Utils.toStringAndClose(is); - } - @Provides @Network @Singleton @@ -234,7 +224,7 @@ public class VCloudRestClientModule extends AbstractModule { } @Provides - @Named(PROPERTY_VCLOUD_DEFAULTNETWORK) + @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) @Singleton String provideDefaultNetworkString(@Network URI network) { return network.toASCIIString(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/CatalogItem.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/CatalogItem.java new file mode 100644 index 0000000000..3546c54764 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/CatalogItem.java @@ -0,0 +1,44 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.domain; + +import java.util.SortedMap; + +import org.jclouds.vcloud.domain.internal.CatalogImpl; + +import com.google.inject.ImplementedBy; + +/** + * @author Adrian Cole + */ +@ImplementedBy(CatalogImpl.class) +public interface CatalogItem extends NamedResource { + + String getDescription(); + + NamedResource getEntity(); + + SortedMap getProperties(); + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/reference/TerremarkVCloudConstants.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java similarity index 65% rename from vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/reference/TerremarkVCloudConstants.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java index 9bcdfe932f..ef1a46f9f8 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/reference/TerremarkVCloudConstants.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java @@ -21,19 +21,16 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloud.terremark.reference; - -import org.jclouds.vcloud.reference.VCloudConstants; +package org.jclouds.vcloud.domain; /** - * Configuration properties and constants used in Terremark VCloud connections. * * @author Adrian Cole */ -public interface TerremarkVCloudConstants extends VCloudConstants { - - public static final String PROPERTY_TERREMARK_DEFAULTGROUP = "jclouds.terremark.defaults.group"; - public static final String PROPERTY_TERREMARK_DEFAULTROW = "jclouds.terremark.defaults.row"; - public static final String PROPERTY_TERREMARK_DEFAULTPASSWORD = "jclouds.terremark.defaults.password"; +public interface VAppTemplate extends NamedResource { -} + VAppStatus getStatus(); + + String getDescription(); + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogItemImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogItemImpl.java new file mode 100644 index 0000000000..05b9473def --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogItemImpl.java @@ -0,0 +1,122 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.domain.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.SortedMap; + +import javax.annotation.Nullable; + +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.NamedResource; + +import com.google.common.collect.Maps; + +/** + * + * @author Adrian Cole + * + */ +public class CatalogItemImpl extends NamedResourceImpl implements CatalogItem { + + /** The serialVersionUID */ + private static final long serialVersionUID = 8464716396538298809L; + private final String description; + private final NamedResource entity; + private final SortedMap properties = Maps.newTreeMap(); + + public CatalogItemImpl(String id, String name, URI location, @Nullable String description, + NamedResource entity, SortedMap properties) { + super(id, name, VCloudMediaType.CATALOGITEM_XML, location); + this.description = description; + this.entity = checkNotNull(entity, "entity"); + this.properties.putAll(checkNotNull(properties, "properties")); + } + + @Override + public String getType() { + return VCloudMediaType.CATALOGITEM_XML; + } + + public NamedResource getEntity() { + return entity; + } + + @Override + public String getDescription() { + return description; + } + + public SortedMap getProperties() { + return properties; + } + + @Override + public String toString() { + return "CatalogItemImpl [id=" + getId() + ", name=" + getName() + ", location=" + + getLocation() + ", type=" + getType() + ", description=" + getDescription() + + ", entity=" + entity + ", properties=" + properties + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((entity == null) ? 0 : entity.hashCode()); + result = prime * result + ((properties == null) ? 0 : properties.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + CatalogItemImpl other = (CatalogItemImpl) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (entity == null) { + if (other.entity != null) + return false; + } else if (!entity.equals(other.entity)) + return false; + if (properties == null) { + if (other.properties != null) + return false; + } else if (!properties.equals(other.properties)) + return false; + return true; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java new file mode 100644 index 0000000000..52b58819b6 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java @@ -0,0 +1,98 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.domain.internal; + +import java.net.URI; + +import javax.annotation.Nullable; + +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; + +/** + * + * @author Adrian Cole + * + */ +public class VAppTemplateImpl extends NamedResourceImpl implements VAppTemplate { + + /** The serialVersionUID */ + private static final long serialVersionUID = 8464716396538298809L; + private final String description; + private final VAppStatus status; + + public VAppTemplateImpl(String id, String name, URI location, @Nullable String description, + @Nullable VAppStatus status) { + super(id, name, VCloudMediaType.VAPPTEMPLATE_XML, location); + this.description = description; + this.status = status; + } + + @Override + public String getDescription() { + return description; + } + + public VAppStatus getStatus() { + return status; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + VAppTemplateImpl other = (VAppTemplateImpl) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + return true; + } + + @Override + public String toString() { + return "VAppTemplateImpl [description=" + description + ", status=" + status + "]"; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java b/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java index 9c6230a78e..5b485e09ec 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java @@ -27,6 +27,9 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; +import java.util.Map; + +import com.google.common.collect.Maps; /** * @@ -36,18 +39,36 @@ import java.net.URI; public class InstantiateVAppTemplateOptions { private String cpuCount; - private String megabytes; + private String memorySizeMegabytes; + private String diskSizeKilobytes; private String network; + private Map properties = Maps.newTreeMap(); - public InstantiateVAppTemplateOptions cpuCount(int cpuCount) { + public InstantiateVAppTemplateOptions productProperty(String key, String value) { + properties.put(checkNotNull(key, "key"), checkNotNull(value, "value")); + return this; + } + + public InstantiateVAppTemplateOptions productProperties(Map properties) { + this.properties.putAll(checkNotNull(properties, "properties")); + return this; + } + + public InstantiateVAppTemplateOptions processorCount(int cpuCount) { checkArgument(cpuCount >= 1, "cpuCount must be positive"); this.cpuCount = cpuCount + ""; return this; } - public InstantiateVAppTemplateOptions megabytes(int megabytes) { + public InstantiateVAppTemplateOptions memory(long megabytes) { checkArgument(megabytes % 512 == 0, "megabytes must be in an increment of 512"); - this.megabytes = megabytes + ""; + this.memorySizeMegabytes = megabytes + ""; + return this; + } + + public InstantiateVAppTemplateOptions disk(long kilobytes) { + checkArgument(kilobytes >= 1, "diskSizeKilobytes must be positive"); + this.diskSizeKilobytes = kilobytes + ""; return this; } @@ -60,30 +81,46 @@ public class InstantiateVAppTemplateOptions { return cpuCount; } - public String getMegabytes() { - return megabytes; + public String getMemorySizeMegabytes() { + return memorySizeMegabytes; + } + + public String getDiskSizeKilobytes() { + return diskSizeKilobytes; } public String getNetwork() { return network; } + public Map getProperties() { + return properties; + } + public static class Builder { /** - * @see InstantiateVAppTemplateOptions#cpuCount(int) + * @see InstantiateVAppTemplateOptions#processorCount(int) */ - public static InstantiateVAppTemplateOptions cpuCount(int cpuCount) { + public static InstantiateVAppTemplateOptions processorCount(int cpuCount) { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - return options.cpuCount(cpuCount); + return options.processorCount(cpuCount); } /** - * @see InstantiateVAppTemplateOptions#megabytes(int) + * @see InstantiateVAppTemplateOptions#memory(int) */ - public static InstantiateVAppTemplateOptions megabytes(int megabytes) { + public static InstantiateVAppTemplateOptions memory(int megabytes) { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - return options.megabytes(megabytes); + return options.memory(megabytes); + } + + /** + * @see InstantiateVAppTemplateOptions#disk(int) + */ + public static InstantiateVAppTemplateOptions disk(long kilobytes) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.disk(kilobytes); } /** @@ -93,5 +130,22 @@ public class InstantiateVAppTemplateOptions { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); return options.inNetwork(networkLocation); } + + /** + * @see InstantiateVAppTemplateOptions#productProperty(String,String) + */ + public static InstantiateVAppTemplateOptions productProperty(String key, String value) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.productProperty(key, value); + } + + /** + * @see InstantiateVAppTemplateOptions#setProperties(Map) + */ + public static InstantiateVAppTemplateOptions productProperties(Map properties) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.productProperties(properties); + } } + } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java index e711f982b2..06e1ce809c 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java @@ -37,8 +37,20 @@ public interface VCloudConstants { * automatically renew vcloud token before this interval expires. */ public static final String PROPERTY_VCLOUD_SESSIONINTERVAL = "jclouds.vcloud.sessioninterval"; - public static final String PROPERTY_VCLOUD_DEFAULTCPUCOUNT = "jclouds.vcloud.defaults.cpucount"; - public static final String PROPERTY_VCLOUD_DEFAULTMEMORY = "jclouds.vcloud.defaults.memory"; - public static final String PROPERTY_VCLOUD_DEFAULTNETWORK = "jclouds.vcloud.defaults.network"; + /** + * cpus + */ + public static final String PROPERTY_VCLOUD_DEFAULT_CPUCOUNT = "jclouds.vcloud.defaults.cpucount"; + /** + * megabytes + */ + public static final String PROPERTY_VCLOUD_DEFAULT_MEMORY = "jclouds.vcloud.defaults.memorysizemegabytes"; + public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network"; + /** + * kilobytes + */ + public static final String PROPERTY_VCLOUD_DEFAULT_DISK = "jclouds.vcloud.defaults.getdisksizekilobytes"; + public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns"; + public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema"; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java index 941e181ed7..4f22c605d8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java @@ -23,18 +23,12 @@ */ package org.jclouds.vcloud.xml; -import java.net.URI; -import java.util.Map; import java.util.SortedMap; -import javax.inject.Inject; - import org.jclouds.http.functions.ParseSax; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.internal.CatalogImpl; -import org.jclouds.vcloud.domain.internal.NamedResourceImpl; -import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.util.Utils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -49,9 +43,6 @@ public class CatalogHandler extends ParseSax.HandlerWithResult { private NamedResource catalog; private SortedMap contents = Maps.newTreeMap(); - @Inject - @CatalogItemRoot - private String catalogItemRoot; private String description; @@ -66,7 +57,7 @@ public class CatalogHandler extends ParseSax.HandlerWithResult { if (qName.equals("Catalog")) { catalog = Utils.newNamedResource(attributes); } else if (qName.equals("CatalogItem")) { - putNamedResource(contents, attributes); + Utils.putNamedResource(contents, attributes); } } @@ -81,19 +72,6 @@ public class CatalogHandler extends ParseSax.HandlerWithResult { currentText.append(ch, start, length); } - public NamedResource newNamedResource(Attributes attributes) { - String href = attributes.getValue(attributes.getIndex("href")); - String id = href.replace(catalogItemRoot + "/", ""); - assert !id.contains("https://") : String.format( - "parse of %s should have stripped, but didn't %s", href, id); - return new NamedResourceImpl(id, attributes.getValue(attributes.getIndex("name")), attributes - .getValue(attributes.getIndex("type")), URI.create(href)); - } - - public void putNamedResource(Map map, Attributes attributes) { - map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes)); - } - protected String currentOrNull() { String returnVal = currentText.toString().trim(); return returnVal.equals("") ? null : returnVal; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogItemHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogItemHandler.java new file mode 100644 index 0000000000..6a7c21a3bc --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogItemHandler.java @@ -0,0 +1,86 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.xml; + +import java.util.SortedMap; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.internal.CatalogItemImpl; +import org.jclouds.vcloud.util.Utils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Maps; + +/** + * @author Adrian Cole + */ +public class CatalogItemHandler extends ParseSax.HandlerWithResult { + private StringBuilder currentText = new StringBuilder(); + + private NamedResource catalog; + private NamedResource entity; + + private String description; + private String key; + private SortedMap properties = Maps.newTreeMap(); + + public CatalogItem getResult() { + return new CatalogItemImpl(catalog.getId(), catalog.getName(), catalog.getLocation(), + description, entity, properties); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + if (qName.equals("CatalogItem")) { + catalog = Utils.newNamedResource(attributes); + } else if (qName.equals("Entity")) { + entity = Utils.newNamedResource(attributes); + } else if (qName.equals("Property")) { + key = attributes.getValue(attributes.getIndex("key")); + } + } + + public void endElement(String uri, String name, String qName) { + if (qName.equals("Description")) { + description = currentOrNull(); + } else if (qName.equals("Property")) { + properties.put(key, currentOrNull()); + key = null; + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java new file mode 100644 index 0000000000..842ec4de0d --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java @@ -0,0 +1,75 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.xml; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.internal.VAppTemplateImpl; +import org.jclouds.vcloud.util.Utils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Adrian Cole + */ +public class VAppTemplateHandler extends ParseSax.HandlerWithResult { + private StringBuilder currentText = new StringBuilder(); + + private NamedResource catalog; + private String description; + private VAppStatus status; + + public VAppTemplate getResult() { + return new VAppTemplateImpl(catalog.getId(), catalog.getName(), catalog.getLocation(), + description, status); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + if (qName.equals("VAppTemplate")) { + catalog = Utils.newNamedResource(attributes); + if (attributes.getIndex("status") != -1) + status = VAppStatus.fromValue(attributes.getValue(attributes.getIndex("status"))); + } + } + + public void endElement(String uri, String name, String qName) { + if (qName.equals("Description")) { + description = currentOrNull(); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } +} diff --git a/vcloud/core/src/main/resources/InstantiateVAppTemplateParams.xml b/vcloud/core/src/main/resources/InstantiateVAppTemplateParams.xml deleted file mode 100644 index 38256f7db8..0000000000 --- a/vcloud/core/src/main/resources/InstantiateVAppTemplateParams.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - allowInOut - false - - - - - - \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index 28b51fc278..454c0eadc6 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -23,11 +23,15 @@ */ package org.jclouds.vcloud; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; import static org.testng.Assert.assertEquals; import java.io.IOException; +import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; +import java.util.Properties; import javax.inject.Provider; @@ -38,6 +42,8 @@ import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Jsr330; +import org.jclouds.util.Utils; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.TasksList; @@ -45,12 +51,16 @@ import org.jclouds.vcloud.endpoints.VCloudApi; import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot; +import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.xml.CatalogHandler; +import org.jclouds.vcloud.xml.CatalogItemHandler; import org.jclouds.vcloud.xml.OrgHandler; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.VAppHandler; +import org.jclouds.vcloud.xml.VAppTemplateHandler; import org.jclouds.vcloud.xml.VDCHandler; import org.testng.annotations.Test; @@ -65,6 +75,54 @@ import com.google.inject.TypeLiteral; */ @Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest") public class VCloudAsyncClientTest extends RestClientTest { + + public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, + IOException { + Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", + String.class, String.class, String.class, Array.newInstance( + InstantiateVAppTemplateOptions.class, 0).getClass()); + GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", + "CentOS 01", 3 + ""); + + assertRequestLineEquals(httpMethod, + "POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + assertHeadersEqual( + httpMethod, + "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 636\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); + assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( + "/newvapp-hosting.xml"))); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + public void testInstantiateVAppTemplateOptions() throws SecurityException, + NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", + String.class, String.class, String.class, Array.newInstance( + InstantiateVAppTemplateOptions.class, 0).getClass()); + GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", + "CentOS 01", 3 + "", processorCount(1).memory(512).disk(1024) + .inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990"))); + + assertRequestLineEquals(httpMethod, + "POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + assertHeadersEqual( + httpMethod, + "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 2018\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); + assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( + "/newvapp-hostingcpumemdisk.xml"))); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getOrganization"); GeneratedHttpRequest httpMethod = processor.createRequest(method); @@ -95,6 +153,36 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(httpMethod); } + public void testCatalogItem() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, "2"); + + assertRequestLineEquals(httpMethod, "GET http://vcloud/catalogItem/2 HTTP/1.1"); + assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + public void testVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, "2"); + + assertRequestLineEquals(httpMethod, "GET http://vcloud/vAppTemplate/2 HTTP/1.1"); + assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); + assertPayloadEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getDefaultVDC"); GeneratedHttpRequest httpMethod = processor.createRequest(method); @@ -340,10 +428,16 @@ public class VCloudAsyncClientTest extends RestClientTest { return new AbstractModule() { @Override protected void configure() { + Properties props = new Properties(); + props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK, + "https://vcloud.safesecureweb.com/network/1990"); + Jsr330.bindProperties(binder(), new VCloudPropertiesBuilder(props).build()); bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org")); bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog")); bind(String.class).annotatedWith(CatalogItemRoot.class) .toInstance("http://catalogItem"); + bind(String.class).annotatedWith(VAppTemplateRoot.class).toInstance( + "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate"); bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vApps"); bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc")); bind(URI.class).annotatedWith(TasksList.class).toInstance( @@ -364,7 +458,6 @@ public class VCloudAsyncClientTest extends RestClientTest { } }); } - }; } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java index 38d1cf48d8..af97db60a3 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -31,6 +31,7 @@ import java.net.URI; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.Task; @@ -71,6 +72,35 @@ public class VCloudClientLiveTest { assert response.size() > 0; } + @Test(enabled = true) + public void testGetCatalogItem() throws Exception { + Catalog response = connection.getCatalog(); + for (NamedResource resource : response.values()) { + if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { + CatalogItem item = connection.getCatalogItem(resource.getId()); + assertNotNull(item); + assertNotNull(item.getEntity()); + assertNotNull(item.getId()); + assertNotNull(item.getLocation()); + assertNotNull(item.getProperties()); + assertNotNull(item.getType()); + } + } + } + + @Test(enabled = true) + public void testGetVAppTemplate() throws Exception { + Catalog response = connection.getCatalog(); + for (NamedResource resource : response.values()) { + if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { + CatalogItem item = connection.getCatalogItem(resource.getId()); + if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { + assertNotNull(connection.getVAppTemplate(item.getEntity().getId())); + } + } + } + } + @Test public void testDefaultVDC() throws Exception { VDC response = connection.getDefaultVDC(); @@ -99,9 +129,8 @@ public class VCloudClientLiveTest { assertNotNull(response); assertNotNull(response.getLocation()); assertNotNull(response.getTasks()); - for (Task t : response.getTasks()) { - assertEquals(connection.getTask(t.getId()).getLocation(), t.getLocation()); - } + Task task = response.getTasks().last(); + assertEquals(connection.getTask(task.getId()).getLocation(), task.getLocation()); } @Test(enabled = true) diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java index 55760d009a..3beffa50cc 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java @@ -87,8 +87,8 @@ public class VCloudComputeClient { String vDCId = tmClient.getDefaultVDC().getId(); logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)", name, minCores, minMegs, templateId, vDCId); - VApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId, vDCId, - InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs)); + VApp vAppResponse = tmClient.instantiateVAppTemplateInVDC(name, templateId, vDCId, + InstantiateVAppTemplateOptions.Builder.processorCount(minCores).memory(minMegs)); tmClient.getVApp(vAppResponse.getId()); logger.debug("<< instantiated VApp(%s)", vAppResponse.getId()); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java index aac5ece888..962094100b 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -23,27 +23,23 @@ */ package org.jclouds.vcloud.binders; +import static com.google.common.base.Preconditions.checkNotNull; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.replay; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK; -import static org.testng.Assert.assertEquals; +import static org.easymock.classextension.EasyMock.verify; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; import java.io.IOException; -import java.io.InputStream; import java.net.URI; -import java.util.Collections; import java.util.Map; - -import javax.inject.Named; -import javax.inject.Singleton; -import javax.ws.rs.core.HttpHeaders; +import java.util.Properties; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; +import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.domain.ResourceType; import org.testng.annotations.Test; import com.google.common.collect.HashMultimap; @@ -53,8 +49,6 @@ import com.google.common.collect.Multimaps; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.Provides; -import com.google.inject.util.Providers; /** * Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload} @@ -63,93 +57,72 @@ import com.google.inject.util.Providers; */ @Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlPayloadTest") public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT)).toProvider( - Providers. of("1")); - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)).toProvider( - Providers. of("512")); - bind(String.class) - .annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK)) - .toProvider( - Providers - . of("https://vcloud.safesecureweb.com/network/1990")); - } + @Override + protected void configure() { + Properties props = new Properties(); + props + .put(PROPERTY_VCLOUD_DEFAULT_NETWORK, + "https://vcloud.safesecureweb.com/network/1990"); + Jsr330.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), + "properties")); + } + }); - @SuppressWarnings("unused") - @Singleton - @Provides - @Named("InstantiateVAppTemplateParams") - String provideInstantiateVAppTemplateParams() throws IOException { - InputStream is = getClass().getResourceAsStream( - "/InstantiateVAppTemplateParams.xml"); - return Utils.toStringAndClose(is); - } - }); - public void testApplyInputStream1() throws IOException { - String expected = Utils.toStringAndClose(getClass().getResourceAsStream( - "/newvapp-hosting.xml")); - Multimap headers = Multimaps - .synchronizedMultimap(HashMultimap. create()); - GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getEndpoint()).andReturn( - URI.create("http://localhost/key")).anyTimes(); - expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); - expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null) - .atLeastOnce(); - expect(request.getHeaders()).andReturn(headers).atLeastOnce(); - request.setPayload(expected); - replay(request); + public void testDefault() throws IOException { + String expected = Utils.toStringAndClose(getClass().getResourceAsStream( + "/newvapp-hosting.xml")); + Multimap headers = Multimaps.synchronizedMultimap(HashMultimap + . create()); + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); + expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce(); + expect(request.getHeaders()).andReturn(headers).atLeastOnce(); + request.setPayload(expected); + replay(request); - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + BindInstantiateVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); - Map map = Maps.newHashMap(); - map.put("name", "CentOS 01"); - map.put("template", - "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); - map.put("count", "1"); - map.put("megabytes", "512"); - map.put("network", "https://vcloud.safesecureweb.com/network/1990"); - binder.bindToRequest(request, map); - assertEquals(headers.get(HttpHeaders.CONTENT_TYPE), Collections - .singletonList("application/unknown")); - assertEquals(headers.get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList("901")); - } + Map map = Maps.newHashMap(); + map.put("name", "CentOS 01"); + map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); + binder.bindToRequest(request, map); + verify(request); - public void testApplyInputStream2() throws IOException { - String expected = Utils.toStringAndClose(getClass().getResourceAsStream( - "/newvapp-hosting.xml")); - Multimap headers = Multimaps - .synchronizedMultimap(HashMultimap. create()); - GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getEndpoint()).andReturn( - URI.create("http://localhost/key")).anyTimes(); - expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); - expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null) - .atLeastOnce(); - expect(request.getHeaders()).andReturn(headers).atLeastOnce(); - request.setPayload(expected); - replay(request); + } + - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + public void testWithProcessorMemoryDisk() throws IOException { + String expected = Utils.toStringAndClose(getClass().getResourceAsStream( + "/newvapp-hostingcpumemdisk.xml")); + Multimap headers = Multimaps.synchronizedMultimap(HashMultimap + . create()); + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); + expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce(); + expect(request.getHeaders()).andReturn(headers).atLeastOnce(); + request.setPayload(expected); + replay(request); - Map map = Maps.newHashMap(); - map.put("name", "CentOS 01"); - map.put("template", - "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); - binder.bindToRequest(request, map); - assertEquals(headers.get(HttpHeaders.CONTENT_TYPE), Collections - .singletonList("application/unknown")); - assertEquals(headers.get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList("901")); + BindInstantiateVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); - } + Map map = Maps.newHashMap(); + map.put("name", "CentOS 01"); + map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); + map.put("network", "https://vcloud.safesecureweb.com/network/1990"); + + map.put(ResourceType.PROCESSOR.value(), "1"); + map.put(ResourceType.MEMORY.value(), "512"); + map.put(ResourceType.DISK_DRIVE.value(), "1024"); + + binder.bindToRequest(request, map); + verify(request); + + } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java index 640634e4e3..1e81167b3a 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java @@ -30,7 +30,6 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; import static org.testng.Assert.assertEquals; -import java.io.IOException; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -45,7 +44,6 @@ import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler; import org.jclouds.util.Jsr330; -import org.jclouds.util.Utils; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; @@ -55,7 +53,6 @@ import com.google.common.base.Supplier; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.Key; /** * @author Adrian Cole @@ -79,15 +76,6 @@ public class VCloudRestClientModuleTest { }); } - @Test - void postStrings() throws IOException { - assertEquals(createInjector().getInstance( - Key.get(String.class, Jsr330.named("InstantiateVAppTemplateParams"))), Utils - .toStringAndClose(getClass().getResourceAsStream( - "/InstantiateVAppTemplateParams.xml"))); - - } - @Test void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException { VCloudRestClientModule module = new VCloudRestClientModule(); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java index 68e30b508c..8f8746870b 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java @@ -23,9 +23,10 @@ */ package org.jclouds.vcloud.options; -import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.cpuCount; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.disk; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.inNetwork; -import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.megabytes; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.memory; import static org.testng.Assert.assertEquals; import java.net.URI; @@ -62,31 +63,50 @@ public class InstantiateVAppTemplateOptionsTest { @Test public void testCpuCount() { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - options.cpuCount(3); + options.processorCount(3); assertEquals(options.getCpuCount(), "3"); } @Test public void testCpuCountStatic() { - InstantiateVAppTemplateOptions options = cpuCount(3); + InstantiateVAppTemplateOptions options = processorCount(3); assertEquals(options.getCpuCount(), "3"); } @Test - public void testMegabytes() { + public void testRam() { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - options.megabytes(512); - assertEquals(options.getMegabytes(), "512"); + options.memory(512); + assertEquals(options.getMemorySizeMegabytes(), "512"); } @Test - public void testMegabytesStatic() { - InstantiateVAppTemplateOptions options = megabytes(512); - assertEquals(options.getMegabytes(), "512"); + public void testRamStatic() { + InstantiateVAppTemplateOptions options = memory(512); + assertEquals(options.getMemorySizeMegabytes(), "512"); } @Test(expectedExceptions = IllegalArgumentException.class) - public void testMegabytesStaticWrong() { - megabytes(511); + public void testRamStaticWrong() { + memory(511); } + + @Test + public void testDisk() { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + options.disk(512); + assertEquals(options.getDiskSizeKilobytes(), "512"); + } + + @Test + public void testDiskStatic() { + InstantiateVAppTemplateOptions options = disk(512); + assertEquals(options.getDiskSizeKilobytes(), "512"); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testDiskStaticWrong() { + disk(0); + } + } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java index 2e7ce93ebb..391da63537 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java @@ -23,7 +23,6 @@ */ package org.jclouds.vcloud.xml; -import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; import static org.testng.Assert.assertEquals; import java.io.InputStream; @@ -32,15 +31,14 @@ import java.net.URI; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.ParserModule; -import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.internal.CatalogItemImpl; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; -import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.testng.annotations.Test; -import com.google.inject.AbstractModule; +import com.google.common.collect.ImmutableSortedMap; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.Provides; /** * Tests behavior of {@code CatalogHandler} @@ -50,155 +48,21 @@ import com.google.inject.Provides; @Test(groups = "unit", testName = "vcloud.CatalogHandlerTest") public class CatalogHandlerTest { - private Injector injector; - - private Factory factory; - public void testApplyInputStream() { - InputStream is = getClass().getResourceAsStream("/catalog.xml"); - injector = Guice.createInjector(new ParserModule(), new AbstractModule() { + InputStream is = getClass().getResourceAsStream("/catalogItem-hosting.xml"); + Injector injector = Guice.createInjector(new ParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + CatalogItem result = factory.create(injector.getInstance(CatalogItemHandler.class)).parse(is); - @Override - protected void configure() { - } + assertEquals(result, new CatalogItemImpl("2", "Windows 2008 Datacenter 64 Bit", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), + "Windows 2008 Datacenter 64 Bit", new NamedResourceImpl("2", + "Windows 2008 Datacenter 64 Bit", + "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")), + ImmutableSortedMap.of("Foo", "Bar", "Hello", "World" - @SuppressWarnings("unused") - @Provides - @CatalogItemRoot - String provide() { - return "https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem"; - } + ))); - }); - factory = injector.getInstance(ParseSax.Factory.class); - Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse( - is); - assertEquals(result.getName(), "Miami Environment 1"); - assert result.getDescription() == null; - - assertEquals(result.getLocation(), URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")); - - assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5 + "", - "CentOS 5.3 (32-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5"))); - assertEquals(result.get("CentOS 5.3 (64-bit)"), new NamedResourceImpl(6 + "", - "CentOS 5.3 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6"))); - assertEquals(result.get("RHEL 5.3 (32-bit)"), new NamedResourceImpl(7 + "", - "RHEL 5.3 (32-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7"))); - assertEquals(result.get("RHEL 5.3 (64-bit)"), new NamedResourceImpl(8 + "", - "RHEL 5.3 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8"))); - assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new NamedResourceImpl(11 + "", - "Ubuntu JeOS 9.04 (32-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11"))); - assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new NamedResourceImpl(12 + "", - "Ubuntu JeOS 9.04 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12"))); - assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new NamedResourceImpl(9 + "", - "Ubuntu Server 9.04 (32-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9"))); - assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new NamedResourceImpl(10 + "", - "Ubuntu Server 9.04 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10"))); - assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new NamedResourceImpl(1 + "", - "Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1"))); - assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new NamedResourceImpl(2 + "", - "Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2"))); - assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new NamedResourceImpl(3 + "", - "Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3"))); - assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new NamedResourceImpl(4 + "", - "Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4"))); - assertEquals( - result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"), - new NamedResourceImpl( - 23 + "", - "Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)", - CATALOGITEM_XML, - URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23"))); - assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new NamedResourceImpl( - 13 + "", "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13"))); - assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new NamedResourceImpl( - 15 + "", "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15"))); - assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new NamedResourceImpl( - 16 + "", "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16"))); - assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new NamedResourceImpl( - 17 + "", "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17"))); - assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new NamedResourceImpl( - 18 + "", "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18"))); - assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new NamedResourceImpl( - 19 + "", "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19"))); - assertEquals( - result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"), - new NamedResourceImpl( - 14 + "", - "Windows Server 2008 Standard w.SQL 2008 Web (64-bit)", - CATALOGITEM_XML, - URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14"))); - assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new NamedResourceImpl(20 + "", - "Windows Web Server 2008 (32-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20"))); - assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new NamedResourceImpl(21 + "", - "Windows Web Server 2008 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21"))); - assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new NamedResourceImpl( - 22 + "", "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22"))); - - } - - public void testHosting() { - InputStream is = getClass().getResourceAsStream("/catalog-hosting.xml"); - injector = Guice.createInjector(new ParserModule(), new AbstractModule() { - - @Override - protected void configure() { - } - - @SuppressWarnings("unused") - @Provides - @CatalogItemRoot - String provide() { - return "https://vcloud.safesecureweb.com/api/v0.8/catalogItem"; - } - - }); - factory = injector.getInstance(ParseSax.Factory.class); - Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse( - is); - assertEquals(result.getName(), "HMSCatalog"); - assertEquals(result.getDescription(), "HMS Shared Catalog"); - assertEquals(result.getLocation(), URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")); - - assertEquals(result.get("Plesk (Linux) 64-bit Template"), new NamedResourceImpl(1 + "", - "Plesk (Linux) 64-bit Template", CATALOGITEM_XML, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1"))); - - assertEquals(result.get("Windows 2008 Datacenter 64 Bit Template"), new NamedResourceImpl( - 2 + "", "Windows 2008 Datacenter 64 Bit Template", CATALOGITEM_XML, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))); - - assertEquals(result.get("Cent OS 64 Bit Template"), new NamedResourceImpl(3 + "", - "Cent OS 64 Bit Template", CATALOGITEM_XML, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/3"))); - - assertEquals(result.get("cPanel (Linux) 64 Bit Template"), new NamedResourceImpl(4 + "", - "cPanel (Linux) 64 Bit Template", CATALOGITEM_XML, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"))); } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogItemHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogItemHandlerTest.java new file mode 100644 index 0000000000..479db84201 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogItemHandlerTest.java @@ -0,0 +1,204 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.xml; + +import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.internal.NamedResourceImpl; +import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Provides; + +/** + * Tests behavior of {@code CatalogHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.CatalogHandlerTest") +public class CatalogItemHandlerTest { + + private Injector injector; + + private Factory factory; + + public void testApplyInputStream() { + InputStream is = getClass().getResourceAsStream("/catalog.xml"); + injector = Guice.createInjector(new ParserModule(), new AbstractModule() { + + @Override + protected void configure() { + } + + @SuppressWarnings("unused") + @Provides + @CatalogItemRoot + String provide() { + return "https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem"; + } + + }); + factory = injector.getInstance(ParseSax.Factory.class); + Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse( + is); + assertEquals(result.getName(), "Miami Environment 1"); + assert result.getDescription() == null; + + assertEquals(result.getLocation(), URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")); + + assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5 + "", + "CentOS 5.3 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5"))); + assertEquals(result.get("CentOS 5.3 (64-bit)"), new NamedResourceImpl(6 + "", + "CentOS 5.3 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6"))); + assertEquals(result.get("RHEL 5.3 (32-bit)"), new NamedResourceImpl(7 + "", + "RHEL 5.3 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7"))); + assertEquals(result.get("RHEL 5.3 (64-bit)"), new NamedResourceImpl(8 + "", + "RHEL 5.3 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8"))); + assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new NamedResourceImpl(11 + "", + "Ubuntu JeOS 9.04 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11"))); + assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new NamedResourceImpl(12 + "", + "Ubuntu JeOS 9.04 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12"))); + assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new NamedResourceImpl(9 + "", + "Ubuntu Server 9.04 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9"))); + assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new NamedResourceImpl(10 + "", + "Ubuntu Server 9.04 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10"))); + assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new NamedResourceImpl(1 + "", + "Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1"))); + assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new NamedResourceImpl(2 + "", + "Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2"))); + assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new NamedResourceImpl(3 + "", + "Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3"))); + assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new NamedResourceImpl(4 + "", + "Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4"))); + assertEquals( + result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"), + new NamedResourceImpl( + 23 + "", + "Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)", + CATALOGITEM_XML, + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23"))); + assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new NamedResourceImpl( + 13 + "", "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13"))); + assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new NamedResourceImpl( + 15 + "", "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15"))); + assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new NamedResourceImpl( + 16 + "", "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16"))); + assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new NamedResourceImpl( + 17 + "", "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17"))); + assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new NamedResourceImpl( + 18 + "", "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18"))); + assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new NamedResourceImpl( + 19 + "", "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19"))); + assertEquals( + result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"), + new NamedResourceImpl( + 14 + "", + "Windows Server 2008 Standard w.SQL 2008 Web (64-bit)", + CATALOGITEM_XML, + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14"))); + assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new NamedResourceImpl(20 + "", + "Windows Web Server 2008 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20"))); + assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new NamedResourceImpl(21 + "", + "Windows Web Server 2008 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21"))); + assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new NamedResourceImpl( + 22 + "", "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22"))); + + } + + public void testHosting() { + InputStream is = getClass().getResourceAsStream("/catalog-hosting.xml"); + injector = Guice.createInjector(new ParserModule(), new AbstractModule() { + + @Override + protected void configure() { + } + + @SuppressWarnings("unused") + @Provides + @CatalogItemRoot + String provide() { + return "https://vcloud.safesecureweb.com/api/v0.8/catalogItem"; + } + + }); + factory = injector.getInstance(ParseSax.Factory.class); + Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse( + is); + assertEquals(result.getName(), "HMSCatalog"); + assertEquals(result.getDescription(), "HMS Shared Catalog"); + assertEquals(result.getLocation(), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")); + + assertEquals(result.get("Plesk (Linux) 64-bit Template"), new NamedResourceImpl(1 + "", + "Plesk (Linux) 64-bit Template", CATALOGITEM_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1"))); + + assertEquals(result.get("Windows 2008 Datacenter 64 Bit Template"), new NamedResourceImpl( + 2 + "", "Windows 2008 Datacenter 64 Bit Template", CATALOGITEM_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))); + + assertEquals(result.get("Cent OS 64 Bit Template"), new NamedResourceImpl(3 + "", + "Cent OS 64 Bit Template", CATALOGITEM_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/3"))); + + assertEquals(result.get("cPanel (Linux) 64 Bit Template"), new NamedResourceImpl(4 + "", + "cPanel (Linux) 64 Bit Template", CATALOGITEM_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"))); + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java new file mode 100644 index 0000000000..4d31195c8a --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java @@ -0,0 +1,75 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.internal.VAppTemplateImpl; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code VAppTemplateHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.VAppTemplateHandlerTest") +public class VAppTemplateHandlerTest { + + private Injector injector; + + private Factory factory; + + public void testTerremark() { + InputStream is = getClass().getResourceAsStream("/vAppTemplate-trmk.xml"); + injector = Guice.createInjector(new ParserModule()); + factory = injector.getInstance(ParseSax.Factory.class); + VAppTemplate result = factory.create(injector.getInstance(VAppTemplateHandler.class)).parse( + is); + assertEquals(result, new VAppTemplateImpl("5", "CentOS 5.3 (32-bit)", URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vAppTemplate/5"), + "description of CentOS 5.3 (32-bit)", null)); + } + + public void testHosting() { + InputStream is = getClass().getResourceAsStream("/vAppTemplate-hosting.xml"); + injector = Guice.createInjector(new ParserModule()); + factory = injector.getInstance(ParseSax.Factory.class); + VAppTemplate result = (VAppTemplate) factory.create( + injector.getInstance(VAppTemplateHandler.class)).parse(is); + assertEquals(result, new VAppTemplateImpl("4", "cPanel (Linux) 64 Bit", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"), + "cPanel (Linux) 64 Bit", VAppStatus.RESOLVED)); + } +} diff --git a/vcloud/core/src/test/resources/catalog.xml b/vcloud/core/src/test/resources/catalog.xml index 2389e55dcc..f2d5eaa196 100644 --- a/vcloud/core/src/test/resources/catalog.xml +++ b/vcloud/core/src/test/resources/catalog.xml @@ -24,4 +24,4 @@ - \ No newline at end of file + diff --git a/vcloud/core/src/test/resources/newvapp-hosting.xml b/vcloud/core/src/test/resources/newvapp-hosting.xml index c18be4cabf..b7a92e3f74 100644 --- a/vcloud/core/src/test/resources/newvapp-hosting.xml +++ b/vcloud/core/src/test/resources/newvapp-hosting.xml @@ -1,17 +1 @@ - - - - - - - - allowInOut - false - - - - - - \ No newline at end of file +allowInOutfalse \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java index f42c8563e5..70c2f14654 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java @@ -87,8 +87,8 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient { @XMLResponseParser(HostingDotComVAppHandler.class) @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) @Override - Future instantiateVAppTemplate( - @MapPayloadParam("name") String appName, + Future instantiateVAppTemplateInVDC( + @PathParam("vDCId") String vDCId, @MapPayloadParam("name") String appName, @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, - @PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options); + InstantiateVAppTemplateOptions... options); } diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java index ca535e87e2..99dc70875a 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java @@ -42,7 +42,7 @@ public interface HostingDotComVCloudClient extends VCloudClient { @Override @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) - HostingDotComVApp instantiateVAppTemplate(String appName, String templateId, String vDCId, + HostingDotComVApp instantiateVAppTemplateInVDC(String vDCId, String appName, String templateId, InstantiateVAppTemplateOptions... options); @Override diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java index 2964790685..eecae5bd08 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java @@ -66,14 +66,18 @@ public class HostingDotComVCloudComputeClient { Image.CENTOS_53, "3").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put( Image.UMBUNTU_JEOS, "11").build(); - public Map start(String name, int minCores, int minMegs, Image image) { + public Map start(String name, Image image, int minCores, int minMegs, + long diskSize, Map properties) { checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); String templateId = imageCatalogIdMap.get(image); String vDCId = tmClient.getDefaultVDC().getId(); - logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)", - name, minCores, minMegs, templateId, vDCId); - HostingDotComVApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId, vDCId, - InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs)); + logger + .debug( + ">> instantiating vApp vDC(%s) name(%s) template(%s) minCores(%d) minMegs(%d) diskSize(%d) properties(%s) ", + vDCId, name, templateId, minCores, minMegs, diskSize, properties); + HostingDotComVApp vAppResponse = tmClient.instantiateVAppTemplateInVDC(vDCId, name, + templateId, InstantiateVAppTemplateOptions.Builder.processorCount(minCores) + .memory(minMegs).disk(diskSize).productProperties(properties)); logger.debug("<< instantiated VApp(%s)", vAppResponse.getId()); logger.debug(">> deploying vApp(%s)", vAppResponse.getId()); @@ -113,7 +117,8 @@ public class HostingDotComVCloudComputeClient { public void stop(String id) { VApp vApp = tmClient.getVApp(id); if (vApp.getStatus() != VAppStatus.OFF) { - logger.debug(">> powering off vApp(%s)", vApp.getId()); + logger.debug(">> powering off vApp(%s), current status: %s", vApp.getId(), vApp + .getStatus()); blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()), "powerOff", VAppStatus.OFF); logger.debug("<< off vApp(%s)", vApp.getId()); diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java index c176d0cc5c..8ee18431f1 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java @@ -81,7 +81,8 @@ public class HostingDotComVCloudComputeService implements ComputeService { @Override public CreateServerResponse createServer(String name, Profile profile, Image image) { - Map metaMap = computeClient.start(name, 1, 512, image); + Map metaMap = computeClient.start(name, image, 1, 512, (10l * 1025 * 1024), + ImmutableMap. of()); VApp vApp = hostingClient.getVApp(metaMap.get("id")); return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), vAppStatusToServerState .get(vApp.getStatus()), vApp.getNetworkToAddresses().values(), ImmutableSet diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java index 73297c22a2..3a7db68538 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java @@ -45,6 +45,7 @@ import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.CaseFormat; import com.google.common.base.Predicate; import com.google.inject.Injector; import com.google.inject.Key; @@ -94,8 +95,10 @@ public class HostingDotComVCloudComputeClientLiveTest { String serverName = getCompatibleServerName(toTest); int processorCount = 1; int memory = 512; + long disk = 10 * 1025 * 1024; + Map properties = ImmutableMap.of("foo", "bar"); - id = client.start(serverName, processorCount, memory, toTest).get("id"); + id = client.start(serverName, toTest, processorCount, memory, disk, properties).get("id"); Expectation expectation = expectationMap.get(toTest); VApp vApp = tmClient.getVApp(id); @@ -105,8 +108,9 @@ public class HostingDotComVCloudComputeClientLiveTest { } private String getCompatibleServerName(Image toTest) { - String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0, - toTest.toString().length() <= 15 ? toTest.toString().length() : 14); + String serverName = CaseFormat.UPPER_UNDERSCORE + .to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0, + toTest.toString().length() <= 15 ? toTest.toString().length() : 14); return serverName; } diff --git a/vcloud/pom.xml b/vcloud/pom.xml index d934f76947..85164916fb 100755 --- a/vcloud/pom.xml +++ b/vcloud/pom.xml @@ -42,6 +42,11 @@ hostingdotcom + + com.jamesmurty.utils + java-xmlbuilder + 0.3 + ${project.groupId} jclouds-jsch 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 37addad345..fd46c0935b 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 @@ -53,7 +53,7 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.functions.CatalogIdToUri; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.binders.TerremarkBindInstantiateVAppTemplateParamsToXmlPayload; -import org.jclouds.vcloud.terremark.domain.ComputeOption; +import org.jclouds.vcloud.terremark.domain.ComputeOptions; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; @@ -113,20 +113,21 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @XMLResponseParser(TerremarkVAppHandler.class) @MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class) @Override - Future instantiateVAppTemplate(@MapPayloadParam("name") String appName, + Future instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId, + @MapPayloadParam("name") String appName, @MapPayloadParam("template") @ParamParser(CatalogIdToUri.class) String templateId, - @PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options); + InstantiateVAppTemplateOptions... options); /** * @see TerremarkVCloudClient#addInternetService */ @POST - @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) - @Path("/internetServices") + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/vdc/{vDCId}/internetServices") @Produces(MediaType.APPLICATION_XML) @XMLResponseParser(InternetServiceHandler.class) @MapBinder(AddInternetServiceOptions.class) - Future addInternetService( + Future addInternetServiceToVDC(@PathParam("vDCId") String vDCId, @MapPayloadParam("name") String serviceName, @MapPayloadParam("protocol") Protocol protocol, @MapPayloadParam("port") int port, AddInternetServiceOptions... options); @@ -135,10 +136,11 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { * @see TerremarkVCloudClient#getAllInternetServices */ @GET - @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) - @Path("/internetServices") + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/vdc/{vDCId}/internetServices") @XMLResponseParser(InternetServicesHandler.class) - Future> getAllInternetServices(); + Future> getAllInternetServicesInVDC( + @PathParam("vDCId") String vDCId); /** * @see TerremarkVCloudClient#addInternetServiceToExistingIp @@ -159,7 +161,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { */ @DELETE @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/PublicIps/{ipId}") + @Path("/publicIps/{ipId}") @ExceptionParser(ReturnVoidOnDeleteDefaultIp.class) Future deletePublicIp(@PathParam("ipId") int ipId); @@ -177,10 +179,11 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { * @see TerremarkVCloudClient#getPublicIpsAssociatedWithVDC */ @GET - @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) - @Path("/publicIps") + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/vdc/{vDCId}/publicIps") @XMLResponseParser(PublicIpAddressesHandler.class) - Future> getPublicIpsAssociatedWithVDC(); + Future> getPublicIpsAssociatedWithVDC( + @PathParam("vDCId") String vDCId); /** * @see TerremarkVCloudClient#deleteInternetService @@ -253,21 +256,42 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { Future getVApp(@PathParam("vAppId") String vAppId); /** - * @see TerremarkVCloudClient#getComputeOptions + * @see TerremarkVCloudClient#getComputeOptionsOfVApp */ @GET @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}/options/compute") @XMLResponseParser(ComputeOptionsHandler.class) - Future> getComputeOptions(@PathParam("vAppId") String vAppId); + Future> getComputeOptionsOfVApp( + @PathParam("vAppId") String vAppId); /** - * @see TerremarkVCloudClient#getCustomizationOptions + * @see TerremarkVCloudClient#getCustomizationOptionsOfVApp */ @GET @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}/options/customization") @XMLResponseParser(CustomizationParametersHandler.class) - Future getCustomizationOptions( + Future getCustomizationOptionsOfVApp( @PathParam("vAppId") String vAppId); + + /** + * @see TerremarkVCloudClient#getComputeOptionsOfCatalogItem + */ + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/catalogItem/{catalogItemId}/options/compute") + @XMLResponseParser(ComputeOptionsHandler.class) + Future> getComputeOptionsOfCatalogItem( + @PathParam("catalogItemId") String catalogItemId); + + /** + * @see TerremarkVCloudClient#getCustomizationOptionsOfCatalogItem + */ + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/catalogItem/{catalogItemId}/options/customization") + @XMLResponseParser(CustomizationParametersHandler.class) + Future getCustomizationOptionsOfCatalogItem( + @PathParam("catalogItemId") String catalogItemId); } 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 26cd8f2b27..45ee3adb42 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 @@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; -import org.jclouds.vcloud.terremark.domain.ComputeOption; +import org.jclouds.vcloud.terremark.domain.ComputeOptions; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; @@ -51,7 +51,7 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions; public interface TerremarkVCloudClient extends VCloudClient { @Override - TerremarkVApp instantiateVAppTemplate(String appName, String templateId, String vDCId, + TerremarkVApp instantiateVAppTemplateInVDC(String vDCId, String appName, String templateId, InstantiateVAppTemplateOptions... options); @Override @@ -62,19 +62,23 @@ public interface TerremarkVCloudClient extends VCloudClient { * configurations supported by Terremark and by the guest operating system of the vApp. This call * also returns the cost per hour for each configuration. */ - SortedSet getComputeOptions(String vAppId); + SortedSet getComputeOptionsOfVApp(String vAppId); + + SortedSet getComputeOptionsOfCatalogItem(String catalogItemId); /** * This call returns the customization options for the vApp. The response lists which * customization options are supported for this particular vApp. The possible customization * options are Network and Password. */ - CustomizationParameters getCustomizationOptions(String vAppId); + CustomizationParameters getCustomizationOptionsOfVApp(String vAppId); + + CustomizationParameters getCustomizationOptionsOfCatalogItem(String catalogItemId); /** * This call returns a list of public IP addresses. */ - SortedSet getPublicIpsAssociatedWithVDC(); + SortedSet getPublicIpsAssociatedWithVDC(String vDCId); void deletePublicIp(int ipId); @@ -82,25 +86,14 @@ public interface TerremarkVCloudClient extends VCloudClient { * The call creates a new internet server, including protocol and port information. The public IP * is dynamically allocated. * - * @param serviceName - * @param protocol - * @param port - * @param options - * @return */ - InternetService addInternetService(String serviceName, Protocol protocol, int port, - AddInternetServiceOptions... options); + InternetService addInternetServiceToVDC(String vDCId, String serviceName, Protocol protocol, + int port, AddInternetServiceOptions... options); /** * This call adds an internet service to a known, existing public IP. This call is identical to * Add Internet Service except you specify the public IP in the request. * - * @param existingIpId - * @param serviceName - * @param protocol - * @param port - * @param options - * @return */ InternetService addInternetServiceToExistingIp(int existingIpId, String serviceName, Protocol protocol, int port, AddInternetServiceOptions... options); @@ -109,7 +102,7 @@ public interface TerremarkVCloudClient extends VCloudClient { InternetService getInternetService(int internetServiceId); - SortedSet getAllInternetServices(); + SortedSet getAllInternetServicesInVDC(String vDCId); /** * This call returns information about the internet service on a public IP. diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java index 7538879a84..43b72f5efd 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java @@ -23,10 +23,10 @@ */ package org.jclouds.vcloud.terremark; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; import java.net.URI; import java.util.Properties; @@ -39,23 +39,22 @@ import org.jclouds.vcloud.VCloudPropertiesBuilder; * @author Adrian Cole */ public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder { - @Override + @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_TERREMARK_DEFAULTGROUP, "group"); - properties.setProperty(PROPERTY_TERREMARK_DEFAULTROW, "row"); - properties.setProperty((PROPERTY_TERREMARK_DEFAULTPASSWORD), "password"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_CPUCOUNT, "1"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_MEMORY, "512"); + properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v1"); properties.setProperty(PROPERTY_VCLOUD_ENDPOINT, "https://services.vcloudexpress.terremark.com/api"); return properties; } - public TerremarkVCloudPropertiesBuilder(Properties properties) { - super(properties); - } + public TerremarkVCloudPropertiesBuilder(Properties properties) { + super(properties); + } - public TerremarkVCloudPropertiesBuilder(String id, String secret) { - super(URI.create("https://services.vcloudexpress.terremark.com/api"), - id, secret); - } + public TerremarkVCloudPropertiesBuilder(String id, String secret) { + super(URI.create("https://services.vcloudexpress.terremark.com/api"), id, secret); + } } 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 23067ded48..13bf070541 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 @@ -23,23 +23,27 @@ */ package org.jclouds.vcloud.terremark.binders; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; import java.util.Map; +import java.util.SortedMap; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import javax.xml.parsers.FactoryConfigurationError; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; import org.jclouds.rest.binders.BindToStringPayload; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; -import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; +import org.jclouds.vcloud.domain.ResourceType; + +import com.jamesmurty.utils.XMLBuilder; /** * @@ -51,37 +55,36 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends BindInstantiateVAppTemplateParamsToXmlPayload { @Inject - public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload( - @Named("InstantiateVAppTemplateParams") String xmlTemplate, - BindToStringPayload stringBinder, - @Named(PROPERTY_VCLOUD_DEFAULTNETWORK) String defaultNetwork, - @Named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT) String defaultCpuCount, - @Named(PROPERTY_VCLOUD_DEFAULTMEMORY) String defaultMemory, - @Named(PROPERTY_TERREMARK_DEFAULTGROUP) String defaultGroup, - @Named(PROPERTY_TERREMARK_DEFAULTROW) String defaultRow, - @Named(PROPERTY_TERREMARK_DEFAULTPASSWORD) String defaultPassword) { - super(xmlTemplate, stringBinder, defaultNetwork, defaultCpuCount, defaultMemory); - this.defaultParams.put("group", defaultGroup); - this.defaultParams.put("row", defaultRow); - this.defaultParams.put("password", defaultPassword); + public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, + @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, + @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, + @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network, + OptionalConstantsHolder optionalDefaults) { + super(stringBinder, ns, schema, network, optionalDefaults); } @Override - protected void addOptionsToMap(Map postParams, GeneratedHttpRequest gRequest) { - super.addOptionsToMap(postParams, gRequest); - for (Object arg : gRequest.getArgs()) { - if (arg instanceof TerremarkInstantiateVAppTemplateOptions) { - TerremarkInstantiateVAppTemplateOptions options = (TerremarkInstantiateVAppTemplateOptions) arg; - if (options.getGroup() != null) { - postParams.put("group", options.getGroup()); - } - if (options.getRow() != null) { - postParams.put("row", options.getRow()); - } - if (options.getPassword() != null) { - postParams.put("password", options.getPassword()); - } - } + protected String generateXml(String name, String template, Map properties, + SortedMap virtualHardwareQuantity, String network) + throws ParserConfigurationException, FactoryConfigurationError, TransformerException { + checkNotNull(virtualHardwareQuantity.get(ResourceType.PROCESSOR), + "cpuCount must be present in instantiateVapp on terremark"); + checkNotNull(virtualHardwareQuantity.get(ResourceType.MEMORY), + "memorySizeMegabytes must be present in instantiateVapp on terremark"); + checkArgument(virtualHardwareQuantity.get(ResourceType.DISK_DRIVE) == null, + "diskSizeKilobytes no settable on instantiateVapp on terremark"); + return super.generateXml(name, template, properties, virtualHardwareQuantity, network); + } + + @Override + protected void addPropertiesifPresent(XMLBuilder instantiationParamsBuilder, + Map properties) { + if (properties.size() == 0) { // terremark requires the product section. + instantiationParamsBuilder.e("ProductSection").a("xmlns:q1", + "http://www.vmware.com/vcloud/v1").a("xmlns:ovf", + "http://schemas.dmtf.org/ovf/envelope/1"); + } else { + super.addPropertiesifPresent(instantiationParamsBuilder, properties); } } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java index 816876e1e6..546fadae6c 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java @@ -38,7 +38,6 @@ import javax.inject.Inject; import org.jclouds.compute.domain.Image; import org.jclouds.logging.Logger; import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.domain.InternetService; @@ -75,15 +74,15 @@ public class TerremarkVCloudComputeClient { Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put( Image.UMBUNTU_JEOS, "11").build(); - public String start(String name, int minCores, int minMegs, Image image) { + public String start(String name, Image image, int minCores, int minMegs, Map properties) { checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); String templateId = imageCatalogIdMap.get(image); String vDCId = tmClient.getDefaultVDC().getId(); - logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)", - name, minCores, minMegs, templateId, vDCId); - TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId, vDCId, - TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores) - .megabytes(minMegs)); + logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) minCores(%d) minMegs(%d) properties(%s)",vDCId, templateId, + name, minCores, minMegs, properties); + TerremarkVApp vApp = tmClient.instantiateVAppTemplateInVDC(vDCId, name, templateId, + TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(minCores) + .memory(minMegs).productProperties(properties)); logger.debug("<< instantiated VApp(%s)", vApp.getId()); logger.debug(">> deploying vApp(%s)", vApp.getId()); @@ -117,7 +116,7 @@ public class TerremarkVCloudComputeClient { logger.debug("<< on vApp(%s)", vApp.getId()); } - public InetAddress createPublicAddressMappedToPorts(VApp vApp, int... ports) { + public InetAddress createPublicAddressMappedToPorts(TerremarkVApp vApp, int... ports) { PublicIpAddress ip = null; InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values()); for (int port : ports) { @@ -136,8 +135,10 @@ public class TerremarkVCloudComputeClient { } if (ip == null) { - logger.debug(">> creating InternetService %d", port); - is = tmClient.addInternetService(vApp.getName() + "-" + port, protocol, port, + logger.debug(">> creating InternetService in vDC %s; port %d", vApp.getVDC().getId(), + port); + is = tmClient.addInternetServiceToVDC(vApp.getVDC().getId(), vApp.getName() + "-" + + port, protocol, port, withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getId(), vApp.getName()))); ip = is.getPublicIpAddress(); @@ -167,7 +168,8 @@ public class TerremarkVCloudComputeClient { deletePublicIpAddressesWithNoServicesAttached(ipAddresses); if (vApp.getStatus() != VAppStatus.OFF) { - logger.debug(">> powering off vApp(%s)", vApp.getId()); + logger.debug(">> powering off vApp(%s), current status: %s", vApp.getId(), vApp + .getStatus()); blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()), "powerOff", VAppStatus.OFF); logger.debug("<< off vApp(%s)", vApp.getId()); @@ -179,7 +181,8 @@ public class TerremarkVCloudComputeClient { private Set deleteInternetServicesAndNodesAssociatedWithVApp(TerremarkVApp vApp) { Set ipAddresses = Sets.newHashSet(); - SERVICE: for (InternetService service : tmClient.getAllInternetServices()) { + SERVICE: for (InternetService service : tmClient.getAllInternetServicesInVDC(vApp.getVDC() + .getId())) { for (Node node : tmClient.getNodes(service.getId())) { if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) { ipAddresses.add(service.getPublicIpAddress()); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java index 91a9e158f3..f98ac87627 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java @@ -49,7 +49,7 @@ import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; -import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.TerremarkVApp; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; @@ -83,8 +83,8 @@ public class TerremarkVCloudComputeService implements ComputeService { @Override public CreateServerResponse createServer(String name, Profile profile, Image image) { - String id = computeClient.start(name, 1, 512, image); - VApp vApp = tmClient.getVApp(id); + String id = computeClient.start(name, image, 1, 512, ImmutableMap. of()); + TerremarkVApp vApp = tmClient.getVApp(id); // bug creating more than one internet service returns 503 or 500 // InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22, 80, 8080); InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22); @@ -104,16 +104,6 @@ public class TerremarkVCloudComputeService implements ComputeService { LoginType.SSH); } - public SortedSet getInternetServicesByName(final String name) { - return Sets.newTreeSet(Iterables.filter(tmClient.getAllInternetServices(), - new Predicate() { - @Override - public boolean apply(InternetService input) { - return input.getName().equalsIgnoreCase(name); - } - })); - } - @Override public SortedSet getServerByName(final String name) { return Sets.newTreeSet(Iterables.filter(listServers(), new Predicate() { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java index 3a42e32eb2..d2f1e517b1 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java @@ -24,7 +24,6 @@ package org.jclouds.vcloud.terremark.config; import java.io.IOException; -import java.io.InputStream; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; @@ -62,8 +61,8 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule { @Singleton protected Predicate socketTester(SocketOpen open) { return new RetryablePredicate(open, 130, 10, TimeUnit.SECONDS);// make it - // longer - // then + // longer + // then // default internet } @@ -102,13 +101,6 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule { return SyncProxy.create(TerremarkVCloudClient.class, client); } - @Override - protected String provideInstantiateVAppTemplateParams() throws IOException { - InputStream is = getClass().getResourceAsStream( - "/terremark/InstantiateVAppTemplateParams.xml"); - return Utils.toStringAndClose(is); - } - @Singleton @Provides @Named("CreateInternetService") diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOption.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOptions.java similarity index 81% rename from vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOption.java rename to vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOptions.java index a9dd3362a1..c9c652247a 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOption.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOptions.java @@ -32,12 +32,12 @@ package org.jclouds.vcloud.terremark.domain; * href="https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/6-using-the-vcloud-express-api.aspx" * >Terremark documentation */ -public class ComputeOption implements Comparable { +public class ComputeOptions implements Comparable { private final int processorCount; private final long memory; private final float costPerHour; - public ComputeOption(int processorCount, long memory, float costPerHour) { + public ComputeOptions(int processorCount, long memory, float costPerHour) { this.processorCount = processorCount; this.memory = memory; this.costPerHour = costPerHour; @@ -56,25 +56,14 @@ public class ComputeOption implements Comparable { } /** - * orders processor, memory, then cost. + * orders by cost */ - public int compareTo(ComputeOption that) { + public int compareTo(ComputeOptions that) { if (this == that) return 0; - double compareThis = compare(this); - double compareThat = compare(that); - if (compareThis < compareThat) + if (this.costPerHour < that.costPerHour) return -1; - if (compareThis > compareThat) - return 1; - return 0; - } - - private double compare(ComputeOption option) { - double comparison = processorCount * 20000; - comparison += memory; - comparison += costPerHour; - return comparison; + return 1; } @Override @@ -95,7 +84,7 @@ public class ComputeOption implements Comparable { return false; if (getClass() != obj.getClass()) return false; - ComputeOption other = (ComputeOption) obj; + ComputeOptions other = (ComputeOptions) obj; if (Float.floatToIntBits(costPerHour) != Float.floatToIntBits(other.costPerHour)) return false; if (memory != other.memory) diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/CustomizationParameters.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/CustomizationParameters.java index e56455e502..1988439ccc 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/CustomizationParameters.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/CustomizationParameters.java @@ -41,11 +41,11 @@ public class CustomizationParameters { this.customizePassword = customizePassword; } - public boolean isCustomizeNetwork() { + public boolean canCustomizeNetwork() { return customizeNetwork; } - public boolean isCustomizePassword() { + public boolean canCustomizePassword() { return customizePassword; } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java index e0874ad6c8..745d457cff 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java @@ -24,6 +24,7 @@ package org.jclouds.vcloud.terremark.options; import java.net.URI; +import java.util.Map; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -34,41 +35,45 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; */ public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemplateOptions { - private String password; - private String group; - private String row; - public TerremarkInstantiateVAppTemplateOptions withPassword(String password) { - this.password = password; + productProperty("password", password); return this; } public TerremarkInstantiateVAppTemplateOptions inGroup(String group) { - this.group = group; + productProperty("group", group); return this; } public TerremarkInstantiateVAppTemplateOptions inRow(String row) { - this.row = row; + productProperty("row", row); return this; } public static class Builder { /** - * @see TerremarkInstantiateVAppTemplateOptions#cpuCount(int) + * @see TerremarkInstantiateVAppTemplateOptions#processorCount(int) */ - public static TerremarkInstantiateVAppTemplateOptions cpuCount(int cpuCount) { + public static TerremarkInstantiateVAppTemplateOptions processorCount(int cpuCount) { TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); - return options.cpuCount(cpuCount); + return options.processorCount(cpuCount); } /** - * @see TerremarkInstantiateVAppTemplateOptions#megabytes(int) + * @see TerremarkInstantiateVAppTemplateOptions#memory(long) */ - public static TerremarkInstantiateVAppTemplateOptions megabytes(int megabytes) { + public static TerremarkInstantiateVAppTemplateOptions memory(long megabytes) { TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); - return options.megabytes(megabytes); + return options.memory(megabytes); + } + + /** + * @see TerremarkInstantiateVAppTemplateOptions#disk(long) + */ + public static TerremarkInstantiateVAppTemplateOptions disk(long kilobytes) { + TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); + return options.disk(kilobytes); } /** @@ -103,11 +108,28 @@ public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemp return options.inRow(row); } + /** + * @see TerremarkInstantiateVAppTemplateOptions#productProperty(String, String) + */ + public static TerremarkInstantiateVAppTemplateOptions productProperty(String key, String value) { + TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); + return (TerremarkInstantiateVAppTemplateOptions) options.productProperty(key, value); + } + + /** + * @see TerremarkInstantiateVAppTemplateOptions#productProperties(Map) + */ + public static TerremarkInstantiateVAppTemplateOptions productProperties( + Map properties) { + TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); + return (TerremarkInstantiateVAppTemplateOptions) options.productProperties(properties); + } + } @Override - public TerremarkInstantiateVAppTemplateOptions cpuCount(int cpuCount) { - return (TerremarkInstantiateVAppTemplateOptions) super.cpuCount(cpuCount); + public TerremarkInstantiateVAppTemplateOptions processorCount(int cpuCount) { + return (TerremarkInstantiateVAppTemplateOptions) super.processorCount(cpuCount); } @Override @@ -116,19 +138,22 @@ public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemp } @Override - public TerremarkInstantiateVAppTemplateOptions megabytes(int megabytes) { - return (TerremarkInstantiateVAppTemplateOptions) super.megabytes(megabytes); + public TerremarkInstantiateVAppTemplateOptions memory(long megabytes) { + return (TerremarkInstantiateVAppTemplateOptions) super.memory(megabytes); } - public String getPassword() { - return password; + @Override + public TerremarkInstantiateVAppTemplateOptions disk(long kilobytes) { + throw new IllegalArgumentException("changing the boot disk size is unsupported in terremark"); } - public String getGroup() { - return group; + @Override + public TerremarkInstantiateVAppTemplateOptions productProperties(Map properties) { + return (TerremarkInstantiateVAppTemplateOptions) super.productProperties(properties); } - public String getRow() { - return row; + @Override + public TerremarkInstantiateVAppTemplateOptions productProperty(String key, String value) { + return (TerremarkInstantiateVAppTemplateOptions) super.productProperty(key, value); } } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandler.java index d3faaa7eeb..d547bb075f 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandler.java @@ -24,12 +24,12 @@ package org.jclouds.vcloud.terremark.xml; import org.jclouds.http.functions.ParseSax.HandlerWithResult; -import org.jclouds.vcloud.terremark.domain.ComputeOption; +import org.jclouds.vcloud.terremark.domain.ComputeOptions; /** * @author Adrian Cole */ -public class ComputeOptionHandler extends HandlerWithResult { +public class ComputeOptionHandler extends HandlerWithResult { private StringBuilder currentText = new StringBuilder(); @@ -43,8 +43,8 @@ public class ComputeOptionHandler extends HandlerWithResult { } @Override - public ComputeOption getResult() { - return new ComputeOption(processorCount, memory, costPerHour); + public ComputeOptions getResult() { + return new ComputeOptions(processorCount, memory, costPerHour); } public void endElement(String uri, String name, String qName) { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandler.java index 91a15639d9..4931e39ba6 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandler.java @@ -30,7 +30,7 @@ import javax.inject.Inject; import org.jclouds.http.functions.ParseSax.HandlerWithResult; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.terremark.domain.ComputeOption; +import org.jclouds.vcloud.terremark.domain.ComputeOptions; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -39,12 +39,12 @@ import com.google.common.collect.Sets; /** * @author Adrian Cole */ -public class ComputeOptionsHandler extends HandlerWithResult> { +public class ComputeOptionsHandler extends HandlerWithResult> { @Resource protected Logger logger = Logger.NULL; private final ComputeOptionHandler handler; - SortedSet result = Sets.newTreeSet(); + SortedSet result = Sets.newTreeSet(); @Inject public ComputeOptionsHandler(ComputeOptionHandler handler) { @@ -52,7 +52,7 @@ public class ComputeOptionsHandler extends HandlerWithResult getResult() { + public SortedSet getResult() { return result; } diff --git a/vcloud/terremark/src/main/resources/terremark/InstantiateVAppTemplateParams.xml b/vcloud/terremark/src/main/resources/terremark/InstantiateVAppTemplateParams.xml deleted file mode 100644 index cbd57e8c19..0000000000 --- a/vcloud/terremark/src/main/resources/terremark/InstantiateVAppTemplateParams.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - 1 - 3 - {count} - - - 2 - 4 - {megabytes} - - - - - - - - - diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java index e8c93e2469..19544b79cb 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java @@ -57,20 +57,22 @@ public class InternetServiceLiveTest { @Test public void testGetAllInternetServices() throws Exception { - SortedSet set = tmClient.getAllInternetServices(); + SortedSet set = tmClient.getAllInternetServicesInVDC(tmClient + .getDefaultVDC().getId()); print(set); } @Test public void testAddInternetService() throws InterruptedException { - InternetService is = tmClient.addInternetService("test-" + 22, Protocol.TCP, 22); + InternetService is = tmClient.addInternetServiceToVDC(tmClient.getDefaultVDC().getId(), + "test-" + 22, Protocol.TCP, 22); services.add(is); PublicIpAddress ip = is.getPublicIpAddress(); // current bug in terremark -// for (int port : new int[] { 80, 8080 }) { -// services.add(tmClient.addInternetServiceToExistingIp(ip.getId(), "test-" + port, -// Protocol.HTTP, port)); -// } + // for (int port : new int[] { 80, 8080 }) { + // services.add(tmClient.addInternetServiceToExistingIp(ip.getId(), "test-" + port, + // Protocol.HTTP, port)); + // } print(tmClient.getInternetServicesOnPublicIp(ip.getId())); } @@ -86,7 +88,8 @@ public class InternetServiceLiveTest { @Test public void testGetAllPublicIps() throws Exception { - for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC()) { + for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.getDefaultVDC() + .getId())) { SortedSet set = tmClient.getInternetServicesOnPublicIp(ip.getId()); print(set); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java index 6d3d4ff732..91cac9ec94 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java @@ -23,14 +23,8 @@ */ package org.jclouds.vcloud.terremark; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled; -import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -38,6 +32,7 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.InetAddress; import java.net.URI; +import java.util.Properties; import javax.inject.Named; import javax.inject.Provider; @@ -63,6 +58,7 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.domain.Protocol; 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.ComputeOptionsHandler; import org.jclouds.vcloud.terremark.xml.CustomizationParametersHandler; import org.jclouds.vcloud.terremark.xml.InternetServiceHandler; @@ -77,7 +73,6 @@ import com.google.inject.AbstractModule; import com.google.inject.Module; import com.google.inject.Provides; import com.google.inject.TypeLiteral; -import com.google.inject.util.Providers; /** * Tests behavior of {@code TerremarkVCloudAsyncClient} @@ -102,19 +97,35 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, + "1"); + + assertRequestLineEquals(httpMethod, "GET http://vcloud/vdc/1 HTTP/1.1"); + assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate", + Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", String.class, String.class, String.class, Array.newInstance( InstantiateVAppTemplateOptions.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, - "name", 3 + "", "1"); + "1", "name", 3 + ""); assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertHeadersEqual( httpMethod, - "Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); + "Content-Length: 1649\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( "/terremark/InstantiateVAppTemplateParams-test.xml"))); @@ -127,18 +138,19 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "name", 3 + "", "1", cpuCount(4).megabytes(1024).inNetwork( - URI.create("http://newnet"))); + "1", "name", 3 + "", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount( + 1).memory(512).inRow("row").inGroup("group").withPassword("password") + .inNetwork(URI.create("http://network"))); assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertHeadersEqual( httpMethod, - "Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); + "Content-Length: 1912\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( "/terremark/InstantiateVAppTemplateParams-options-test.xml"))); @@ -151,13 +163,13 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "name", Protocol.TCP, 22); + "1", "name", Protocol.TCP, 22); - assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1"); + assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/internetServices HTTP/1.1"); assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n"); assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( "/terremark/CreateInternetService-test2.xml"))); @@ -171,13 +183,13 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "name", Protocol.TCP, 22, disabled().withDescription("yahoo")); + "1", "name", Protocol.TCP, 22, disabled().withDescription("yahoo")); - assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1"); + assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/internetServices HTTP/1.1"); assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n"); assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( "/terremark/CreateInternetService-options-test.xml"))); @@ -190,10 +202,12 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method); + Method method = TerremarkVCloudAsyncClient.class.getMethod("getAllInternetServicesInVDC", + String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + "1"); - assertRequestLineEquals(httpMethod, "GET http://vdc/internetServices HTTP/1.1"); + assertRequestLineEquals(httpMethod, "GET http://vcloud/vdc/1/internetServices HTTP/1.1"); assertHeadersEqual(httpMethod, ""); assertPayloadEquals(httpMethod, null); @@ -366,8 +380,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); @@ -382,9 +398,9 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); @@ -401,6 +417,43 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, + 12); + + assertRequestLineEquals(httpMethod, "GET http://vcloud/catalogItem/12/options/compute HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertPayloadEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, ComputeOptionsHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + public void testGetCustomizationOptionsOfCatalogItem() throws SecurityException, + NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod( + "getCustomizationOptionsOfCatalogItem", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); + + assertRequestLineEquals(httpMethod, + "GET http://vcloud/catalogItem/12/options/customization HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertPayloadEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, CustomizationParametersHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + @Override protected void checkFilters(GeneratedHttpRequest httpMethod) { assertEquals(httpMethod.getFilters().size(), 1); @@ -418,21 +471,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest of("group")); - bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW)) - .toProvider(Providers. of("row")); - bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD)) - .toProvider(Providers. of("password")); - bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT)) - .toProvider(Providers. of("1")); - bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)) - .toProvider(Providers. of("512")); - bind(String.class) - .annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK)) - .toProvider( - Providers - . of("https://vcloud.safesecureweb.com/network/1990")); + Properties props = new Properties(); + props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK, + "https://vcloud.safesecureweb.com/network/1990"); + Jsr330.bindProperties(binder(), new TerremarkVCloudPropertiesBuilder(props).build()); bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog")); bind(String.class).annotatedWith(CatalogItemRoot.class) .toInstance("http://catalogItem"); @@ -456,15 +498,6 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest options = tmClient + .getComputeOptionsOfCatalogItem(item.getId()); + assert options.size() == 32 || options.size() == 20 : item.getId() + ": " + + options.size(); + assert tmClient.getCustomizationOptionsOfCatalogItem(item.getId()) != null; + } } } @@ -104,20 +128,39 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException, IOException { String serverName = "adriantest"; - int processorCount = 1; - int memory = 512; - // long hardDisk = 4194304; - // String catalogOs = "Ubuntu JeOS 9.04 (32-bit)"; - // String expectedOs = "Ubuntu Linux (32-bit)"; - long hardDisk = 4194304 / 4 * 10; - String catalogOs = "CentOS 5.3 (32-bit)"; - String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)"; + long hardDisk = 4194304; - String templateId = tmClient.getCatalog().get(catalogOs).getId(); + String expectedOs = "Ubuntu Linux (32-bit)"; + // long hardDisk = 4194304 / 4 * 10; + // String catalogOs = "CentOS 5.3 (32-bit)"; + // String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)"; + + // lookup the id of the datacenter you are deploying into String vDCId = tmClient.getDefaultVDC().getId(); - System.out.printf("%d: instantiating vApp%n", System.currentTimeMillis()); - vApp = tmClient.instantiateVAppTemplate(serverName, templateId, vDCId); + // lookup the id of the item in the catalog you wish to deploy by name + String itemId = tmClient.getCatalog().get("Ubuntu JeOS 9.04 (32-bit)").getId(); + + // determine the cheapest configuration size + SortedSet sizeOptions = tmClient.getComputeOptionsOfCatalogItem(itemId); + ComputeOptions cheapestOption = sizeOptions.first(); + + // create an options object to collect the configuration we want. + TerremarkInstantiateVAppTemplateOptions instantiateOptions = processorCount( + cheapestOption.getProcessorCount()).memory(cheapestOption.getMemory()); + + // if this template supports setting the root password, let's add it to our options + CustomizationParameters customizationOptions = tmClient + .getCustomizationOptionsOfCatalogItem(itemId); + if (customizationOptions.canCustomizePassword()) + instantiateOptions.withPassword("robotsarefun"); + + // the vAppTemplateId tends to be the same as the itemId, but just in case, convert + String vAppTemplateId = tmClient.getCatalogItem(itemId).getEntity().getId(); + + // instantiate, noting vApp returned has minimal details + vApp = tmClient.instantiateVAppTemplateInVDC(vDCId, serverName, vAppTemplateId, + instantiateOptions); assertEquals(vApp.getStatus(), VAppStatus.UNRESOLVED); @@ -147,6 +190,8 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { NamedResource vAppResource = tmClient.getDefaultVDC().getResourceEntities().get(serverName); assertEquals(vAppResource.getId(), vApp.getId()); + int processorCount = cheapestOption.getProcessorCount(); + long memory = cheapestOption.getMemory(); verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk); assertEquals(vApp.getStatus(), VAppStatus.OFF); @@ -155,14 +200,15 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { vApp = tmClient.getVApp(vApp.getId()); assertEquals(vApp.getStatus(), VAppStatus.ON); - System.out.println(tmClient.getComputeOptions(vApp.getId())); - System.out.println(tmClient.getCustomizationOptions(vApp.getId())); + System.out.println(tmClient.getComputeOptionsOfVApp(vApp.getId())); + System.out.println(tmClient.getCustomizationOptionsOfVApp(vApp.getId())); } @Test public void testAddInternetService() throws InterruptedException, ExecutionException, TimeoutException, IOException { - is = tmClient.addInternetService("SSH", Protocol.TCP, 22); + is = tmClient.addInternetServiceToVDC(tmClient.getDefaultVDC().getId(), "SSH", Protocol.TCP, + 22); } @Test(dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" }) @@ -208,7 +254,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { } private void verifyConfigurationOfVApp(TerremarkVApp vApp, String serverName, String expectedOs, - int processorCount, int memory, long hardDisk) { + int processorCount, long memory, long hardDisk) { assertEquals(vApp.getName(), serverName); assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR) diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest.java index 64ba2beb23..9ac6a47f8b 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -23,27 +23,23 @@ */ package org.jclouds.vcloud.terremark.binders; +import static com.google.common.base.Preconditions.checkNotNull; + import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.replay; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD; -import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; import java.io.IOException; -import java.io.InputStream; import java.net.URI; import java.util.Map; - -import javax.inject.Named; -import javax.inject.Singleton; +import java.util.Properties; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; +import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder; +import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.testng.annotations.Test; import com.google.common.collect.HashMultimap; @@ -53,110 +49,54 @@ import com.google.common.collect.Multimaps; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.Provides; -import com.google.inject.util.Providers; /** - * Tests behavior of {@code - * TerremarkBindInstantiateVAppTemplateParamsToXmlPayload} + * Tests behavior of {@code TerremarkBindInstantiateVAppTemplateParamsToXmlPayload} * * @author Adrian Cole */ @Test(groups = "unit", testName = "vcloud.TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest") public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_TERREMARK_DEFAULTGROUP)).toProvider( - Providers. of("group")); - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW)).toProvider( - Providers. of("row")); - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD)) - .toProvider(Providers. of("password")); - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT)).toProvider( - Providers. of("1")); - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)).toProvider( - Providers. of("512")); - bind(String.class) - .annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK)) - .toProvider( - Providers - . of("https://vcloud.safesecureweb.com/network/1990")); - } + @Override + protected void configure() { + Properties props = new Properties(); + props + .put(PROPERTY_VCLOUD_DEFAULT_NETWORK, + "https://vcloud.safesecureweb.com/network/1990"); + Jsr330.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props) + .build(), "properties")); + } - @SuppressWarnings("unused") - @Singleton - @Provides - @Named("InstantiateVAppTemplateParams") - String provideInstantiateVAppTemplateParams() throws IOException { - InputStream is = getClass().getResourceAsStream( - "/terremark/InstantiateVAppTemplateParams.xml"); - return Utils.toStringAndClose(is); - } - }); + }); - public void testApplyInputStream() throws IOException { + public void testAllOptions() throws IOException { - String expected = Utils.toStringAndClose(getClass().getResourceAsStream( - "/terremark/InstantiateVAppTemplateParams-test-2.xml")); - Multimap headers = Multimaps - .synchronizedMultimap(HashMultimap. create()); - GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getEndpoint()).andReturn( - URI.create("http://localhost/key")).anyTimes(); - expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); - expect(request.getFirstHeaderOrNull("Content-Type")).andReturn( - "application/unknown").atLeastOnce(); - expect(request.getHeaders()).andReturn(headers).atLeastOnce(); - request.setPayload(expected); - replay(request); + String expected = Utils.toStringAndClose(getClass().getResourceAsStream( + "/terremark/InstantiateVAppTemplateParams-options-test.xml")); + Multimap headers = Multimaps.synchronizedMultimap(HashMultimap + . create()); + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn( + new Object[] { TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(1) + .memory(512).inRow("row").inGroup("group").withPassword( + "password").inNetwork(URI.create("http://network")) }) + .atLeastOnce(); + expect(request.getFirstHeaderOrNull("Content-Type")).andReturn("application/unknown") + .atLeastOnce(); + expect(request.getHeaders()).andReturn(headers).atLeastOnce(); + request.setPayload(expected); + replay(request); - TerremarkBindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class); + TerremarkBindInstantiateVAppTemplateParamsToXmlPayload binder = injector + .getInstance(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class); - Map map = Maps.newHashMap(); - map.put("name", "name"); - map.put("password", "password"); - map.put("row", "row"); - map.put("group", "group"); - map.put("template", "http://catalogItem/3"); - map.put("count", "1"); - map.put("megabytes", "512"); - map.put("network", "http://network"); - binder.bindToRequest(request, map); - } + Map map = Maps.newHashMap(); + map.put("name", "name"); + map.put("template", "http://catalogItem/3"); + binder.bindToRequest(request, map); + } - public void testApplyInputStream2() throws IOException { - - String expected = Utils.toStringAndClose(getClass().getResourceAsStream( - "/terremark/InstantiateVAppTemplateParams-test-2.xml")); - Multimap headers = Multimaps - .synchronizedMultimap(HashMultimap. create()); - GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getEndpoint()).andReturn( - URI.create("http://localhost/key")).anyTimes(); - expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); - expect(request.getFirstHeaderOrNull("Content-Type")).andReturn( - "application/unknown").atLeastOnce(); - expect(request.getHeaders()).andReturn(headers).atLeastOnce(); - request.setPayload(expected); - replay(request); - - TerremarkBindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class); - - Map map = Maps.newHashMap(); - map.put("name", "name"); - map.put("template", "http://catalogItem/3"); - map.put("count", "1"); - map.put("megabytes", "512"); - map.put("network", "http://network"); - binder.bindToRequest(request, map); - } } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java index 145cfa0782..71e938efe0 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java @@ -45,6 +45,7 @@ import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.CaseFormat; import com.google.common.base.Predicate; import com.google.inject.Injector; import com.google.inject.Key; @@ -77,11 +78,9 @@ public class TerremarkVCloudComputeClientLiveTest { } private Map expectationMap = ImmutableMap. builder() - .put(Image.CENTOS_53, - new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( - Image.RHEL_53, - new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( - Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put( + .put(Image.CENTOS_53, new Expectation(10485760, "Red Hat Enterprise Linux 5 (64-bit)")) + .put(Image.RHEL_53, new Expectation(10485760, "Red Hat Enterprise Linux 5 (64-bit)")) + .put(Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put( Image.UMBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build(); private Predicate addressTester; @@ -94,8 +93,9 @@ public class TerremarkVCloudComputeClientLiveTest { String serverName = getCompatibleServerName(toTest); int processorCount = 1; int memory = 512; + Map properties = ImmutableMap.of(); - id = client.start(serverName, processorCount, memory, toTest); + id = client.start(serverName, toTest, processorCount, memory, properties); Expectation expectation = expectationMap.get(toTest); TerremarkVApp vApp = tmClient.getVApp(id); @@ -105,8 +105,9 @@ public class TerremarkVCloudComputeClientLiveTest { } private String getCompatibleServerName(Image toTest) { - String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0, - toTest.toString().length() <= 15 ? toTest.toString().length() : 14); + String serverName = CaseFormat.UPPER_UNDERSCORE + .to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0, + toTest.toString().length() <= 15 ? toTest.toString().length() : 14); return serverName; } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java index 8a86dcb6c0..78432af47f 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java @@ -66,10 +66,6 @@ public class TerremarkVCloudRestClientModuleTest { @Test void postStrings() throws IOException { - assertEquals(createInjector().getInstance( - Key.get(String.class, Jsr330.named("InstantiateVAppTemplateParams"))), Utils - .toStringAndClose(getClass().getResourceAsStream( - "/terremark/InstantiateVAppTemplateParams.xml"))); assertEquals(createInjector().getInstance( Key.get(String.class, Jsr330.named("CreateInternetService"))), Utils .toStringAndClose(getClass().getResourceAsStream( diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptionsTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptionsTest.java index f64be49a6c..64777d4677 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptionsTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptionsTest.java @@ -23,11 +23,13 @@ */ package org.jclouds.vcloud.terremark.options; -import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount; +import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inGroup; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inNetwork; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inRow; -import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.megabytes; +import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.memory; +import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.disk; + import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.withPassword; import static org.testng.Assert.assertEquals; @@ -53,39 +55,39 @@ public class TerremarkInstantiateVAppTemplateOptionsTest { public void testInGroup() { TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); options.inGroup("group1"); - assertEquals(options.getGroup(), "group1"); + assertEquals(options.getProperties().get("group"), "group1"); } @Test public void testInGroupStatic() { TerremarkInstantiateVAppTemplateOptions options = inGroup("group1"); - assertEquals(options.getGroup(), "group1"); + assertEquals(options.getProperties().get("group"), "group1"); } @Test public void testInRow() { TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); options.inRow("row1"); - assertEquals(options.getRow(), "row1"); + assertEquals(options.getProperties().get("row"), "row1"); } @Test public void testInRowStatic() { TerremarkInstantiateVAppTemplateOptions options = inRow("row1"); - assertEquals(options.getRow(), "row1"); + assertEquals(options.getProperties().get("row"), "row1"); } @Test public void testWithPassword() { TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); options.withPassword("password1"); - assertEquals(options.getPassword(), "password1"); + assertEquals(options.getProperties().get("password"), "password1"); } @Test public void testWithPasswordStatic() { TerremarkInstantiateVAppTemplateOptions options = withPassword("password1"); - assertEquals(options.getPassword(), "password1"); + assertEquals(options.getProperties().get("password"), "password1"); } @Test @@ -103,30 +105,42 @@ public class TerremarkInstantiateVAppTemplateOptionsTest { @Test public void testCpuCount() { - assertEquals(cpuCount(3).getCpuCount(), "3"); + assertEquals(processorCount(3).getCpuCount(), "3"); } @Test public void testCpuCountStatic() { - TerremarkInstantiateVAppTemplateOptions options = cpuCount(3); + TerremarkInstantiateVAppTemplateOptions options = processorCount(3); assertEquals(options.getCpuCount(), "3"); } @Test public void testMegabytes() { TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); - options.megabytes(512); - assertEquals(options.getMegabytes(), "512"); + options.memory(512); + assertEquals(options.getMemorySizeMegabytes(), "512"); } @Test public void testMegabytesStatic() { - TerremarkInstantiateVAppTemplateOptions options = megabytes(512); - assertEquals(options.getMegabytes(), "512"); + TerremarkInstantiateVAppTemplateOptions options = memory(512); + assertEquals(options.getMemorySizeMegabytes(), "512"); } @Test(expectedExceptions = IllegalArgumentException.class) public void testMegabytesStaticWrong() { - megabytes(511); + memory(511); } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testDiskSizeKilobytes() { + TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); + options.disk(512); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testDiskSizeKilobytesStatic() { + disk(512); + } + } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandlerTest.java index c26aa7c981..b61df42f23 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandlerTest.java @@ -29,7 +29,7 @@ import java.io.InputStream; import java.net.UnknownHostException; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.vcloud.terremark.domain.ComputeOption; +import org.jclouds.vcloud.terremark.domain.ComputeOptions; import org.testng.annotations.Test; /** @@ -43,8 +43,8 @@ public class ComputeOptionHandlerTest extends BaseHandlerTest { public void test1() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/terremark/ComputeOption.xml"); - ComputeOption result = (ComputeOption) factory.create( + ComputeOptions result = (ComputeOptions) factory.create( injector.getInstance(ComputeOptionHandler.class)).parse(is); - assertEquals(result, new ComputeOption(1, 512, 0.039f)); + assertEquals(result, new ComputeOptions(1, 512, 0.039f)); } } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandlerTest.java index 9f508a2c0d..e5d8015ddd 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandlerTest.java @@ -30,7 +30,7 @@ import java.net.UnknownHostException; import java.util.SortedSet; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.vcloud.terremark.domain.ComputeOption; +import org.jclouds.vcloud.terremark.domain.ComputeOptions; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSortedSet; @@ -46,9 +46,9 @@ public class ComputeOptionsHandlerTest extends BaseHandlerTest { public void test1() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/terremark/ComputeOptions.xml"); - SortedSet result = factory.create( + SortedSet result = factory.create( injector.getInstance(ComputeOptionsHandler.class)).parse(is); - assertEquals(result, ImmutableSortedSet.of(new ComputeOption(1, 512, 0.039f), - new ComputeOption(8, 16384, 1.61f))); + assertEquals(result, ImmutableSortedSet.of(new ComputeOptions(1, 512, 0.039f), + new ComputeOptions(8, 16384, 1.61f))); } } diff --git a/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-options-test.xml b/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-options-test.xml index 95b941aafb..dbd51bd717 100644 --- a/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-options-test.xml +++ b/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-options-test.xml @@ -1,38 +1 @@ - - - - - - - - - - - 1 - 3 - 4 - - - 2 - 4 - 1024 - - - - - - - - - +13124512allowInOutfalse \ No newline at end of file diff --git a/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-test-2.xml b/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-test-2.xml deleted file mode 100644 index 954985a7d4..0000000000 --- a/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-test-2.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - 1 - 3 - 1 - - - 2 - 4 - 512 - - - - - - - - - diff --git a/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-test.xml b/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-test.xml index 954985a7d4..9d72f40449 100644 --- a/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-test.xml +++ b/vcloud/terremark/src/test/resources/terremark/InstantiateVAppTemplateParams-test.xml @@ -1,38 +1 @@ - - - - - - - - - - - 1 - 3 - 1 - - - 2 - 4 - 512 - - - - - - - - - +13124512allowInOutfalse \ No newline at end of file