Issue 280: added screen thumbnail

This commit is contained in:
Adrian Cole 2010-09-12 20:11:57 -07:00
parent 9a3b8e151f
commit 60bd5ede4f
4 changed files with 62 additions and 3 deletions

View File

@ -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<InputStream> getThumbnailOfVm(@EndpointParam URI vm);
/**
*
* @see VCloudClient#listOrgs

View File

@ -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.

View File

@ -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<VCloudAsyncClient> {
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<VCloudAsyncClient> {
"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);

View File

@ -116,6 +116,27 @@ public class VCloudClientLiveTest extends CommonVCloudClientLiveTest<VCloudClien
}
}
@Test
public void testGetThumbnailOfVm() throws Exception {
Org org = connection.findOrgNamed(null);
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = connection.getVApp(item.getHref());
assertNotNull(app);
for (Vm vm : app.getChildren()) {
assert connection.getThumbnailOfVm(vm.getHref()) != null;
}
} catch (RuntimeException e) {
}
}
}
}
}
@Test
public void testGetVm() throws Exception {
Org org = connection.findOrgNamed(null);
@ -148,7 +169,7 @@ public class VCloudClientLiveTest extends CommonVCloudClientLiveTest<VCloudClien
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
try {
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(), item
.getEntity().getName()));
.getEntity().getName()));
} catch (AuthorizationException e) {
}