From 1fdae80eac358949a50f2d024b4ed24264c3b560 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Thu, 1 Mar 2012 23:09:38 +0000 Subject: [PATCH] VCloud Director 1.5: initial work on VAppTemplate client --- .../v1_5/VCloudDirectorConstants.java | 2 ++ .../v1_5/VCloudDirectorMediaType.java | 9 ++++++ .../features/VAppTemplateAsyncClient.java | 11 ++++++- .../VAppTemplateClientExpectTest.java | 30 ++++++++++++++----- ...aseVCloudDirectorRestClientExpectTest.java | 9 ++++++ .../resources/vapptemplate/vAppTemplate.xml | 1 - 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java index bdec38397e..c42c0bcc8f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java @@ -31,6 +31,8 @@ public class VCloudDirectorConstants { public static final String VCLOUD_OVF_NS = "http://schemas.dmtf.org/ovf/envelope/1"; + public static final String VCLOUD_CIM_NS = "http://schemas.dmtf.org/wbem/wscim/1/common"; + /** The property used to configure the timeout for task completion. */ public static final String PROPERTY_VCLOUD_DIRECTOR_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud-director.timeout.task-complete"; 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 6e502cb6cf..a2f87e8062 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 @@ -121,7 +121,14 @@ public class VCloudDirectorMediaType { public static final String PRODUCT_SECTION_LIST = "application/vnd.vmware.vcloud.vAppTemplate+xml"; + public static final String RELOCATE_TEMPLATE = "application/vnd.vmware.vcloud.relocateTemplate+xml"; + + public static final String LEASE_SETTINGS_SECTION = "application/vnd.vmware.vcloud.leastSettingsSection+xml"; + + public static final String ENVELOPE = "application/vnd.???"; + /** + * * All acceptable media types. * * This list must be updated whenever a new media type constant is added. @@ -137,5 +144,7 @@ public class VCloudDirectorMediaType { QUERY_RESULT_RECORDS, QUERY_RESULT_REFERENCES, QUERY_RESULT_ID_RECORDS, VAPP_TEMPLATE, CUSTOMIZATION_SECTION, GUEST_CUSTOMIZATION_SECTION, NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, CONTROL_ACCESS + , + LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateAsyncClient.java index 7dbc58e560..a6e19b44c2 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateAsyncClient.java @@ -54,6 +54,7 @@ public interface VAppTemplateAsyncClient { * @see org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient#editVAppTemplate(org.jclouds.vcloud.director.v1_5.domain.URISupplier, org.jclouds.vcloud.director.v1_5.domain.VAppTemplate) */ @PUT + @Produces(VAPP_TEMPLATE) @Consumes(TASK) @JAXBResponseParser ListenableFuture editVAppTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier reference, @@ -98,6 +99,7 @@ public interface VAppTemplateAsyncClient { * @see VAppTemplateClient#relocateVappTemplate(org.jclouds.vcloud.director.v1_5.domain.URISupplier, org.jclouds.vcloud.director.v1_5.domain.RelocateParams) */ @POST + @Produces(RELOCATE_TEMPLATE) @Consumes(TASK) @Path("/action/relocate") @JAXBResponseParser @@ -117,6 +119,8 @@ public interface VAppTemplateAsyncClient { * @see VAppTemplateClient#editVAppTemplateCustomizationSection(org.jclouds.vcloud.director.v1_5.domain.URISupplier, org.jclouds.vcloud.director.v1_5.domain.CustomizationSection) */ @PUT + @Produces(CUSTOMIZATION_SECTION) + @Consumes(TASK) @Path("/customizationSection") @JAXBResponseParser ListenableFuture editVAppTemplateCustomizationSection(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference, @@ -135,6 +139,7 @@ public interface VAppTemplateAsyncClient { * @see VAppTemplateClient#editVAppTemplateGuestCustomizationSection(org.jclouds.vcloud.director.v1_5.domain.URISupplier, org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection) */ @PUT + @Produces(GUEST_CUSTOMIZATION_SECTION) @Consumes(TASK) @Path("/guestCustomizationSection") @JAXBResponseParser @@ -145,6 +150,7 @@ public interface VAppTemplateAsyncClient { * @see VAppTemplateClient#getVappTemplateLeaseSettingsSection(org.jclouds.vcloud.director.v1_5.domain.URISupplier) */ @GET + @Consumes(LEASE_SETTINGS_SECTION) @Path("/leaseSettingsSection") @JAXBResponseParser LeaseSettingsSection getVappTemplateLeaseSettingsSection(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference); @@ -153,6 +159,7 @@ public interface VAppTemplateAsyncClient { * @see VAppTemplateClient#editVappTemplateLeaseSettingsSection(org.jclouds.vcloud.director.v1_5.domain.URISupplier, org.jclouds.vcloud.director.v1_5.domain.LeaseSettingsSection) */ @PUT + @Produces(LEASE_SETTINGS_SECTION) @Consumes(TASK) @Path("/leaseSettingsSection") @JAXBResponseParser @@ -169,6 +176,7 @@ public interface VAppTemplateAsyncClient { ListenableFuture getMetadataForVappTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference); @PUT + @Produces(METADATA) @Consumes(TASK) @Path("/metadata") @JAXBResponseParser @@ -188,6 +196,7 @@ public interface VAppTemplateAsyncClient { * @see VAppTemplateClient#editMetadataEntryForVAppTemplate(org.jclouds.vcloud.director.v1_5.domain.URISupplier, String, org.jclouds.vcloud.director.v1_5.domain.MetadataEntry) */ @PUT + @Produces(METADATA_ENTRY) @Consumes(TASK) @Path("/metadata/{key}") ListenableFuture editMetadataEntryForVAppTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference, @@ -198,7 +207,6 @@ public interface VAppTemplateAsyncClient { * @see VAppTemplateClient#deleteMetadataEntryForVAppTemplate(org.jclouds.vcloud.director.v1_5.domain.URISupplier, String) */ @DELETE - @Produces() @Consumes(TASK) @Path("/metadata/{key}") ListenableFuture deleteMetadataEntryForVAppTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference, @@ -259,6 +267,7 @@ public interface VAppTemplateAsyncClient { * @see VAppTemplateClient#getOvfForVAppTemplate(org.jclouds.vcloud.director.v1_5.domain.URISupplier) */ @GET + @Consumes(ENVELOPE) @Path("/ovf") ListenableFuture getOvfForVAppTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java index 79a5ba51b6..3cf590e9e5 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java @@ -39,21 +39,31 @@ import static org.testng.Assert.fail; * * @author Adam Lowe */ -@Test(groups = {"unit", "user"}, singleThreaded = true, testName = "VAppTemplateClientExpectTest") +@Test(groups = {"unit", "user"}, testName = "VAppTemplateClientExpectTest") public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { - public void testGetVAppTemplate() { + public void testVAppTemplate() { final String templateId = "/vAppTemplate/vAppTemplate/vappTemplate-xxxx-xxxx-xxxx-xxx"; Reference vappTemplateRef = Reference.builder().href(URI.create(endpoint + templateId)).build(); - VAppTemplateClient client = requestsSendResponses(loginRequest, sessionResponse, + VAppTemplateClient client = orderedRequestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer().apiCommand("GET", templateId).acceptMedia(VAPP_TEMPLATE).httpRequestBuilder().build(), - new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/vAppTemplate.xml", VAPP_TEMPLATE).httpResponseBuilder().build() - ).getVAppTemplateClient(); + new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/vAppTemplate.xml", VAPP_TEMPLATE).httpResponseBuilder().build(), + new VcloudHttpRequestPrimer().apiCommand("PUT", templateId).xmlFilePayload("/vapptemplate/vAppTemplate.xml", VAPP_TEMPLATE).acceptMedia(TASK).httpRequestBuilder().build(), + new VcloudHttpResponsePrimer().xmlFilePayload("/task/task.xml", TASK).httpResponseBuilder().build(), + new VcloudHttpRequestPrimer().apiCommand("DELETE", templateId).acceptMedia(TASK).httpRequestBuilder().build(), + new VcloudHttpResponsePrimer().xmlFilePayload("/task/task.xml", TASK).httpResponseBuilder().build() + ).getVAppTemplateClient(); assertNotNull(client); VAppTemplate template = client.getVAppTemplate(vappTemplateRef); assertEquals(template, exampleTemplate()); + + Task task = client.editVAppTemplate(vappTemplateRef, template); + assertNotNull(task); + + task = client.deleteVappTemplate(vappTemplateRef); + assertNotNull(task); } private VAppTemplate exampleTemplate() { @@ -67,28 +77,32 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx LeaseSettingsSection leaseSettings = LeaseSettingsSection.builder().type("application/vnd.vmware.vcloud.leaseSettingsSection+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/leaseSettingsSection/")) .info("Lease settings section") - .links(ImmutableList.of(Link.builder().rel("edit").type("application/vnd.vmware.vcloud.leaseSettingsSection+xml") + .links(ImmutableSet.of(Link.builder().rel("edit").type("application/vnd.vmware.vcloud.leaseSettingsSection+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/leaseSettingsSection/")).build())) .storageLeaseInSeconds(0) + .required(false) .build(); CustomizationSection customization = CustomizationSection.builder() .type("application/vnd.vmware.vcloud.customizationSection+xml") + .info("VApp template customization section") .customizeOnInstantiate(true) .href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/customizationSection/")) + .required(false) .build(); return VAppTemplate.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9")) .links(ImmutableSet.of(aLink, bLink)) - .children(VAppTemplateChildren.builder().build()) + .children(ImmutableSet.of()) .type("application/vnd.vmware.vcloud.vAppTemplate+xml") .description("For testing") .id("urn:vcloud:vapptemplate:ef4415e6-d413-4cbb-9262-f9bbec5f2ea9") .name("ubuntu10") - .sections(ImmutableList.of(leaseSettings, customization)) + .sections(ImmutableSet.of(leaseSettings, customization)) .status(-1) .owner(owner) .ovfDescriptorUploaded(true) .goldMaster(false) .build(); + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index dc041d9469..b0c8ec88ca 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -28,6 +28,7 @@ import org.jclouds.Constants; import org.jclouds.date.DateService; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; +import org.jclouds.io.payloads.StringPayload; import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; @@ -65,6 +66,14 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect props.put(Constants.PROPERTY_MAX_RETRIES, 1); return props; } + + @Override + public HttpRequestComparisonType compareHttpRequestAsType(HttpRequest input) { + if (input.getPayload() == null || input.getPayload().getContentMetadata().getContentLength() == 0) { + return HttpRequestComparisonType.DEFAULT; + } + return HttpRequestComparisonType.XML; + } protected HttpRequest loginRequest = HttpRequest.builder() .method("POST") diff --git a/labs/vcloud-director/src/test/resources/vapptemplate/vAppTemplate.xml b/labs/vcloud-director/src/test/resources/vapptemplate/vAppTemplate.xml index 1059ddea7c..98bbd2387a 100644 --- a/labs/vcloud-director/src/test/resources/vapptemplate/vAppTemplate.xml +++ b/labs/vcloud-director/src/test/resources/vapptemplate/vAppTemplate.xml @@ -16,7 +16,6 @@ href="https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69"/> -