From c4f1fa040f0e29ecabd7c124c0791bd0499b7ad1 Mon Sep 17 00:00:00 2001 From: Jason King Date: Tue, 22 Nov 2011 14:31:59 +0000 Subject: [PATCH] Issue 695: Added getTasksByVirtualMachine method call --- .../features/TaskAsyncClient.java | 9 ++++++++ .../enterprisecloud/features/TaskClient.java | 10 ++++++++- .../features/TaskAsyncClientTest.java | 16 ++++++++++++-- .../features/TaskClientLiveTest.java | 22 +++++++++++++------ 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TaskAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TaskAsyncClient.java index c0aa108a82..22fdabe3c8 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TaskAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TaskAsyncClient.java @@ -62,4 +62,13 @@ public interface TaskAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getTask(@EndpointParam URI taskId); + /** + * @see TaskClient#getTasksByVirtualMachine + */ + @GET + @Consumes("application/vnd.tmrk.cloud.task; type=collection") + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTasksByVirtualMachine(@EndpointParam URI uri); + } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TaskClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TaskClient.java index 9dfb811c8e..e59dd4b138 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TaskClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TaskClient.java @@ -52,6 +52,14 @@ public interface TaskClient { * * @return the task or null if not found */ - Task getTask(URI taskId); + Task getTask(URI taskUri); + + /** + * The Get Tasks by Virtual Machine call returns information regarding tasks + * for a specified virtual machine in an environment. + * @param uri The uri corresponding to the tasks. e.g. /cloudapi/ecloud/tasks/virtualmachines/{id} + * @return Tasks + */ + Tasks getTasksByVirtualMachine(URI uri); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TaskAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TaskAsyncClientTest.java index 0d1fac9cdc..42016ac354 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TaskAsyncClientTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TaskAsyncClientTest.java @@ -52,12 +52,11 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); checkFilters(httpRequest); - } public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { Method method = TaskAsyncClient.class.getMethod("getTask", URI.class); - HttpRequest httpRequest = processor.createRequest(method, URI.create("https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1")); + HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/tasks/1")); assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n"); @@ -67,7 +66,20 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); checkFilters(httpRequest); + } + public void testGetTasksByVirtualMachine() throws SecurityException, NoSuchMethodException, IOException { + Method method = TaskAsyncClient.class.getMethod("getTasksByVirtualMachine", URI.class); + HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/tasks/virtualmachines/5504")); + + assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/virtualmachines/5504 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task; type=collection\nx-tmrk-version: 2011-07-01\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); } @Override diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TaskClientLiveTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TaskClientLiveTest.java index 2efc0e1429..e163ce689c 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TaskClientLiveTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TaskClientLiveTest.java @@ -43,18 +43,26 @@ public class TaskClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTe private TaskClient client; - @Test public void testGetTasks() throws Exception { // TODO: don't hard-code id - // TODO: docs say don't parse the href, yet no xml includes "identifier", - // I suspect we may need to change to URI args as opposed to long Tasks response = client.getTasksInEnvironment(new URI("/cloudapi/ecloud/tasks/environments/77")); - assert null != response; + assertTasks(response); + } - assertTrue(response.getTasks().size() >= 0); - for (Task task : response.getTasks()) { + public void testGetTasksByVirtualMachine() throws Exception { + // TODO: don't hard-code id + Tasks response = client.getTasksByVirtualMachine(URI.create("/cloudapi/ecloud/tasks/virtualmachines/5504")); + assertTasks(response); + } + + private void assertTasks(final Tasks tasks) { + assert null != tasks; + + assertTrue(tasks.getTasks().size() >= 0); + for (Task task : tasks.getTasks()) { assertEquals(client.getTask(task.getHref()), task); - assert task.getStatus() != Task.Status.UNRECOGNIZED : response; + assert task.getStatus() != Task.Status.UNRECOGNIZED : tasks; } } + }