diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java index ad69b75a6b..2662ed2619 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java @@ -435,7 +435,7 @@ public class ISO { private final String zoneName; @ConstructorProperties({ - "id", "account", "accountid", "bootable", "checksum", "created", "crossZones", "displaytext", "domain", "domainId", "format", "hostid", "hostname", "hypervisor", "isextractable", "isfeatured", "ispublic", "isready", "jobid", "jobstatus", "name", "ostypeid", "ostypename", "passwordenabled", "removed", "size", "sourcetemplateid", "status", "templatetag", "templatetype", "zoneid", "zonename" + "id", "account", "accountid", "bootable", "checksum", "created", "crossZones", "displaytext", "domain", "domainid", "format", "hostid", "hostname", "hypervisor", "isextractable", "isfeatured", "ispublic", "isready", "jobid", "jobstatus", "name", "ostypeid", "ostypename", "passwordenabled", "removed", "size", "sourcetemplateid", "status", "templatetag", "templatetype", "zoneid", "zonename" }) protected ISO(String id, @Nullable String account, @Nullable String accountId, boolean bootable, @Nullable String checksum, @Nullable Date created, boolean crossZones, @Nullable String displayText, @Nullable String domain, diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ISOAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ISOAsyncClient.java index 5c2f5a2a57..940e0fe789 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ISOAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ISOAsyncClient.java @@ -37,12 +37,15 @@ import org.jclouds.cloudstack.options.ListISOsOptions; import org.jclouds.cloudstack.options.RegisterISOOptions; import org.jclouds.cloudstack.options.UpdateISOOptions; import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions; +import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.OnlyElement; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Unwrap; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -95,6 +98,7 @@ public interface ISOAsyncClient { @QueryParams(keys = { "command", "listAll" }, values = { "listIsos", "true" }) @SelectJson("iso") @OnlyElement + @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getISO(@QueryParam("id") String id); /** @@ -107,6 +111,7 @@ public interface ISOAsyncClient { @Consumes(MediaType.APPLICATION_JSON) @QueryParams(keys = { "command", "listAll" }, values = { "listIsos", "true" }) @SelectJson("iso") + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listISOs(ListISOsOptions... options); /** diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOAsyncClientTest.java index af78a51f8a..11b3899380 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOAsyncClientTest.java @@ -21,13 +21,11 @@ package org.jclouds.cloudstack.features; import java.lang.reflect.Method; import org.jclouds.cloudstack.domain.ExtractMode; -import org.jclouds.cloudstack.domain.ISO; import org.jclouds.cloudstack.domain.PermissionOperation; import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest; import org.jclouds.cloudstack.options.AccountInDomainOptions; import org.jclouds.cloudstack.options.DeleteISOOptions; import org.jclouds.cloudstack.options.ExtractISOOptions; -import org.jclouds.cloudstack.options.ListISOsOptions; import org.jclouds.cloudstack.options.RegisterISOOptions; import org.jclouds.cloudstack.options.UpdateISOOptions; import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions; @@ -84,53 +82,6 @@ public class ISOAsyncClientTest extends BaseCloudStackAsyncClientTest { + + private static final ISO iso1 = ISO.builder() + .id("018e0928-8205-4d8e-9329-f731a9ccd488") + .name("xs-tools.iso") + .displayText("xen-pv-drv-iso") + .isPublic(true) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-08-21T15:45:01+0530")) + .isReady(true) + .passwordEnabled(false) + .bootable(false) + .isFeatured(true) + .crossZones(false) + .account("system") + .domain("ROOT") + .domainid("9d189ea2-097e-4b2b-9bae-d885f5430d69") + .isExtractable(false).build(); + + private static final ISO iso2 = ISO.builder() + .id("1e29244b-9cf0-4ff2-9978-677eb83f6bfb") + .name("vmware-tools.iso") + .displayText("VMware Tools Installer ISO") + .isPublic(true) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-08-21T15:45:01+0530")) + .isReady(true) + .passwordEnabled(false) + .bootable(false) + .isFeatured(true) + .crossZones(false) + .account("system") + .domain("ROOT") + .domainid("9d189ea2-097e-4b2b-9bae-d885f5430d69") + .isExtractable(false).build(); + + HttpRequest listIsos = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listIsos") + .addQueryParam("listAll", "true") + .addQueryParam("apiKey", "identity") + .addQueryParam("signature", "qUUF6hCDc57Bc%2FnHriS9umbZBKA%3D") + .addHeader("Accept", "application/json") + .build(); + + public void testListISOsWhenResponseIs2xx() { + ISOClient client = requestSendsResponse(listIsos, + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/listisosresponse.json")) + .build()); + + assertEquals(client.listISOs().toString(), ImmutableSet.of(iso1, iso2).toString()); + } + + public void testListISOsWhenResponseIs404() { + ISOClient client = requestSendsResponse(listIsos, + HttpResponse.builder() + .statusCode(404) + .build()); + + assertEquals(client.listISOs(), ImmutableSet.of()); + } + + HttpRequest listIsosOptions = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listIsos") + .addQueryParam("listAll", "true") + .addQueryParam("account", "fred") + .addQueryParam("domainid", "5") + .addQueryParam("bootable", "true") + .addQueryParam("hypervisor", "xen") + .addQueryParam("id", "3") + .addQueryParam("isofilter", "featured") + .addQueryParam("ispublic", "true") + .addQueryParam("isready", "true") + .addQueryParam("keyword", "bob") + .addQueryParam("name", "bob%27s%20iso") + .addQueryParam("zoneid", "7") + .addQueryParam("apiKey", "identity") + .addQueryParam("signature", "4S5ustbaBErEnpymWLSj1rEJ%2Fnk%3D") + .addHeader("Accept", "application/json") + .build(); + + public void testListISOsOptionsWhenResponseIs2xx() { + ISOClient client = requestSendsResponse(listIsosOptions, + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/listisosresponse.json")) + .build()); + + assertEquals(client.listISOs(accountInDomain("fred", "5").bootable().hypervisor("xen").id("3").isoFilter(ISO.ISOFilter.featured).isPublic().isReady().keyword("bob").name("bob's iso").zoneId("7")).toString(), ImmutableSet.of(iso1, iso2).toString()); + } + + HttpRequest getIso = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listIsos") + .addQueryParam("listAll", "true") + .addQueryParam("id", "018e0928-8205-4d8e-9329-f731a9ccd488") + .addQueryParam("apiKey", "identity") + .addQueryParam("signature", "uZyPUJt6ThMDcQSDa%2BEv5LMs%2B2U%3D") + .addHeader("Accept", "application/json") + .build(); + + public void testGetISOWhenResponseIs2xx() { + ISOClient client = requestSendsResponse(getIso, + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/getisoresponse.json")) + .build()); + + assertEquals(client.getISO("018e0928-8205-4d8e-9329-f731a9ccd488").toString(), iso1.toString()); + } + + public void testGetISOWhenResponseIs404() { + ISOClient client = requestSendsResponse(getIso, + HttpResponse.builder() + .statusCode(404) + .build()); + + assertNull(client.getISO("018e0928-8205-4d8e-9329-f731a9ccd488")); + } + + + @Override + protected ISOClient clientFrom(CloudStackContext context) { + return context.getProviderSpecificContext().getApi().getISOClient(); + } +} diff --git a/apis/cloudstack/src/test/resources/getisoresponse.json b/apis/cloudstack/src/test/resources/getisoresponse.json new file mode 100644 index 0000000000..e54a578ebf --- /dev/null +++ b/apis/cloudstack/src/test/resources/getisoresponse.json @@ -0,0 +1 @@ +{ "listisosresponse" : { "count":1 ,"iso" : [ {"id":"018e0928-8205-4d8e-9329-f731a9ccd488","name":"xs-tools.iso","displaytext":"xen-pv-drv-iso","ispublic":true,"created":"2012-08-21T15:45:01+0530","isready":true,"passwordenabled":false,"bootable":false,"isfeatured":true,"crossZones":false,"account":"system","domain":"ROOT","domainid":"9d189ea2-097e-4b2b-9bae-d885f5430d69","isextractable":false,"tags":[]} ] } } \ No newline at end of file diff --git a/apis/cloudstack/src/test/resources/listisosresponse.json b/apis/cloudstack/src/test/resources/listisosresponse.json new file mode 100644 index 0000000000..c1dba0bb1b --- /dev/null +++ b/apis/cloudstack/src/test/resources/listisosresponse.json @@ -0,0 +1 @@ +{ "listisosresponse" : { "count":2 ,"iso" : [ {"id":"018e0928-8205-4d8e-9329-f731a9ccd488","name":"xs-tools.iso","displaytext":"xen-pv-drv-iso","ispublic":true,"created":"2012-08-21T15:45:01+0530","isready":true,"passwordenabled":false,"bootable":false,"isfeatured":true,"crossZones":false,"account":"system","domain":"ROOT","domainid":"9d189ea2-097e-4b2b-9bae-d885f5430d69","isextractable":false,"tags":[]}, {"id":"1e29244b-9cf0-4ff2-9978-677eb83f6bfb","name":"vmware-tools.iso","displaytext":"VMware Tools Installer ISO","ispublic":true,"created":"2012-08-21T15:45:01+0530","isready":true,"passwordenabled":false,"bootable":false,"isfeatured":true,"crossZones":false,"account":"system","domain":"ROOT","domainid":"9d189ea2-097e-4b2b-9bae-d885f5430d69","isextractable":false,"tags":[]} ] } } \ No newline at end of file