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 3ed614c2c0..05ae7f2421 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 @@ -137,6 +137,8 @@ public class VCloudDirectorMediaType { public static final String ORG_VAPP_TEMPLATE_LEASE_SETTINGS = "application/vnd.vmware.admin.vAppTemplateLeaseSettings+xml"; + public static final String ORG_LEASE_SETTINGS = "application/vnd.vmware.admin.vAppLeaseSettings+xml"; + /** * * All acceptable media types. @@ -155,8 +157,7 @@ public class VCloudDirectorMediaType { CONTROL_ACCESS, VAPP_TEMPLATE, CUSTOMIZATION_SECTION, GUEST_CUSTOMIZATION_SECTION, NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, - PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS + PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, + ORG_LEASE_SETTINGS ); - - } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLeaseSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLeaseSettings.java index 26e9ace80e..b6722e8d5d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLeaseSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLeaseSettings.java @@ -27,6 +27,7 @@ import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import com.google.common.base.Objects; @@ -60,7 +61,8 @@ import com.google.common.base.Objects.ToStringHelper; * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "OrgLeaseSettings", propOrder = { +@XmlRootElement(name = "VAppLeaseSettings") +@XmlType(propOrder = { "deleteOnStorageLeaseExpiration", "deploymentLeaseSeconds", "storageLeaseSeconds" diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index c4fc90fec0..74c38465b2 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -33,6 +33,7 @@ import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; @@ -69,6 +70,30 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { // GET /admin/org/{id}/settings/passwordPolicy // PUT /admin/org/{id}/settings/passwordPolicy + + /** + * @see AdminOrgClient#getVAppLeaseSettings(URI) + */ + @GET + @Path("/settings/vAppLeaseSettings") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getVAppLeaseSettings( + @EndpointParam URI orgRef); + + /** + * @see AdminOrgClient#updateVAppLeaseSettings(URI, OrgVAppLeaseSettings) + */ + @PUT + @Path("/settings/vAppLeaseSettings") + @Consumes(VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + @Produces(VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updateVAppLeaseSettings( + @EndpointParam URI orgRef, + @BinderParam(BindToXMLPayload.class) OrgLeaseSettings group); /** * @see AdminOrgClient#getVAppTemplateLeaseSettings(URI) 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 a1bf2d399c..fdb3f962da 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 @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Group; +import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; /** @@ -58,9 +59,30 @@ public interface AdminOrgClient extends OrgClient { // PUT /admin/org/{id}/settings/passwordPolicy -// GET /admin/org/{id}/settings/vAppLeaseSettings + /** + * Gets organization resource cleanup settings on the level of vApp. + * + *
+    * GET /admin/org/{id}/settings/vAppLeaseSettings
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the lease settings + */ + OrgLeaseSettings getVAppLeaseSettings(URI orgRef); -// PUT /admin/org/{id}/settings/vAppLeaseSettings + /** + * Updates organization resource cleanup settings on the level of vApp. + * + *
+    * PUT /admin/org/{id}/settings/vAppLeaseSettings
+    * 
+ * @param orgRef the reference for the admin org + * @param newSettings the requested updated settings + * @return the resultant settings + */ + OrgLeaseSettings updateVAppLeaseSettings(URI orgRef, + OrgLeaseSettings newSettings); /** * Retrieves expiration and storage policy for vApp templates in an organization. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java index 0554271b2a..44b37023d0 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java @@ -24,6 +24,7 @@ import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; @@ -67,9 +68,53 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect // PUT /admin/org/{id}/settings/passwordPolicy -// GET /admin/org/{id}/settings/vAppLeaseSettings - -// PUT /admin/org/{id}/settings/vAppLeaseSettings + @Test(enabled = false) + public void testGetVAppLeaseSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/???/settings/vAppLeaseSettings") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/vAppLeaseSettings.xml", + VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + .httpResponseBuilder().build()); + + OrgLeaseSettings expected = orgVAppLeaseSettings(); + + assertEquals(client.getAdminOrgClient().getVAppLeaseSettings(orgRef.getURI()), expected); + } + + public static final OrgLeaseSettings orgVAppLeaseSettings() { + return OrgLeaseSettings.builder() + + .build(); + } + + @Test(enabled = false) + public void testUpdateOrgVAppLeaseSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/org/???/settings/vAppLeaseSettings") + .xmlFilePayload("/org/admin/updateVAppLeaseSettingsSource.xml", + VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + .acceptMedia(VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml", + VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + .httpResponseBuilder().build()); + + OrgLeaseSettings expected = updateOrgVAppLeaseSettings(); + + assertEquals(client.getAdminOrgClient().updateVAppLeaseSettings(orgRef.getURI(), expected), expected); + } + + public static final OrgLeaseSettings updateOrgVAppLeaseSettings() { + return orgVAppLeaseSettings().toBuilder() + + .build(); + } @Test(enabled = false) public void testGetVAppTemplateLeaseSettings() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index b5105f4552..7e81d09ec6 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -24,6 +24,7 @@ import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Checks; +import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; @@ -54,6 +55,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { private ReferenceType orgRef; private AdminOrg org; OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; + OrgLeaseSettings vAppLeaseSettings; @Override @BeforeClass(inheritGroups = true) @@ -86,10 +88,55 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // GET /admin/org/{id}/settings/passwordPolicy // PUT /admin/org/{id}/settings/passwordPolicy - -// GET /admin/org/{id}/settings/vAppLeaseSettings - -// PUT /admin/org/{id}/settings/vAppLeaseSettings + + @Test(testName = "GET /admin/org/{id}/settings/vAppLeaseSettings") + public void testGetVAppLeaseSettings() { + vAppLeaseSettings = orgClient.getVAppLeaseSettings(orgRef.getURI()); + + Checks.checkVAppLeaseSettings(vAppLeaseSettings); + } + + @Test(testName = "PUT /admin/org/{id}/settings/vAppLeaseSettings", + dependsOnMethods = { "testGetVAppLeaseSettings" }, enabled = false) // FIXME: fails with 403 forbidden + public void testUpdateVAppLeaseSettings() { + boolean deleteOnStorageLeaseExpiration = vAppLeaseSettings.deleteOnStorageLeaseExpiration(); + Integer storageLeaseSeconds = vAppLeaseSettings.getStorageLeaseSeconds(); + Integer deploymentLeaseSeconds = vAppLeaseSettings.getDeploymentLeaseSeconds(); + + try { + vAppLeaseSettings = vAppLeaseSettings.toBuilder() + .deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds+1) + .deploymentLeaseSeconds(deploymentLeaseSeconds+1) + .build(); + + vAppLeaseSettings = orgClient.updateVAppLeaseSettings( + orgRef.getURI(), vAppLeaseSettings); + + assertTrue(equal(vAppLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), + String.format(OBJ_FIELD_UPDATABLE, + "vAppLeaseSettings", "deleteOnStorageLeaseExpiration")); + assertTrue(equal(vAppLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds+1), + String.format(OBJ_FIELD_UPDATABLE, + "vAppLeaseSettings", "storageLeaseSeconds")); + assertTrue(equal(vAppLeaseSettings.getDeploymentLeaseSeconds(), deploymentLeaseSeconds+1), + String.format(OBJ_FIELD_UPDATABLE, + "vAppLeaseSettings", "deploymentLeaseSeconds")); + + //TODO negative tests? + + Checks.checkVAppLeaseSettings(vAppLeaseSettings); + } finally { + vAppLeaseSettings = vAppLeaseSettings.toBuilder() + .deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds) + .deploymentLeaseSeconds(deploymentLeaseSeconds) + .build(); + + vAppLeaseSettings = orgClient.updateVAppLeaseSettings( + orgRef.getURI(), vAppLeaseSettings); + } + } @Test(testName = "GET /admin/org/{id}/settings/vAppTemplateLeaseSettings") public void testGetVAppTemplateLeaseSettings() {