From 22e10f84a6fbdada0d00083217dd9b3e77834a0d Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 13 Aug 2010 20:11:09 -0700 Subject: [PATCH] Issue 306, Issue 327: more progress unraveling vcloud URI-based operations --- .../internal/RestAnnotationProcessor.java | 18 +- .../compute/BlueLockVCloudComputeClient.java | 16 +- ...ParseVAppTemplatesInVDCToSizeProvider.java | 7 +- .../org/jclouds/vcloud/VCloudAsyncClient.java | 110 +++---- .../java/org/jclouds/vcloud/VCloudClient.java | 52 ++-- .../compute/BaseVCloudComputeClient.java | 21 +- .../vcloud/compute/VCloudComputeClient.java | 5 +- .../VCloudComputeServiceContextModule.java | 12 +- .../OrgAndVDCToLocationProvider.java | 4 +- .../vcloud/compute/domain/VCloudLocation.java | 19 +- .../functions/ImageForVAppTemplate.java | 7 +- .../functions/VCloudGetNodeMetadata.java | 49 +--- ...IdIntoNameRunNodesAndAddToSetStrategy.java | 73 ----- .../VCloudAddNodeWithTagStrategy.java | 6 +- .../strategy/VCloudListNodesStrategy.java | 8 +- .../config/BaseVCloudRestClientModule.java | 179 ++++++++++-- .../vcloud/config/VCloudRestClientModule.java | 6 +- .../jclouds/vcloud/domain/CatalogItem.java | 8 +- .../vcloud/domain/internal/CatalogImpl.java | 8 +- .../domain/internal/CatalogItemImpl.java | 16 +- .../functions/AllCatalogItemsInCatalog.java | 4 +- .../functions/AllCatalogsInOrganization.java | 21 +- .../functions/AllVDCsInOrganization.java | 2 +- .../OrgNameAndCatalogNameToEndpoint.java | 4 +- .../OrgNameAndTasksListNameToEndpoint.java | 6 +- .../OrgNameAndVDCNameToEndpoint.java | 6 +- .../OrgNameCatalogNameItemNameToEndpoint.java | 76 +++++ ...CatalogNameVAppTemplateNameToEndpoint.java | 77 +++++ .../functions/OrganizationsForNames.java | 70 +++++ .../functions/OrganizatonsForLocations.java | 28 +- .../VAppTemplatesForCatalogItems.java | 7 +- .../VAppTemplatesForResourceEntities.java | 7 +- .../vcloud/xml/CatalogItemHandler.java | 14 +- .../jclouds/vcloud/VCloudAsyncClientTest.java | 276 +++++++++--------- .../jclouds/vcloud/VCloudClientLiveTest.java | 30 +- .../compute/VCloudComputeClientLiveTest.java | 8 +- ...toNameRunNodesAndAddToSetStrategyTest.java | 88 ------ .../HostingDotComVCloudAsyncClient.java | 31 +- .../HostingDotComVCloudClient.java | 8 +- .../HostingDotComVCloudComputeClient.java | 11 +- ...tingDotComVCloudComputeClientLiveTest.java | 2 +- .../terremark/TerremarkVCloudAsyncClient.java | 90 ++++-- .../terremark/TerremarkVCloudClient.java | 33 ++- .../BindNodeConfigurationToXmlPayload.java | 61 ++-- .../compute/TerremarkVCloudComputeClient.java | 16 +- ...markVCloudComputeServiceContextModule.java | 10 +- ...IdIntoNameRunNodesAndAddToSetStrategy.java | 73 ----- ...erremarkVCloudExpressRestClientModule.java | 2 +- .../terremark/domain/NodeConfiguration.java | 98 ------- .../domain/TerremarkCatalogItem.java | 38 +++ .../internal/TerremarkCatalogItemImpl.java | 88 ++++++ ...eTerremarkVCloudErrorFromHttpResponse.java | 3 + .../xml/TerremarkCatalogItemHandler.java | 59 ++++ .../terremark/TerremarkClientLiveTest.java | 56 ++-- .../TerremarkECloudAsyncClientTest.java | 58 ++-- .../TerremarkVCloudClientLiveTest.java | 4 +- ...TerremarkVCloudExpressAsyncClientTest.java | 146 +++++++-- ...BindNodeConfigurationToXmlPayloadTest.java | 45 +-- .../TerremarkVCloudComputeClientTest.java | 21 +- ...remarkVCloudErrorFromHttpResponseTest.java | 10 +- .../xml/TerremarkCatalogItemHandlerTest.java | 95 ++++++ .../test/resources/terremark/catalogItem.xml | 17 ++ 62 files changed, 1418 insertions(+), 1005 deletions(-) delete mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameCatalogNameItemNameToEndpoint.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameCatalogNameVAppTemplateNameToEndpoint.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrganizationsForNames.java delete mode 100644 vcloud/core/src/test/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest.java delete mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java delete mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/NodeConfiguration.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkCatalogItem.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkCatalogItemImpl.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkCatalogItemHandler.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkCatalogItemHandlerTest.java create mode 100644 vcloud/terremark/src/test/resources/terremark/catalogItem.xml diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 0f1f829780..b7180d9fe2 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -21,6 +21,9 @@ package org.jclouds.rest.internal; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Collections2.filter; +import static com.google.common.collect.Iterables.concat; +import static com.google.common.collect.Iterables.get; +import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newLinkedList; import static com.google.common.collect.Maps.filterValues; @@ -28,6 +31,7 @@ import static com.google.common.collect.Maps.newHashMap; import static com.google.common.collect.Maps.newLinkedHashMap; import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.newHashSet; +import static com.google.common.collect.Sets.newTreeSet; import static java.util.Arrays.asList; import static javax.ws.rs.core.HttpHeaders.ACCEPT; import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE; @@ -53,6 +57,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedSet; import java.util.Map.Entry; import javax.annotation.Nullable; @@ -122,7 +127,6 @@ import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.MapMaker; @@ -460,10 +464,10 @@ public class RestAnnotationProcessor { if (payload == null) payload = findPayloadInArgs(args); - List parts = getParts(method, args, Iterables.concat(tokenValues.entries(), formParams.entries())); + List parts = getParts(method, args, concat(tokenValues.entries(), formParams.entries())); if (parts.size() > 0) { if (formParams.size() > 0) { - parts = newLinkedList(Iterables.concat(Iterables.transform(formParams.entries(), ENTRY_TO_PART), parts)); + parts = newLinkedList(concat(transform(formParams.entries(), ENTRY_TO_PART), parts)); } payload = new MultipartForm(BOUNDARY, parts); } else if (formParams.size() > 0) { @@ -618,7 +622,7 @@ public class RestAnnotationProcessor { Map> map = indexWithAtLeastOneAnnotation(method, methodToIndexOfParamToEndpointParamAnnotations); if (map.size() >= 1 && args.length > 0) { - EndpointParam firstAnnotation = (EndpointParam) Iterables.get(Iterables.get(map.values(), 0), 0); + EndpointParam firstAnnotation = (EndpointParam) get(get(map.values(), 0), 0); Function parser = injector.getInstance(firstAnnotation.parser()); if (map.size() == 1) { @@ -632,7 +636,8 @@ public class RestAnnotationProcessor { throw new IllegalArgumentException(String.format("argument at index %d on method %s", index, method), e); } } else { - Iterable argsToParse = Iterables.transform(map.keySet(), new Function() { + SortedSet keys = newTreeSet(map.keySet()); + Iterable argsToParse = transform(keys, new Function() { @Override public Object apply(Integer from) { @@ -1145,9 +1150,8 @@ public class RestAnnotationProcessor { if (extractors != null && extractors.size() > 0) { ParamParser extractor = (ParamParser) extractors.iterator().next(); paramValue = injector.getInstance(extractor.value()).apply(args[entry.getKey()]); - } else { - paramValue = args[entry.getKey()].toString(); + paramValue = args[entry.getKey()] != null ? args[entry.getKey()].toString() : null; } postParams.put(paramKey, paramValue); diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudComputeClient.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudComputeClient.java index 41e044da16..15b5d71cac 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudComputeClient.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudComputeClient.java @@ -31,6 +31,7 @@ import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.BaseVCloudComputeClient; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; import com.google.common.base.Predicate; @@ -42,21 +43,16 @@ public class BlueLockVCloudComputeClient extends BaseVCloudComputeClient { private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider; @Inject - protected BlueLockVCloudComputeClient( - PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, - VCloudClient client, Predicate successTester, - Map vAppStatusToNodeState) { + protected BlueLockVCloudComputeClient(PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, + VCloudClient client, Predicate successTester, Map vAppStatusToNodeState) { super(client, successTester, vAppStatusToNodeState); this.credentialsProvider = credentialsProvider; } @Override - protected Map parseAndValidateResponse(String templateId, - VApp vAppResponse) { - Credentials credentials = credentialsProvider.execute(client - .getVAppTemplate(templateId)); - Map toReturn = super.parseResponse(templateId, - vAppResponse); + protected Map parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) { + Credentials credentials = credentialsProvider.execute(template); + Map toReturn = super.parseResponse(template, vAppResponse); toReturn.put("username", credentials.identity); toReturn.put("password", credentials.credential); return toReturn; diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/providers/ParseVAppTemplatesInVDCToSizeProvider.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/providers/ParseVAppTemplatesInVDCToSizeProvider.java index 0c593b680b..d7ef164cc1 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/providers/ParseVAppTemplatesInVDCToSizeProvider.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/providers/ParseVAppTemplatesInVDCToSizeProvider.java @@ -65,7 +65,8 @@ public class ParseVAppTemplatesInVDCToSizeProvider implements Provider sizes = Sets.newHashSet(); logger.debug(">> providing vAppTemplates"); for (final NamedResource vDC : client.getDefaultOrganization().getVDCs().values()) { - VDC vdc = client.getVDC(vDC.getId()); + VDC vdc = client.getVDC(vDC.getLocation()); addSizesFromVAppTemplatesInVDC(vdc, sizes); } return sizes; @@ -99,7 +100,7 @@ public class ParseVAppTemplatesInVDCToSizeProvider implements Provider of(), - cores, ram, disk, ImagePredicates.idEquals(id))); + cores, ram, disk, ImagePredicates.idEquals(id))); } catch (NoSuchElementException e) { logger.debug("<< didn't match at all(%s)", resource); } 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 57bc23a8f9..2cd1b59204 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -29,6 +29,8 @@ import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; +import java.net.URI; + import javax.annotation.Nullable; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -44,7 +46,6 @@ import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.MapPayloadParam; -import org.jclouds.rest.annotations.ParamParser; import org.jclouds.rest.annotations.ParamValidators; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; @@ -66,9 +67,9 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameAndTasksListNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameToEndpoint; -import org.jclouds.vcloud.functions.VAppIdToUri; -import org.jclouds.vcloud.functions.VAppTemplateIdToUri; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.xml.CatalogHandler; @@ -106,14 +107,11 @@ public interface VCloudAsyncClient { /** * @see VCloudClient#getOrganization */ - @Deprecated @GET - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/org/{orgId}") @XMLResponseParser(OrgHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) @Consumes(ORG_XML) - ListenableFuture getOrganization(@PathParam("orgId") String orgId); + ListenableFuture getOrganization(@EndpointParam URI orgId); /** * @see VCloudClient#getOrganizationNamed @@ -122,7 +120,7 @@ public interface VCloudAsyncClient { @XMLResponseParser(OrgHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) @Consumes(ORG_XML) - ListenableFuture getOrganizationNamed( + ListenableFuture findOrganizationNamed( @Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName); /** @@ -148,13 +146,13 @@ public interface VCloudAsyncClient { ListenableFuture getCatalog(@PathParam("catalogId") String catalogId); /** - * @see VCloudClient#getCatalogInOrg + * @see VCloudClient#findCatalogInOrgNamed */ @GET @XMLResponseParser(CatalogHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) @Consumes(CATALOG_XML) - ListenableFuture getCatalogInOrg( + ListenableFuture findCatalogInOrgNamed( @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName, @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName); @@ -162,23 +160,43 @@ public interface VCloudAsyncClient { * @see VCloudClient#getVAppTemplate */ @GET - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/vAppTemplate/{vAppTemplateId}") @Consumes(VAPPTEMPLATE_XML) @XMLResponseParser(VAppTemplateHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getVAppTemplate(@PathParam("vAppTemplateId") String vAppTemplateId); + ListenableFuture getVAppTemplate(@EndpointParam URI vAppTemplate); + + /** + * @see VCloudClient#findVAppTemplateInOrgCatalogNameds + */ + @GET + @Consumes(VAPPTEMPLATE_XML) + @XMLResponseParser(VAppTemplateHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findVAppTemplateInOrgCatalogNamed( + @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName); /** * @see VCloudClient#getCatalogItem */ @GET - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/catalogItem/{catalogItemId}") @Consumes(CATALOGITEM_XML) @XMLResponseParser(CatalogItemHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getCatalogItem(@PathParam("catalogItemId") String catalogItemId); + ListenableFuture getCatalogItem(@EndpointParam URI catalogItem); + + /** + * @see VCloudClient#getCatalogItemInOrg + */ + @GET + @Consumes(CATALOGITEM_XML) + @XMLResponseParser(CatalogItemHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findCatalogItemInOrgCatalogNamed( + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName); /** * @see VCloudClient#getNetwork @@ -202,25 +220,22 @@ public interface VCloudAsyncClient { ListenableFuture getDefaultVDC(); /** - * @see VCloudClient#getVDC(String) + * @see VCloudClient#getVDC(URI) */ - @Deprecated @GET - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/vdc/{vDCId}") @XMLResponseParser(VDCHandler.class) @Consumes(VDC_XML) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getVDC(@PathParam("vDCId") String vDCId); + ListenableFuture getVDC(@EndpointParam URI vdc); /** - * @see VCloudClient#getVDCInOrg(String, String) + * @see VCloudClient#findVDCInOrgNamed(String, String) */ @GET @XMLResponseParser(VDCHandler.class) @Consumes(VDC_XML) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getVDCInOrg( + ListenableFuture findVDCInOrgNamed( @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName, @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName); @@ -243,7 +258,7 @@ public interface VCloudAsyncClient { @Consumes(TASKSLIST_XML) @XMLResponseParser(TasksListHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getTasksListInOrg( + ListenableFuture findTasksListInOrgNamed( @Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String orgName, @Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String tasksListName); @@ -364,40 +379,22 @@ public interface VCloudAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getVApp(@PathParam("vAppId") String appId); - /** - * @see VCloudClient#instantiateVAppTemplate - */ - @POST - @Path("/action/instantiateVAppTemplate") - @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") - @Consumes(VAPP_XML) - @XMLResponseParser(VAppHandler.class) - @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) - ListenableFuture instantiateVAppTemplateInOrg( - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName, - @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, - @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, - InstantiateVAppTemplateOptions... options); - /** * @see VCloudClient#instantiateVAppTemplateInVDC */ - @Deprecated @POST - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/vdc/{vDCId}/action/instantiateVAppTemplate") + @Path("action/instantiateVAppTemplate") @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") @Consumes(VAPP_XML) @XMLResponseParser(VAppHandler.class) @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) - ListenableFuture instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId, + ListenableFuture instantiateVAppTemplateInVDC(@EndpointParam URI vdc, + @MapPayloadParam("template") URI template, @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, - @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, InstantiateVAppTemplateOptions... options); /** - * @see VCloudClient#cloneVApp + * @see VCloudClient#cloneVAppInVDC */ @POST @Path("/action/cloneVApp") @@ -405,26 +402,7 @@ public interface VCloudAsyncClient { @Consumes(TASK_XML) @XMLResponseParser(TaskHandler.class) @MapBinder(BindCloneVAppParamsToXmlPayload.class) - ListenableFuture cloneVAppInOrg( - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName, - @MapPayloadParam("vApp") @ParamParser(VAppIdToUri.class) String vAppIdToClone, - @MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, - CloneVAppOptions... options); - - /** - * - * @see VCloudClient#cloneVAppInVDC - */ - @Deprecated - @POST - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/vdc/{vDCId}/action/cloneVApp") - @Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml") - @Consumes(TASK_XML) - @XMLResponseParser(TaskHandler.class) - @MapBinder(BindCloneVAppParamsToXmlPayload.class) - ListenableFuture cloneVAppInVDC(@PathParam("vDCId") String vDCId, - @MapPayloadParam("vApp") @ParamParser(VAppIdToUri.class) String vAppIdToClone, + ListenableFuture cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone, @MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, CloneVAppOptions... 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 c007c5ae81..8d61eae5b8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud; +import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -44,17 +45,14 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; */ @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) public interface VCloudClient { + /** - * Please use {@link #getOrganizationNamed(String)} passing null + * Please use {@link #findOrganizationNamed(String)} passing null */ @Deprecated Organization getDefaultOrganization(); - /** - * Please use #getOrganizationNamed - */ - @Deprecated - Organization getOrganization(String orgId); + Organization getOrganization(URI orgId); /** * This call returns a list of all vCloud Data Centers (vdcs), catalogs, and @@ -63,49 +61,49 @@ public interface VCloudClient { * @param name * organization name, or null for the default */ - Organization getOrganizationNamed(String name); + Organization findOrganizationNamed(String name); /** - * Please use #getCatalogInOrg(null, null) + * Please use #findCatalogInOrgNamed(null, null) */ @Deprecated Catalog getDefaultCatalog(); /** - * Please use #getCatalogInOrg + * Please use #findCatalogInOrgNamed */ @Deprecated Catalog getCatalog(String catalogId); - Catalog getCatalogInOrg(String orgName, String catalogName); + Catalog findCatalogInOrgNamed(String orgName, String catalogName); - CatalogItem getCatalogItem(String catalogItemId); + CatalogItem getCatalogItem(URI catalogItem); - VAppTemplate getVAppTemplate(String vAppTemplateId); + CatalogItem findCatalogItemInOrgCatalogNamed(String orgName, String catalogName, String itemName); + + VAppTemplate getVAppTemplate(URI vAppTemplate); + + VAppTemplate findVAppTemplateInOrgCatalogNamed(String orgName, String catalogName, String templateName); Network getNetwork(String networkId); - /** - * please use {@link #getVDCInOrg} - */ - @Deprecated - VDC getVDC(String vDCId); + VDC getVDC(URI vdc); - VDC getVDCInOrg(String orgName, String vdcName); + VDC findVDCInOrgNamed(String orgName, String vdcName); /** - * Please use #getVDCInOrg(null, null) + * Please use #findVDCInOrgNamed */ @Deprecated VDC getDefaultVDC(); /** - * Please use #getTasksListInOrg + * Please use #findTasksListInOrgNamed */ @Deprecated TasksList getTasksList(String tasksListId); - TasksList getTasksListInOrg(String orgName, String tasksListName); + TasksList findTasksListInOrgNamed(String orgName, String tasksListName); /** * Please use #getTasksListInOrg(null, null) @@ -152,16 +150,8 @@ public interface VCloudClient { VApp getVApp(String appId); - @Deprecated - VApp instantiateVAppTemplateInVDC(String vDCId, String appName, String templateId, - InstantiateVAppTemplateOptions... options); + VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options); - VApp instantiateVAppTemplateInOrg(String org, String vdc, String appName, String templateId, - InstantiateVAppTemplateOptions... options); - - @Deprecated - Task cloneVAppInVDC(String vDCId, String vAppIdToClone, String newName, CloneVAppOptions... options); - - Task cloneVAppInOrg(String org, String vdc, String vAppIdToClone, String newName, CloneVAppOptions... options); + Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java index 962a9494cd..0dd438d12a 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java @@ -22,6 +22,7 @@ package org.jclouds.vcloud.compute; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import java.net.URI; import java.util.Map; import java.util.Set; @@ -37,6 +38,8 @@ import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import com.google.common.base.Predicate; @@ -67,13 +70,15 @@ public class BaseVCloudComputeClient implements VCloudComputeClient { } @Override - public Map start(@Nullable String orgName, @Nullable String vDCName, String name, String templateId, + public Map start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options, int... portsToOpen) { checkNotNull(options, "options"); - logger.debug(">> instantiating vApp org(%s) vDC(%s) name(%s) template(%s) options(%s) ", orgName, vDCName, name, - templateId, options); + logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options); - VApp vAppResponse = client.instantiateVAppTemplateInOrg(orgName, vDCName, name, templateId, options); + VDC vdc = client.getVDC(VDC); + VAppTemplate template = client.getVAppTemplate(templateId); + + VApp vAppResponse = client.instantiateVAppTemplateInVDC(vdc.getLocation(), template.getLocation(), name, options); logger.debug("<< instantiated VApp(%s)", vAppResponse.getId()); logger.debug(">> deploying vApp(%s)", vAppResponse.getId()); @@ -92,18 +97,18 @@ public class BaseVCloudComputeClient implements VCloudComputeClient { } logger.debug("<< on vApp(%s)", vAppResponse.getId()); } - return parseAndValidateResponse(templateId, vAppResponse); + return parseAndValidateResponse(template, vAppResponse); } - protected Map parseAndValidateResponse(String templateId, VApp vAppResponse) { - Map response = parseResponse(templateId, vAppResponse); + protected Map parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) { + Map response = parseResponse(template, vAppResponse); checkState(response.containsKey("id"), "bad configuration: [id] should be in response"); checkState(response.containsKey("username"), "bad configuration: [username] should be in response"); checkState(response.containsKey("password"), "bad configuration: [password] should be in response"); return response; } - protected Map parseResponse(String templateId, VApp vAppResponse) { + protected Map parseResponse(VAppTemplate template, VApp vAppResponse) { Map config = Maps.newLinkedHashMap();// Allows nulls config.put("id", vAppResponse.getId()); config.put("username", null); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeClient.java index d62e1d496f..c24d8a19f7 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeClient.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.compute; +import java.net.URI; import java.util.Map; import java.util.Set; @@ -66,8 +67,8 @@ public interface VCloudComputeClient { * password - console login password * */ - Map start(@Nullable String orgName, @Nullable String vDCName, String name, String templateId, - InstantiateVAppTemplateOptions options, int... portsToOpen); + Map start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options, + int... portsToOpen); /** * returns a set of addresses that are only visible to the private network. diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index 4487dc3379..60dc9d22d4 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -42,6 +42,7 @@ import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; +import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.domain.Location; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; @@ -51,13 +52,14 @@ import org.jclouds.vcloud.compute.BaseVCloudComputeClient; import org.jclouds.vcloud.compute.config.providers.OrgAndVDCToLocationProvider; import org.jclouds.vcloud.compute.config.providers.StaticSizeProvider; import org.jclouds.vcloud.compute.config.providers.VAppTemplatesInVDCs; -import org.jclouds.vcloud.compute.strategy.EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy; +import org.jclouds.vcloud.compute.domain.VCloudLocation; import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy; import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy; import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VDC; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; @@ -106,7 +108,7 @@ public class VCloudComputeServiceContextModule extends AbstractModule { bind(new TypeLiteral>() { }).to(new TypeLiteral>() { }).in(Scopes.SINGLETON); - bind(RunNodesAndAddToSetStrategy.class).to(EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.class); + bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class); bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class); bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class); bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class); @@ -121,7 +123,7 @@ public class VCloudComputeServiceContextModule extends AbstractModule { @Named("NAMING_CONVENTION") @Singleton protected String provideNamingConvention() { - return "%s-%s%s"; + return "%s-%s"; } protected void bindLoadBalancer() { @@ -157,12 +159,12 @@ public class VCloudComputeServiceContextModule extends AbstractModule { @Provides @Singleton Location getVDC(VCloudClient client, Set locations) { - final String vdc = client.getDefaultVDC().getName(); + final VDC vdc = client.findVDCInOrgNamed(null, null); return Iterables.find(locations, new Predicate() { @Override public boolean apply(Location input) { - return input.getId().equals(vdc); + return VCloudLocation.class.cast(input).getResource().getLocation().equals(vdc.getLocation()); } }); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/providers/OrgAndVDCToLocationProvider.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/providers/OrgAndVDCToLocationProvider.java index fa8786bae9..883de89cee 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/providers/OrgAndVDCToLocationProvider.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/providers/OrgAndVDCToLocationProvider.java @@ -44,12 +44,12 @@ import com.google.common.collect.Sets; public class OrgAndVDCToLocationProvider implements Provider> { private final String providerName; private final Supplier> orgNameToResource; - private final Supplier> orgNameToVDCResource; + private final Supplier> orgNameToVDCResource; @Inject OrgAndVDCToLocationProvider(@org.jclouds.rest.annotations.Provider String providerName, @Org Supplier> orgNameToResource, - Supplier> orgNameToVDCResource) { + Supplier> orgNameToVDCResource) { this.providerName = providerName; this.orgNameToResource = orgNameToResource; this.orgNameToVDCResource = orgNameToVDCResource; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudLocation.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudLocation.java index 67d3d92853..9110f6b0d5 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudLocation.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudLocation.java @@ -32,21 +32,18 @@ import org.jclouds.vcloud.domain.NamedResource; */ public class VCloudLocation extends LocationImpl { + private static final long serialVersionUID = -5052812549904524841L; + private final NamedResource resource; + public VCloudLocation(NamedResource resource, Location parent) { + super(checkNotNull(resource, "resource").getType().endsWith("org+xml") ? LocationScope.REGION + : LocationScope.ZONE, resource.getLocation().toASCIIString(), resource.getName(), parent); + this.resource = resource; + } + public NamedResource getResource() { return resource; } - public VCloudLocation(NamedResource resource, Location parent) { - super(checkNotNull(resource, "resource").getType().endsWith("org+xml") ? LocationScope.REGION - : LocationScope.ZONE, resource.getName(), resource.getName(), parent); - this.resource = resource; - } - - /** - * - */ - private static final long serialVersionUID = -5052812549904524841L; - } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java index 9ccd70c9c1..ce7f0bb6fb 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java @@ -46,7 +46,7 @@ public class ImageForVAppTemplate implements Function { @Inject protected ImageForVAppTemplate(FindLocationForResource findLocationForResource, - PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider) { + PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider) { this.findLocationForResource = findLocationForResource; this.credentialsProvider = credentialsProvider; } @@ -63,8 +63,9 @@ public class ImageForVAppTemplate implements Function { Location location = findLocationForResource.apply(parent); String name = getName(from.getName()); String desc = from.getDescription() != null ? from.getDescription() : from.getName(); - return new ImageImpl(from.getId(), name, parent.getId() + "/" + from.getId(), location, from.getLocation(), - ImmutableMap. of(), desc, "", myOs, name, arch, credentialsProvider.execute(from)); + return new ImageImpl(from.getLocation().toASCIIString(), name, from.getLocation().toASCIIString(), location, from + .getLocation(), ImmutableMap. of(), desc, "", myOs, name, arch, credentialsProvider + .execute(from)); } protected String getName(String name) { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java index a4cbd2c41f..219641a788 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java @@ -22,7 +22,6 @@ package org.jclouds.vcloud.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -46,13 +45,11 @@ import org.jclouds.vcloud.compute.VCloudComputeClient; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; /** - * Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient} - * bound. + * Configures the {@link VCloudComputeServiceContext}; requires + * {@link BaseVCloudComputeClient} bound. * * @author Adrian Cole */ @@ -69,16 +66,12 @@ public class VCloudGetNodeMetadata { protected final GetExtra getExtra; protected final Map vAppStatusToNodeState; - // hex [][][] are templateId, last two are instanceId - public static final Pattern TAG_PATTERN_WITH_TEMPLATE = Pattern - .compile("([^-]+)-([0-9a-f][0-9a-f][0-9a-f])[0-9a-f]+"); - public static final Pattern TAG_PATTERN_WITHOUT_TEMPLATE = Pattern.compile("([^-]+)-[0-9]+"); @Inject VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient, - Map vAppStatusToNodeState, GetExtra getExtra, - FindLocationForResource findLocationForResourceInVDC, Provider> images) { + Map vAppStatusToNodeState, GetExtra getExtra, + FindLocationForResource findLocationForResourceInVDC, Provider> images) { this.client = checkNotNull(client, "client"); this.images = checkNotNull(images, "images"); this.getExtra = checkNotNull(getExtra, "getExtra"); @@ -94,37 +87,15 @@ public class VCloudGetNodeMetadata { String tag = null; Image image = null; - Matcher matcher = vApp.getName() != null ? TAG_PATTERN_WITH_TEMPLATE.matcher(vApp.getName()) : null; - - final Location location = findLocationForResourceInVDC.apply(vApp.getVDC()); - if (matcher != null && matcher.find()) { + Matcher matcher = TAG_PATTERN_WITHOUT_TEMPLATE.matcher(vApp.getName()); + if (matcher.find()) { tag = matcher.group(1); - String templateIdInHexWithoutLeadingZeros = matcher.group(2).replaceAll("^[0]+", ""); - final String templateId = Integer.parseInt(templateIdInHexWithoutLeadingZeros, 16) + ""; - try { - image = Iterables.find(images.get(), new Predicate() { - - @Override - public boolean apply(Image input) { - return input.getProviderId().equals(templateId) - && (input.getLocation().equals(location) || input.getLocation().equals(location.getParent())); - } - - }); - } catch (NoSuchElementException e) { - logger.warn("could not find a matching image for vapp %s; vapptemplate %s in location %s", vApp, - templateId, location); - } } else { - matcher = TAG_PATTERN_WITHOUT_TEMPLATE.matcher(vApp.getName()); - if (matcher.find()) { - tag = matcher.group(1); - } else { - tag = "NOTAG-" + vApp.getName(); - } + tag = "NOTAG-" + vApp.getName(); } + Location location = findLocationForResourceInVDC.apply(vApp.getVDC()); return new NodeMetadataImpl(vApp.getId(), vApp.getName(), vApp.getId(), location, vApp.getLocation(), - ImmutableMap. of(), tag, image, vAppStatusToNodeState.get(vApp.getStatus()), - computeClient.getPublicAddresses(id), computeClient.getPrivateAddresses(id), getExtra.apply(vApp), null); + ImmutableMap. of(), tag, image, vAppStatusToNodeState.get(vApp.getStatus()), computeClient + .getPublicAddresses(id), computeClient.getPrivateAddresses(id), getExtra.apply(vApp), null); } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java deleted file mode 100644 index 72a6425620..0000000000 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.compute.strategy; - -import java.security.SecureRandom; -import java.util.concurrent.ExecutorService; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.strategy.AddNodeWithTagStrategy; -import org.jclouds.compute.strategy.ListNodesStrategy; -import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; -import org.jclouds.compute.util.ComputeUtils; - -import com.google.common.base.Strings; - -/** - * - * @author Adrian Cole - */ -@Singleton -public class EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy extends - EncodeTagIntoNameRunNodesAndAddToSetStrategy { - - private final SecureRandom random; - - @Inject - protected EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy( - AddNodeWithTagStrategy addNodeWithTagStrategy, - ListNodesStrategy listNodesStrategy, - @Named("NAMING_CONVENTION") String nodeNamingConvention, - ComputeUtils utils, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, - SecureRandom random) { - super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, - utils, executor); - this.random = random; - } - - /** - * Get a name corresponding to the tag-hex*5 where the first 3 hex correspond - * to the template id and the last a random number - * - */ - @Override - protected String getNextName(final String tag, final Template template) { - return String.format(nodeNamingConvention, tag, Strings.padStart( - Integer.toHexString(Integer.parseInt(template.getImage() - .getProviderId())), 3, '0'), Strings.padStart(Integer - .toHexString(random.nextInt(255)), 2, '0')); - } -} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudAddNodeWithTagStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudAddNodeWithTagStrategy.java index a2e5329d2d..a427da9620 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudAddNodeWithTagStrategy.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudAddNodeWithTagStrategy.java @@ -21,6 +21,7 @@ package org.jclouds.vcloud.compute.strategy; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; +import java.net.URI; import java.util.Map; import javax.inject.Inject; @@ -63,9 +64,8 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy { .memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l); if (!template.getOptions().shouldBlockUntilRunning()) options.blockOnDeploy(false); - Map metaMap = computeClient.start(template.getLocation().getParent().getId(), template - .getLocation().getId(), name, template.getImage().getProviderId(), options, template.getOptions() - .getInboundPorts()); + Map metaMap = computeClient.start(URI.create(template.getLocation().getDescription()), URI + .create(template.getImage().getId()), name, options, template.getOptions().getInboundPorts()); VApp vApp = client.getVApp(metaMap.get("id")); return newCreateNodeResponse(tag, template, metaMap, vApp); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java index 96617b3db7..448a532366 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java @@ -86,8 +86,8 @@ public class VCloudListNodesStrategy implements ListNodesStrategy { public Iterable list() { Set nodes = Sets.newHashSet(); for (String org : orgNameToEndpoint.get().keySet()) { - for (NamedResource vdc : client.getOrganizationNamed(org).getVDCs().values()) { - for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) { + for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) { + for (NamedResource resource : client.getVDC(vdc.getLocation()).getResourceEntities().values()) { if (validVApp(resource)) { nodes.add(convertVAppToComputeMetadata(vdc, resource)); } @@ -111,8 +111,8 @@ public class VCloudListNodesStrategy implements ListNodesStrategy { public Iterable listDetailsOnNodesMatching(Predicate filter) { Set nodes = Sets.newHashSet(); for (String org : orgNameToEndpoint.get().keySet()) { - for (NamedResource vdc : client.getOrganizationNamed(org).getVDCs().values()) { - for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) { + for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) { + for (NamedResource resource : client.getVDC(vdc.getLocation()).getResourceEntities().values()) { if (validVApp(resource) && filter.apply(convertVAppToComputeMetadata(vdc, resource))) { addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java index 3b598ecb3f..eb91141454 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java @@ -21,6 +21,12 @@ package org.jclouds.vcloud.config; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Throwables.propagate; +import static com.google.common.collect.Iterables.get; +import static com.google.common.collect.Iterables.getLast; +import static com.google.common.collect.Maps.newLinkedHashMap; +import static com.google.common.collect.Maps.transformValues; +import static com.google.common.collect.Maps.uniqueIndex; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_IDENTITY; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; @@ -56,6 +62,7 @@ import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSu import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudToken; +import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.endpoints.Catalog; @@ -68,17 +75,18 @@ 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.functions.AllCatalogItemsInCatalog; +import org.jclouds.vcloud.functions.AllCatalogsInOrganization; +import org.jclouds.vcloud.functions.OrganizationsForNames; import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient; import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; import org.jclouds.vcloud.predicates.TaskSuccess; +import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; import com.google.inject.Provides; import com.google.inject.TypeLiteral; @@ -126,27 +134,27 @@ public abstract class BaseVCloudRestClientModule orgs) { - return Iterables.getLast(orgs).getLocation(); + return getLast(orgs).getLocation(); } @Provides @Org @Singleton protected String provideOrgName(@Org Iterable orgs) { - return Iterables.getLast(orgs).getName(); + return getLast(orgs).getName(); } @Provides @Singleton @VDC protected Supplier> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final Supplier> orgToVDCSupplier) { + final Supplier> orgToVDCSupplier) { return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, seconds, new Supplier>() { @Override public Map get() { - Map returnVal = Maps.newLinkedHashMap(); - for (Entry orgr : orgToVDCSupplier.get().entrySet()) { + Map returnVal = newLinkedHashMap(); + for (Entry orgr : orgToVDCSupplier.get().entrySet()) { for (String vdc : orgr.getValue().getVDCs().keySet()) { returnVal.put(vdc, orgr.getKey()); } @@ -187,7 +195,7 @@ public abstract class BaseVCloudRestClientModule> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final OrganizationMapSupplier supplier) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, - seconds, new Supplier>() { + protected Supplier> provideOrgMapCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationMapSupplier supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( + authException, seconds, new Supplier>() { @Override - public Map get() { + public Map get() { + return supplier.get(); + } + + }); + } + + private final static Function name = new Function() { + + @Override + public String apply(NamedResource from) { + return from.getName(); + } + + }; + + @Singleton + public static class OrganizationMapSupplier implements Supplier> { + protected final Supplier sessionSupplier; + private final OrganizationsForNames organizationsForNames; + + @Inject + protected OrganizationMapSupplier(Supplier sessionSupplier, + OrganizationsForNames organizationsForNames) { + this.sessionSupplier = sessionSupplier; + this.organizationsForNames = organizationsForNames; + } + + @Override + public Map get() { + return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name); + } + } + + @Singleton + public static class OrganizationCatalogSupplier implements + Supplier>> { + protected final Supplier> orgSupplier; + private final AllCatalogsInOrganization allCatalogsInOrganization; + + @Inject + protected OrganizationCatalogSupplier(Supplier> orgSupplier, + AllCatalogsInOrganization allCatalogsInOrganization) { + this.orgSupplier = orgSupplier; + this.allCatalogsInOrganization = allCatalogsInOrganization; + } + + @Override + public Map> get() { + return transformValues( + transformValues(orgSupplier.get(), allCatalogsInOrganization), + new Function, Map>() { + + @Override + public Map apply( + Iterable from) { + return uniqueIndex(from, name); + } + + }); + } + } + + @Provides + @Singleton + protected Supplier>> provideOrganizationCatalogItemMapSupplierCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogSupplier supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>( + authException, seconds, + new Supplier>>() { + @Override + public Map> get() { return supplier.get(); } @@ -211,25 +290,55 @@ public abstract class BaseVCloudRestClientModule> { - protected final Supplier sessionSupplier; - private final VCloudClient client; + public static class OrganizationCatalogItemSupplier implements + Supplier>>> { + protected final Supplier>> catalogSupplier; + private final AllCatalogItemsInCatalog allCatalogItemsInCatalog; @Inject - protected OrganizationMapSupplier(Supplier sessionSupplier, VCloudClient client) { - this.sessionSupplier = sessionSupplier; - this.client = client; + protected OrganizationCatalogItemSupplier( + Supplier>> catalogSupplier, + AllCatalogItemsInCatalog allCatalogItemsInCatalog) { + this.catalogSupplier = catalogSupplier; + this.allCatalogItemsInCatalog = allCatalogItemsInCatalog; } @Override - public Map get() { - Map returnVal = Maps.newLinkedHashMap(); - for (String orgName : sessionSupplier.get().getOrgs().keySet()) { - returnVal.put(orgName, client.getOrganizationNamed(orgName)); - } - return returnVal; - } + public Map>> get() { + return transformValues( + catalogSupplier.get(), + new Function, Map>>() { + @Override + public Map> apply( + Map from) { + return transformValues( + from, + new Function>() { + + @Override + public Map apply(org.jclouds.vcloud.domain.Catalog from) { + return uniqueIndex(allCatalogItemsInCatalog.apply(from), name); + } + }); + + } + }); + } + } + + @Provides + @Singleton + protected Supplier>>> provideOrganizationCatalogItemSupplierCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogItemSupplier supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>>( + authException, seconds, + new Supplier>>>() { + @Override + public Map>> get() { + return supplier.get(); + } + }); } @Provides @@ -312,7 +421,7 @@ public abstract class BaseVCloudRestClientModule 0, "No vdcs present in org: " + org.getName()); - return Iterables.get(org.getVDCs().values(), 0).getLocation(); + return get(org.getVDCs().values(), 0).getLocation(); } @Provides @@ -320,7 +429,15 @@ public abstract class BaseVCloudRestClientModule 0, "No catalogs present in org: " + org.getName()); - return Iterables.get(org.getCatalogs().values(), 0).getLocation(); + return get(org.getCatalogs().values(), 0).getLocation(); + } + + @Provides + @Catalog + @Singleton + protected String provideCatalogName( + Supplier>> catalogs) { + return getLast(getLast(catalogs.get().values()).keySet()); } @Provides @@ -334,7 +451,7 @@ public abstract class BaseVCloudRestClientModule networks = vDC.getAvailableNetworks(); checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName()); - return Iterables.get(networks.values(), 0).getLocation(); + return get(networks.values(), 0).getLocation(); } catch (AuthorizationException e) { authException.set(e); throw e; @@ -360,6 +477,6 @@ public abstract class BaseVCloudRestClientModule 0, "No tasks lists present in org: " + org.getName()); - return Iterables.get(org.getTasksLists().values(), 0).getLocation(); + return get(org.getTasksLists().values(), 0).getLocation(); } } 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 165b095517..f178373306 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 @@ -25,14 +25,14 @@ import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; /** - * Configures the VCloud authentication service connection, including logging and http transport. + * Configures the VCloud authentication service connection, including logging + * and http transport. * * @author Adrian Cole */ @RequiresHttp @ConfiguresRestClient -public class VCloudRestClientModule extends - BaseVCloudRestClientModule { +public class VCloudRestClientModule extends BaseVCloudRestClientModule { public VCloudRestClientModule() { super(VCloudClient.class, VCloudAsyncClient.class); 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 index 5fbafc53c4..e4479d434d 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/CatalogItem.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/CatalogItem.java @@ -19,22 +19,22 @@ package org.jclouds.vcloud.domain; -import java.util.SortedMap; +import java.util.Map; -import org.jclouds.vcloud.domain.internal.CatalogImpl; +import org.jclouds.vcloud.domain.internal.CatalogItemImpl; import com.google.inject.ImplementedBy; /** * @author Adrian Cole */ -@ImplementedBy(CatalogImpl.class) +@ImplementedBy(CatalogItemImpl.class) public interface CatalogItem extends NamedResource { String getDescription(); NamedResource getEntity(); - SortedMap getProperties(); + Map getProperties(); } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java index e9eabafdf9..542efa1d0c 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java @@ -22,8 +22,8 @@ package org.jclouds.vcloud.domain.internal; import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; -import java.util.SortedMap; -import java.util.TreeMap; +import java.util.LinkedHashMap; +import java.util.Map; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Catalog; @@ -37,7 +37,7 @@ import com.google.inject.internal.Nullable; * @author Adrian Cole * */ -public class CatalogImpl extends TreeMap implements Catalog { +public class CatalogImpl extends LinkedHashMap implements Catalog { /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; @@ -47,7 +47,7 @@ public class CatalogImpl extends TreeMap implements Catal private final URI location; public CatalogImpl(String id, String name, URI location, @Nullable String description, - SortedMap contents) { + Map contents) { this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name"); this.description = description; 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 index e56741547b..2f02a2b5ce 100644 --- 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 @@ -22,7 +22,7 @@ package org.jclouds.vcloud.domain.internal; import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; -import java.util.SortedMap; +import java.util.Map; import javax.annotation.Nullable; @@ -43,10 +43,10 @@ public class CatalogItemImpl extends NamedResourceImpl implements CatalogItem { private static final long serialVersionUID = 8464716396538298809L; private final String description; private final NamedResource entity; - private final SortedMap properties = Maps.newTreeMap(); + private final Map properties = Maps.newLinkedHashMap(); - public CatalogItemImpl(String id, String name, URI location, @Nullable String description, - NamedResource entity, SortedMap properties) { + public CatalogItemImpl(String id, String name, URI location, @Nullable String description, NamedResource entity, + Map properties) { super(id, name, VCloudMediaType.CATALOGITEM_XML, location); this.description = description; this.entity = checkNotNull(entity, "entity"); @@ -67,15 +67,15 @@ public class CatalogItemImpl extends NamedResourceImpl implements CatalogItem { return description; } - public SortedMap getProperties() { + public Map getProperties() { return properties; } @Override public String toString() { - return "CatalogItemImpl [id=" + getId() + ", name=" + getName() + ", location=" - + getLocation() + ", type=" + getType() + ", description=" + getDescription() - + ", entity=" + entity + ", properties=" + properties + "]"; + return "CatalogItemImpl [id=" + getId() + ", name=" + getName() + ", location=" + getLocation() + ", type=" + + getType() + ", description=" + getDescription() + ", entity=" + entity + ", properties=" + properties + + "]"; } @Override diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java index 71baa347dc..674aef09b3 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java @@ -75,10 +75,10 @@ public class AllCatalogItemsInCatalog implements Function apply(NamedResource from) { - return (Future) aclient.getCatalogItem(from.getId()); + return (Future) aclient.getCatalogItem(from.getLocation()); } - }, executor, null, logger, "catalogItems in " + from.getId()); + }, executor, null, logger, "catalogItems in " + from.getLocation()); return catalogItems; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrganization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrganization.java index 53a209d788..6b66335ab2 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrganization.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrganization.java @@ -58,17 +58,16 @@ public class AllCatalogsInOrganization implements Function apply(Organization from) { + public Iterable apply(final Organization org) { + Iterable catalogs = transformParallel(org.getCatalogs().values(), + new Function>() { + @SuppressWarnings("unchecked") + @Override + public Future apply(NamedResource from) { + return (Future) aclient.findCatalogInOrgNamed(org.getName(), from.getName()); + } - Iterable catalogItems = transformParallel(from.getCatalogs().values(), - new Function>() { - @SuppressWarnings("unchecked") - @Override - public Future apply(NamedResource from) { - return (Future) aclient.getCatalog(from.getId()); - } - - }, executor, null, logger, "catalogs in " + from.getName()); - return catalogItems; + }, executor, null, logger, "catalogs in " + org.getName()); + return catalogs; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrganization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrganization.java index 7812c3228d..51b5f55661 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrganization.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrganization.java @@ -65,7 +65,7 @@ public class AllVDCsInOrganization implements Function apply(NamedResource from) { - return (Future) aclient.getVDCInOrg(org.getName(), from.getName()); + return (Future) aclient.findVDCInOrgNamed(org.getName(), from.getName()); } }, executor, null, logger, "vdcs in " + org.getName()); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndCatalogNameToEndpoint.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndCatalogNameToEndpoint.java index b6f266bc78..abb67a9407 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndCatalogNameToEndpoint.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndCatalogNameToEndpoint.java @@ -43,12 +43,12 @@ import com.google.common.collect.Iterables; */ @Singleton public class OrgNameAndCatalogNameToEndpoint implements Function { - private final Supplier> orgMap; + private final Supplier> orgMap; private final String defaultOrg; private final URI defaultUri; @Inject - public OrgNameAndCatalogNameToEndpoint(Supplier> orgMap, @Org String defaultOrg, + public OrgNameAndCatalogNameToEndpoint(Supplier> orgMap, @Org String defaultOrg, @Catalog URI defaultUri) { this.orgMap = orgMap; this.defaultOrg = defaultOrg; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndTasksListNameToEndpoint.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndTasksListNameToEndpoint.java index 192cc8fdbf..a10af1a07b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndTasksListNameToEndpoint.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndTasksListNameToEndpoint.java @@ -43,13 +43,13 @@ import com.google.common.collect.Iterables; */ @Singleton public class OrgNameAndTasksListNameToEndpoint implements Function { - private final Supplier> orgMap; + private final Supplier> orgMap; private final String defaultOrg; private final URI defaultUri; @Inject - public OrgNameAndTasksListNameToEndpoint(Supplier> orgMap, @Org String defaultOrg, - @TasksList URI defaultUri) { + public OrgNameAndTasksListNameToEndpoint(Supplier> orgMap, + @Org String defaultOrg, @TasksList URI defaultUri) { this.orgMap = orgMap; this.defaultOrg = defaultOrg; this.defaultUri = defaultUri; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndVDCNameToEndpoint.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndVDCNameToEndpoint.java index 225a19edf9..6896be4026 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndVDCNameToEndpoint.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameAndVDCNameToEndpoint.java @@ -43,13 +43,13 @@ import com.google.common.collect.Iterables; */ @Singleton public class OrgNameAndVDCNameToEndpoint implements Function { - private final Supplier> orgNameToVDCEndpoint; + private final Supplier> orgNameToVDCEndpoint; private final String defaultOrg; private final URI defaultUri; @Inject - public OrgNameAndVDCNameToEndpoint(Supplier> orgNameToVDCEndpoint, @Org String defaultOrg, - @VDC URI defaultUri) { + public OrgNameAndVDCNameToEndpoint(Supplier> orgNameToVDCEndpoint, + @Org String defaultOrg, @VDC URI defaultUri) { this.orgNameToVDCEndpoint = orgNameToVDCEndpoint; this.defaultOrg = defaultOrg; this.defaultUri = defaultUri; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameCatalogNameItemNameToEndpoint.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameCatalogNameItemNameToEndpoint.java new file mode 100644 index 0000000000..f0eb4ae6c0 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameCatalogNameItemNameToEndpoint.java @@ -0,0 +1,76 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Map; +import java.util.NoSuchElementException; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.vcloud.endpoints.Catalog; +import org.jclouds.vcloud.endpoints.Org; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class OrgNameCatalogNameItemNameToEndpoint implements Function { + private final Supplier>> orgCatalogMap; + private final String defaultOrg; + private final String defaultCatalog; + + @Inject + public OrgNameCatalogNameItemNameToEndpoint( + Supplier>> orgCatalogMap, + @Org String defaultOrg, @Catalog String defaultCatalog) { + this.orgCatalogMap = orgCatalogMap; + this.defaultOrg = defaultOrg; + this.defaultCatalog = defaultCatalog; + } + + @SuppressWarnings("unchecked") + public URI apply(Object from) { + Iterable orgCatalog = (Iterable) checkNotNull(from, "args"); + Object org = Iterables.get(orgCatalog, 0); + Object catalog = Iterables.get(orgCatalog, 1); + Object catalogItem = Iterables.get(orgCatalog, 2); + if (org == null) + org = defaultOrg; + if (catalog == null) + catalog = defaultCatalog; + try { + Map catalogs = checkNotNull(orgCatalogMap.get().get(org)); + return catalogs.get(catalog).get(catalogItem).getLocation(); + } catch (NullPointerException e) { + throw new NoSuchElementException(org + "/" + catalog + "/" + catalogItem + " not found in " + + orgCatalogMap.get()); + } + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameCatalogNameVAppTemplateNameToEndpoint.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameCatalogNameVAppTemplateNameToEndpoint.java new file mode 100644 index 0000000000..b25719b0b0 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgNameCatalogNameVAppTemplateNameToEndpoint.java @@ -0,0 +1,77 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Map; +import java.util.NoSuchElementException; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.endpoints.Catalog; +import org.jclouds.vcloud.endpoints.Org; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements Function { + private final Supplier>>> orgCatalogItemMap; + private final String defaultOrg; + private final String defaultCatalog; + + @Inject + public OrgNameCatalogNameVAppTemplateNameToEndpoint( + Supplier>>> orgCatalogItemMap, + @Org String defaultOrg, @Catalog String defaultCatalog) { + this.orgCatalogItemMap = orgCatalogItemMap; + this.defaultOrg = defaultOrg; + this.defaultCatalog = defaultCatalog; + } + + @SuppressWarnings("unchecked") + public URI apply(Object from) { + Iterable orgCatalog = (Iterable) checkNotNull(from, "args"); + Object org = Iterables.get(orgCatalog, 0); + Object catalog = Iterables.get(orgCatalog, 1); + Object catalogItem = Iterables.get(orgCatalog, 2); + if (org == null) + org = defaultOrg; + if (catalog == null) + catalog = defaultCatalog; + try { + Map> catalogs = checkNotNull(orgCatalogItemMap.get().get(org)); + return catalogs.get(catalog).get(catalogItem).getEntity().getLocation(); + } catch (NullPointerException e) { + throw new NoSuchElementException(org + "/" + catalog + "/" + catalogItem + " not found in " + + orgCatalogItemMap.get()); + } + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrganizationsForNames.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrganizationsForNames.java new file mode 100644 index 0000000000..45f28db659 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrganizationsForNames.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.functions; + +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.domain.Organization; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class OrganizationsForNames implements Function, Iterable> { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + private final VCloudAsyncClient aclient; + private final ExecutorService executor; + + @Inject + OrganizationsForNames(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.aclient = aclient; + this.executor = executor; + } + + @Override + public Iterable apply(Iterable from) { + return transformParallel(from, new Function>() { + + @SuppressWarnings("unchecked") + @Override + public Future apply(String from) { + return (Future) aclient.findOrganizationNamed(from); + } + + }, executor, null, logger, "organizations for names"); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrganizatonsForLocations.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrganizatonsForLocations.java index c8bb0d7d75..980c99b890 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrganizatonsForLocations.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrganizatonsForLocations.java @@ -20,8 +20,10 @@ package org.jclouds.vcloud.functions; import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; import static org.jclouds.concurrent.FutureIterables.transformParallel; +import java.net.URI; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; @@ -36,17 +38,19 @@ import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.logging.Logger; import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.compute.domain.VCloudLocation; import org.jclouds.vcloud.domain.Organization; import com.google.common.base.Function; import com.google.common.base.Predicate; +import com.google.common.collect.Sets; /** * @author Adrian Cole */ @Singleton public class OrganizatonsForLocations implements - Function, Iterable> { + Function, Iterable> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; @@ -60,27 +64,35 @@ public class OrganizatonsForLocations implements } /** - * regions are not currently an assignable location, so they don't show up in the list. As such, - * we'll blindly look for all zones, and get their "parents" + * Zones are assignable, but we want regions. so we look for zones, whose + * parent is region. then, we use a set to extract the unique set. */ @Override public Iterable apply(Iterable from) { - return transformParallel(filter(from, new Predicate() { + + return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate() { @Override public boolean apply(Location input) { return input.getScope() == LocationScope.ZONE; } - }), new Function>() { + }), new Function() { + + @Override + public URI apply(Location from) { + return VCloudLocation.class.cast(from.getParent()).getResource().getLocation(); + } + + })), new Function>() { @SuppressWarnings("unchecked") @Override - public Future apply(Location from) { - return (Future) aclient.getOrganizationNamed(from.getParent().getId()); + public Future apply(URI from) { + return (Future) aclient.getOrganization(from); } - }, executor, null, logger, "organizations for locations"); + }, executor, null, logger, "organizations for uris"); } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java index e74df348fa..cdbb635059 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java @@ -40,12 +40,13 @@ import org.jclouds.vcloud.domain.VAppTemplate; import com.google.common.base.Function; import com.google.common.base.Predicate; + /** * @author Adrian Cole */ @Singleton public class VAppTemplatesForCatalogItems implements - Function, Iterable> { + Function, Iterable> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; @@ -54,7 +55,7 @@ public class VAppTemplatesForCatalogItems implements @Inject VAppTemplatesForCatalogItems(VCloudAsyncClient aclient, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; } @@ -73,7 +74,7 @@ public class VAppTemplatesForCatalogItems implements @SuppressWarnings("unchecked") @Override public Future apply(CatalogItem from) { - return (Future) aclient.getVAppTemplate(from.getEntity().getId()); + return (Future) aclient.getVAppTemplate(from.getEntity().getLocation()); } }, executor, null, logger, "vappTemplates in"); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForResourceEntities.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForResourceEntities.java index b7e5f0681f..fbedc85bd1 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForResourceEntities.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForResourceEntities.java @@ -40,12 +40,13 @@ import org.jclouds.vcloud.domain.VAppTemplate; import com.google.common.base.Function; import com.google.common.base.Predicate; + /** * @author Adrian Cole */ @Singleton public class VAppTemplatesForResourceEntities implements - Function, Iterable> { + Function, Iterable> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; @@ -54,7 +55,7 @@ public class VAppTemplatesForResourceEntities implements @Inject VAppTemplatesForResourceEntities(VCloudAsyncClient aclient, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; } @@ -73,7 +74,7 @@ public class VAppTemplatesForResourceEntities implements @SuppressWarnings("unchecked") @Override public Future apply(NamedResource from) { - return (Future) aclient.getVAppTemplate(from.getId()); + return (Future) aclient.getVAppTemplate(from.getLocation()); } }, executor, null, logger, "vappTemplates in"); 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 index 2fa87692de..0540161e3b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogItemHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogItemHandler.java @@ -37,15 +37,15 @@ import com.google.common.collect.Maps; public class CatalogItemHandler extends ParseSax.HandlerWithResult { private StringBuilder currentText = new StringBuilder(); - private NamedResource catalog; - private NamedResource entity; + protected NamedResource catalogItem; + protected NamedResource entity; - private String description; - private String key; - private SortedMap properties = Maps.newTreeMap(); + protected String description; + protected String key; + protected SortedMap properties = Maps.newTreeMap(); public CatalogItem getResult() { - return new CatalogItemImpl(catalog.getId(), catalog.getName(), catalog.getLocation(), + return new CatalogItemImpl(catalogItem.getId(), catalogItem.getName(), catalogItem.getLocation(), description, entity, properties); } @@ -53,7 +53,7 @@ public class CatalogItemHandler extends ParseSax.HandlerWithResult public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equals("CatalogItem")) { - catalog = Utils.newNamedResource(attributes); + catalogItem = Utils.newNamedResource(attributes); } else if (qName.equals("Entity")) { entity = Utils.newNamedResource(attributes); } else if (qName.equals("Property")) { 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 ee2b25f400..73ee0cff85 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -26,7 +26,6 @@ import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder. 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.Map; @@ -52,6 +51,8 @@ import org.jclouds.util.Utils; import org.jclouds.vcloud.config.VCloudRestClientModule; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.internal.CatalogImpl; +import org.jclouds.vcloud.domain.internal.CatalogItemImpl; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.OrganizationImpl; import org.jclouds.vcloud.endpoints.Org; @@ -85,10 +86,13 @@ 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()); - HttpRequest request = processor.createRequest(method, "1", "my-vapp", 3 + ""); + + public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, + String.class, InstantiateVAppTemplateOptions[].class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp"); assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); @@ -103,100 +107,13 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } - 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()); - HttpRequest request = processor.createRequest(method, "1", "my-vapp", 3 + "", processorCount(1).memory(512).disk( - 1024).fenceMode("allowInOut").inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990"))); - - assertRequestLineEquals(request, - "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); - assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream( - "/newvapp-hostingcpumemdisk.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", - false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, VAppHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInstantiateVAppTemplateOptionsIllegalName() throws SecurityException, NoSuchMethodException, + public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", String.class, String.class, - String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass()); - processor.createRequest(method, "1", "CentOS 01", 3 + "", processorCount(1).memory(512).disk(1024).inNetwork( - URI.create("https://vcloud.safesecureweb.com/network/1990"))); - } - - public void testCloneVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class, - Array.newInstance(CloneVAppOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, "1", "4181", "my-vapp"); - - assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); - assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")), - "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testCloneVAppOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class, - Array.newInstance(CloneVAppOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, "1", "201", "new-linux-server", new CloneVAppOptions() - .deploy().powerOn().withDescription("The description of the new vApp")); - - assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); - assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml")), - "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testCloneVAppOptionsIllegalName() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class, - Array.newInstance(CloneVAppOptions.class, 0).getClass()); - processor.createRequest(method, "1", "201", "New Linux Server", new CloneVAppOptions().deploy().powerOn() - .withDescription("The description of the new vApp")); - } - - public void testInstantiateVAppTemplateInOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class, String.class, - String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, "org", "vdc", "my-vapp", 3 + ""); - - assertRequestLineEquals(request, - "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); - assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-hosting.xml")), - "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, VAppHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testInstantiateVAppTemplateInOrgOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class, String.class, - String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, "org", "vdc", "my-vapp", 3 + "", processorCount(1).memory( + Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, + String.class, InstantiateVAppTemplateOptions[].class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", processorCount(1).memory( 512).disk(1024).fenceMode("allowInOut").inNetwork( URI.create("https://vcloud.safesecureweb.com/network/1990"))); @@ -217,16 +134,19 @@ public class VCloudAsyncClientTest extends RestClientTest { @Test(expectedExceptions = IllegalArgumentException.class) public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class, String.class, - String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass()); - processor.createRequest(method, "org", "vdc", "CentOS 01", 3 + "", processorCount(1).memory(512).disk(1024) - .inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990"))); + Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, + String.class, InstantiateVAppTemplateOptions[].class); + processor.createRequest(method, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "CentOS 01", processorCount(1).memory(512) + .disk(1024).inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990"))); } - public void testCloneVAppInOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("cloneVAppInOrg", String.class, String.class, String.class, - String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, "org", "vdc", "4181", "my-vapp"); + public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, + CloneVAppOptions[].class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/4181"), "my-vapp"); assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); @@ -240,11 +160,13 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } - public void testCloneVAppInOrgOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("cloneVAppInOrg", String.class, String.class, String.class, - String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, "org", "vdc", "201", "new-linux-server", - new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp")); + public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, + CloneVAppOptions[].class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/201"), "new-linux-server", new CloneVAppOptions() + .deploy().powerOn().withDescription("The description of the new vApp")); assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); @@ -274,8 +196,9 @@ public class VCloudAsyncClientTest extends RestClientTest { } public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getOrganization", String.class); - HttpRequest request = processor.createRequest(method, "1"); + Method method = VCloudAsyncClient.class.getMethod("getOrganization", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/org/1")); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); @@ -288,8 +211,8 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } - public void testOrganizationNamed() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getOrganizationNamed", String.class); + public void testFindOrganizationNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findOrganizationNamed", String.class); HttpRequest request = processor.createRequest(method, "org"); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1"); @@ -334,7 +257,7 @@ public class VCloudAsyncClientTest extends RestClientTest { } public void testCatalogInOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getCatalogInOrg", String.class, String.class); + Method method = VCloudAsyncClient.class.getMethod("findCatalogInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, "org", "catalog"); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1"); @@ -363,9 +286,10 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } - public void testCatalogItem() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", String.class); - HttpRequest request = processor.createRequest(method, "2"); + public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); @@ -378,9 +302,42 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } - public void testVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", String.class); - HttpRequest request = processor.createRequest(method, "2"); + public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, String.class, + String.class); + HttpRequest request = processor.createRequest(method, "org", "catalog", "item"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class, + String.class, String.class); + HttpRequest request = processor.createRequest(method, "org", "catalog", "template"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); @@ -408,8 +365,8 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } - public void testGetVDCByOrgAndName() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class); + public void testFindVDCInOrgNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, "org", "vdc"); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); @@ -424,19 +381,19 @@ public class VCloudAsyncClientTest extends RestClientTest { } @Test(expectedExceptions = NoSuchElementException.class) - public void testGetVDCByOrgAndNameBadVDC() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class); + public void testFindVDCInOrgNamedBadVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); processor.createRequest(method, "org", "vdc1"); } @Test(expectedExceptions = NoSuchElementException.class) - public void testGetVDCByOrgAndNameBadOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class); + public void testFindVDCInOrgNamedBadOrg() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); processor.createRequest(method, "org1", "vdc"); } - public void testGetVDCByOrgAndNameNullOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class); + public void testFindVDCInOrgNamedNullOrg() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, null, "vdc"); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); @@ -450,8 +407,8 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } - public void testGetVDCByOrgAndNameNullOrgAndVDC() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class); + public void testFindVDCInOrgNamedNullOrgAndVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, null, null); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); @@ -465,9 +422,10 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } - public void testGetVDCString() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getVDC", String.class); - HttpRequest request = processor.createRequest(method, "1"); + public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1")); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); @@ -510,8 +468,8 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } - public void testGetTasksListInOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getTasksListInOrg", String.class, String.class); + public void testFindTasksListInOrgNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("findTasksListInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, "org", "tasksList"); assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1"); @@ -732,6 +690,8 @@ public class VCloudAsyncClientTest extends RestClientTest { protected void configure() { super.configure(); bind(OrganizationMapSupplier.class).to(TestOrganizationMapSupplier.class); + bind(OrganizationCatalogSupplier.class).to(TestOrganizationCatalogItemMapSupplier.class); + bind(OrganizationCatalogItemSupplier.class).to(TestOrganizationCatalogItemSupplier.class); } @Override @@ -817,6 +777,48 @@ public class VCloudAsyncClientTest extends RestClientTest { } } + @Singleton + public static class TestOrganizationCatalogItemMapSupplier extends OrganizationCatalogSupplier { + @Inject + protected TestOrganizationCatalogItemMapSupplier() { + super(null, null); + } + + @Override + public Map> get() { + return ImmutableMap.> of("org", + + ImmutableMap. of("catalog", new CatalogImpl("1", "catalog", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"), "description", ImmutableMap + . of("item", new NamedResourceImpl("1", "item", + "application/vnd.vmware.vcloud.catalogItem+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")), "template", + new NamedResourceImpl("2", "template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")))))); + } + } + + @Singleton + public static class TestOrganizationCatalogItemSupplier extends OrganizationCatalogItemSupplier { + protected TestOrganizationCatalogItemSupplier() { + super(null, null); + } + + @Override + public Map>> get() { + return ImmutableMap.>> of( + "org", ImmutableMap.> of( + "catalog", ImmutableMap. of("template", + new CatalogItemImpl("2", "template", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), "description", + new NamedResourceImpl("2", "template", + "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")), + ImmutableMap. of())))); + + } + } + } } 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 80e55fb0fd..be106fe6c4 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -56,28 +56,28 @@ public class VCloudClientLiveTest { @Test public void testOrganization() throws Exception { - Organization response = connection.getOrganizationNamed(null); + Organization response = connection.findOrganizationNamed(null); assertNotNull(response); assertNotNull(response.getName()); assert response.getCatalogs().size() >= 1; assert response.getTasksLists().size() >= 1; assert response.getVDCs().size() >= 1; - assertEquals(connection.getOrganizationNamed(response.getName()), response); + assertEquals(connection.findOrganizationNamed(response.getName()), response); } @Test public void testCatalog() throws Exception { - Catalog response = connection.getCatalogInOrg(null, null); + Catalog response = connection.findCatalogInOrgNamed(null, null); assertNotNull(response); assertNotNull(response.getId()); assertNotNull(response.getName()); assertNotNull(response.getLocation()); - assertEquals(connection.getCatalogInOrg(null, response.getName()), response); + assertEquals(connection.findCatalogInOrgNamed(null, response.getName()), response); } @Test public void testGetNetwork() throws Exception { - VDC response = connection.getVDCInOrg(null, null); + VDC response = connection.findVDCInOrgNamed(null, null); for (NamedResource resource : response.getAvailableNetworks().values()) { if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) { Network item = connection.getNetwork(resource.getId()); @@ -88,10 +88,10 @@ public class VCloudClientLiveTest { @Test public void testGetCatalogItem() throws Exception { - Catalog response = connection.getCatalogInOrg(null, null); + Catalog response = connection.findCatalogInOrgNamed(null, null); for (NamedResource resource : response.values()) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { - CatalogItem item = connection.getCatalogItem(resource.getId()); + CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(null, null, resource.getName()); assertNotNull(item); assertNotNull(item.getEntity()); assertNotNull(item.getId()); @@ -104,12 +104,12 @@ public class VCloudClientLiveTest { @Test public void testGetVAppTemplate() throws Exception { - Catalog response = connection.getCatalogInOrg(null, null); + Catalog response = connection.findCatalogInOrgNamed(null, null); for (NamedResource resource : response.values()) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { - CatalogItem item = connection.getCatalogItem(resource.getId()); + CatalogItem item = connection.getCatalogItem(resource.getLocation()); if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { - assertNotNull(connection.getVAppTemplate(item.getEntity().getId())); + assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(null, null, item.getEntity().getName())); } } } @@ -117,19 +117,19 @@ public class VCloudClientLiveTest { @Test public void testDefaultVDC() throws Exception { - VDC response = connection.getVDCInOrg(null, null); + VDC response = connection.findVDCInOrgNamed(null, null); assertNotNull(response); assertNotNull(response.getId()); assertNotNull(response.getName()); assertNotNull(response.getLocation()); assertNotNull(response.getResourceEntities()); assertNotNull(response.getAvailableNetworks()); - assertEquals(connection.getVDC(response.getId()).getId(), response.getId()); + assertEquals(connection.getVDC(response.getLocation()), response); } @Test public void testDefaultTasksList() throws Exception { - org.jclouds.vcloud.domain.TasksList response = connection.getTasksListInOrg(null, null); + org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null, null); assertNotNull(response); assertNotNull(response.getId()); assertNotNull(response.getLocation()); @@ -139,7 +139,7 @@ public class VCloudClientLiveTest { @Test public void testGetTask() throws Exception { - org.jclouds.vcloud.domain.TasksList response = connection.getTasksListInOrg(null, null); + org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null, null); assertNotNull(response); assertNotNull(response.getLocation()); assertNotNull(response.getTasks()); @@ -151,7 +151,7 @@ public class VCloudClientLiveTest { @Test public void testGetVApp() throws Exception { - VDC response = connection.getVDCInOrg(null, null); + VDC response = connection.findVDCInOrgNamed(null, null); for (NamedResource item : response.getResourceEntities().values()) { if (item.getType().equals(VCloudMediaType.VAPP_XML)) { VApp app = connection.getVApp(item.getId()); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java index dbb19f219a..ae8f0e8a34 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java @@ -36,6 +36,7 @@ import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; @@ -64,7 +65,7 @@ public class VCloudComputeClientLiveTest { protected String id; protected String publicAddress; - protected String templateId; + protected String templateName; public static class Expectation { final long hardDisk; @@ -88,10 +89,11 @@ public class VCloudComputeClientLiveTest { int processorCount = 1; int memory = 512; + VAppTemplate template = client.findVAppTemplateInOrgCatalogNamed(null, null, templateName); InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024).productProperties( ImmutableMap.of("foo", "bar")); - id = computeClient.start(null, null, serverName, templateId, options).get("id"); + id = computeClient.start(null, template.getLocation(), templateName, options).get("id"); Expectation expectation = expectationMap.get(toTest); VApp vApp = client.getVApp(id); @@ -149,7 +151,7 @@ public class VCloudComputeClientLiveTest { expectationMap = ImmutableMap. builder().put(OsFamily.CENTOS, new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); provider = "vcloudtest"; - templateId = "3"; + templateName = "Ubuntu JeOS 9.10 (32-bit)"; } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest.java deleted file mode 100644 index b46235642e..0000000000 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.compute.strategy; - -import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.createNiceMock; -import static org.easymock.classextension.EasyMock.replay; -import static org.easymock.classextension.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import java.security.SecureRandom; -import java.util.concurrent.ExecutorService; - -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.strategy.AddNodeWithTagStrategy; -import org.jclouds.compute.strategy.ListNodesStrategy; -import org.jclouds.compute.util.ComputeUtils; -import org.testng.annotations.Test; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "vcloud.EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest") -public class EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest { - - @Test - public void testGetNextName() { - SecureRandom random = createMock(SecureRandom.class); - expect(random.nextInt(255)).andReturn(12).atLeastOnce(); - - replay(random); - - EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy strategy = new EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy( - createNiceMock(AddNodeWithTagStrategy.class), - createNiceMock(ListNodesStrategy.class), "%s-%s%s", - createNiceMock(ComputeUtils.class), - createNiceMock(ExecutorService.class), random); - - String oldName = null; - for (int i = 0; i < 5; i++) { - Template template = createMock(Template.class); - Image image = createMock(Image.class); - - expect(template.getImage()).andReturn(image); - expect(image.getProviderId()).andReturn("233"); - - replay(template); - replay(image); - - String name = strategy.getNextName("test", template); - if (oldName != null) { - assert !oldName.equals(name); - oldName = name; - } - - assertEquals(name.length(), 10); - assertEquals(name.substring(0, 4), "test"); - System.out.println(name); - assertEquals(name.substring(5, 8), "0e9"); - assert name.substring(8, 9).matches("[0-9a-f]+"); - - verify(template); - verify(image); - - } - verify(random); - - } -} 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 5531bea295..9d284f19aa 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 @@ -22,7 +22,8 @@ package org.jclouds.vcloud.hostingdotcom; import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; -import javax.annotation.Nullable; +import java.net.URI; + import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -30,12 +31,13 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import org.jclouds.predicates.validators.DnsNameValidator; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.MapPayloadParam; -import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.ParamValidators; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -43,8 +45,6 @@ import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; -import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint; -import org.jclouds.vcloud.functions.VAppTemplateIdToUri; import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp; import org.jclouds.vcloud.hostingdotcom.xml.HostingDotComVAppHandler; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -89,26 +89,9 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient { @XMLResponseParser(HostingDotComVAppHandler.class) @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) @Override - ListenableFuture instantiateVAppTemplateInOrg( - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName, - @MapPayloadParam("name") String appName, - @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, - InstantiateVAppTemplateOptions... options); - - @Deprecated - @POST - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/vdc/{vDCId}/action/instantiateVAppTemplate") - @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") - @Consumes(VAPP_XML) - // required for hosting.com to operate - @XMLResponseParser(HostingDotComVAppHandler.class) - @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) - @Override - ListenableFuture instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId, - @MapPayloadParam("name") String appName, - @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, + ListenableFuture instantiateVAppTemplateInVDC(@EndpointParam URI vdc, + @MapPayloadParam("template") URI template, + @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, 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 c79d067131..349fade506 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 @@ -19,6 +19,7 @@ package org.jclouds.vcloud.hostingdotcom; +import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -39,12 +40,7 @@ public interface HostingDotComVCloudClient extends VCloudClient { @Override @Timeout(duration = 600, timeUnit = TimeUnit.SECONDS) - HostingDotComVApp instantiateVAppTemplateInOrg(String org, String vDC, String appName, String templateId, - InstantiateVAppTemplateOptions... options); - - @Override - @Timeout(duration = 600, timeUnit = TimeUnit.SECONDS) - HostingDotComVApp instantiateVAppTemplateInVDC(String vDC, String appName, String templateId, + HostingDotComVApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, 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 9c71ae52e6..f490cb57f4 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 @@ -29,6 +29,7 @@ import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.BaseVCloudComputeClient; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp; import com.google.common.base.Predicate; @@ -41,18 +42,16 @@ import com.google.common.collect.ImmutableMap; public class HostingDotComVCloudComputeClient extends BaseVCloudComputeClient { @Inject - protected HostingDotComVCloudComputeClient(VCloudClient client, - Predicate successTester, + protected HostingDotComVCloudComputeClient(VCloudClient client, Predicate successTester, Map vAppStatusToNodeState) { super(client, successTester, vAppStatusToNodeState); } @Override - protected Map parseResponse(String templateId, - VApp vAppResponse) { + protected Map parseResponse(VAppTemplate template, VApp vAppResponse) { HostingDotComVApp hVApp = HostingDotComVApp.class.cast(vAppResponse); - return ImmutableMap. of("id", vAppResponse.getId(), - "username", hVApp.getUsername(), "password", hVApp.getPassword()); + return ImmutableMap. of("id", vAppResponse.getId(), "username", hVApp.getUsername(), "password", + hVApp.getPassword()); } } \ No newline at end of file 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 4f20f35e92..dd1f8ad4ff 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 @@ -63,7 +63,7 @@ public class HostingDotComVCloudComputeClientLiveTest extends VCloudComputeClien expectationMap = ImmutableMap. builder().put(OsFamily.CENTOS, new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); provider = "vcloudtest"; - templateId = "3"; + templateName = "3"; } } 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 eeb0d5a3c9..1670a8f5d8 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 @@ -19,6 +19,7 @@ package org.jclouds.vcloud.terremark; +import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; @@ -30,6 +31,7 @@ import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.NODESERVICE_ import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.PUBLICIPSLIST_XML; import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.PUBLICIP_XML; +import java.net.URI; import java.util.Set; import javax.annotation.Nullable; @@ -43,7 +45,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import org.jclouds.predicates.validators.DnsNameValidator; -import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; @@ -66,9 +67,9 @@ import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameToEndpoint; import org.jclouds.vcloud.functions.VAppId; -import org.jclouds.vcloud.functions.VAppTemplateIdToUri; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.binders.BindNodeConfigurationToXmlPayload; import org.jclouds.vcloud.terremark.binders.BindVAppConfigurationToXmlPayload; @@ -76,10 +77,11 @@ import org.jclouds.vcloud.terremark.binders.TerremarkBindInstantiateVAppTemplate import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; -import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; +import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem; import org.jclouds.vcloud.terremark.domain.TerremarkOrganization; +import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.VAppConfiguration; import org.jclouds.vcloud.terremark.functions.ParseTaskFromLocationHeader; import org.jclouds.vcloud.terremark.functions.ReturnVoidOnDeleteDefaultIp; @@ -91,6 +93,7 @@ import org.jclouds.vcloud.terremark.xml.InternetServicesHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler; import org.jclouds.vcloud.terremark.xml.NodesHandler; import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler; +import org.jclouds.vcloud.terremark.xml.TerremarkCatalogItemHandler; import org.jclouds.vcloud.terremark.xml.TerremarkOrgHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler; import org.jclouds.vcloud.xml.CatalogHandler; @@ -108,6 +111,27 @@ import com.google.common.util.concurrent.ListenableFuture; */ @RequestFilters(SetVCloudTokenCookie.class) public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { + /** + * @see VCloudClient#getCatalogItemInOrg + */ + @GET + @Consumes(CATALOGITEM_XML) + @XMLResponseParser(TerremarkCatalogItemHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findCatalogItemInOrgCatalogNamed( + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName); + + /** + * @see VCloudClient#getCatalogItem + */ + @Override + @GET + @Consumes(CATALOGITEM_XML) + @XMLResponseParser(TerremarkCatalogItemHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getCatalogItem(@EndpointParam URI catalogItem); @GET @Deprecated @@ -117,22 +141,20 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { ListenableFuture getDefaultOrganization(); @GET - @Deprecated - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/org/{orgId}") @XMLResponseParser(TerremarkOrgHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) @Consumes(ORG_XML) - ListenableFuture getOrganization(@PathParam("orgId") String orgId); + ListenableFuture getOrganization(@EndpointParam URI orgId); /** - * @see VCloudClient#getOrganizationNamed + * @see VCloudClient#findOrganizationNamed */ + @Override @GET @XMLResponseParser(TerremarkOrgHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) @Consumes(ORG_XML) - ListenableFuture getOrganizationNamed( + ListenableFuture findOrganizationNamed( @Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName); /** @@ -147,7 +169,9 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { /** * Terremark does not have multiple catalogs, so we ignore this parameter. */ + @Deprecated @GET + @Override @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) @XMLResponseParser(CatalogHandler.class) @Consumes(CATALOG_XML) @@ -157,46 +181,37 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { /** * @see TerremarkVCloudExpressClient#getVDC */ + @Override @GET - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/vdc/{vDCId}") @XMLResponseParser(TerremarkVDCHandler.class) @Consumes(VDC_XML) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getVDC(@PathParam("vDCId") String vDCId); + ListenableFuture getVDC(@EndpointParam URI vdc); /** - * @see VCloudClient#instantiateVAppTemplate + * @see VCloudClient#findVDCInOrgNamed */ + @GET @Override - @POST - @Path("/action/instantiateVAppTemplate") - @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") - @Consumes(VAPP_XML) - @XMLResponseParser(VAppHandler.class) - @MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class) - ListenableFuture instantiateVAppTemplateInOrg( + @XMLResponseParser(TerremarkVDCHandler.class) + @Consumes(VDC_XML) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findVDCInOrgNamed( @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName, - @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, - @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, - InstantiateVAppTemplateOptions... options); + @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName); /** * @see VCloudClient#instantiateVAppTemplateInVDC */ - @Deprecated - @Override @POST - @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/vdc/{vDCId}/action/instantiateVAppTemplate") + @Path("action/instantiateVAppTemplate") @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") @Consumes(VAPP_XML) @XMLResponseParser(VAppHandler.class) @MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class) - ListenableFuture instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId, + ListenableFuture instantiateVAppTemplateInVDC(@EndpointParam URI vdc, + @MapPayloadParam("template") URI template, @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, - @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, InstantiateVAppTemplateOptions... options); /** @@ -331,8 +346,10 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @Produces(NODESERVICE_XML) @Consumes(NODESERVICE_XML) @XMLResponseParser(NodeHandler.class) + @MapBinder(BindNodeConfigurationToXmlPayload.class) ListenableFuture configureNode(@PathParam("nodeId") int nodeId, - @BinderParam(BindNodeConfigurationToXmlPayload.class) NodeConfiguration nodeConfiguration); + @MapPayloadParam("name") String name, @MapPayloadParam("enabled") boolean enabled, + @Nullable @MapPayloadParam("description") String description); /** * @see TerremarkVCloudExpressClient#deleteNode @@ -357,8 +374,9 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { VAppConfiguration configuration); /** - * @see TerremarkVCloudExpressClient#getCustomizationOptionsOfCatalogItem + * @see TerremarkVCloudClient#getCustomizationOptionsOfCatalogItem */ + @Deprecated @GET @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/extensions/template/{catalogItemId}/options/customization") @@ -367,4 +385,12 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { ListenableFuture getCustomizationOptionsOfCatalogItem( @PathParam("catalogItemId") String catalogItemId); + /** + * @see TerremarkVCloudClient#getCustomizationOptions + */ + @GET + @XMLResponseParser(CustomizationParametersHandler.class) + @Consumes(CATALOGITEMCUSTOMIZATIONPARAMETERS_XML) + ListenableFuture getCustomizationOptions(@EndpointParam URI customization); + } \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java index 9f1bfc5b66..23612ceae5 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 @@ -19,9 +19,12 @@ package org.jclouds.vcloud.terremark; +import java.net.URI; import java.util.Set; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.domain.Task; @@ -29,10 +32,11 @@ import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; -import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; +import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem; import org.jclouds.vcloud.terremark.domain.TerremarkOrganization; +import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.VAppConfiguration; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions; @@ -47,19 +51,31 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions; */ @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) public interface TerremarkVCloudClient extends VCloudClient { + + @Override + TerremarkCatalogItem getCatalogItem(URI catalogItem); + + @Override + TerremarkVDC getVDC(URI catalogItem); + + @Override + TerremarkCatalogItem findCatalogItemInOrgCatalogNamed(String orgName, String catalogName, String itemName); + @Deprecated @Override TerremarkOrganization getDefaultOrganization(); + @Override + TerremarkOrganization getOrganization(URI orgId); + + @Override + TerremarkOrganization findOrganizationNamed(String orgName); + @Deprecated - @Override - TerremarkOrganization getOrganization(String orgId); - - @Override - TerremarkOrganization getOrganizationNamed(String orgName); - CustomizationParameters getCustomizationOptionsOfCatalogItem(String catalogItemId); + CustomizationParameters getCustomizationOptions(URI customizationOptions); + /** * This call returns a list of public IP addresses. */ @@ -67,7 +83,6 @@ public interface TerremarkVCloudClient extends VCloudClient { void deletePublicIp(int ipId); - /** * 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 @@ -109,7 +124,7 @@ public interface TerremarkVCloudClient extends VCloudClient { Node getNode(int nodeId); - Node configureNode(int nodeId, NodeConfiguration nodeConfiguration); + Node configureNode(int nodeId, String name, boolean enabled, @Nullable String description); void deleteNode(int nodeId); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayload.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayload.java index e71658cb5d..4e35f33920 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayload.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayload.java @@ -19,10 +19,10 @@ package org.jclouds.vcloud.terremark.binders; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS; +import java.util.Map; import java.util.Properties; import javax.inject.Inject; @@ -33,9 +33,10 @@ 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.vcloud.terremark.domain.NodeConfiguration; +import com.google.common.base.Throwables; import com.jamesmurty.utils.XMLBuilder; /** @@ -44,51 +45,41 @@ import com.jamesmurty.utils.XMLBuilder; * */ @Singleton -public class BindNodeConfigurationToXmlPayload extends BindToStringPayload { +public class BindNodeConfigurationToXmlPayload implements MapBinder { private final String ns; + private final BindToStringPayload stringBinder; @Inject - BindNodeConfigurationToXmlPayload(@Named(PROPERTY_TERREMARK_EXTENSION_NS) String ns) { + BindNodeConfigurationToXmlPayload(@Named(PROPERTY_TERREMARK_EXTENSION_NS) String ns, BindToStringPayload stringBinder) { this.ns = ns; + this.stringBinder = stringBinder; } - @Override - public void bindToRequest(HttpRequest request, Object input) { - NodeConfiguration nodeConfiguration = (NodeConfiguration) checkNotNull(input, - "nodeConfiguration"); - checkArgument(nodeConfiguration.getDescription() != null - || nodeConfiguration.getEnabled() != null || nodeConfiguration.getName() != null, - "no configuration set"); - try { - super.bindToRequest(request, generateXml(nodeConfiguration)); - } catch (ParserConfigurationException e) { - throw new RuntimeException(e); - } catch (FactoryConfigurationError e) { - throw new RuntimeException(e); - } catch (TransformerException e) { - throw new RuntimeException(e); - } - - } - - protected String generateXml(NodeConfiguration nodeConfiguration) - throws ParserConfigurationException, FactoryConfigurationError, TransformerException { + protected String generateXml(Map postParams) throws ParserConfigurationException, + FactoryConfigurationError, TransformerException { XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns", ns).a("xmlns:xsi", - "http://www.w3.org/2001/XMLSchema-instance").a("xmlns:xsd", - "http://www.w3.org/2001/XMLSchema"); - if (nodeConfiguration.getDescription() != null) - rootBuilder.e("Description").t(nodeConfiguration.getDescription()); - if (nodeConfiguration.getName() != null) - rootBuilder.e("Name").t(nodeConfiguration.getName()); - if (nodeConfiguration.getEnabled() != null) - rootBuilder.e("Enabled").t(nodeConfiguration.getEnabled()); + "http://www.w3.org/2001/XMLSchema-instance").a("xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); + rootBuilder.e("Name").t(checkNotNull(postParams.get("name"), "name")); + rootBuilder.e("Enabled").t(checkNotNull(postParams.get("enabled"), "enabled")); + if (postParams.containsKey("description") && postParams.get("description") != null) + rootBuilder.e("Description").t(postParams.get("description")); Properties outputProperties = new Properties(); outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); return rootBuilder.asString(outputProperties); } - protected String ifNullDefaultTo(String value, String defaultValue) { - return value != null ? value : checkNotNull(defaultValue, "defaultValue"); + @Override + public void bindToRequest(HttpRequest request, Map postParams) { + try { + stringBinder.bindToRequest(request, generateXml(postParams)); + } catch (Exception e) { + Throwables.propagate(e); + } + } + + @Override + public void bindToRequest(HttpRequest request, Object input) { + throw new IllegalArgumentException("this is a map binder"); } } 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 256701a9f2..7c86df5fad 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 @@ -23,11 +23,13 @@ import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.getLast; import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.withDescription; +import java.net.URI; import java.util.LinkedHashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; +import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Provider; @@ -42,6 +44,7 @@ import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.TerremarkECloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient; @@ -76,16 +79,16 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient { } @Override - protected Map parseAndValidateResponse(String templateId, VApp vAppResponse) { - Credentials credentials = credentialsProvider.execute(client.getVAppTemplate(templateId)); - Map toReturn = super.parseResponse(templateId, vAppResponse); + protected Map parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) { + Credentials credentials = credentialsProvider.execute(template); + Map toReturn = super.parseResponse(template, vAppResponse); toReturn.put("username", credentials.identity); toReturn.put("password", credentials.credential); return toReturn; } @Override - public Map start(String org, String vDC, String name, String templateId, + public Map start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options, int... portsToOpen) { if (options.getDiskSizeKilobytes() != null) { logger.warn("trmk does not support resizing the primary disk; unsetting disk size"); @@ -94,11 +97,12 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient { if (portsToOpen.length > 0 && !options.shouldBlockOnDeploy()) throw new IllegalArgumentException("We cannot open ports on terremark unless we can deploy the vapp"); String password = null; - if (client.getVAppTemplate(templateId).getDescription().indexOf("Windows") != -1) { + VAppTemplate template = client.getVAppTemplate(templateId); + if (template.getDescription().indexOf("Windows") != -1) { password = passwordGenerator.get(); options.getProperties().put("password", password); } - Map response = super.start(org, vDC, name, templateId, options, portsToOpen); + Map response = super.start(VDC, templateId, name, options, portsToOpen); if (password != null) { response = new LinkedHashMap(response); response.put("password", password); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java index 1edde71731..f8603a772b 100755 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java @@ -22,6 +22,7 @@ package org.jclouds.vcloud.terremark.compute.config; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount; +import java.net.URI; import java.security.SecureRandom; import java.util.Map; import java.util.Set; @@ -49,6 +50,7 @@ import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; +import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.VCloudComputeClient; @@ -64,7 +66,6 @@ import org.jclouds.vcloud.terremark.compute.domain.OrgAndName; import org.jclouds.vcloud.terremark.compute.functions.NodeMetadataToOrgAndName; import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions; import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials; -import org.jclouds.vcloud.terremark.compute.strategy.TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.vcloud.terremark.compute.strategy.TerremarkVCloudGetNodeMetadataStrategy; import org.jclouds.vcloud.terremark.domain.KeyPair; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; @@ -115,9 +116,8 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer @Override public NodeMetadata execute(String tag, String name, Template template) { TerremarkInstantiateVAppTemplateOptions options = getOptions.apply(template); - Map metaMap = computeClient.start(template.getLocation().getParent().getId(), template - .getLocation().getId(), name, template.getImage().getProviderId(), options, template.getOptions() - .getInboundPorts()); + Map metaMap = computeClient.start(URI.create(template.getLocation().getId()), URI + .create(template.getImage().getId()), name, options, template.getOptions().getInboundPorts()); return getNode.execute(metaMap.get("id")); } @@ -150,7 +150,7 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer }).to(new TypeLiteral>() { }).in(Scopes.SINGLETON); // NOTE - bind(RunNodesAndAddToSetStrategy.class).to(TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.class); + bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class); bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class); // NOTE bind(GetNodeMetadataStrategy.class).to(TerremarkVCloudGetNodeMetadataStrategy.class); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java deleted file mode 100644 index 291f59da4b..0000000000 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.terremark.compute.strategy; - -import java.security.SecureRandom; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutorService; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.strategy.AddNodeWithTagStrategy; -import org.jclouds.compute.strategy.ListNodesStrategy; -import org.jclouds.compute.util.ComputeUtils; -import org.jclouds.domain.LocationScope; -import org.jclouds.vcloud.compute.strategy.EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy; -import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions; - -import java.util.concurrent.Future; - -/** - * creates futures that correlate to - * - * @author Adrian Cole - */ -@Singleton -public class TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy extends - EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy { - - private final CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise; - - @Inject - protected TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy( - AddNodeWithTagStrategy addNodeWithTagStrategy, ListNodesStrategy listNodesStrategy, - @Named("NAMING_CONVENTION") String nodeNamingConvention, ComputeUtils utils, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, SecureRandom random, - CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) { - super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, utils, executor, random); - this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise; - } - - @Override - public Map> execute(String tag, int count, Template template, Set nodes, - Map badNodes) { - assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: " - + template.getLocation(); - createNewKeyPairUnlessUserSpecifiedOtherwise.execute(template.getLocation().getParent().getId(), tag, template - .getOptions().as(TerremarkVCloudTemplateOptions.class)); - return super.execute(tag, count, template, nodes, badNodes); - } -} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java index 03ba3fe577..a115e2815d 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java @@ -102,7 +102,7 @@ public class TerremarkVCloudExpressRestClientModule extends @Override public NamedResource apply(NamedResource from) { - return client.getOrganizationNamed(from.getName()).getKeysList(); + return client.findOrganizationNamed(from.getName()).getKeysList(); } }); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/NodeConfiguration.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/NodeConfiguration.java deleted file mode 100644 index 11b2f71498..0000000000 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/NodeConfiguration.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.terremark.domain; - - -/** - * - * @author Adrian Cole - * - */ -public class NodeConfiguration { - private String name = null; - private String description = null; - private String enabled = null; - - public NodeConfiguration enableTraffic() { - this.enabled = "true"; - return this; - } - - public NodeConfiguration disableTraffic() { - this.enabled = "false"; - return this; - } - - public NodeConfiguration changeNameTo(String name) { - this.name = name; - return this; - } - - public NodeConfiguration changeDescriptionTo(String description) { - this.description = description; - return this; - } - - public static class Builder { - /** - * @see NodeConfiguration#changeNameTo(String) - */ - public static NodeConfiguration changeNameTo(String name) { - NodeConfiguration options = new NodeConfiguration(); - return options.changeNameTo(name); - } - - /** - * @see NodeConfiguration#changeDescriptionTo(String) - */ - public static NodeConfiguration changeDescriptionTo(String description) { - NodeConfiguration options = new NodeConfiguration(); - return options.changeDescriptionTo(description); - } - - /** - * @see NodeConfiguration#enableTraffic() - */ - public static NodeConfiguration enableTraffic() { - NodeConfiguration options = new NodeConfiguration(); - return options.enableTraffic(); - } - - /** - * @see NodeConfiguration#disableTraffic() - */ - public static NodeConfiguration disableTraffic() { - NodeConfiguration options = new NodeConfiguration(); - return options.disableTraffic(); - } - } - - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public String getEnabled() { - return enabled; - } -} diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkCatalogItem.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkCatalogItem.java new file mode 100644 index 0000000000..4ef4b8c0fd --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkCatalogItem.java @@ -0,0 +1,38 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.terremark.domain; + +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.terremark.domain.internal.TerremarkCatalogItemImpl; + +import com.google.inject.ImplementedBy; + +/** + * @author Adrian Cole + */ +@ImplementedBy(TerremarkCatalogItemImpl.class) +public interface TerremarkCatalogItem extends CatalogItem { + + NamedResource getComputeOptions(); + + NamedResource getCustomizationOptions(); + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkCatalogItemImpl.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkCatalogItemImpl.java new file mode 100644 index 0000000000..d2197acbfd --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkCatalogItemImpl.java @@ -0,0 +1,88 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.terremark.domain.internal; + +import java.net.URI; +import java.util.Map; + +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.internal.CatalogItemImpl; +import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem; + +/** + * + * @author Adrian Cole + * + */ +public class TerremarkCatalogItemImpl extends CatalogItemImpl implements TerremarkCatalogItem { + + private final NamedResource computeOptions; + private final NamedResource customizationOptions; + + public TerremarkCatalogItemImpl(String id, String name, URI location, String description, + NamedResource computeOptions, NamedResource customizationOptions, NamedResource entity, + Map properties) { + super(id, name, location, description, entity, properties); + this.computeOptions = computeOptions; + this.customizationOptions = customizationOptions; + } + + @Override + public NamedResource getComputeOptions() { + return computeOptions; + } + + @Override + public NamedResource getCustomizationOptions() { + return customizationOptions; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((computeOptions == null) ? 0 : computeOptions.hashCode()); + result = prime * result + ((customizationOptions == null) ? 0 : customizationOptions.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; + TerremarkCatalogItemImpl other = (TerremarkCatalogItemImpl) obj; + if (computeOptions == null) { + if (other.computeOptions != null) + return false; + } else if (!computeOptions.equals(other.computeOptions)) + return false; + if (customizationOptions == null) { + if (other.customizationOptions != null) + return false; + } else if (!customizationOptions.equals(other.customizationOptions)) + return false; + return true; + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java index 653d61d666..9d45ad2dbe 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java @@ -55,6 +55,9 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl try { String content = parseErrorFromContentOrNull(command, response); switch (response.getStatusCode()) { + case 400: + exception = new IllegalArgumentException(response.getMessage(), exception); + break; case 401: exception = new AuthorizationException(command.getRequest(), content); break; diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkCatalogItemHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkCatalogItemHandler.java new file mode 100644 index 0000000000..61d983f82e --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkCatalogItemHandler.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.terremark.xml; + +import static org.jclouds.vcloud.util.Utils.newNamedResource; + +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem; +import org.jclouds.vcloud.terremark.domain.internal.TerremarkCatalogItemImpl; +import org.jclouds.vcloud.xml.CatalogItemHandler; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Adrian Cole + */ +public class TerremarkCatalogItemHandler extends CatalogItemHandler { + + private NamedResource customizationOptions; + private NamedResource computeOptions; + + public TerremarkCatalogItem getResult() { + return new TerremarkCatalogItemImpl(catalogItem.getId(), catalogItem.getName(), catalogItem.getLocation(), + description, computeOptions, customizationOptions, entity, properties); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + super.startElement(uri, localName, qName, attributes); + if (qName.equals("Link")) { + int nameIndex = attributes.getIndex("name"); + if (nameIndex != -1) { + if (attributes.getValue(nameIndex).equals("Customization Options")) { + customizationOptions = newNamedResource(attributes); + } else if (attributes.getValue(nameIndex).equals("Compute Options")) { + computeOptions = newNamedResource(attributes); + } + } + + } + } +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java index beffcb4fa2..495192cb68 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java @@ -47,21 +47,22 @@ import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.vcloud.VCloudClientLiveTest; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Catalog; -import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; -import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; +import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem; import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.testng.annotations.AfterTest; @@ -96,6 +97,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { private RetryablePredicate socketTester; private RetryablePredicate successTester; private VApp clone; + private VDC vdc; public static final String PREFIX = System.getProperty("user.name") + "-terremark"; @Test(expectedExceptions = NullPointerException.class) @@ -106,14 +108,15 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { @Test public void testGetAllInternetServices() throws Exception { - for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.getDefaultVDC().getId())) { + for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.findVDCInOrgNamed(null, null) + .getId())) { assertNotNull(tmClient.getNodes(service.getId())); } } @Test public void testGetPublicIpsAssociatedWithVDC() throws Exception { - for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.getDefaultVDC().getId())) { + for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getId())) { assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId())); assertNotNull(tmClient.getPublicIp(ip.getId())); } @@ -121,11 +124,11 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { @Test public void testGetConfigCustomizationOptions() throws Exception { - Catalog response = connection.getDefaultCatalog(); + Catalog response = connection.findCatalogInOrgNamed(null, null); for (NamedResource resource : response.values()) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { - CatalogItem item = connection.getCatalogItem(resource.getId()); - assert tmClient.getCustomizationOptionsOfCatalogItem(item.getId()) != null; + TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(null, null, resource.getName()); + assert tmClient.getCustomizationOptions(item.getCustomizationOptions().getLocation()) != null; } } } @@ -133,7 +136,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { @Test public void testDefaultVDC() throws Exception { super.testDefaultVDC(); - TerremarkVDC response = (TerremarkVDC) tmClient.getDefaultVDC(); + TerremarkVDC response = (TerremarkVDC) tmClient.findVDCInOrgNamed(null, null); assertNotNull(response); assertNotNull(response.getCatalog()); assertNotNull(response.getInternetServices()); @@ -155,27 +158,26 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { // String catalogOs = "CentOS 5.3 (32-bit)"; // String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)"; - // lookup the name of the datacenter you are deploying into - String vdc = tmClient.getDefaultVDC().getName(); + // lookup the datacenter you are deploying into + vdc = tmClient.findVDCInOrgNamed(null, null); - // lookup the id of the item in the catalog you wish to deploy by name - Catalog catalog = tmClient.getDefaultCatalog(); - String itemId = catalog.get(itemName).getId(); // create an options object to collect the configuration we want. TerremarkInstantiateVAppTemplateOptions instantiateOptions = createInstantiateOptions(); + TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(null, null, itemName); + // if this template supports setting the root password, let's add it to // our options - CustomizationParameters customizationOptions = tmClient.getCustomizationOptionsOfCatalogItem(itemId); + CustomizationParameters customizationOptions = tmClient.getCustomizationOptions(item.getCustomizationOptions() + .getLocation()); 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(); + VAppTemplate vAppTemplate = tmClient.getVAppTemplate(item.getEntity().getLocation()); // instantiate, noting vApp returned has minimal details - vApp = tmClient.instantiateVAppTemplateInOrg(null, vdc, serverName, vAppTemplateId, instantiateOptions); + vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getLocation(), vAppTemplate.getLocation(), serverName, + instantiateOptions); assertEquals(vApp.getStatus(), VAppStatus.RESOLVED); @@ -203,7 +205,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { vApp = tmClient.getVApp(vApp.getId()); - NamedResource vAppResource = tmClient.getDefaultVDC().getResourceEntities().get(serverName); + NamedResource vAppResource = tmClient.findVDCInOrgNamed(null, null).getResourceEntities().get(serverName); assertEquals(vAppResource.getId(), vApp.getId()); int processorCount = 1; @@ -229,11 +231,11 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { PublicIpAddress ip; if (tmClient instanceof TerremarkVCloudExpressClient) { is = TerremarkVCloudExpressClient.class.cast(tmClient).addInternetServiceToVDC( - tmClient.getVDCInOrg(null, null).getId(), "SSH", Protocol.TCP, 22); + tmClient.findVDCInOrgNamed(null, null).getId(), "SSH", Protocol.TCP, 22); ip = is.getPublicIpAddress(); } else { - ip = TerremarkECloudClient.class.cast(tmClient) - .activatePublicIpInVDC(tmClient.getVDCInOrg(null, null).getId()); + ip = TerremarkECloudClient.class.cast(tmClient).activatePublicIpInVDC( + tmClient.findVDCInOrgNamed(null, null).getId()); is = tmClient.addInternetServiceToExistingIp(ip.getId(), "SSH", Protocol.TCP, 22); } publicIp = ip.getAddress(); @@ -244,11 +246,6 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getId()); System.out.printf("%d: done powering off vApp%n", System.currentTimeMillis()); - // lookup the id of the datacenter you are deploying into - String vdc = tmClient.getDefaultVDC().getName(); - - String vAppIdToClone = vApp.getId(); - StringBuffer name = new StringBuffer(); for (int i = 0; i < 15; i++) name.append("b"); @@ -257,7 +254,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { CloneVAppOptions options = deploy().powerOn().withDescription("The description of " + newName); System.out.printf("%d: cloning vApp%n", System.currentTimeMillis()); - Task task = tmClient.cloneVAppInOrg(null, vdc, vAppIdToClone, newName, options); + Task task = tmClient.cloneVAppInVDC(vdc.getLocation(), vApp.getLocation(), newName, options); // wait for the task to complete assert successTester.apply(task.getId()); @@ -300,8 +297,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { @Test(enabled = true, dependsOnMethods = "testPublicIp") public void testConfigureNode() throws InterruptedException, ExecutionException, TimeoutException, IOException { - node = tmClient.configureNode(node.getId(), new NodeConfiguration().changeDescriptionTo("holy cow")); - assertEquals(node.getDescription(), "holy cow"); + tmClient.configureNode(node.getId(), node.getName(), node.isEnabled(), "holy cow"); } @Test(enabled = true, dependsOnMethods = "testPublicIp") diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java index 486b5e1d42..abe7c67a62 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java @@ -62,7 +62,6 @@ import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule; -import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions; @@ -127,8 +126,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTesteggs", + "nametrueeggs", + "application/vnd.tmrk.vCloud.nodeService+xml", false); + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, NodeHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testConfigureNodeNoDescription() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkECloudAsyncClient.class.getMethod("configureNode", int.class, String.class, + boolean.class, String.class); + HttpRequest request = processor.createRequest(method, 12, "name", true, null); + + assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); + assertPayloadEquals( + request, + "nametrue", "application/vnd.tmrk.vCloud.nodeService+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, NodeHandler.class); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java index 8be7403ce0..f8b94dac2e 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java @@ -48,7 +48,7 @@ public class TerremarkVCloudClientLiveTest extends TerremarkClientLiveTest { @Test public void testKeysList() throws Exception { TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient); - TerremarkOrganization org = vCloudExpressClient.getOrganizationNamed(null); + TerremarkOrganization org = vCloudExpressClient.findOrganizationNamed(null); Set response = vCloudExpressClient.listKeyPairsInOrg(null); assertNotNull(response); System.err.println(response); @@ -59,7 +59,7 @@ public class TerremarkVCloudClientLiveTest extends TerremarkClientLiveTest { protected void prepare() { TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient); - TerremarkOrganization org = vCloudExpressClient.getOrganizationNamed(null); + TerremarkOrganization org = vCloudExpressClient.findOrganizationNamed(null); try { key = vCloudExpressClient.generateKeyPairInOrg(org.getName(), "livetest", false); } catch (IllegalStateException e) { diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressAsyncClientTest.java index 65f7a20974..19411a5bf0 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressAsyncClientTest.java @@ -52,8 +52,11 @@ import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.internal.CatalogImpl; +import org.jclouds.vcloud.domain.internal.CatalogItemImpl; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.OrganizationImpl; import org.jclouds.vcloud.endpoints.Org; @@ -63,7 +66,6 @@ import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule; -import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions; @@ -76,6 +78,7 @@ import org.jclouds.vcloud.terremark.xml.KeyPairHandler; import org.jclouds.vcloud.terremark.xml.KeyPairsHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler; import org.jclouds.vcloud.terremark.xml.NodesHandler; +import org.jclouds.vcloud.terremark.xml.TerremarkCatalogItemHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler; import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.VAppHandler; @@ -96,6 +99,39 @@ import com.google.inject.TypeLiteral; */ @Test(groups = "unit", sequential = true, testName = "TerremarkVCloudExpressAsyncClientTest") public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest { + + public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getCatalogItem", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TerremarkCatalogItemHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", + String.class, String.class, String.class); + HttpRequest request = processor.createRequest(method, "org", "catalog", "item"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TerremarkCatalogItemHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + /** * ignore parameter of catalog id since this doesn't work */ @@ -130,8 +166,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTesteggs", + "nametrueeggs", + "application/vnd.tmrk.vCloud.nodeService+xml", false); + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, NodeHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testConfigureNodeNoDescription() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("configureNode", int.class, String.class, + boolean.class, String.class); + HttpRequest request = processor.createRequest(method, 12, "name", true, null); + + assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); + assertPayloadEquals( + request, + "nametrue", "application/vnd.tmrk.vCloud.nodeService+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, NodeHandler.class); @@ -558,6 +614,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest> get() { + return ImmutableMap.> of("org", + + ImmutableMap. of("catalog", new CatalogImpl("1", "catalog", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"), "description", ImmutableMap + . of("item", new NamedResourceImpl("1", "item", + "application/vnd.vmware.vcloud.catalogItem+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")), "template", + new NamedResourceImpl("2", "template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")))))); + } + } + + @Singleton + public static class TestOrganizationCatalogItemSupplier extends OrganizationCatalogItemSupplier { + protected TestOrganizationCatalogItemSupplier() { + super(null, null); + } + + @Override + public Map>> get() { + return ImmutableMap.>> of( + "org", ImmutableMap.> of( + "catalog", ImmutableMap. of("template", + new CatalogItemImpl("2", "template", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), "description", + new NamedResourceImpl("2", "template", + "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")), + ImmutableMap. of())))); + + } } @Override @@ -662,6 +763,11 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest>> catalogs) { + return "catalog"; + } + @Override protected URI provideDefaultNetwork(VCloudClient client) { return URI.create("https://vcloud.safesecureweb.com/network/1990"); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayloadTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayloadTest.java index f75885b633..f1d72ad70c 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayloadTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayloadTest.java @@ -27,13 +27,14 @@ import static org.easymock.classextension.EasyMock.verify; import java.io.IOException; import java.net.URI; +import java.util.Map; import java.util.Properties; import org.jclouds.http.HttpRequest; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressPropertiesBuilder; -import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableMap; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -51,51 +52,35 @@ public class BindNodeConfigurationToXmlPayloadTest { @Override protected void configure() { Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudExpressPropertiesBuilder( - props).build(), "properties")); + Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudExpressPropertiesBuilder(props).build(), + "properties")); } }); - public void testChangeName() throws IOException { - NodeConfiguration config = new NodeConfiguration().changeNameTo("willie"); - String expectedPayload = "willie"; - assertConfigMakesPayload(config, expectedPayload); - } - public void testChangeDescription() throws IOException { - NodeConfiguration config = new NodeConfiguration().changeDescriptionTo("description"); - String expectedPayload = "description"; - assertConfigMakesPayload(config, expectedPayload); - } - - public void testEnableTraffic() throws IOException { - NodeConfiguration config = new NodeConfiguration().enableTraffic(); - String expectedPayload = "true"; - assertConfigMakesPayload(config, expectedPayload); + String expectedPayload = "willietruedescription"; + assertConfigMakesPayload(ImmutableMap. of("name", "willie", "enabled", "true", "description", + "description"), expectedPayload); } public void testDisableTraffic() throws IOException { - NodeConfiguration config = new NodeConfiguration().disableTraffic(); - String expectedPayload = "false"; - assertConfigMakesPayload(config, expectedPayload); + String expectedPayload = "williefalse"; + assertConfigMakesPayload(ImmutableMap. of("name", "willie", "enabled", "false"), expectedPayload); } public void testTwoOptions() throws IOException { - NodeConfiguration config = new NodeConfiguration().disableTraffic().changeNameTo("willie"); - String expectedPayload = "williefalse"; - assertConfigMakesPayload(config, expectedPayload); + String expectedPayload = "willietrue"; + assertConfigMakesPayload(ImmutableMap. of("name", "willie", "enabled", "true"), expectedPayload); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test(expectedExceptions = NullPointerException.class) public void testNoOptions() throws IOException { - NodeConfiguration config = new NodeConfiguration(); String expectedPayload = "williefalse"; - assertConfigMakesPayload(config, expectedPayload); + assertConfigMakesPayload(ImmutableMap. of(), expectedPayload); } - private void assertConfigMakesPayload(NodeConfiguration config, String expectedPayload) { - BindNodeConfigurationToXmlPayload binder = injector - .getInstance(BindNodeConfigurationToXmlPayload.class); + private void assertConfigMakesPayload(Map config, String expectedPayload) { + BindNodeConfigurationToXmlPayload binder = injector.getInstance(BindNodeConfigurationToXmlPayload.class); HttpRequest request = createMock(HttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); request.setPayload(expectedPayload); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java index 4970e9ec10..a6c873e09a 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java @@ -27,6 +27,7 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.util.Map; import javax.inject.Provider; @@ -38,6 +39,7 @@ import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient; import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials; +import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.testng.annotations.Test; @@ -55,19 +57,28 @@ public class TerremarkVCloudComputeClientTest { InputStream is = getClass().getResourceAsStream("/terremark/windows_description.txt"); String description = new String(ByteStreams.toByteArray(is)); VAppTemplate template = createMock(VAppTemplate.class); + TerremarkVDC vdc = createMock(TerremarkVDC.class); + URI templateURI = URI.create("template"); + URI vdcURI = URI.create("vdc"); + expect(template.getDescription()).andReturn(description).atLeastOnce(); TerremarkVCloudExpressClient client = createMock(TerremarkVCloudExpressClient.class); - expect(client.getVAppTemplate("templateId")).andReturn(template); VApp vApp = createMock(VApp.class); + expect(client.getVDC(vdcURI)).andReturn(vdc); + expect(client.getVAppTemplate(templateURI)).andReturn(template); + // TODO make this call only once + expect(client.getVAppTemplate(templateURI)).andReturn(template); + + expect(vdc.getLocation()).andReturn(vdcURI); + expect(template.getLocation()).andReturn(templateURI); expect( - client.instantiateVAppTemplateInOrg("org", "vDC", "name", "templateId", + client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name", new TerremarkInstantiateVAppTemplateOptions().productProperty("password", "password"))).andReturn( vApp); Task task = createMock(Task.class); expect(vApp.getId()).andReturn("1").atLeastOnce(); - expect(client.getVAppTemplate("templateId")).andReturn(template); expect(client.deployVApp("1")).andReturn(task); expect(task.getId()).andReturn("1").atLeastOnce(); Predicate successTester = createMock(Predicate.class); @@ -87,6 +98,7 @@ public class TerremarkVCloudComputeClientTest { }, successTester, vAppStatusToNodeState); + replay(vdc); replay(template); replay(vApp); replay(task); @@ -95,13 +107,14 @@ public class TerremarkVCloudComputeClientTest { replay(notFoundTester); replay(vAppStatusToNodeState); - Map response = computeClient.start("org", "vDC", "name", "templateId", + Map response = computeClient.start(vdcURI, templateURI, "name", new TerremarkInstantiateVAppTemplateOptions()); assertEquals(response.get("id"), "1"); assertEquals(response.get("username"), "Administrator"); assertEquals(response.get("password"), "password"); + verify(vdc); verify(template); verify(vApp); verify(task); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java index cc9915362e..2e4c0b6c76 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java @@ -34,7 +34,15 @@ import org.testng.annotations.Test; */ @Test(groups = { "unit" }) public class ParseTerremarkVCloudErrorFromHttpResponseTest extends BaseHttpErrorHandlerTest { - + @Test + public void testGet400SetsIllegalArgumentException() { + assertCodeMakes( + "GET", + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), + 400, + "HTTP/1.1 400 Service name is required.", + "", IllegalArgumentException.class); + } @Test public void testGet403SetsResourceNotFoundException() { assertCodeMakes( diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkCatalogItemHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkCatalogItemHandlerTest.java new file mode 100644 index 0000000000..d05807c322 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkCatalogItemHandlerTest.java @@ -0,0 +1,95 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.terremark.xml; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.vcloud.domain.internal.NamedResourceImpl; +import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder; +import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem; +import org.jclouds.vcloud.terremark.domain.internal.TerremarkCatalogItemImpl; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Guice; +import com.google.inject.name.Names; + +/** + * Tests behavior of {@code TerremarkCatalogItemHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.TerremarkCatalogItemHandlerTest") +public class TerremarkCatalogItemHandlerTest extends BaseHandlerTest { + @Override + @BeforeTest + protected void setUpInjector() { + injector = Guice.createInjector(new SaxParserModule() { + @Override + public void configure() { + super.configure(); + Properties props = new Properties(); + Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props).build(), + "properties")); + } + }); + factory = injector.getInstance(ParseSax.Factory.class); + assert factory != null; + } + + public void testApplyInputStream() { + + InputStream is = getClass().getResourceAsStream("/terremark/catalogItem.xml"); + + TerremarkCatalogItem result = (TerremarkCatalogItem) factory.create( + injector.getInstance(TerremarkCatalogItemHandler.class)).parse(is); + assertEquals( + result, + new TerremarkCatalogItemImpl( + "37-159", + "CentOS 5.3 (32-bit)", + URI.create("https://services.vCloudexpress.terremark.com/api/v0.8a-13ext1.6/catalogItem/37-159"), + null, + new NamedResourceImpl( + "compute", + "Compute Options", + "application/vnd.tmrk.vcloudExpress.vappComputeOptionParameters+xml", + URI + .create("https://services.vCloudexpress.terremark.com/api/v0.8a-ext1.6/extensions/template/37-159/options/compute")), + new NamedResourceImpl( + "customization", + "Customization Options", + "application/vnd.tmrk.vcloudExpress.vappCustomizationParameters+xml", + URI + .create("https://services.vCloudexpress.terremark.com/api/v0.8a-ext1.6/extensions/template/37-159/options/customization")), + new NamedResourceImpl("37", "CentOS 5.3 (32-bit)", "application/vnd.vmware.vCloud.vAppTemplate+xml", + URI.create("https://services.vCloudexpress.terremark.com/api/v0.8a-ext1.6/vappTemplate/37")), + ImmutableMap. of("LicensingCost", "0"))); + } +} diff --git a/vcloud/terremark/src/test/resources/terremark/catalogItem.xml b/vcloud/terremark/src/test/resources/terremark/catalogItem.xml new file mode 100644 index 0000000000..f8d279a15b --- /dev/null +++ b/vcloud/terremark/src/test/resources/terremark/catalogItem.xml @@ -0,0 +1,17 @@ + + + + + 0 + \ No newline at end of file