From 60bd5ede4f073cde2ccec24b74d2f85d1cb9da2f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 12 Sep 2010 20:11:57 -0700 Subject: [PATCH] Issue 280: added screen thumbnail --- .../org/jclouds/vcloud/VCloudAsyncClient.java | 12 ++++++++++ .../java/org/jclouds/vcloud/VCloudClient.java | 9 ++++++++ .../jclouds/vcloud/VCloudAsyncClientTest.java | 21 +++++++++++++++-- .../jclouds/vcloud/VCloudClientLiveTest.java | 23 ++++++++++++++++++- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index aebf0df4d5..911a1723d8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -27,6 +27,7 @@ import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import static org.jclouds.vcloud.VCloudMediaType.VM_XML; +import java.io.InputStream; import java.net.URI; import java.util.Map; @@ -89,6 +90,17 @@ import com.google.common.util.concurrent.ListenableFuture; */ @RequestFilters(SetVCloudTokenCookie.class) public interface VCloudAsyncClient extends CommonVCloudAsyncClient { + + /** + * + * @see VCloudClient#getThumbnailOfVm + */ + @GET + @Path("/screen") + @Consumes("image/png") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getThumbnailOfVm(@EndpointParam URI vm); + /** * * @see VCloudClient#listOrgs diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java index 2ed33f48ff..c9612edae5 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud; +import java.io.InputStream; import java.net.URI; import java.util.Map; import java.util.NoSuchElementException; @@ -46,6 +47,14 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; */ @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) public interface VCloudClient extends CommonVCloudClient { + + /** + * Get a Screen Thumbnail for a Virtual Machine + * + * @param vm to snapshot + */ + InputStream getThumbnailOfVm(URI vm); + /** * The response to a login request includes a list of the organizations to which the * authenticated user has access. diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index d7b10ec51a..b7c1dd95c5 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -41,6 +41,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; @@ -98,6 +99,23 @@ import domain.VCloudVersionsAsyncClient; */ @Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest") public class VCloudAsyncClientTest extends RestClientTest { + + public void testGetThumbnailOfVm() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getThumbnailOfVm", URI.class); + HttpRequest request = processor + .createRequest(method, URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12")); + + assertRequestLineEquals(request, "GET http://vcloud.example.com/api/v1.0/vApp/vm-12/screen HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: image/png\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReturnInputStream.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + public void testUpdateGuestConfiguration() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("updateGuestCustomizationOfVm", URI.class, GuestCustomizationSection.class); @@ -111,8 +129,7 @@ public class VCloudAsyncClientTest extends RestClientTest { "PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream( - "/guestCustomizationSection.xml")), "application/vnd.vmware.vcloud.guestCustomizationSection+xml", - false); + "/guestCustomizationSection.xml")), "application/vnd.vmware.vcloud.guestCustomizationSection+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java index d52a686d36..e0fd1df2a5 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -116,6 +116,27 @@ public class VCloudClientLiveTest extends CommonVCloudClientLiveTest