VCloud Director 1.5: initial work on VAppTemplate client

This commit is contained in:
Adam Lowe 2012-03-01 23:09:38 +00:00
parent 04501d46a7
commit 1fdae80eac
6 changed files with 52 additions and 10 deletions

View File

@ -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_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. */ /** 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"; public static final String PROPERTY_VCLOUD_DIRECTOR_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud-director.timeout.task-complete";

View File

@ -121,7 +121,14 @@ public class VCloudDirectorMediaType {
public static final String PRODUCT_SECTION_LIST = "application/vnd.vmware.vcloud.vAppTemplate+xml"; 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. * All acceptable media types.
* *
* This list must be updated whenever a new media type constant is added. * 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, 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, VAPP_TEMPLATE, CUSTOMIZATION_SECTION, GUEST_CUSTOMIZATION_SECTION, NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION,
CONTROL_ACCESS CONTROL_ACCESS
,
LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE
); );
} }

View File

@ -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) * @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 @PUT
@Produces(VAPP_TEMPLATE)
@Consumes(TASK) @Consumes(TASK)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> editVAppTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier reference, ListenableFuture<Task> 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) * @see VAppTemplateClient#relocateVappTemplate(org.jclouds.vcloud.director.v1_5.domain.URISupplier, org.jclouds.vcloud.director.v1_5.domain.RelocateParams)
*/ */
@POST @POST
@Produces(RELOCATE_TEMPLATE)
@Consumes(TASK) @Consumes(TASK)
@Path("/action/relocate") @Path("/action/relocate")
@JAXBResponseParser @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) * @see VAppTemplateClient#editVAppTemplateCustomizationSection(org.jclouds.vcloud.director.v1_5.domain.URISupplier, org.jclouds.vcloud.director.v1_5.domain.CustomizationSection)
*/ */
@PUT @PUT
@Produces(CUSTOMIZATION_SECTION)
@Consumes(TASK)
@Path("/customizationSection") @Path("/customizationSection")
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> editVAppTemplateCustomizationSection(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference, ListenableFuture<Task> 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) * @see VAppTemplateClient#editVAppTemplateGuestCustomizationSection(org.jclouds.vcloud.director.v1_5.domain.URISupplier, org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection)
*/ */
@PUT @PUT
@Produces(GUEST_CUSTOMIZATION_SECTION)
@Consumes(TASK) @Consumes(TASK)
@Path("/guestCustomizationSection") @Path("/guestCustomizationSection")
@JAXBResponseParser @JAXBResponseParser
@ -145,6 +150,7 @@ public interface VAppTemplateAsyncClient {
* @see VAppTemplateClient#getVappTemplateLeaseSettingsSection(org.jclouds.vcloud.director.v1_5.domain.URISupplier) * @see VAppTemplateClient#getVappTemplateLeaseSettingsSection(org.jclouds.vcloud.director.v1_5.domain.URISupplier)
*/ */
@GET @GET
@Consumes(LEASE_SETTINGS_SECTION)
@Path("/leaseSettingsSection") @Path("/leaseSettingsSection")
@JAXBResponseParser @JAXBResponseParser
LeaseSettingsSection getVappTemplateLeaseSettingsSection(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference); 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) * @see VAppTemplateClient#editVappTemplateLeaseSettingsSection(org.jclouds.vcloud.director.v1_5.domain.URISupplier, org.jclouds.vcloud.director.v1_5.domain.LeaseSettingsSection)
*/ */
@PUT @PUT
@Produces(LEASE_SETTINGS_SECTION)
@Consumes(TASK) @Consumes(TASK)
@Path("/leaseSettingsSection") @Path("/leaseSettingsSection")
@JAXBResponseParser @JAXBResponseParser
@ -169,6 +176,7 @@ public interface VAppTemplateAsyncClient {
ListenableFuture<Metadata> getMetadataForVappTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference); ListenableFuture<Metadata> getMetadataForVappTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference);
@PUT @PUT
@Produces(METADATA)
@Consumes(TASK) @Consumes(TASK)
@Path("/metadata") @Path("/metadata")
@JAXBResponseParser @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) * @see VAppTemplateClient#editMetadataEntryForVAppTemplate(org.jclouds.vcloud.director.v1_5.domain.URISupplier, String, org.jclouds.vcloud.director.v1_5.domain.MetadataEntry)
*/ */
@PUT @PUT
@Produces(METADATA_ENTRY)
@Consumes(TASK) @Consumes(TASK)
@Path("/metadata/{key}") @Path("/metadata/{key}")
ListenableFuture<Task> editMetadataEntryForVAppTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference, ListenableFuture<Task> 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) * @see VAppTemplateClient#deleteMetadataEntryForVAppTemplate(org.jclouds.vcloud.director.v1_5.domain.URISupplier, String)
*/ */
@DELETE @DELETE
@Produces()
@Consumes(TASK) @Consumes(TASK)
@Path("/metadata/{key}") @Path("/metadata/{key}")
ListenableFuture<Task> deleteMetadataEntryForVAppTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference, ListenableFuture<Task> 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) * @see VAppTemplateClient#getOvfForVAppTemplate(org.jclouds.vcloud.director.v1_5.domain.URISupplier)
*/ */
@GET @GET
@Consumes(ENVELOPE)
@Path("/ovf") @Path("/ovf")
ListenableFuture<Envelope> getOvfForVAppTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference); ListenableFuture<Envelope> getOvfForVAppTemplate(@EndpointParam(parser = ReferenceToEndpoint.class) URISupplier templateReference);

View File

@ -39,21 +39,31 @@ import static org.testng.Assert.fail;
* *
* @author Adam Lowe * @author Adam Lowe
*/ */
@Test(groups = {"unit", "user"}, singleThreaded = true, testName = "VAppTemplateClientExpectTest") @Test(groups = {"unit", "user"}, testName = "VAppTemplateClientExpectTest")
public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
public void testGetVAppTemplate() { public void testVAppTemplate() {
final String templateId = "/vAppTemplate/vAppTemplate/vappTemplate-xxxx-xxxx-xxxx-xxx"; final String templateId = "/vAppTemplate/vAppTemplate/vappTemplate-xxxx-xxxx-xxxx-xxx";
Reference vappTemplateRef = Reference.builder().href(URI.create(endpoint + templateId)).build(); 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 VcloudHttpRequestPrimer().apiCommand("GET", templateId).acceptMedia(VAPP_TEMPLATE).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/vAppTemplate.xml", VAPP_TEMPLATE).httpResponseBuilder().build() new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/vAppTemplate.xml", VAPP_TEMPLATE).httpResponseBuilder().build(),
).getVAppTemplateClient(); 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); assertNotNull(client);
VAppTemplate template = client.getVAppTemplate(vappTemplateRef); VAppTemplate template = client.getVAppTemplate(vappTemplateRef);
assertEquals(template, exampleTemplate()); assertEquals(template, exampleTemplate());
Task task = client.editVAppTemplate(vappTemplateRef, template);
assertNotNull(task);
task = client.deleteVappTemplate(vappTemplateRef);
assertNotNull(task);
} }
private VAppTemplate exampleTemplate() { private VAppTemplate exampleTemplate() {
@ -67,28 +77,32 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
LeaseSettingsSection leaseSettings = LeaseSettingsSection.builder().type("application/vnd.vmware.vcloud.leaseSettingsSection+xml") 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/")) .href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/leaseSettingsSection/"))
.info("Lease settings section") .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())) .href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/leaseSettingsSection/")).build()))
.storageLeaseInSeconds(0) .storageLeaseInSeconds(0)
.required(false)
.build(); .build();
CustomizationSection customization = CustomizationSection.builder() CustomizationSection customization = CustomizationSection.builder()
.type("application/vnd.vmware.vcloud.customizationSection+xml") .type("application/vnd.vmware.vcloud.customizationSection+xml")
.info("VApp template customization section")
.customizeOnInstantiate(true) .customizeOnInstantiate(true)
.href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/customizationSection/")) .href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/customizationSection/"))
.required(false)
.build(); .build();
return VAppTemplate.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9")) return VAppTemplate.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9"))
.links(ImmutableSet.of(aLink, bLink)) .links(ImmutableSet.of(aLink, bLink))
.children(VAppTemplateChildren.builder().build()) .children(ImmutableSet.<VAppTemplate>of())
.type("application/vnd.vmware.vcloud.vAppTemplate+xml") .type("application/vnd.vmware.vcloud.vAppTemplate+xml")
.description("For testing") .description("For testing")
.id("urn:vcloud:vapptemplate:ef4415e6-d413-4cbb-9262-f9bbec5f2ea9") .id("urn:vcloud:vapptemplate:ef4415e6-d413-4cbb-9262-f9bbec5f2ea9")
.name("ubuntu10") .name("ubuntu10")
.sections(ImmutableList.<SectionType>of(leaseSettings, customization)) .sections(ImmutableSet.<SectionType>of(leaseSettings, customization))
.status(-1) .status(-1)
.owner(owner) .owner(owner)
.ovfDescriptorUploaded(true) .ovfDescriptorUploaded(true)
.goldMaster(false) .goldMaster(false)
.build(); .build();
} }
} }

View File

@ -28,6 +28,7 @@ import org.jclouds.Constants;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.io.payloads.StringPayload;
import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.rest.BaseRestClientExpectTest;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
@ -65,6 +66,14 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
props.put(Constants.PROPERTY_MAX_RETRIES, 1); props.put(Constants.PROPERTY_MAX_RETRIES, 1);
return props; 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() protected HttpRequest loginRequest = HttpRequest.builder()
.method("POST") .method("POST")

View File

@ -16,7 +16,6 @@
href="https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69"/> href="https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69"/>
</Owner> </Owner>
<Children/> <Children/>
<LeaseSettingsSection type="application/vnd.vmware.vcloud.leaseSettingsSection+xml" <LeaseSettingsSection type="application/vnd.vmware.vcloud.leaseSettingsSection+xml"
href="https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/leaseSettingsSection/" href="https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/leaseSettingsSection/"
ovf:required="false"> ovf:required="false">