From 1cf89c6b6fec53462e1a1454bb6a90d106762da5 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 24 Nov 2011 14:58:52 +0000 Subject: [PATCH] Issue 695: Added remove virtual machine call, plus test and commented out live test --- .../features/VirtualMachineAsyncClient.java | 18 ++++++++++++------ .../features/VirtualMachineClient.java | 6 ++++++ .../VirtualMachineAsyncClientTest.java | 14 ++++++++++++++ .../VirtualMachineClientActionsLiveTest.java | 14 +++++++++++++- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClient.java index ca10fc8846..75b3b36d65 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClient.java @@ -30,10 +30,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOpt import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines; import org.jclouds.tmrk.enterprisecloud.functions.ReturnEmptyVirtualMachinesOnNotFoundOr404; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; +import javax.ws.rs.*; import java.net.URI; /** @@ -135,7 +132,7 @@ public interface VirtualMachineAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture shutdown(@EndpointParam URI uri); -/** + /** * @see VirtualMachineClient#mountTools */ @POST @@ -145,7 +142,7 @@ public interface VirtualMachineAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture mountTools(@EndpointParam URI uri); -/** + /** * @see VirtualMachineClient#unmountTools */ @POST @@ -154,4 +151,13 @@ public interface VirtualMachineAsyncClient { @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture unmountTools(@EndpointParam URI uri); + + /** + * @see VirtualMachineClient#remove + */ + @DELETE + @Consumes("application/vnd.tmrk.cloud.task") + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture remove(@EndpointParam URI uri); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClient.java index a1da7809d6..ff9935efaa 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClient.java @@ -141,4 +141,10 @@ public interface VirtualMachineClient { */ Task unmountTools(URI uri); + /** + * * The Action Virtual Machines Remove call removes a specified virtual machine from the compute pool. + * If successful, the call returns the task that removed the virtual machine. + * Note: To remove a virtual machine requires a Status value of Deployed and a PoweredOn value of false. + */ + Task remove(URI uri); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClientTest.java index 2b7dcf10a3..8cba225cb1 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClientTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClientTest.java @@ -193,6 +193,20 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA checkFilters(httpRequest); } + public void testRemove() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException { + Method method = VirtualMachineAsyncClient.class.getMethod("remove", URI.class); + HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504")); + + assertRequestLineEquals(httpRequest, "DELETE https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + @Override protected TypeLiteral> createTypeLiteral() { return new TypeLiteral>() { diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClientActionsLiveTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClientActionsLiveTest.java index f9740944fc..f91fc9943a 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClientActionsLiveTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClientActionsLiveTest.java @@ -26,7 +26,6 @@ import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import javax.annotation.Nullable; import java.net.URI; import static org.testng.Assert.*; @@ -127,6 +126,19 @@ public class VirtualMachineClientActionsLiveTest extends BaseTerremarkEnterprise assertFalse(vm.isPoweredOn()); } + /* TODO: Not ready to delete the 5504 VM until I can create one. + @Test(dependsOnMethods = "testPowerOff") + public void testRemove() throws URISyntaxException { + // Don't want to delete quite yet! + RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60); + if (!retryablePredicate.apply(client.remove(vm.getHref()))) { + fail("Did not manage to finish remove task"); + } + + assertNull(client.getVirtualMachine(vm.getHref())); + } + */ + private boolean mountTools(URI uri) { // Wait for task to finish AND tools to get into currentOrOutOfDate state return new RetryablePredicate(taskFinished(), 1000*60).apply(client.mountTools(uri)) &&