diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeClient.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeClient.java index 58411a6e40..1a6f6494d4 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeClient.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeClient.java @@ -30,8 +30,8 @@ import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrat import org.jclouds.domain.Credentials; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl; -import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.Status; +import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppTemplate; import com.google.common.base.Predicate; diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeClient.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeClient.java index cfda41e4ba..6e38405efe 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeClient.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeClient.java @@ -32,7 +32,7 @@ import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.Status; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import com.google.common.base.Predicate; @@ -51,7 +51,7 @@ public class BlueLockVCloudExpressComputeClient extends VCloudExpressComputeClie } @Override - protected Map parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) { + protected Map parseAndValidateResponse(VCloudExpressVAppTemplate template, VApp vAppResponse) { Credentials credentials = credentialsProvider.execute(template); Map toReturn = super.parseResponse(template, vAppResponse); toReturn.put("username", credentials.identity); diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudDirectorComputeServiceContextModule.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudDirectorComputeServiceContextModule.java index acbf6d57e1..0a2b234ec0 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudDirectorComputeServiceContextModule.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudDirectorComputeServiceContextModule.java @@ -29,7 +29,7 @@ import org.jclouds.vcloud.bluelock.compute.functions.BlueLockVCloudImageForVAppT import org.jclouds.vcloud.bluelock.compute.strategy.DefaultLoginCredentialsFromBlueLockFAQ; import org.jclouds.vcloud.compute.VCloudComputeClient; import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; -import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate; +import org.jclouds.vcloud.compute.functions.ImageForVCloudExpressVAppTemplate; import com.google.common.base.Supplier; import com.google.inject.Injector; @@ -45,7 +45,7 @@ public class BlueLockVCloudDirectorComputeServiceContextModule extends VCloudCom @Override protected void configure() { super.configure(); - bind(ImageForVAppTemplate.class).to(BlueLockVCloudImageForVAppTemplate.class); + bind(ImageForVCloudExpressVAppTemplate.class).to(BlueLockVCloudImageForVAppTemplate.class); bind(VCloudComputeClient.class).to(BlueLockVCloudDirectorComputeClient.class); bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(DefaultLoginCredentialsFromBlueLockFAQ.class); } diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudExpressComputeServiceContextModule.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudExpressComputeServiceContextModule.java index ff3659e864..702b52c8b3 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudExpressComputeServiceContextModule.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudExpressComputeServiceContextModule.java @@ -29,7 +29,7 @@ import org.jclouds.vcloud.bluelock.compute.functions.BlueLockVCloudImageForVAppT import org.jclouds.vcloud.bluelock.compute.strategy.DefaultLoginCredentialsFromBlueLockFAQ; import org.jclouds.vcloud.compute.VCloudExpressComputeClient; import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule; -import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate; +import org.jclouds.vcloud.compute.functions.ImageForVCloudExpressVAppTemplate; import com.google.common.base.Supplier; import com.google.inject.Injector; @@ -45,7 +45,7 @@ public class BlueLockVCloudExpressComputeServiceContextModule extends VCloudExpr @Override protected void configure() { super.configure(); - bind(ImageForVAppTemplate.class).to(BlueLockVCloudImageForVAppTemplate.class); + bind(ImageForVCloudExpressVAppTemplate.class).to(BlueLockVCloudImageForVAppTemplate.class); bind(VCloudExpressComputeClient.class).to(BlueLockVCloudExpressComputeClient.class); bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(DefaultLoginCredentialsFromBlueLockFAQ.class); } diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/suppliers/ParseSizeFromImageSupplier.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/suppliers/ParseSizeFromImageSupplier.java index 895c77dbcd..c144b5d31a 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/suppliers/ParseSizeFromImageSupplier.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/suppliers/ParseSizeFromImageSupplier.java @@ -39,8 +39,8 @@ import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.compute.domain.VCloudImage; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.compute.domain.VCloudExpressImage; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import com.google.common.base.Function; import com.google.common.base.Predicates; @@ -77,7 +77,7 @@ public class ParseSizeFromImageSupplier implements Supplier> @Override public Size apply(Image from) { try { - VAppTemplate template = VCloudImage.class.cast(from).getVAppTemplate(); + VCloudExpressVAppTemplate template = VCloudExpressImage.class.cast(from).getVAppTemplate(); Matcher matcher = getMatcherAndFind(template.getName()); double cores = Double.parseDouble(matcher.group(1)); int ram = Integer.parseInt(matcher.group(2)); diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudImageForVAppTemplate.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudImageForVAppTemplate.java index 1e1e12c70a..f6bc9c1b87 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudImageForVAppTemplate.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudImageForVAppTemplate.java @@ -24,14 +24,14 @@ import javax.inject.Singleton; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.vcloud.compute.functions.FindLocationForResource; -import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate; +import org.jclouds.vcloud.compute.functions.ImageForVCloudExpressVAppTemplate; /** * * @author Adrian Cole */ @Singleton -public class BlueLockVCloudImageForVAppTemplate extends ImageForVAppTemplate { +public class BlueLockVCloudImageForVAppTemplate extends ImageForVCloudExpressVAppTemplate { @Inject protected BlueLockVCloudImageForVAppTemplate(FindLocationForResource findLocationForResource, diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/strategy/DefaultLoginCredentialsFromBlueLockFAQ.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/strategy/DefaultLoginCredentialsFromBlueLockFAQ.java index 45e555cc78..66d27947b9 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/strategy/DefaultLoginCredentialsFromBlueLockFAQ.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/strategy/DefaultLoginCredentialsFromBlueLockFAQ.java @@ -26,7 +26,7 @@ import javax.inject.Singleton; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.domain.Credentials; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; /** * @@ -42,9 +42,9 @@ public class DefaultLoginCredentialsFromBlueLockFAQ implements @Override public Credentials execute(Object resourceToAuthenticate) { checkNotNull(resourceToAuthenticate); - checkArgument(resourceToAuthenticate instanceof VAppTemplate, + checkArgument(resourceToAuthenticate instanceof VCloudExpressVAppTemplate, "Resource must be an VAppTemplate (for Terremark)"); - VAppTemplate template = (VAppTemplate) resourceToAuthenticate; + VCloudExpressVAppTemplate template = (VCloudExpressVAppTemplate) resourceToAuthenticate; if (template.getDescription().indexOf("Windows") >= 0) { return new Credentials("expressuser", "ExpressPassword#1"); } else { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/CommonVCloudAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/CommonVCloudAsyncClient.java index 85fce4fd50..45e5f340a8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/CommonVCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/CommonVCloudAsyncClient.java @@ -25,7 +25,6 @@ import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML; import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; -import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; @@ -50,14 +49,12 @@ import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.VApp; -import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.network.OrgNetwork; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint; 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.OrgNameToTasksListEndpoint; import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint; @@ -68,7 +65,6 @@ import org.jclouds.vcloud.xml.OrgNetworkHandler; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.VAppHandler; -import org.jclouds.vcloud.xml.VAppTemplateHandler; import org.jclouds.vcloud.xml.VDCHandler; import com.google.common.util.concurrent.ListenableFuture; @@ -122,27 +118,6 @@ public interface CommonVCloudAsyncClient { @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName, @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName); - /** - * @see VCloudClient#getVAppTemplate - */ - @GET - @Consumes(VAPPTEMPLATE_XML) - @XMLResponseParser(VAppTemplateHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - 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, - @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName); - /** * @see VCloudClient#getCatalogItem */ diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/CommonVCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/CommonVCloudClient.java index c64eafc70d..744547350f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/CommonVCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/CommonVCloudClient.java @@ -32,7 +32,6 @@ import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.VApp; -import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.network.OrgNetwork; @@ -92,25 +91,6 @@ public interface CommonVCloudClient { */ CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName); - VAppTemplate getVAppTemplate(URI vAppTemplate); - - /** - * returns the vapp template corresponding to a catalog item in the catalog associated with the - * specified name. Note that the org and catalog parameters can be null to choose default. - * - * @param orgName - * organization name, or null for the default - * @param catalogName - * catalog name, or null for the default - * @param itemName - * item you wish to lookup - * - * @throws NoSuchElementException - * if you specified an org, catalog, or catalog item name that isn't present - */ - VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, - String itemName); - OrgNetwork findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName); OrgNetwork getNetwork(URI network); 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 b1a9b79263..894005b27c 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -20,31 +20,39 @@ package org.jclouds.vcloud; import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; +import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import java.net.URI; +import javax.annotation.Nullable; import javax.ws.rs.Consumes; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import org.jclouds.predicates.validators.DnsNameValidator; 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.ParamValidators; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload; -import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; +import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.VAppHandler; +import org.jclouds.vcloud.xml.VAppTemplateHandler; import com.google.common.util.concurrent.ListenableFuture; @@ -52,12 +60,34 @@ import com.google.common.util.concurrent.ListenableFuture; * Provides access to VCloud resources via their REST API. *

* - * @see + * @see * @author Adrian Cole */ @RequestFilters(SetVCloudTokenCookie.class) public interface VCloudAsyncClient extends CommonVCloudAsyncClient { + /** + * @see VCloudClient#getVAppTemplate + */ + @GET + @Consumes(VAPPTEMPLATE_XML) + @XMLResponseParser(VAppTemplateHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVAppTemplate(@EndpointParam URI vAppTemplate); + + /** + * @see VCloudClient#findVAppTemplateInOrgCatalogNamed + */ + @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, + @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName); + /** * @see VCloudClient#instantiateVAppTemplateInVDC */ @@ -66,11 +96,12 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient { @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") @Consumes(VAPP_XML) @XMLResponseParser(VAppHandler.class) - @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) + // TODO convert this. + @MapBinder(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class) ListenableFuture instantiateVAppTemplateInVDC(@EndpointParam URI vdc, - @MapPayloadParam("template") URI template, - @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, - InstantiateVAppTemplateOptions... options); + @MapPayloadParam("template") URI template, + @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, + InstantiateVAppTemplateOptions... options); /** * @see VCloudClient#cloneVAppInVDC @@ -82,7 +113,7 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient { @XMLResponseParser(TaskHandler.class) @MapBinder(BindCloneVAppParamsToXmlPayload.class) ListenableFuture cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone, - @MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, - CloneVAppOptions... options); + @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 1c12549f18..7712181672 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -20,11 +20,15 @@ package org.jclouds.vcloud; import java.net.URI; +import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -40,9 +44,28 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) public interface VCloudClient extends CommonVCloudClient { - VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options); Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options); + VAppTemplate getVAppTemplate(URI vAppTemplate); + + /** + * returns the vapp template corresponding to a catalog item in the catalog + * associated with the specified name. Note that the org and catalog + * parameters can be null to choose default. + * + * @param orgName + * organization name, or null for the default + * @param catalogName + * catalog name, or null for the default + * @param itemName + * item you wish to lookup + * + * @throws NoSuchElementException + * if you specified an org, catalog, or catalog item name that + * isn't present + */ + VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, + String itemName); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressAsyncClient.java index 68413d4266..3e7c1ad38d 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressAsyncClient.java @@ -21,6 +21,7 @@ package org.jclouds.vcloud; import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML; import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; +import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import java.net.URI; @@ -42,17 +43,20 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload; -import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; +import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.domain.network.OrgNetwork; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.xml.OrgNetworkFromVCloudExpressNetworkHandler; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.VAppHandler; +import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler; import com.google.common.util.concurrent.ListenableFuture; @@ -60,11 +64,34 @@ import com.google.common.util.concurrent.ListenableFuture; * Provides access to VCloud resources via their REST API. *

* - * @see + * @see * @author Adrian Cole */ @RequestFilters(SetVCloudTokenCookie.class) public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient { + + /** + * @see VCloudClient#getVAppTemplate + */ + @GET + @Consumes(VAPPTEMPLATE_XML) + @XMLResponseParser(VCloudExpressVAppTemplateHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVAppTemplate(@EndpointParam URI vAppTemplate); + + /** + * @see VCloudClient#findVAppTemplateInOrgCatalogNamed + */ + @GET + @Consumes(VAPPTEMPLATE_XML) + @XMLResponseParser(VCloudExpressVAppTemplateHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findVAppTemplateInOrgCatalogNamed( + @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName, + @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName); + /** * @see VCloudClient#findNetworkInOrgVDCNamed */ @@ -74,9 +101,9 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient { @XMLResponseParser(OrgNetworkFromVCloudExpressNetworkHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture findNetworkInOrgVDCNamed( - @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName, - @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName); + @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName, + @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName); /** * @see VCloudClient#getNetwork @@ -96,11 +123,11 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient { @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") @Consumes(VAPP_XML) @XMLResponseParser(VAppHandler.class) - @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) + @MapBinder(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class) ListenableFuture instantiateVAppTemplateInVDC(@EndpointParam URI vdc, - @MapPayloadParam("template") URI template, - @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, - InstantiateVAppTemplateOptions... options); + @MapPayloadParam("template") URI template, + @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, + InstantiateVAppTemplateOptions... options); /** * @see VCloudExpressClient#cloneVAppInVDC @@ -112,7 +139,7 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient { @XMLResponseParser(TaskHandler.class) @MapBinder(BindCloneVAppParamsToXmlPayload.class) ListenableFuture cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone, - @MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, - CloneVAppOptions... options); + @MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, + CloneVAppOptions... options); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressClient.java index c9c468a372..acd6926c32 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressClient.java @@ -20,11 +20,15 @@ package org.jclouds.vcloud; import java.net.URI; +import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -32,7 +36,8 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; * Provides access to VCloud resources via their REST API. *

* - * @see + * @see * @author Adrian Cole */ @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) @@ -42,4 +47,24 @@ public interface VCloudExpressClient extends CommonVCloudClient { Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options); + VCloudExpressVAppTemplate getVAppTemplate(URI vAppTemplate); + + /** + * returns the vapp template corresponding to a catalog item in the catalog + * associated with the specified name. Note that the org and catalog + * parameters can be null to choose default. + * + * @param orgName + * organization name, or null for the default + * @param catalogName + * catalog name, or null for the default + * @param itemName + * item you wish to lookup + * + * @throws NoSuchElementException + * if you specified an org, catalog, or catalog item name that + * isn't present + */ + VCloudExpressVAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, + String itemName); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java similarity index 98% rename from vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java index b4309ac4a1..10fab06373 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java @@ -59,7 +59,7 @@ import com.jamesmurty.utils.XMLBuilder; * */ @Singleton -public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder { +public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implements MapBinder { protected final String ns; protected final String schema; @@ -71,7 +71,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder private final String apiVersion; @Inject - public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, + public BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network, @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) { 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 6c663faf4c..e8b6a8c5bf 100644 --- 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 @@ -22,6 +22,7 @@ package org.jclouds.vcloud.compute.config; import javax.inject.Singleton; import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.rest.RestContext; @@ -29,9 +30,12 @@ import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.CommonVCloudComputeClient; import org.jclouds.vcloud.compute.VCloudComputeClient; +import org.jclouds.vcloud.compute.functions.ImagesInOrg; import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl; import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy; +import org.jclouds.vcloud.domain.Org; +import com.google.common.base.Function; import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; @@ -53,6 +57,9 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic bind(new TypeLiteral>() { }).to(new TypeLiteral>() { }).in(Scopes.SINGLETON); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModule.java index f1818694cf..8fb87981b8 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModule.java @@ -22,6 +22,7 @@ package org.jclouds.vcloud.compute.config; import javax.inject.Singleton; import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.rest.RestContext; @@ -29,9 +30,12 @@ import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.compute.CommonVCloudComputeClient; import org.jclouds.vcloud.compute.VCloudExpressComputeClient; +import org.jclouds.vcloud.compute.functions.ImagesInVCloudExpressOrg; import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl; import org.jclouds.vcloud.compute.strategy.VCloudExpressAddNodeWithTagStrategy; +import org.jclouds.vcloud.domain.Org; +import com.google.common.base.Function; import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; @@ -53,6 +57,9 @@ public class VCloudExpressComputeServiceContextModule extends CommonVCloudComput bind(new TypeLiteral>() { }).to(new TypeLiteral>() { }).in(Scopes.SINGLETON); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); bind(AddNodeWithTagStrategy.class).to(VCloudExpressAddNodeWithTagStrategy.class); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudExpressImage.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudExpressImage.java new file mode 100644 index 0000000000..8a835ef620 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudExpressImage.java @@ -0,0 +1,55 @@ +/** + * + * 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.domain; + +import java.net.URI; +import java.util.Map; + +import javax.annotation.Nullable; + +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.internal.ImageImpl; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; + +/** + * @author Adrian Cole + */ +public class VCloudExpressImage extends ImageImpl { + + /** The serialVersionUID */ + private static final long serialVersionUID = -8520373150950058296L; + + private final VCloudExpressVAppTemplate template; + + public VCloudExpressImage(VCloudExpressVAppTemplate template, String providerId, String name, String id, Location location, URI uri, + Map userMetadata, OperatingSystem operatingSystem, String description, + @Nullable String version, @Nullable Credentials defaultCredentials) { + super(providerId, name, id, location, uri, userMetadata, operatingSystem, description, version, + defaultCredentials); + this.template = template; + } + + public VCloudExpressVAppTemplate getVAppTemplate() { + return template; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudImage.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudImage.java index d96d81602b..660c57735f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudImage.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudImage.java @@ -41,10 +41,10 @@ public class VCloudImage extends ImageImpl { private final VAppTemplate template; public VCloudImage(VAppTemplate template, String providerId, String name, String id, Location location, URI uri, - Map userMetadata, OperatingSystem operatingSystem, String description, - @Nullable String version, @Nullable Credentials defaultCredentials) { + Map userMetadata, OperatingSystem operatingSystem, String description, + @Nullable String version, @Nullable Credentials defaultCredentials) { super(providerId, name, id, location, uri, userMetadata, operatingSystem, description, version, - defaultCredentials); + defaultCredentials); this.template = template; } 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 13d827cc36..b06992f465 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 = checkNotNull(findLocationForResource, "findLocationForResource"); this.credentialsProvider = checkNotNull(credentialsProvider, "credentialsProvider"); } @@ -70,7 +70,7 @@ public class ImageForVAppTemplate implements Function { String name = getName(from.getName()); String desc = from.getDescription() != null ? from.getDescription() : from.getName(); return new VCloudImage(from, from.getId().toASCIIString(), name, from.getId().toASCIIString(), location, from - .getId(), ImmutableMap. of(), os, desc, "", credentialsProvider.execute(from)); + .getId(), ImmutableMap. of(), os, desc, "", credentialsProvider.execute(from)); } protected String getName(String name) { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java new file mode 100644 index 0000000000..e7dd087916 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java @@ -0,0 +1,79 @@ +/** + * + * 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.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrNull; + +import javax.inject.Inject; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.domain.Location; +import org.jclouds.vcloud.compute.domain.VCloudExpressImage; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +public class ImageForVCloudExpressVAppTemplate implements Function { + private final FindLocationForResource findLocationForResource; + private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider; + private NamedResource parent; + + @Inject + protected ImageForVCloudExpressVAppTemplate(FindLocationForResource findLocationForResource, + PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider) { + this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); + this.credentialsProvider = checkNotNull(credentialsProvider, "credentialsProvider"); + } + + public ImageForVCloudExpressVAppTemplate withParent(NamedResource parent) { + this.parent = parent; + return this; + } + + @Override + public Image apply(VCloudExpressVAppTemplate from) { + OsFamily osFamily = parseOsFamilyOrNull(checkNotNull(from, "vapp template").getName()); + String osName = null; + String osArch = null; + String osVersion = null; + String osDescription = from.getName(); + boolean is64Bit = from.getName().indexOf("64") != -1; + OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); + + Location location = findLocationForResource.apply(checkNotNull(parent, "parent")); + String name = getName(from.getName()); + String desc = from.getDescription() != null ? from.getDescription() : from.getName(); + return new VCloudExpressImage(from, from.getId().toASCIIString(), name, from.getId().toASCIIString(), location, from + .getId(), ImmutableMap. of(), os, desc, "", credentialsProvider.execute(from)); + } + + protected String getName(String name) { + return name; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVCloudExpressOrg.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVCloudExpressOrg.java new file mode 100644 index 0000000000..4e9ed5b5fa --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVCloudExpressOrg.java @@ -0,0 +1,61 @@ +/** + * + * 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.functions; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Image; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; +import org.jclouds.vcloud.functions.AllCatalogItemsInOrg; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Singleton +public class ImagesInVCloudExpressOrg implements Function> { + + private final AllCatalogItemsInOrg allCatalogItemsInOrg; + private final Function, Iterable> vAppTemplatesForCatalogItems; + private final Provider imageForVAppTemplateProvider; + + @Inject + ImagesInVCloudExpressOrg(AllCatalogItemsInOrg allCatalogItemsInOrg, + Provider imageForVAppTemplateProvider, + Function, Iterable> vAppTemplatesForCatalogItems) { + this.imageForVAppTemplateProvider = imageForVAppTemplateProvider; + this.allCatalogItemsInOrg = allCatalogItemsInOrg; + this.vAppTemplatesForCatalogItems = vAppTemplatesForCatalogItems; + } + + @Override + public Iterable apply(Org from) { + Iterable catalogs = allCatalogItemsInOrg.apply(from); + Iterable vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs); + return Iterables.transform(vAppTemplates, imageForVAppTemplateProvider.get().withParent(from)); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVCloudExpressVDC.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVCloudExpressVDC.java new file mode 100644 index 0000000000..f7b55ca7d9 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVCloudExpressVDC.java @@ -0,0 +1,57 @@ +/** + * + * 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.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Image; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; +import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.functions.VCloudExpressVAppTemplatesForResourceEntities; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Singleton +public class ImagesInVCloudExpressVDC implements Function> { + private final VCloudExpressVAppTemplatesForResourceEntities vAppTemplatesForResourceEntities; + private final ImageForVCloudExpressVAppTemplate imageForVAppTemplateProvider; + + @Inject + public ImagesInVCloudExpressVDC(VCloudExpressVAppTemplatesForResourceEntities vAppTemplatesForResourceEntities, + ImageForVCloudExpressVAppTemplate imageForVAppTemplateProvider) { + this.vAppTemplatesForResourceEntities = checkNotNull(vAppTemplatesForResourceEntities, "vAppTemplatesForResourceEntities"); + this.imageForVAppTemplateProvider = checkNotNull(imageForVAppTemplateProvider, "imageForVAppTemplateProvider"); + } + + @Override + public Iterable apply(VDC from) { + Iterable vAppTemplates = vAppTemplatesForResourceEntities.apply(checkNotNull(from, "vdc") + .getResourceEntities().values()); + return Iterables.transform(vAppTemplates, imageForVAppTemplateProvider.withParent(from)); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVDC.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVDC.java index bf1ecdf8e0..166bd69774 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVDC.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInVDC.java @@ -42,15 +42,16 @@ public class ImagesInVDC implements Function> { @Inject public ImagesInVDC(VAppTemplatesForResourceEntities vAppTemplatesForResourceEntities, - ImageForVAppTemplate imageForVAppTemplateProvider) { - this.vAppTemplatesForResourceEntities = checkNotNull(vAppTemplatesForResourceEntities, "vAppTemplatesForResourceEntities"); + ImageForVAppTemplate imageForVAppTemplateProvider) { + this.vAppTemplatesForResourceEntities = checkNotNull(vAppTemplatesForResourceEntities, + "vAppTemplatesForResourceEntities"); this.imageForVAppTemplateProvider = checkNotNull(imageForVAppTemplateProvider, "imageForVAppTemplateProvider"); } @Override public Iterable apply(VDC from) { Iterable vAppTemplates = vAppTemplatesForResourceEntities.apply(checkNotNull(from, "vdc") - .getResourceEntities().values()); + .getResourceEntities().values()); return Iterables.transform(vAppTemplates, imageForVAppTemplateProvider.withParent(from)); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java index 9f34d2c50c..2d953a9f82 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java @@ -33,10 +33,9 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.vcloud.CommonVCloudClient; import org.jclouds.vcloud.compute.CommonVCloudComputeClient; +import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; -import org.jclouds.vcloud.domain.Status; -import org.jclouds.vcloud.domain.VAppTemplate; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; @@ -48,7 +47,7 @@ import com.google.inject.Inject; * @author Adrian Cole */ @Singleton -public class CommonVCloudComputeClientImpl implements CommonVCloudComputeClient { +public class CommonVCloudComputeClientImpl implements CommonVCloudComputeClient { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @@ -62,7 +61,7 @@ public class CommonVCloudComputeClientImpl implements CommonVCloudComputeClient this.taskTester = successTester; } - protected Map parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) { + protected Map parseAndValidateResponse(T 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"); @@ -70,7 +69,7 @@ public class CommonVCloudComputeClientImpl implements CommonVCloudComputeClient return response; } - protected Map parseResponse(VAppTemplate template, VApp vAppResponse) { + protected Map parseResponse(T template, VApp vAppResponse) { Map config = Maps.newLinkedHashMap();// Allows nulls config.put("id", vAppResponse.getId().toASCIIString()); config.put("username", null); @@ -137,7 +136,7 @@ public class CommonVCloudComputeClientImpl implements CommonVCloudComputeClient public TaskException(String type, VApp vApp, Task task) { super(String.format("failed to %s vApp %s status %s;task %s status %s", type, vApp.getName(), - vApp.getStatus(), task.getLocation(), task.getStatus()), vApp); + vApp.getStatus(), task.getLocation(), task.getStatus()), vApp); this.task = task; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudComputeClientImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudComputeClientImpl.java index 452af905f3..d6c0a10f1e 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudComputeClientImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudComputeClientImpl.java @@ -30,9 +30,9 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.NodeState; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.VCloudComputeClient; +import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; -import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -44,28 +44,28 @@ import com.google.inject.Inject; * @author Adrian Cole */ @Singleton -public class VCloudComputeClientImpl extends CommonVCloudComputeClientImpl implements VCloudComputeClient { +public class VCloudComputeClientImpl extends CommonVCloudComputeClientImpl implements VCloudComputeClient { protected final Map vAppStatusToNodeState; @Inject public VCloudComputeClientImpl(VCloudClient client, Predicate successTester, - Map vAppStatusToNodeState) { + Map vAppStatusToNodeState) { super(client, successTester); this.vAppStatusToNodeState = vAppStatusToNodeState; } @Override public Map start(@Nullable URI VDC, URI templateId, String name, - InstantiateVAppTemplateOptions options, int... portsToOpen) { + InstantiateVAppTemplateOptions options, int... portsToOpen) { checkNotNull(options, "options"); logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options); VDC vdc = client.getVDC(VDC); - VAppTemplate template = client.getVAppTemplate(templateId); + VAppTemplate template = VCloudClient.class.cast(client).getVAppTemplate(templateId); VApp vAppResponse = VCloudClient.class.cast(client).instantiateVAppTemplateInVDC(vdc.getId(), template.getId(), - name, options); + name, options); logger.debug("<< instantiated VApp(%s)", vAppResponse.getName()); logger.debug(">> deploying vApp(%s)", vAppResponse.getName()); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudExpressComputeClientImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudExpressComputeClientImpl.java index 5809b77c91..3aa2dc7192 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudExpressComputeClientImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudExpressComputeClientImpl.java @@ -30,10 +30,10 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.NodeState; import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.compute.VCloudExpressComputeClient; +import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; -import org.jclouds.vcloud.domain.Status; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -44,28 +44,29 @@ import com.google.inject.Inject; * @author Adrian Cole */ @Singleton -public class VCloudExpressComputeClientImpl extends CommonVCloudComputeClientImpl implements VCloudExpressComputeClient { +public class VCloudExpressComputeClientImpl extends CommonVCloudComputeClientImpl implements + VCloudExpressComputeClient { protected final Map vAppStatusToNodeState; @Inject public VCloudExpressComputeClientImpl(VCloudExpressClient client, Predicate successTester, - Map vAppStatusToNodeState) { + Map vAppStatusToNodeState) { super(client, successTester); this.vAppStatusToNodeState = vAppStatusToNodeState; } @Override public Map start(@Nullable URI VDC, URI templateId, String name, - InstantiateVAppTemplateOptions options, int... portsToOpen) { + InstantiateVAppTemplateOptions options, int... portsToOpen) { checkNotNull(options, "options"); logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options); VDC vdc = client.getVDC(VDC); - VAppTemplate template = client.getVAppTemplate(templateId); + VCloudExpressVAppTemplate template = VCloudExpressClient.class.cast(client).getVAppTemplate(templateId); VApp vAppResponse = VCloudExpressClient.class.cast(client).instantiateVAppTemplateInVDC(vdc.getId(), - template.getId(), name, options); + template.getId(), name, options); logger.debug("<< instantiated VApp(%s)", vAppResponse.getName()); logger.debug(">> deploying vApp(%s)", vAppResponse.getName()); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudExpressRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudExpressRestClientModule.java index 25bd236428..45e6e82b20 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudExpressRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudExpressRestClientModule.java @@ -33,27 +33,41 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.domain.VCloudSession; +import org.jclouds.vcloud.functions.VCloudExpressVAppTemplatesForCatalogItems; +import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.inject.Provides; +import com.google.inject.TypeLiteral; import domain.VCloudExpressLoginAsyncClient; /** - * 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 abstract class BaseVCloudExpressRestClientModule - extends CommonVCloudRestClientModule { + extends CommonVCloudRestClientModule { public BaseVCloudExpressRestClientModule(Class syncClientType, Class asyncClientType) { super(syncClientType, asyncClientType); } + @Override + protected void configure() { + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + super.configure(); + } + @Provides @Singleton protected VCloudExpressLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) { @@ -63,22 +77,22 @@ public abstract class BaseVCloudExpressRestClientModule provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final VCloudExpressLoginAsyncClient login) { + final VCloudExpressLoginAsyncClient login) { return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier(authException, seconds, - new Supplier() { + new Supplier() { - @Override - public VCloudSession get() { - try { - return login.login().get(10, TimeUnit.SECONDS); - } catch (Exception e) { - propagate(e); - assert false : e; - return null; - } + @Override + public VCloudSession get() { + try { + return login.login().get(10, TimeUnit.SECONDS); + } catch (Exception e) { + propagate(e); + assert false : e; + return null; } + } - }); + }); } } 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 b066e969b9..f04f44ea33 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 @@ -33,27 +33,41 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VCloudSession; +import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems; +import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.inject.Provides; +import com.google.inject.TypeLiteral; import domain.VCloudLoginAsyncClient; /** - * 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 abstract class BaseVCloudRestClientModule extends - CommonVCloudRestClientModule { + CommonVCloudRestClientModule { public BaseVCloudRestClientModule(Class syncClientType, Class asyncClientType) { super(syncClientType, asyncClientType); } + @Override + protected void configure() { + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + super.configure(); + } + @Provides @Singleton protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) { @@ -63,21 +77,21 @@ public abstract class BaseVCloudRestClientModule provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final VCloudLoginAsyncClient login) { + final VCloudLoginAsyncClient login) { return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier(authException, seconds, - new Supplier() { + new Supplier() { - @Override - public VCloudSession get() { - try { - return login.login().get(10, TimeUnit.SECONDS); - } catch (Exception e) { - propagate(e); - assert false : e; - return null; - } + @Override + public VCloudSession get() { + try { + return login.login().get(10, TimeUnit.SECONDS); + } catch (Exception e) { + propagate(e); + assert false : e; + return null; } + } - }); + }); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java index 8a21ceed18..e590abc2ba 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java @@ -48,7 +48,6 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.compute.domain.Image; import org.jclouds.domain.Location; import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.RequiresHttp; @@ -65,12 +64,10 @@ import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSu import org.jclouds.vcloud.CommonVCloudAsyncClient; import org.jclouds.vcloud.CommonVCloudClient; import org.jclouds.vcloud.VCloudToken; -import org.jclouds.vcloud.compute.functions.ImagesInOrg; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Org; -import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.endpoints.Network; @@ -80,7 +77,6 @@ import org.jclouds.vcloud.functions.AllCatalogsInOrg; import org.jclouds.vcloud.functions.AllVDCsInOrg; import org.jclouds.vcloud.functions.OrgsForLocations; import org.jclouds.vcloud.functions.OrgsForNames; -import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems; import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse; import org.jclouds.vcloud.predicates.TaskSuccess; @@ -123,15 +119,9 @@ public class CommonVCloudRestClientModule, Iterable>>() { }).to(new TypeLiteral() { }); - bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { - }); bind(new TypeLiteral>>() { }).to(new TypeLiteral() { }); - bind(new TypeLiteral, Iterable>>() { - }).to(new TypeLiteral() { - }); } @Singleton diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudExpressRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudExpressRestClientModule.java index 3b402f0dd1..f1c4638918 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudExpressRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudExpressRestClientModule.java @@ -25,14 +25,15 @@ import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.VCloudExpressClient; /** - * 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 VCloudExpressRestClientModule extends - BaseVCloudExpressRestClientModule { + BaseVCloudExpressRestClientModule { public VCloudExpressRestClientModule() { super(VCloudExpressClient.class, VCloudExpressAsyncClient.class); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java index 5145754b33..00cd03e43e 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java @@ -19,14 +19,68 @@ package org.jclouds.vcloud.domain; +import java.util.List; + +import javax.annotation.Nullable; + +import org.jclouds.vcloud.domain.internal.VDCImpl; + +import com.google.inject.ImplementedBy; + /** + * A VAppTemplate is an abstract description of a vApp. It is created when you + * upload an OVF package to a vDC. * * @author Adrian Cole */ +@ImplementedBy(VDCImpl.class) public interface VAppTemplate extends NamedResource { + /** + * Reference to the VDC containing this template. + * + * @since vcloud api 1.0 + * @return org, or null if this is a version before 1.0 where the vdc isn't + * present + */ + NamedResource getVDC(); + /** + * @return creation status of the VAppTemplate. + * + * @since vcloud api 1.0 + */ Status getStatus(); + /** + * optional description + * + * @since vcloud api 1.0 + */ + @Nullable String getDescription(); + /** + * read-only container for Task elements. Each element in the container + * represents a queued, running, or failed task owned by this object. + * + * @since vcloud api 1.0 + */ + List getTasks(); + + /** + * + * @return true if the OVF descriptor for the template has been uploaded to + * the containing vDC. + * @since vcloud api 1.0 + */ + boolean isOvfDescriptorUploaded(); + + /** + * read-only identifier created on import + * + * @since vcloud api 1.0 + */ + @Nullable + String getVAppScopedLocalId(); + } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VCloudExpressVAppTemplate.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VCloudExpressVAppTemplate.java new file mode 100644 index 0000000000..150214742e --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VCloudExpressVAppTemplate.java @@ -0,0 +1,32 @@ +/** + * + * 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.domain; + +/** + * + * @author Adrian Cole + */ +public interface VCloudExpressVAppTemplate extends NamedResource { + + Status getStatus(); + + String getDescription(); + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java index b385c35dd6..de5e4c78d2 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java @@ -7,7 +7,7 @@ * 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 + * http://www.apache.vdc/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, @@ -19,39 +19,95 @@ package org.jclouds.vcloud.domain.internal; +import static com.google.common.base.Preconditions.checkNotNull; + import java.net.URI; +import java.util.List; import javax.annotation.Nullable; -import org.jclouds.vcloud.VCloudExpressMediaType; +import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Status; +import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VAppTemplate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + /** + * Locations of resources in vCloud * * @author Adrian Cole * */ public class VAppTemplateImpl extends NamedResourceImpl implements VAppTemplate { - /** The serialVersionUID */ - private static final long serialVersionUID = 8464716396538298809L; - private final String description; private final Status status; + private final NamedResource vdc; + @Nullable + private final String description; + private final List tasks = Lists.newArrayList(); + private final boolean ovfDescriptorUploaded; + private final String vAppScopedLocalId; - public VAppTemplateImpl(String name, URI id, @Nullable String description, @Nullable Status status) { - super(name, VCloudExpressMediaType.VAPPTEMPLATE_XML, id); + public VAppTemplateImpl(String name, String type, URI id, Status status, NamedResource vdc, + @Nullable String description, Iterable tasks, boolean ovfDescriptorUploaded, + @Nullable String vAppScopedLocalId) { + super(name, type, id); + this.status = checkNotNull(status, "status"); + this.vdc = vdc;// TODO: once <1.0 is killed check not null this.description = description; - this.status = status; + Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks")); + this.vAppScopedLocalId = vAppScopedLocalId; + this.ovfDescriptorUploaded = ovfDescriptorUploaded; } + /** + * {@inheritDoc} + */ + @Override + public Status getStatus() { + return status; + } + + /** + * {@inheritDoc} + */ + @Override + public NamedResource getVDC() { + return vdc; + } + + /** + * {@inheritDoc} + */ @Override public String getDescription() { return description; } - public Status getStatus() { - return status; + /** + * {@inheritDoc} + */ + @Override + public List getTasks() { + return tasks; + } + + /** + * {@inheritDoc} + */ + @Override + public String getVAppScopedLocalId() { + return vAppScopedLocalId; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isOvfDescriptorUploaded() { + return ovfDescriptorUploaded; } @Override @@ -59,7 +115,11 @@ public class VAppTemplateImpl extends NamedResourceImpl implements VAppTemplate final int prime = 31; int result = super.hashCode(); result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + (ovfDescriptorUploaded ? 1231 : 1237); result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((tasks == null) ? 0 : tasks.hashCode()); + result = prime * result + ((vAppScopedLocalId == null) ? 0 : vAppScopedLocalId.hashCode()); + result = prime * result + ((vdc == null) ? 0 : vdc.hashCode()); return result; } @@ -77,17 +137,35 @@ public class VAppTemplateImpl extends NamedResourceImpl implements VAppTemplate return false; } else if (!description.equals(other.description)) return false; + if (ovfDescriptorUploaded != other.ovfDescriptorUploaded) + return false; if (status == null) { if (other.status != null) return false; } else if (!status.equals(other.status)) return false; + if (tasks == null) { + if (other.tasks != null) + return false; + } else if (!tasks.equals(other.tasks)) + return false; + if (vAppScopedLocalId == null) { + if (other.vAppScopedLocalId != null) + return false; + } else if (!vAppScopedLocalId.equals(other.vAppScopedLocalId)) + return false; + if (vdc == null) { + if (other.vdc != null) + return false; + } else if (!vdc.equals(other.vdc)) + return false; return true; } @Override public String toString() { - return "VAppTemplateImpl [description=" + description + ", status=" + status + "]"; + return "[id=" + getId() + ", name=" + getName() + ", vdc=" + vdc + ", description=" + description + ", status=" + + status + "]"; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VCloudExpressVAppTemplateImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VCloudExpressVAppTemplateImpl.java new file mode 100644 index 0000000000..179b615982 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VCloudExpressVAppTemplateImpl.java @@ -0,0 +1,93 @@ +/** + * + * 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.domain.internal; + +import java.net.URI; + +import javax.annotation.Nullable; + +import org.jclouds.vcloud.VCloudExpressMediaType; +import org.jclouds.vcloud.domain.Status; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; + +/** + * + * @author Adrian Cole + * + */ +public class VCloudExpressVAppTemplateImpl extends NamedResourceImpl implements VCloudExpressVAppTemplate { + + /** The serialVersionUID */ + private static final long serialVersionUID = 8464716396538298809L; + private final String description; + private final Status status; + + public VCloudExpressVAppTemplateImpl(String name, URI id, @Nullable String description, @Nullable Status status) { + super(name, VCloudExpressMediaType.VAPPTEMPLATE_XML, id); + this.description = description; + this.status = status; + } + + @Override + public String getDescription() { + return description; + } + + public Status getStatus() { + return status; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + VCloudExpressVAppTemplateImpl other = (VCloudExpressVAppTemplateImpl) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + return true; + } + + @Override + public String toString() { + return "VAppTemplateImpl [description=" + description + ", status=" + status + "]"; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java index 17c435fbd2..464462a974 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 @@ -34,6 +34,7 @@ import org.jclouds.Constants; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.vcloud.CommonVCloudAsyncClient; +import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.VAppTemplate; @@ -46,7 +47,7 @@ import com.google.common.base.Predicate; */ @Singleton public class VAppTemplatesForCatalogItems implements - Function, Iterable> { + Function, Iterable> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; @@ -55,7 +56,7 @@ public class VAppTemplatesForCatalogItems implements @Inject VAppTemplatesForCatalogItems(CommonVCloudAsyncClient aclient, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; } @@ -74,7 +75,8 @@ public class VAppTemplatesForCatalogItems implements @SuppressWarnings("unchecked") @Override public Future apply(CatalogItem from) { - return (Future) aclient.getVAppTemplate(from.getEntity().getId()); + return (Future) VCloudAsyncClient.class.cast(aclient).getVAppTemplate( + from.getEntity().getId()); } }, 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 4f2c2b5dbd..616cbacf28 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 @@ -34,8 +34,8 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.VCloudExpressAsyncClient; -import org.jclouds.vcloud.VCloudExpressMediaType; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.VAppTemplate; @@ -47,16 +47,16 @@ import com.google.common.base.Predicate; */ @Singleton public class VAppTemplatesForResourceEntities implements - Function, Iterable> { + Function, Iterable> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; - private final VCloudExpressAsyncClient aclient; + private final VCloudAsyncClient aclient; private final ExecutorService executor; @Inject - VAppTemplatesForResourceEntities(VCloudExpressAsyncClient aclient, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + VAppTemplatesForResourceEntities(VCloudAsyncClient aclient, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; } @@ -67,7 +67,7 @@ public class VAppTemplatesForResourceEntities implements @Override public boolean apply(NamedResource input) { - return input.getType().equals(VCloudExpressMediaType.VAPPTEMPLATE_XML); + return input.getType().equals(VCloudMediaType.VAPPTEMPLATE_XML); } }), new Function>() { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForCatalogItems.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForCatalogItems.java index fa664717de..a2db5d2d1f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForCatalogItems.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForCatalogItems.java @@ -36,7 +36,7 @@ import org.jclouds.logging.Logger; import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.CatalogItem; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -46,7 +46,7 @@ import com.google.common.base.Predicate; */ @Singleton public class VCloudExpressVAppTemplatesForCatalogItems implements - Function, Iterable> { + Function, Iterable> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; @@ -61,7 +61,7 @@ public class VCloudExpressVAppTemplatesForCatalogItems implements } @Override - public Iterable apply(Iterable from) { + public Iterable apply(Iterable from) { return transformParallel(filter(from, new Predicate() { @Override @@ -69,12 +69,12 @@ public class VCloudExpressVAppTemplatesForCatalogItems implements return input.getEntity().getType().equals(VCloudExpressMediaType.VAPPTEMPLATE_XML); } - }), new Function>() { + }), new Function>() { @SuppressWarnings("unchecked") @Override - public Future apply(CatalogItem from) { - return (Future) aclient.getVAppTemplate(from.getEntity().getId()); + public Future apply(CatalogItem from) { + return (Future) aclient.getVAppTemplate(from.getEntity().getId()); } }, executor, null, logger, "vappTemplates in"); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForResourceEntities.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForResourceEntities.java new file mode 100644 index 0000000000..255a6fae0b --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForResourceEntities.java @@ -0,0 +1,84 @@ +/** + * + * 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 static com.google.common.collect.Iterables.filter; +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.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressMediaType; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressVAppTemplatesForResourceEntities implements + Function, Iterable> { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + private final VCloudExpressAsyncClient aclient; + private final ExecutorService executor; + + @Inject + VCloudExpressVAppTemplatesForResourceEntities(VCloudExpressAsyncClient aclient, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.aclient = aclient; + this.executor = executor; + } + + @Override + public Iterable apply(Iterable from) { + return transformParallel(filter(checkNotNull(from, "named resources"), new Predicate() { + + @Override + public boolean apply(NamedResource input) { + return input.getType().equals(VCloudExpressMediaType.VAPPTEMPLATE_XML); + } + + }), new Function>() { + + @SuppressWarnings("unchecked") + @Override + public Future apply(NamedResource from) { + return (Future) aclient.getVAppTemplate(from.getId()); + } + + }, executor, null, logger, "vappTemplates in"); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/handlers/ParseVCloudErrorFromHttpResponse.java b/vcloud/core/src/main/java/org/jclouds/vcloud/handlers/ParseVCloudErrorFromHttpResponse.java index de5e56d629..a1c0c8e459 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/handlers/ParseVCloudErrorFromHttpResponse.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/handlers/ParseVCloudErrorFromHttpResponse.java @@ -55,24 +55,25 @@ public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler { try { String content = parseErrorFromContentOrNull(command, response); switch (response.getStatusCode()) { - case 401: - exception = new AuthorizationException(command.getRequest(), content); - break; - case 404: - if (!command.getRequest().getMethod().equals("DELETE")) { - String path = command.getRequest().getEndpoint().getPath(); - Matcher matcher = RESOURCE_PATTERN.matcher(path); - String message; - if (matcher.find()) { - message = String.format("%s %s not found", matcher.group(1), matcher.group(2)); - } else { - message = path; - } - exception = new ResourceNotFoundException(message); + case 401: + case 403: + exception = new AuthorizationException(command.getRequest(), content); + break; + case 404: + if (!command.getRequest().getMethod().equals("DELETE")) { + String path = command.getRequest().getEndpoint().getPath(); + Matcher matcher = RESOURCE_PATTERN.matcher(path); + String message; + if (matcher.find()) { + message = String.format("%s %s not found", matcher.group(1), matcher.group(2)); + } else { + message = path; } - break; - default: - exception = new HttpResponseException(command, response, content); + exception = new ResourceNotFoundException(message); + } + break; + default: + exception = new HttpResponseException(command, response, content); } } finally { releasePayload(response); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java b/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java index b9999c5d8a..9d9cbbb395 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java @@ -33,16 +33,20 @@ import org.xml.sax.Attributes; * @author Adrian Cole */ public class Utils { + public static NamedResource newNamedResource(Attributes attributes, String defaultType) { + String uri = attributes.getValue(attributes.getIndex("href")); + String type = attributes.getValue(attributes.getIndex("type")); + return new NamedResourceImpl(attributes.getValue(attributes.getIndex("name")), type != null ? type : defaultType, + URI.create(uri)); + } public static NamedResource newNamedResource(Attributes attributes) { - String uri = attributes.getValue(attributes.getIndex("href")); - return new NamedResourceImpl(attributes.getValue(attributes.getIndex("name")), attributes.getValue(attributes - .getIndex("type")), URI.create(uri)); + return newNamedResource(attributes, null); } public static Task.Error newError(Attributes attributes) { return new ErrorImpl(attrOrNull(attributes, "message"), attrOrNull(attributes, "majorErrorCode"), attrOrNull( - attributes, "minorErrorCode")); + attributes, "minorErrorCode")); } public static String attrOrNull(Attributes attributes, String attr) { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java index 579edec340..2b10e3cd02 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java @@ -27,6 +27,7 @@ import java.util.SortedMap; import javax.inject.Inject; import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Task; @@ -62,13 +63,13 @@ public class CatalogHandler extends ParseSax.HandlerWithResult { public Catalog getResult() { return new CatalogImpl(catalog.getName(), catalog.getType(), catalog.getId(), org, description, contents, tasks, - published); + published); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equals("Catalog")) { - catalog = Utils.newNamedResource(attributes); + catalog = Utils.newNamedResource(attributes, VCloudMediaType.CATALOG_XML); } else if (qName.equals("CatalogItem")) { Utils.putNamedResource(contents, attributes); } else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java index a5a3a895aa..1072b660d1 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java @@ -7,7 +7,7 @@ * 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 + * http://www.apache.vdc/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, @@ -19,41 +19,82 @@ package org.jclouds.vcloud.xml; +import static org.jclouds.vcloud.util.Utils.newNamedResource; + +import java.util.List; + +import javax.inject.Inject; + import org.jclouds.http.functions.ParseSax; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Status; +import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.internal.VAppTemplateImpl; import org.jclouds.vcloud.util.Utils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import com.google.common.collect.Lists; + /** * @author Adrian Cole */ public class VAppTemplateHandler extends ParseSax.HandlerWithResult { - private StringBuilder currentText = new StringBuilder(); - private NamedResource catalog; - private String description; - private Status status; + protected final TaskHandler taskHandler; + + @Inject + public VAppTemplateHandler(TaskHandler taskHandler) { + this.taskHandler = taskHandler; + } + + protected StringBuilder currentText = new StringBuilder(); + + protected NamedResource template; + protected Status status; + protected NamedResource vdc; + protected String description; + protected List tasks = Lists.newArrayList(); + protected boolean ovfDescriptorUploaded = true; + protected String vAppScopedLocalId; + + private boolean inChildren; public VAppTemplate getResult() { - return new VAppTemplateImpl(catalog.getName(), catalog.getId(), description, status); + return new VAppTemplateImpl(template.getName(), template.getType(), template.getId(), status, vdc, description, + tasks, ovfDescriptorUploaded, vAppScopedLocalId); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - if (qName.equals("VAppTemplate")) { - catalog = Utils.newNamedResource(attributes); - if (attributes.getIndex("status") != -1) - status = Status.fromValue(attributes.getValue(attributes.getIndex("status"))); + if (qName.equals("Children")) { + inChildren = true; + } else if (qName.equals("VAppTemplate")) { + template = newNamedResource(attributes); + String status = Utils.attrOrNull(attributes, "status"); + if (status != null) + this.status = Status.fromValue(Integer.parseInt(status)); + } else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel")) && !inChildren) { + vdc = newNamedResource(attributes); + } else { + taskHandler.startElement(uri, localName, qName, attributes); } + } public void endElement(String uri, String name, String qName) { - if (qName.equals("Description")) { + taskHandler.endElement(uri, name, qName); + if (qName.equals("Children")) { + inChildren = false; + } else if (qName.equals("Task") && !inChildren) { + this.tasks.add(taskHandler.getResult()); + } else if (qName.equals("Description") && !inChildren) { description = currentOrNull(); + } else if (qName.equals("VAppScopedLocalId")) { + vAppScopedLocalId = currentOrNull(); + } else if (qName.equals("ovfDescriptorUploaded")) { + ovfDescriptorUploaded = Boolean.parseBoolean(currentOrNull()); } currentText = new StringBuilder(); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VCloudExpressVAppTemplateHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VCloudExpressVAppTemplateHandler.java new file mode 100644 index 0000000000..edc2e4c49f --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VCloudExpressVAppTemplateHandler.java @@ -0,0 +1,69 @@ +/** + * + * 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.xml; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.Status; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; +import org.jclouds.vcloud.domain.internal.VCloudExpressVAppTemplateImpl; +import org.jclouds.vcloud.util.Utils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Adrian Cole + */ +public class VCloudExpressVAppTemplateHandler extends ParseSax.HandlerWithResult { + private StringBuilder currentText = new StringBuilder(); + + private NamedResource catalog; + private String description; + private Status status; + + public VCloudExpressVAppTemplate getResult() { + return new VCloudExpressVAppTemplateImpl(catalog.getName(), catalog.getId(), description, status); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if (qName.equals("VAppTemplate")) { + catalog = Utils.newNamedResource(attributes); + if (attributes.getIndex("status") != -1) + status = Status.fromValue(attributes.getValue(attributes.getIndex("status"))); + } + } + + public void endElement(String uri, String name, String qName) { + if (qName.equals("Description")) { + description = currentOrNull(); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java index 1683322d97..44f2e6d676 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java @@ -111,33 +111,38 @@ public abstract class CommonVCloudClientLiveTest of(new Log4JLoggingModule()), props).getProviderSpecificContext(); + ImmutableSet. of(new Log4JLoggingModule()), props).getProviderSpecificContext(); connection = context.getApi(); } 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 c33e59bbc5..97fefc1233 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -92,16 +92,16 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); + String.class, InstantiateVAppTemplateOptions[].class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp"); + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp"); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp.xml")), - "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); + "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); @@ -111,20 +111,19 @@ public class VCloudAsyncClientTest extends RestClientTest { } public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException, - IOException { + IOException { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); - HttpRequest request = processor - .createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp", - processorCount(1).memory(512).disk(1024).inNetwork( - URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"))); + String.class, InstantiateVAppTemplateOptions[].class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp", processorCount(1).memory( + 512).disk(1024).inNetwork(URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"))); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-cpumemdisk.xml")), - "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); + "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); @@ -135,26 +134,26 @@ public class VCloudAsyncClientTest extends RestClientTest { @Test(expectedExceptions = IllegalArgumentException.class) public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException, - IOException { + IOException { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); + String.class, InstantiateVAppTemplateOptions[].class); processor.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "CentOS 01", processorCount(1).memory(512) - .disk(1024).inNetwork(URI.create("https://vcenterprise.bluelock.com/network/1990"))); + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "CentOS 01", processorCount(1).memory(512) + .disk(1024).inNetwork(URI.create("https://vcenterprise.bluelock.com/network/1990"))); } public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, - CloneVAppOptions[].class); + CloneVAppOptions[].class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-vapp"); + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-vapp"); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/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); + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -165,17 +164,17 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, - CloneVAppOptions[].class); + CloneVAppOptions[].class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "new-linux-server", - new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "new-linux-server", new CloneVAppOptions() + .deploy().powerOn().withDescription("The description of the new vApp")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/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); + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -187,7 +186,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testOrg() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getOrg", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/org/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/org/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); @@ -218,7 +217,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalog", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); @@ -249,7 +248,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getNetwork", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/network/2")); + .create("https://vcenterprise.bluelock.com/api/v1.0/network/2")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/network/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); @@ -265,7 +264,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2")); + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); @@ -280,7 +279,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, String.class, - String.class); + String.class); HttpRequest request = processor.createRequest(method, "org", "catalog", "item"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1 HTTP/1.1"); @@ -296,7 +295,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class, - String.class, String.class); + String.class, String.class); HttpRequest request = processor.createRequest(method, "org", "catalog", "template"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); @@ -313,7 +312,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); @@ -386,7 +385,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); @@ -402,7 +401,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getTasksList", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); @@ -433,7 +432,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("deployVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); @@ -449,7 +448,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); @@ -465,10 +464,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("undeployVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -482,7 +481,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("deleteVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, "DELETE https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -498,10 +497,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -515,10 +514,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -532,10 +531,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testReset() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("resetVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -549,10 +548,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testSuspend() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("suspendVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -566,10 +565,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testShutdown() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -583,7 +582,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getTask", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/task/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); @@ -599,7 +598,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cancelTask", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/task/1/action/cancel HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -641,7 +640,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public static class VCloudRestClientModuleExtension extends VCloudRestClientModule { @Override protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, - @Named(PROPERTY_API_VERSION) String version) { + @Named(PROPERTY_API_VERSION) String version) { return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login"); } @@ -684,13 +683,13 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final VCloudLoginAsyncClient login) { + final VCloudLoginAsyncClient login) { return Suppliers. ofInstance(new VCloudSession() { @Override public Map getOrgs() { return ImmutableMap. of("org", new NamedResourceImpl("org", - VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"))); + VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"))); } @Override @@ -711,44 +710,19 @@ public class VCloudAsyncClientTest extends RestClientTest { } protected Supplier>> provideOrgVDCSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) { + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) { - return Suppliers - .>> ofInstance(ImmutableMap - .> of( - "org", + return Suppliers.>> ofInstance(ImmutableMap + .> of("org", - ImmutableMap - . of( - "vdc", - new VDCImpl( - "vdc", - null, - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), - null, - null, - "description", - null, - null, - null, - null, - null, - ImmutableMap - . of( - "vapp", - new NamedResourceImpl( - "vapp", - "application/vnd.vmware.vcloud.vApp+xml", - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")), - "network", - new NamedResourceImpl( - "network", - "application/vnd.vmware.vcloud.vAppTemplate+xml", - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))), - null, 0, 0, 0, false)))); + ImmutableMap. of("vdc", new VDCImpl("vdc", null, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), null, null, "description", null, + null, null, null, null, ImmutableMap. of("vapp", new NamedResourceImpl( + "vapp", "application/vnd.vmware.vcloud.vApp+xml", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")), "network", + new NamedResourceImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))), null, 0, 0, 0, + false)))); } @@ -762,18 +736,15 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override public Map get() { return ImmutableMap. of("org", new OrgImpl("org", null, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org", "description", ImmutableMap - . of("catalog", new NamedResourceImpl("catalog", - VCloudMediaType.CATALOG_XML, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap - . of("vdc", new NamedResourceImpl("vdc", VCloudMediaType.VDC_XML, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap - . of("network", new NamedResourceImpl("network", - VCloudMediaType.NETWORK_XML, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/network/1"))), - new NamedResourceImpl("tasksList", VCloudMediaType.TASKSLIST_XML, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")), ImmutableList - . of())); + .create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org", "description", ImmutableMap + . of("catalog", new NamedResourceImpl("catalog", VCloudMediaType.CATALOG_XML, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap + . of("vdc", new NamedResourceImpl("vdc", VCloudMediaType.VDC_XML, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap + . of("network", new NamedResourceImpl("network", VCloudMediaType.NETWORK_XML, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1"))), new NamedResourceImpl( + "tasksList", VCloudMediaType.TASKSLIST_XML, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")), ImmutableList. of())); } } @@ -789,14 +760,13 @@ public class VCloudAsyncClientTest extends RestClientTest { return ImmutableMap.> of("org", ImmutableMap. of("catalog", new CatalogImpl("catalog", "type", - URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description", - ImmutableMap. of("item", new NamedResourceImpl("item", + URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description", ImmutableMap + . of("item", new NamedResourceImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")), - "template", new NamedResourceImpl("template", - "application/vnd.vmware.vcloud.vAppTemplate+xml", URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))), - ImmutableList. of(), true))); + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")), "template", + new NamedResourceImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))), + ImmutableList. of(), true))); } } @@ -808,26 +778,14 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override public Map>> get() { - return ImmutableMap - .>> of( - "org", - ImmutableMap - .> of( - "catalog", - ImmutableMap - . of( - "template", - new CatalogItemImpl( - "template", - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), - "description", - new NamedResourceImpl( - "template", - "application/vnd.vmware.vcloud.vAppTemplate+xml", - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")), - ImmutableMap. of())))); + return ImmutableMap.>> of( + "org", ImmutableMap.> of( + "catalog", ImmutableMap. of("template", + new CatalogItemImpl("template", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), "description", + new NamedResourceImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI.create("https://vcenterprise.bluelock.com/api/v1.0/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 7f62bcf59c..f95e8c2d32 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -20,7 +20,13 @@ package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertNotNull; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.Org; import org.testng.annotations.Test; /** @@ -37,4 +43,44 @@ public class VCloudClientLiveTest extends CommonVCloudClientLiveTest map = Maps.newHashMap(); map.put("name", "my-vapp"); @@ -91,8 +91,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("name", "my-vapp"); @@ -113,8 +113,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("name", "my-vapp"); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayloadTest.java similarity index 89% rename from vcloud/core/src/test/java/org/jclouds/vcloud/binders/VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayloadTest.java index 8a0db45c87..fa15a13ea0 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayloadTest.java @@ -50,7 +50,7 @@ import com.google.inject.name.Names; * @author Adrian Cole */ @Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlPayloadTest") -public class VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest { +public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayloadTest { Injector injector = Guice.createInjector(new AbstractModule() { @Override @@ -69,8 +69,8 @@ public class VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("name", "my-vapp"); @@ -92,8 +92,8 @@ public class VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("name", "my-vapp"); @@ -115,8 +115,8 @@ public class VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("name", "my-vapp"); 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 d5e3212faf..96adabaa6c 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 @@ -39,8 +39,8 @@ import org.jclouds.net.IPSocket; import org.jclouds.rest.RestContextFactory; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.domain.ResourceType; -import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.Status; +import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.testng.annotations.AfterTest; @@ -98,7 +98,7 @@ public class VCloudComputeClientLiveTest { VAppTemplate template = client.findVAppTemplateInOrgCatalogNamed(null, null, templateName); InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024).productProperties( - ImmutableMap.of("foo", "bar")); + ImmutableMap.of("foo", "bar")); id = URI.create(computeClient.start(null, template.getId(), templateName, options).get("id")); Expectation expectation = expectationMap.get(toTest); @@ -110,7 +110,7 @@ public class VCloudComputeClientLiveTest { private String getCompatibleServerName(OsFamily toTest) { String serverName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0, - toTest.toString().length() <= 15 ? toTest.toString().length() : 14); + toTest.toString().length() <= 15 ? toTest.toString().length() : 14); return serverName; } @@ -121,20 +121,19 @@ public class VCloudComputeClientLiveTest { } private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, int processorCount, - int memory, long hardDisk) { + int memory, long hardDisk) { // assertEquals(vApp.getName(), serverName); // assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(Iterables - .getOnlyElement(filter(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR))) - .getVirtualQuantity(), processorCount); + .getOnlyElement(filter(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR))) + .getVirtualQuantity(), processorCount); assertEquals(Iterables.getOnlyElement( - filter(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER))).getVirtualQuantity(), - 1); + filter(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER))).getVirtualQuantity(), 1); assertEquals(Iterables.getOnlyElement(filter(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY))) - .getVirtualQuantity(), memory); + .getVirtualQuantity(), memory); assertEquals(Iterables.getOnlyElement( - filter(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE))).getVirtualQuantity(), - hardDisk); + filter(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE))).getVirtualQuantity(), + hardDisk); } @AfterTest @@ -154,14 +153,14 @@ public class VCloudComputeClientLiveTest { Properties properties = new Properties(); properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true"); Injector injector = new RestContextFactory().createContextBuilder("vcloud", identity, credential, - ImmutableSet. of(new Log4JLoggingModule()), properties).buildInjector(); + ImmutableSet. of(new Log4JLoggingModule()), properties).buildInjector(); computeClient = injector.getInstance(VCloudComputeClient.class); client = injector.getInstance(VCloudClient.class); addressTester = injector.getInstance(Key.get(new TypeLiteral>() { })); expectationMap = ImmutableMap. builder().put(OsFamily.CENTOS, - new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); + new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); provider = "vcloudtest"; templateName = "Ubuntu JeOS 9.10 (32-bit)"; } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeClientLiveTest.java index 9440756640..46c05f3cb2 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeClientLiveTest.java @@ -38,7 +38,7 @@ import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.Status; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; @@ -93,7 +93,7 @@ public class VCloudExpressComputeClientLiveTest { int processorCount = 1; int memory = 512; - VAppTemplate template = client.findVAppTemplateInOrgCatalogNamed(null, null, templateName); + VCloudExpressVAppTemplate template = client.findVAppTemplateInOrgCatalogNamed(null, null, templateName); InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024).productProperties( ImmutableMap.of("foo", "bar")); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java index 2bc57d1499..557c7c4208 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java @@ -27,11 +27,13 @@ import java.net.URI; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.VAppTemplate; -import org.jclouds.vcloud.domain.internal.VAppTemplateImpl; +import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableList; import com.google.inject.Guice; import com.google.inject.Injector; @@ -42,28 +44,21 @@ import com.google.inject.Injector; */ @Test(groups = "unit", testName = "vcloud.VAppTemplateHandlerTest") public class VAppTemplateHandlerTest { - - private Injector injector; - - private Factory factory; - - public void testTerremark() { - InputStream is = getClass().getResourceAsStream("/vAppTemplate-trmk.xml"); - injector = Guice.createInjector(new SaxParserModule()); - factory = injector.getInstance(ParseSax.Factory.class); + public void testVCloud1_0() { + InputStream is = getClass().getResourceAsStream("/vAppTemplate.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); VAppTemplate result = factory.create(injector.getInstance(VAppTemplateHandler.class)).parse(is); - assertEquals(result, new VAppTemplateImpl("CentOS 5.3 (32-bit)", URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/vAppTemplate/5"), - "description of CentOS 5.3 (32-bit)", null)); + assertEquals(result.getName(), "Ubuntu Template"); + assertEquals(result.getId(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-1201908921")); + assertEquals(result.getType(), "application/vnd.vmware.vcloud.vAppTemplate+xml"); + assertEquals(result.getStatus(), Status.OFF); + assertEquals(result.getVDC(), new NamedResourceImpl(null, VCloudMediaType.VDC_XML, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439"))); + assertEquals(result.getDescription(), null); + assertEquals(result.getTasks(), ImmutableList.of()); + assertEquals(result.getVAppScopedLocalId(), "02_ubuntu_template"); + assert result.isOvfDescriptorUploaded(); } - public void testHosting() { - InputStream is = getClass().getResourceAsStream("/vAppTemplate-hosting.xml"); - injector = Guice.createInjector(new SaxParserModule()); - factory = injector.getInstance(ParseSax.Factory.class); - VAppTemplate result = (VAppTemplate) factory.create(injector.getInstance(VAppTemplateHandler.class)).parse(is); - assertEquals(result, new VAppTemplateImpl("cPanel (Linux) 64 Bit", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"), "cPanel (Linux) 64 Bit", - Status.RESOLVED)); - } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressVAppTemplateHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressVAppTemplateHandlerTest.java new file mode 100644 index 0000000000..32bef9e105 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressVAppTemplateHandlerTest.java @@ -0,0 +1,69 @@ +/** + * + * 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.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.vcloud.domain.Status; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; +import org.jclouds.vcloud.domain.internal.VCloudExpressVAppTemplateImpl; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code VAppTemplateHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.VAppTemplateHandlerTest") +public class VCloudExpressVAppTemplateHandlerTest { + + private Injector injector; + + private Factory factory; + + public void testTerremark() { + InputStream is = getClass().getResourceAsStream("/express/vAppTemplate-trmk.xml"); + injector = Guice.createInjector(new SaxParserModule()); + factory = injector.getInstance(ParseSax.Factory.class); + VCloudExpressVAppTemplate result = factory.create(injector.getInstance(VCloudExpressVAppTemplateHandler.class)).parse(is); + assertEquals(result, new VCloudExpressVAppTemplateImpl("CentOS 5.3 (32-bit)", URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vAppTemplate/5"), + "description of CentOS 5.3 (32-bit)", null)); + } + + public void testHosting() { + InputStream is = getClass().getResourceAsStream("/express/vAppTemplate-hosting.xml"); + injector = Guice.createInjector(new SaxParserModule()); + factory = injector.getInstance(ParseSax.Factory.class); + VCloudExpressVAppTemplate result = (VCloudExpressVAppTemplate) factory.create(injector.getInstance(VCloudExpressVAppTemplateHandler.class)).parse(is); + assertEquals(result, new VCloudExpressVAppTemplateImpl("cPanel (Linux) 64 Bit", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"), "cPanel (Linux) 64 Bit", + Status.RESOLVED)); + } +} diff --git a/vcloud/core/src/test/resources/vAppTemplate-hosting.xml b/vcloud/core/src/test/resources/express/vAppTemplate-hosting.xml similarity index 100% rename from vcloud/core/src/test/resources/vAppTemplate-hosting.xml rename to vcloud/core/src/test/resources/express/vAppTemplate-hosting.xml diff --git a/vcloud/core/src/test/resources/vAppTemplate-trmk.xml b/vcloud/core/src/test/resources/express/vAppTemplate-trmk.xml similarity index 100% rename from vcloud/core/src/test/resources/vAppTemplate-trmk.xml rename to vcloud/core/src/test/resources/express/vAppTemplate-trmk.xml diff --git a/vcloud/core/src/test/resources/vAppTemplate.xml b/vcloud/core/src/test/resources/vAppTemplate.xml new file mode 100644 index 0000000000..bb5fcafff8 --- /dev/null +++ b/vcloud/core/src/test/resources/vAppTemplate.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + Specifies the available VM network connections + 0 + + 0 + 192.168.2.100 + true + 00:50:56:8c:00:13 + POOL + + + + Specifies Guest OS Customization Settings + true + false + 172837194 + false + false + true + true + %3eD%gmF + false + #!/bin/bash if [ "$1" = "postcustomization" ]; then echo "post customization" touch /root/.postcustomization sleep 30 #regenerate keys /bin/rm /etc/ssh/ssh_host_* /usr/sbin/dpkg-reconfigure openssh-server echo "completed" fi + Ubuntu1004 + + 02_ubuntu_template + + + + The list of logical networks + + + + + + The configuration parameters for logical networks + + + + + false + 192.168.2.1 + 255.255.255.0 + 8.8.8.8 + + + 192.168.2.100 + 192.168.2.199 + + + + 192.168.2.100 + + + isolated + + + false + 7200 + 7200 + + + + true + + + true + ipTranslation + allowTraffic + + + automatic + 02_ubuntu_template + 0 + + + + + + false + + + + Lease settings section + + 0 + + + VApp template customization section + true + + + diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java index 4e58de9697..f3db45cc6d 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java @@ -38,7 +38,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import org.jclouds.rest.binders.BindToStringPayload; -import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; +import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.domain.ResourceType; import com.jamesmurty.utils.XMLBuilder; @@ -50,7 +50,7 @@ import com.jamesmurty.utils.XMLBuilder; */ @Singleton public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends - BindInstantiateVAppTemplateParamsToXmlPayload { + BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload { @Inject public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, 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 47ff3ea560..b6aeeeddf0 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 @@ -44,7 +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.Status; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.TerremarkECloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient; @@ -79,7 +79,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl } @Override - protected Map parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) { + protected Map parseAndValidateResponse(VCloudExpressVAppTemplate template, VApp vAppResponse) { Credentials credentials = credentialsProvider.execute(template); Map toReturn = super.parseResponse(template, vAppResponse); toReturn.put("username", credentials.identity); @@ -97,7 +97,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl if (portsToOpen.length > 0 && !options.shouldBlockOnDeploy()) throw new IllegalArgumentException("We cannot open ports on terremark unless we can deploy the vapp"); String password = null; - VAppTemplate template = client.getVAppTemplate(templateId); + VCloudExpressVAppTemplate template = client.getVAppTemplate(templateId); if (template.getDescription().indexOf("Windows") != -1) { password = passwordGenerator.get(); options.getProperties().put("password", password); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java index 0e8e337a39..ddc61cca9c 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java @@ -29,7 +29,7 @@ import javax.inject.Singleton; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.domain.Credentials; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; /** * @author Adrian Cole @@ -44,8 +44,8 @@ public class ParseVAppTemplateDescriptionToGetDefaultLoginCredentials implements @Override public Credentials execute(Object resourceToAuthenticate) { checkNotNull(resourceToAuthenticate); - checkArgument(resourceToAuthenticate instanceof VAppTemplate, "Resource must be an VAppTemplate (for Terremark)"); - VAppTemplate template = (VAppTemplate) resourceToAuthenticate; + checkArgument(resourceToAuthenticate instanceof VCloudExpressVAppTemplate, "Resource must be an VAppTemplate (for Terremark)"); + VCloudExpressVAppTemplate template = (VCloudExpressVAppTemplate) resourceToAuthenticate; String search = template.getDescription() != null ? template.getDescription() : template.getName(); if (search.indexOf("Windows") >= 0) { return new Credentials("Administrator", null); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgs.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgs.java index 3ddffc7b75..b971b3b57c 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgs.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgs.java @@ -32,7 +32,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.compute.functions.ImagesInOrg; +import org.jclouds.vcloud.compute.functions.ImagesInVCloudExpressOrg; import org.jclouds.vcloud.domain.Org; import com.google.common.base.Function; @@ -51,12 +51,12 @@ public class VAppTemplatesInOrgs implements Supplier> { private final Supplier> locations; private final Function, Iterable> organizatonsForLocations; - private final ImagesInOrg imagesInOrg; + private final ImagesInVCloudExpressOrg imagesInOrg; @Inject VAppTemplatesInOrgs(Supplier> locations, Function, Iterable> organizatonsForLocations, - ImagesInOrg imagesInOrg) { + ImagesInVCloudExpressOrg imagesInOrg) { this.locations = locations; this.organizatonsForLocations = organizatonsForLocations; this.imagesInOrg = imagesInOrg; 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 f64c556f33..bc9c27698a 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 @@ -56,7 +56,7 @@ import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.Status; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.predicates.TaskSuccess; @@ -171,7 +171,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes if (customizationOptions.canCustomizePassword()) instantiateOptions.withPassword("robotsarefun"); - VAppTemplate vAppTemplate = tmClient.getVAppTemplate(item.getEntity().getId()); + VCloudExpressVAppTemplate vAppTemplate = tmClient.getVAppTemplate(item.getEntity().getId()); // instantiate, noting vApp returned has minimal details vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getId(), vAppTemplate.getId(), serverName, instantiateOptions); 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 5f23e4f5ca..9489ad471f 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 @@ -36,7 +36,7 @@ import org.jclouds.compute.domain.NodeState; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.Status; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient; import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials; import org.jclouds.vcloud.terremark.domain.TerremarkVDC; @@ -56,7 +56,7 @@ public class TerremarkVCloudComputeClientTest { public void testStartWindows() throws IOException { InputStream is = getClass().getResourceAsStream("/terremark/windows_description.txt"); String description = new String(ByteStreams.toByteArray(is)); - VAppTemplate template = createMock(VAppTemplate.class); + VCloudExpressVAppTemplate template = createMock(VCloudExpressVAppTemplate.class); TerremarkVDC vdc = createMock(TerremarkVDC.class); URI templateURI = URI.create("template"); URI vdcURI = URI.create("vdc"); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/PopulateDefaultLoginCredentialsForVAppTemplateTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/PopulateDefaultLoginCredentialsForVAppTemplateTest.java index 555411d27a..eab1f7a580 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/PopulateDefaultLoginCredentialsForVAppTemplateTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/PopulateDefaultLoginCredentialsForVAppTemplateTest.java @@ -29,7 +29,7 @@ import java.io.IOException; import java.io.InputStream; import org.jclouds.domain.Credentials; -import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.testng.annotations.Test; import com.google.common.io.ByteStreams; @@ -44,7 +44,7 @@ public class PopulateDefaultLoginCredentialsForVAppTemplateTest { public void testRhel() throws IOException { InputStream is = getClass().getResourceAsStream("/terremark/rhel_description.txt"); String description = new String(ByteStreams.toByteArray(is)); - VAppTemplate template = createMock(VAppTemplate.class); + VCloudExpressVAppTemplate template = createMock(VCloudExpressVAppTemplate.class); expect(template.getDescription()).andReturn(description).atLeastOnce(); replay(template); ParseVAppTemplateDescriptionToGetDefaultLoginCredentials converter = new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(); @@ -58,7 +58,7 @@ public class PopulateDefaultLoginCredentialsForVAppTemplateTest { public void testLamp() throws IOException { InputStream is = getClass().getResourceAsStream("/terremark/lamp_description.txt"); String description = new String(ByteStreams.toByteArray(is)); - VAppTemplate template = createMock(VAppTemplate.class); + VCloudExpressVAppTemplate template = createMock(VCloudExpressVAppTemplate.class); expect(template.getDescription()).andReturn(description).atLeastOnce(); replay(template); ParseVAppTemplateDescriptionToGetDefaultLoginCredentials converter = new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(); @@ -72,7 +72,7 @@ public class PopulateDefaultLoginCredentialsForVAppTemplateTest { public void testFt() throws IOException { InputStream is = getClass().getResourceAsStream("/terremark/ft_description.txt"); String description = new String(ByteStreams.toByteArray(is)); - VAppTemplate template = createMock(VAppTemplate.class); + VCloudExpressVAppTemplate template = createMock(VCloudExpressVAppTemplate.class); expect(template.getDescription()).andReturn(description).atLeastOnce(); replay(template); ParseVAppTemplateDescriptionToGetDefaultLoginCredentials converter = new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(); @@ -86,7 +86,7 @@ public class PopulateDefaultLoginCredentialsForVAppTemplateTest { public void testWindows() throws IOException { InputStream is = getClass().getResourceAsStream("/terremark/windows_description.txt"); String description = new String(ByteStreams.toByteArray(is)); - VAppTemplate template = createMock(VAppTemplate.class); + VCloudExpressVAppTemplate template = createMock(VCloudExpressVAppTemplate.class); expect(template.getDescription()).andReturn(description).atLeastOnce(); replay(template); ParseVAppTemplateDescriptionToGetDefaultLoginCredentials converter = new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials();