From eef98d85d3f6c216b8c359074eabf9c32b383cba Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Wed, 14 Mar 2012 16:38:48 +0000 Subject: [PATCH 1/3] Comments for media types --- .../v1_5/VCloudDirectorMediaType.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 5ce5b496ee..995a85611f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -32,11 +32,16 @@ import com.google.common.collect.ImmutableList; */ public class VCloudDirectorMediaType { + // Wildcarded media types + public static final String ANY = "*/*"; public static final String ANY_IMAGE = "image/*"; + /** The default {@literal Accept} header for the vCloud API. */ public static final String APPLICATION_XML_1_5 = "application/*+xml;version=1.5"; + + // Specific media types public static final String SESSION = "application/vnd.vmware.vcloud.session+xml"; @@ -188,14 +193,15 @@ public class VCloudDirectorMediaType { public static final String OVF_TEXT_XML = "text/xml"; + /** + * All acceptable OVF-specific media types. + */ public static final List ALL_OVF = ImmutableList.of( OVF_TEXT_XML ); /** - * All acceptable vcloud-specific media types. - * - * This list must be updated whenever a new media type constant is added. + * All acceptable vCloud-specific media types. */ public static final List ALL = ImmutableList.of( SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY, METADATA_VALUE, @@ -215,7 +221,10 @@ public class VCloudDirectorMediaType { ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS, ORG_LDAP_SETTINGS, ORG_GENERAL_SETTINGS, ORG_EMAIL_SETTINGS, ORG_SETTINGS, ADMIN_NETWORK, ADMIN_ORG_NETWORK, USER, ROLE, DEPLOY_VAPP_PARAMS, RECOMPOSE_VAPP_PARAMS, - RELOCATE_VM_PARAMS, UNDEPLOY_VAPP_PARAMS, ADMIN_VDC, MEDIA_PARAMS, RUNTIME_INFO_SECTION, - SCREEN_TICKET, VAPP_NETWORK + RELOCATE_VM_PARAMS, UNDEPLOY_VAPP_PARAMS, ADMIN_VDC, MEDIA_PARAMS, + RUNTIME_INFO_SECTION, SCREEN_TICKET, VAPP_NETWORK ); + + // NOTE These lists must be updated whenever a new media type constant is added. + } From 5bb34f4599b8f76f82cfa2dd4f9c482101492183 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 15 Mar 2012 17:06:42 +0000 Subject: [PATCH 2/3] Refactor clients to be more consistent --- .../director/v1_5/domain/CustomizationSection.java | 2 +- .../director/v1_5/features/AdminOrgClient.java | 1 + .../director/v1_5/features/AdminVdcAsyncClient.java | 1 + .../director/v1_5/features/AdminVdcClient.java | 1 + .../director/v1_5/features/QueryAsyncClient.java | 12 ++++++------ .../vcloud/director/v1_5/features/QueryClient.java | 12 ++++++------ .../director/v1_5/features/VAppAsyncClient.java | 2 +- .../vcloud/director/v1_5/features/VAppClient.java | 2 +- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomizationSection.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomizationSection.java index 7982c4c05a..c57961bea0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomizationSection.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomizationSection.java @@ -135,7 +135,7 @@ public class CustomizationSection extends SectionType { // For JAXB } - @XmlElement(name = "CustomizeOnInstantiate") + @XmlElement(name = "CustomizeOnInstantiate", required = true) protected boolean customizeOnInstantiate; @XmlElement(name = "Link") protected Set links = Sets.newLinkedHashSet(); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index 471572b512..9fec488165 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -53,6 +53,7 @@ public interface AdminOrgClient extends OrgClient { * @param orgRef the reference for the admin org * @return the admin org */ + @Override AdminOrg getOrg(URI orgRef); /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcAsyncClient.java index c2b70be3e7..1131a083d6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcAsyncClient.java @@ -47,5 +47,6 @@ public interface AdminVdcAsyncClient extends VdcAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) + @Override ListenableFuture getVdc(@EndpointParam URI vdcRef); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcClient.java index e0e4ea75a3..1254b2fcd6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcClient.java @@ -44,5 +44,6 @@ public interface AdminVdcClient extends VdcClient { * * @return the admin vDC or null if not found */ + @Override AdminVdc getVdc(URI vdcRef); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java index cebd6eac94..b9f25392b8 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java @@ -60,21 +60,21 @@ public interface QueryAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture queryAll(@QueryParam("type") String type); + ListenableFuture> queryAll(@QueryParam("type") String type); @GET @Path("/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture query(@QueryParam("type") String type, @QueryParam("filter") String filter); + ListenableFuture> query(@QueryParam("type") String type, @QueryParam("filter") String filter); @GET @Path("/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture query(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, + ListenableFuture> query(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, @QueryParam("format") String format, @QueryParam("type") String type, @QueryParam("filter") String filter); /** @@ -85,21 +85,21 @@ public interface QueryAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture catalogsQueryAll(); + ListenableFuture> catalogsQueryAll(); @GET @Path("/catalogs/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture catalogsQuery(@QueryParam("filter") String filter); + ListenableFuture> catalogsQuery(@QueryParam("filter") String filter); @GET @Path("/catalogs/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture catalogsQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, + ListenableFuture> catalogsQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, @QueryParam("filter") String filter); @GET diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java index 9df4ffa54a..a48d361b9d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java @@ -43,11 +43,11 @@ public interface QueryClient { */ QueryList queryList(); - QueryResultRecords queryAll(String type); + QueryResultRecords queryAll(String type); - QueryResultRecords query(String type, String filter); + QueryResultRecords query(String type, String filter); - QueryResultRecords query(Integer page, Integer pageSize, String format, String type, String filter); + QueryResultRecords query(Integer page, Integer pageSize, String format, String type, String filter); /** * Retrieves a list of Catalogs by using REST API general QueryHandler. @@ -60,11 +60,11 @@ public interface QueryClient { * GET /catalogs/query * */ - QueryResultRecords catalogsQueryAll(); + QueryResultRecords catalogsQueryAll(); - QueryResultRecords catalogsQuery(String filter); + QueryResultRecords catalogsQuery(String filter); - QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String filter); + QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String filter); CatalogReferences catalogReferencesQueryAll(); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppAsyncClient.java index 9c108a739f..e6df71aa84 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppAsyncClient.java @@ -361,7 +361,7 @@ public interface VAppAsyncClient { @BinderParam(BindToXMLPayload.class) MediaInsertOrEjectParams mediaParams); /** - * @return asynchronous access to {@link Writable} features + * @return asynchronous access to {@link Metadata} features */ @Delegate MetadataAsyncClient.Writable getMetadataClient(); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppClient.java index bac7eaa5d3..c1e5be9ca6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppClient.java @@ -434,7 +434,7 @@ public interface VAppClient { Task insertMedia(URI vAppURI, MediaInsertOrEjectParams mediaParams); /** - * @return synchronous access to {@link Metadata.Writeable} features + * @return synchronous access to {@link Metadata} features */ @Delegate MetadataClient.Writeable getMetadataClient(); From 3420a1794c20b0c1c273761f5c1e9aa8e7694197 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 15 Mar 2012 18:16:51 +0000 Subject: [PATCH 3/3] Fix VApp instantiation failure --- .../v1_5/domain/AbstractVAppType.java | 1 + .../director/v1_5/domain/Reference.java | 3 +- .../v1_5/features/QueryAsyncClient.java | 12 +- .../director/v1_5/features/QueryClient.java | 12 +- .../v1_5/features/VAppClientLiveTest.java | 211 +++++++++++------- .../BaseVCloudDirectorClientLiveTest.java | 11 +- 6 files changed, 154 insertions(+), 96 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AbstractVAppType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AbstractVAppType.java index 293dbf26c4..3003ae7add 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AbstractVAppType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AbstractVAppType.java @@ -51,6 +51,7 @@ public abstract class AbstractVAppType extends ResourceEntityType { return new ConcreteBuilder(); } + @Override public Builder toBuilder() { return builder().fromResourceEntityType(this); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java index 33e6fb920a..b5dba21794 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java @@ -25,6 +25,7 @@ import java.util.Map; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlType; import org.jclouds.logging.Logger; @@ -45,7 +46,7 @@ import com.google.common.base.Objects.ToStringHelper; @XmlSeeAlso({ CatalogReference.class }) -//@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "ReferenceType") public class Reference { @javax.annotation.Resource diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java index b9f25392b8..cebd6eac94 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java @@ -60,21 +60,21 @@ public interface QueryAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture> queryAll(@QueryParam("type") String type); + ListenableFuture queryAll(@QueryParam("type") String type); @GET @Path("/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture> query(@QueryParam("type") String type, @QueryParam("filter") String filter); + ListenableFuture query(@QueryParam("type") String type, @QueryParam("filter") String filter); @GET @Path("/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture> query(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, + ListenableFuture query(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, @QueryParam("format") String format, @QueryParam("type") String type, @QueryParam("filter") String filter); /** @@ -85,21 +85,21 @@ public interface QueryAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture> catalogsQueryAll(); + ListenableFuture catalogsQueryAll(); @GET @Path("/catalogs/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture> catalogsQuery(@QueryParam("filter") String filter); + ListenableFuture catalogsQuery(@QueryParam("filter") String filter); @GET @Path("/catalogs/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture> catalogsQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, + ListenableFuture catalogsQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, @QueryParam("filter") String filter); @GET diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java index a48d361b9d..9df4ffa54a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java @@ -43,11 +43,11 @@ public interface QueryClient { */ QueryList queryList(); - QueryResultRecords queryAll(String type); + QueryResultRecords queryAll(String type); - QueryResultRecords query(String type, String filter); + QueryResultRecords query(String type, String filter); - QueryResultRecords query(Integer page, Integer pageSize, String format, String type, String filter); + QueryResultRecords query(Integer page, Integer pageSize, String format, String type, String filter); /** * Retrieves a list of Catalogs by using REST API general QueryHandler. @@ -60,11 +60,11 @@ public interface QueryClient { * GET /catalogs/query * */ - QueryResultRecords catalogsQueryAll(); + QueryResultRecords catalogsQueryAll(); - QueryResultRecords catalogsQuery(String filter); + QueryResultRecords catalogsQuery(String filter); - QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String filter); + QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String filter); CatalogReferences catalogReferencesQueryAll(); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppClientLiveTest.java index 5779c285da..2b2925d542 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppClientLiveTest.java @@ -149,16 +149,32 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertNotNull(vAppTemplate, String.format(ENTITY_NON_NULL, VAPP_TEMPLATE)); // Delete the test-vapp VApp if present - Optional testVApp = Iterables.tryFind( + Iterable vApps = Iterables.filter( vdc.getResourceEntities().getResourceEntities(), Predicates.and( ReferenceTypePredicates.typeEquals(VCloudDirectorMediaType.VAPP), - ReferenceTypePredicates.nameEquals("test-vapp") + Predicates.or( + ReferenceTypePredicates.nameEquals("test-vapp"), + ReferenceTypePredicates.nameEquals("new-name") + ) ) ); - if (testVApp.isPresent()) { - Task deleteTestVApp = vAppClient.deleteVApp(testVApp.get().getHref()); - retryTaskSuccess.apply(deleteTestVApp); + if (vApps != null && !Iterables.isEmpty(vApps)) { + for (Reference each : vApps) { + VApp found = vAppClient.getVApp(each.getHref()); + // debug(found); + if (found.getStatus().equals(Status.POWERED_ON.getValue())) { + Task shutdownTask = vAppClient.shutdown(found.getHref()); + retryTaskSuccess.apply(shutdownTask); + } + if (found.isDeployed()) { + UndeployVAppParams params = UndeployVAppParams.builder().build(); + Task undeployTask = vAppClient.undeploy(vApp.getHref(), params); + retryTaskSuccess.apply(undeployTask); + } + Task deleteTask = vAppClient.deleteVApp(found.getHref()); + retryTaskSuccess.apply(deleteTask); + } } } @@ -168,6 +184,10 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { @Test(testName = "GET /vApp/{id}") public void testGetVApp() { VApp vAppInstantiated = instantiateVApp(); + + // Wait for the task to complete + Task instantiateTask = Iterables.getOnlyElement(vAppInstantiated.getTasks()); + assertTrue(retryTaskSuccessLong.apply(instantiateTask), String.format(TASK_COMPLETE_TIMELY, "instantiateTask")); // The method under test vApp = vAppClient.getVApp(vAppInstantiated.getHref()); @@ -175,15 +195,13 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { // Check the retrieved object is well formed checkVApp(vApp); - // Check that task progress is increasing - Integer vAppProgress = Iterables.getOnlyElement(vApp.getTasks()).getProgress(); - Integer vAppInstantiatedProgress = Iterables.getOnlyElement(vAppInstantiated.getTasks()).getProgress(); - assertTrue(vAppProgress >= vAppInstantiatedProgress, - String.format(ENTITY_CONDITION, VAPP, "have an increasing value in the Progress field", String.format("%d < %d", vAppProgress, vAppInstantiatedProgress))); - - // Cheat and copy the VApp with the progress of the instantiate task modified for equality testing - VApp vAppCopy = vApp.toBuilder().tasks(ImmutableSet.of(Iterables.getOnlyElement(vApp.getTasks()).toBuilder().progress(vAppInstantiatedProgress).build())).build(); - assertEquals(vAppCopy, vAppInstantiated, String.format(ENTITY_EQUAL, VAPP)); + // Check the required fields are set + assertEquals(vApp.isDeployed(), Boolean.FALSE, String.format(OBJ_FIELD_EQ, VAPP, "deployed", "FALSE", vApp.isDeployed().toString())); + // TODO others + + // Check status + Status poweredOffStatus = Status.POWERED_OFF; + assertEquals(vApp.getStatus(), poweredOffStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus.toString(), Status.fromValue(vApp.getStatus()).toString())); } /** @@ -200,7 +218,10 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { Task modifyVApp = vAppClient.modifyVApp(vApp.getHref(), newVApp); assertTrue(retryTaskSuccess.apply(modifyVApp), String.format(TASK_COMPLETE_TIMELY, "modifyVApp")); + // Get the updated VApp vApp = vAppClient.getVApp(vApp.getHref()); + + // Check the required fields are set assertEquals(vApp.getName(), newVApp.getName(), String.format(OBJ_FIELD_EQ, VAPP, "Name", newVApp.getName(), vApp.getName())); assertEquals(vApp.getDescription(), newVApp.getDescription(), String.format(OBJ_FIELD_EQ, VAPP, "Description", newVApp.getDescription(), vApp.getDescription())); } @@ -209,17 +230,23 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { public void testDeployVApp() { DeployVAppParams params = DeployVAppParams.builder() .deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS)) - .forceCustomization() + .notForceCustomization() .notPowerOn() .build(); // The method under test Task deployVApp = vAppClient.deploy(vApp.getHref(), params); - assertTrue(retryTaskSuccess.apply(deployVApp), String.format(TASK_COMPLETE_TIMELY, "deployVApp")); + assertTrue(retryTaskSuccessLong.apply(deployVApp), String.format(TASK_COMPLETE_TIMELY, "deployVApp")); + // Get the updated VApp vApp = vAppClient.getVApp(vApp.getHref()); - Integer deployedStatus = Status.DEPLOYED.getValue(); - assertEquals(vApp.getStatus(), deployedStatus, String.format(OBJ_FIELD_EQ, VAPP, "status", deployedStatus, vApp.getStatus())); + + // Check the required fields are set + assertEquals(vApp.isDeployed(), Boolean.TRUE, String.format(OBJ_FIELD_EQ, VAPP, "deployed", "TRUE", vApp.isDeployed().toString())); + + // Check status + Status deployedStatus = Status.POWERED_OFF; + assertEquals(vApp.getStatus(), deployedStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", deployedStatus.toString(), Status.fromValue(vApp.getStatus()).toString())); } @Test(testName = "POST /vApp/{id}/power/action/powerOn", dependsOnMethods = { "testDeployVApp" }) @@ -228,9 +255,84 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { Task powerOnVApp = vAppClient.powerOn(vApp.getHref()); assertTrue(retryTaskSuccess.apply(powerOnVApp), String.format(TASK_COMPLETE_TIMELY, "powerOnVApp")); + // Get the updated VApp vApp = vAppClient.getVApp(vApp.getHref()); - Integer poweredOnStatus = Status.POWERED_ON.getValue(); - assertEquals(vApp.getStatus(), poweredOnStatus, String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus, vApp.getStatus())); + + // Check status + Status poweredOnStatus = Status.POWERED_ON; + assertEquals(vApp.getStatus(), poweredOnStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus.toString(), Status.fromValue(vApp.getStatus()).toString())); + } + + @Test(testName = "POST /vApp/{id}/power/action/reboot", dependsOnMethods = { "testPowerOnVApp" }) + public void testReboot() { + // The method under test + Task reboot = vAppClient.reboot(vApp.getHref()); + assertTrue(retryTaskSuccess.apply(reboot), String.format(TASK_COMPLETE_TIMELY, "reboot")); + + // Get the updated VApp + vApp = vAppClient.getVApp(vApp.getHref()); + + // Check status + Status poweredOnStatus = Status.POWERED_ON; + assertEquals(vApp.getStatus(), poweredOnStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus.toString(), Status.fromValue(vApp.getStatus()).toString())); + } + + @Test(testName = "POST /vApp/{id}/power/action/shutdown", dependsOnMethods = { "testReboot" }) + public void testShutdown() { + // The method under test + Task shutdown = vAppClient.shutdown(vApp.getHref()); + assertTrue(retryTaskSuccess.apply(shutdown), String.format(TASK_COMPLETE_TIMELY, "shutdown")); + + // Get the updated VApp + vApp = vAppClient.getVApp(vApp.getHref()); + + // Check status + Status poweredOnStatus = Status.POWERED_ON; + assertEquals(vApp.getStatus(), poweredOnStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus.toString(), Status.fromValue(vApp.getStatus()).toString())); + } + + @Test(testName = "POST /vApp/{id}/power/action/suspend", dependsOnMethods = { "testShutdown" }) + public void testSuspend() { + // The method under test + Task suspend = vAppClient.suspend(vApp.getHref()); + assertTrue(retryTaskSuccess.apply(suspend), String.format(TASK_COMPLETE_TIMELY, "suspend")); + + // Get the updated VApp + vApp = vAppClient.getVApp(vApp.getHref()); + + // Check status + Status poweredOnStatus = Status.POWERED_ON; + assertEquals(vApp.getStatus(), poweredOnStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus.toString(), Status.fromValue(vApp.getStatus()).toString())); + } + + @Test(testName = "POST /vApp/{id}/power/action/reset", dependsOnMethods = { "testSuspend" }) + public void testReset() { + // The method under test + Task reset = vAppClient.reset(vApp.getHref()); + assertTrue(retryTaskSuccess.apply(reset), String.format(TASK_COMPLETE_TIMELY, "reset")); + + // Get the updated VApp + vApp = vAppClient.getVApp(vApp.getHref()); + + // Check status + Status poweredOnStatus = Status.POWERED_ON; + assertEquals(vApp.getStatus(), poweredOnStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus.toString(), Status.fromValue(vApp.getStatus()).toString())); + } + + @Test(testName = "POST /vApp/{id}/action/undeploy", dependsOnMethods = { "testReset" }) + public void testUndeployVApp() { + UndeployVAppParams params = UndeployVAppParams.builder().build(); + + // The method under test + Task undeploy = vAppClient.undeploy(vApp.getHref(), params); + assertTrue(retryTaskSuccess.apply(undeploy), String.format(TASK_COMPLETE_TIMELY, "undeploy")); + + // Get the updated VApp + vApp = vAppClient.getVApp(vApp.getHref()); + + // Check status + Status poweredOnStatus = Status.POWERED_ON; + assertEquals(vApp.getStatus(), poweredOnStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus.toString(), Status.fromValue(vApp.getStatus()).toString())); } @Test(testName = "POST /vApp/{id}/power/action/powerOff", dependsOnMethods = { "testUndeployVApp" }) @@ -239,12 +341,15 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { Task powerOffVApp = vAppClient.powerOff(vApp.getHref()); assertTrue(retryTaskSuccess.apply(powerOffVApp), String.format(TASK_COMPLETE_TIMELY, "powerOffVApp")); + // Get the updated VApp vApp = vAppClient.getVApp(vApp.getHref()); - Integer poweredOffStatus = Status.POWERED_OFF.getValue(); - assertEquals(vApp.getStatus(), poweredOffStatus, String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus, vApp.getStatus())); + + // Check status + Status poweredOffStatus = Status.POWERED_OFF; + assertEquals(vApp.getStatus(), poweredOffStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus.toString(), Status.fromValue(vApp.getStatus()).toString())); } - @Test(testName = "POST /vApp/{id}/action/consolidate", dependsOnMethods = { "testGetVApp" }) + @Test(testName = "POST /vApp/{id}/action/consolidate", dependsOnMethods = { "testPowerOnVApp" }) public void testConsolidateVApp() { // The method under test Task consolidateVApp = vAppClient.consolidateVApp(vApp.getHref()); @@ -282,7 +387,7 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertEquals(modified, params, String.format(ENTITY_EQUAL, "ControlAccessParams")); } - @Test(testName = "POST /vApp/{id}/action/discardSuspendedState", dependsOnMethods = { "testGetVApp" }) + @Test(testName = "POST /vApp/{id}/action/discardSuspendedState", dependsOnMethods = { "testSuspend" }) public void testDiscardSuspendedState() { // The method under test Task discardSuspendedState = vAppClient.discardSuspendedState(vApp.getHref()); @@ -337,20 +442,6 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertTrue(retryTaskSuccess.apply(relocate), String.format(TASK_COMPLETE_TIMELY, "relocate")); } - @Test(testName = "POST /vApp/{id}/action/undeploy", dependsOnMethods = { "testDeployVApp" }) - public void testUndeployVApp() { - UndeployVAppParams params = UndeployVAppParams.builder() - .build(); - - // The method under test - Task undeploy = vAppClient.undeploy(vApp.getHref(), params); - assertTrue(retryTaskSuccess.apply(undeploy), String.format(TASK_COMPLETE_TIMELY, "undeploy")); - - vApp = vAppClient.getVApp(vApp.getHref()); - Integer resolvedStatus = Status.RESOLVED.getValue(); - assertEquals(vApp.getStatus(), resolvedStatus, String.format(OBJ_FIELD_EQ, VAPP, "status", resolvedStatus, vApp.getStatus())); - } - @Test(testName = "POST /vApp/{id}/action/upgradeHardwareVersion", dependsOnMethods = { "testGetVApp" }) public void testUpgradeHardwareVersion() { // The method under test @@ -358,50 +449,6 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertTrue(retryTaskSuccess.apply(upgradeHardwareVersion), String.format(TASK_COMPLETE_TIMELY, "upgradeHardwareVersion")); } - @Test(testName = "POST /vApp/{id}/power/action/reboot", dependsOnMethods = { "testGetVApp" }) - public void testReboot() { - // The method under test - Task reboot = vAppClient.reboot(vApp.getHref()); - assertTrue(retryTaskSuccess.apply(reboot), String.format(TASK_COMPLETE_TIMELY, "reboot")); - - vApp = vAppClient.getVApp(vApp.getHref()); - Integer poweredOnStatus = Status.POWERED_ON.getValue(); - assertEquals(vApp.getStatus(), poweredOnStatus, String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus, "powered off")); - } - - @Test(testName = "POST /vApp/{id}/power/action/reset", dependsOnMethods = { "testGetVApp" }) - public void testReset() { - // The method under test - Task reset = vAppClient.reset(vApp.getHref()); - assertTrue(retryTaskSuccess.apply(reset), String.format(TASK_COMPLETE_TIMELY, "reset")); - - vApp = vAppClient.getVApp(vApp.getHref()); - Integer poweredOffStatus = Status.POWERED_ON.getValue(); - assertEquals(vApp.getStatus(), poweredOffStatus, String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus, "powered off")); - } - - @Test(testName = "POST /vApp/{id}/power/action/shutdown", dependsOnMethods = { "testGetVApp" }) - public void testShutdown() { - // The method under test - Task shutdown = vAppClient.shutdown(vApp.getHref()); - assertTrue(retryTaskSuccess.apply(shutdown), String.format(TASK_COMPLETE_TIMELY, "shutdown")); - - vApp = vAppClient.getVApp(vApp.getHref()); - Integer poweredOffStatus = Status.POWERED_OFF.getValue(); - assertEquals(vApp.getStatus(), poweredOffStatus, String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus, "powered off")); - } - - @Test(testName = "POST /vApp/{id}/power/action/suspend", dependsOnMethods = { "testGetVApp" }) - public void testSuspend() { - // The method under test - Task suspend = vAppClient.suspend(vApp.getHref()); - assertTrue(retryTaskSuccess.apply(suspend), String.format(TASK_COMPLETE_TIMELY, "suspend")); - - vApp = vAppClient.getVApp(vApp.getHref()); - Integer poweredOffStatus = Status.POWERED_OFF.getValue(); - assertEquals(vApp.getStatus(), poweredOffStatus, String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus, "powered off")); - } - @Test(testName = "GET /vApp/{id}/controlAccess", dependsOnMethods = { "testGetVApp" }) public void testGetControlAccess() { // The method under test diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index dd13abebf5..3903d9a30c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -61,6 +61,9 @@ import com.google.inject.Module; @Listeners(FormatApiResultsListener.class) @Test(groups = "live") public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest { + + protected static final long TASK_TIMEOUT_SECONDS = 10L; + protected static final long LONG_TASK_TIMEOUT_SECONDS = 300L; protected BaseVCloudDirectorClientLiveTest() { provider = "vcloud-director"; @@ -70,10 +73,16 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ public abstract void setupRequiredClients(); public Predicate retryTaskSuccess; + public Predicate retryTaskSuccessLong; @Inject protected void initTaskSuccess(TaskSuccess taskSuccess) { - retryTaskSuccess = new RetryablePredicate(taskSuccess, 1000L); + retryTaskSuccess = new RetryablePredicate(taskSuccess, TASK_TIMEOUT_SECONDS * 1000L); + } + + @Inject + protected void initTaskSuccessLong(TaskSuccess taskSuccess) { + retryTaskSuccessLong = new RetryablePredicate(taskSuccess, LONG_TASK_TIMEOUT_SECONDS * 1000L); } protected RestContext context;