get/put vAppTemplateLeaseSettings

This commit is contained in:
danikov 2012-03-09 16:44:15 +00:00
parent 1df9409a3a
commit a05d76fabf
7 changed files with 175 additions and 24 deletions

View File

@ -18,15 +18,33 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.JAXBResponseParser;
import org.jclouds.rest.annotations.RequestFilters; 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.OrgVAppTemplateLeaseSettings;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @see GroupClient * @see GroupClient
* @author danikov * @author danikov
*/ */
@RequestFilters(AddVCloudAuthorizationToRequest.class) @RequestFilters(AddVCloudAuthorizationToRequest.class)
public interface AdminOrgAsyncClient { public interface AdminOrgAsyncClient extends OrgAsyncClient {
// GET /admin/org/{id} // GET /admin/org/{id}
@ -52,12 +70,28 @@ public interface AdminOrgAsyncClient {
// PUT /admin/org/{id}/settings/passwordPolicy // PUT /admin/org/{id}/settings/passwordPolicy
// GET /admin/org/{id}/settings/vAppLeaseSettings /**
* @see AdminOrgClient#getVAppTemplateLeaseSettings(URI)
*/
@GET
@Path("/settings/vAppTemplateLeaseSettings")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<OrgVAppTemplateLeaseSettings> getVAppTemplateLeaseSettings(
@EndpointParam URI orgRef);
// PUT /admin/org/{id}/settings/vAppLeaseSettings /**
* @see AdminOrgClient#updateVAppTemplateLeaseSettings(URI, OrgVAppTemplateLeaseSettings)
// GET /admin/org/{id}/settings/vAppTemplateLeaseSettings */
@PUT
// PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings @Path("/settings/vAppTemplateLeaseSettings")
@Consumes(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<OrgVAppTemplateLeaseSettings> updateVAppTemplateLeaseSettings(
@EndpointParam URI orgRef,
@BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings group);
} }

View File

@ -18,9 +18,12 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.Group;
import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings;
/** /**
* Provides synchronous access to {@link Group} objects. * Provides synchronous access to {@link Group} objects.
@ -29,7 +32,7 @@ import org.jclouds.concurrent.Timeout;
* @author danikov * @author danikov
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface AdminOrgClient { public interface AdminOrgClient extends OrgClient {
// GET /admin/org/{id} // GET /admin/org/{id}
@ -59,8 +62,29 @@ public interface AdminOrgClient {
// PUT /admin/org/{id}/settings/vAppLeaseSettings // PUT /admin/org/{id}/settings/vAppLeaseSettings
// GET /admin/org/{id}/settings/vAppTemplateLeaseSettings /**
* Retrieves expiration and storage policy for vApp templates in an organization.
*
* <pre>
* GET /admin/org/{id}/settings/vAppTemplateLeaseSettings
* </pre>
*
* @param orgRef the reference for the admin org
* @return the lease settings
*/
OrgVAppTemplateLeaseSettings getVAppTemplateLeaseSettings(URI orgRef);
// PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings /**
* Updates vApp template policy settings for organization.
*
* <pre>
* PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings
* </pre>
* @param orgRef the reference for the admin org
* @param newSettings the requested updated settings
* @return the resultant settings
*/
OrgVAppTemplateLeaseSettings updateVAppTemplateLeaseSettings(URI orgRef,
OrgVAppTemplateLeaseSettings newSettings);
} }

View File

@ -18,8 +18,13 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import static org.testng.Assert.assertEquals;
import java.net.URI; 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.OrgVAppTemplateLeaseSettings;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -66,7 +71,51 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect
// PUT /admin/org/{id}/settings/vAppLeaseSettings // PUT /admin/org/{id}/settings/vAppLeaseSettings
// GET /admin/org/{id}/settings/vAppTemplateLeaseSettings @Test(enabled = false)
public void testGetVAppTemplateLeaseSettings() {
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/???/settings/vAppTemplateLeaseSettings")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/vAppTemplateLeaseSettings.xml",
VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
.httpResponseBuilder().build());
// PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings OrgVAppTemplateLeaseSettings expected = orgVAppTemplateLeaseSettings();
assertEquals(client.getAdminOrgClient().getVAppTemplateLeaseSettings(orgRef.getURI()), expected);
}
public static final OrgVAppTemplateLeaseSettings orgVAppTemplateLeaseSettings() {
return OrgVAppTemplateLeaseSettings.builder()
.build();
}
@Test(enabled = false)
public void testUpdateOrgVAppTemplateLeaseSettings() {
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/org/???/settings/vAppTemplateLeaseSettings")
.xmlFilePayload("/org/admin/updateVAppLeaseSettingsSource.xml",
VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
.acceptMedia(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml",
VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
.httpResponseBuilder().build());
OrgVAppTemplateLeaseSettings expected = updateOrgVAppTemplateLeaseSettings();
assertEquals(client.getAdminOrgClient().updateVAppTemplateLeaseSettings(orgRef.getURI(), expected), expected);
}
public static final OrgVAppTemplateLeaseSettings updateOrgVAppTemplateLeaseSettings() {
return orgVAppTemplateLeaseSettings().toBuilder()
.build();
}
} }

View File

@ -18,15 +18,20 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import java.net.URI; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.testng.Assert.assertNotNull;
import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; import org.jclouds.vcloud.director.v1_5.domain.AdminOrg;
import org.jclouds.vcloud.director.v1_5.domain.Reference; 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.OrgVAppTemplateLeaseSettings;
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/** /**
* Tests live behavior of {@link AdminGroupClient}. * Tests live behavior of {@link AdminGroupClient}.
* *
@ -35,7 +40,7 @@ import org.testng.annotations.Test;
@Test(groups = { "live", "admin", "org" }, singleThreaded = true, testName = "AdminOrgClientLiveTest") @Test(groups = { "live", "admin", "org" }, singleThreaded = true, testName = "AdminOrgClientLiveTest")
public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String GROUP = "admin org"; public static final String ORG = "admin org";
/* /*
* Convenience references to API clients. * Convenience references to API clients.
@ -48,14 +53,14 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
*/ */
private ReferenceType<?> orgRef; private ReferenceType<?> orgRef;
private AdminOrg org; private AdminOrg org;
OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings;
@Override @Override
@BeforeClass(inheritGroups = true) @BeforeClass(inheritGroups = true)
public void setupRequiredClients() { public void setupRequiredClients() {
orgClient = context.getApi().getAdminOrgClient(); orgClient = context.getApi().getAdminOrgClient();
orgRef = Reference.builder() orgRef = Iterables.getFirst(orgClient.getOrgList().getOrgs(), null).toAdminReference(endpoint);
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/???")) assertNotNull(orgRef, String.format(REF_REQ_LIVE, "admin org"));
.build();
} }
// GET /admin/org/{id} // GET /admin/org/{id}
@ -86,7 +91,46 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
// PUT /admin/org/{id}/settings/vAppLeaseSettings // PUT /admin/org/{id}/settings/vAppLeaseSettings
// GET /admin/org/{id}/settings/vAppTemplateLeaseSettings @Test(testName = "GET /admin/org/{id}/settings/vAppTemplateLeaseSettings")
public void testGetVAppTemplateLeaseSettings() {
vAppTemplateLeaseSettings = orgClient.getVAppTemplateLeaseSettings(orgRef.getURI());
// PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings Checks.checkVAppTemplateLeaseSettings(vAppTemplateLeaseSettings);
}
@Test(testName = "PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings",
dependsOnMethods = { "testGetVAppTemplateLeaseSettings" }, enabled = false) // FIXME: fails with 403 forbidden
public void testUpdateVAppTemplateLeaseSettings() {
boolean deleteOnStorageLeaseExpiration = vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration();
Integer storageLeaseSeconds = vAppTemplateLeaseSettings.getStorageLeaseSeconds();
try {
vAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder()
.deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration)
.storageLeaseSeconds(storageLeaseSeconds+1)
.build();
vAppTemplateLeaseSettings = orgClient.updateVAppTemplateLeaseSettings(
orgRef.getURI(), vAppTemplateLeaseSettings);
assertTrue(equal(vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration),
String.format(OBJ_FIELD_UPDATABLE,
"vAppTemplateLeaseSettings", "deleteOnStorageLeaseExpiration"));
assertTrue(equal(vAppTemplateLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds+1),
String.format(OBJ_FIELD_UPDATABLE,
"vAppTemplateLeaseSettings", "storageLeaseSeconds"));
//TODO negative tests?
Checks.checkVAppTemplateLeaseSettings(vAppTemplateLeaseSettings);
} finally {
vAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder()
.deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration)
.storageLeaseSeconds(storageLeaseSeconds)
.build();
vAppTemplateLeaseSettings = orgClient.updateVAppTemplateLeaseSettings(
orgRef.getURI(), vAppTemplateLeaseSettings);
}
}
} }