From 68820d5d612b039fccfb7f29bdf0129d98afe2c5 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 21 Dec 2011 23:29:53 -0800 Subject: [PATCH] iso cleanup --- .../cloudstack/domain/ISOPermissions.java | 51 +++++++++++------- .../cloudstack/domain/PortForwardingRule.java | 6 +-- .../cloudstack/features/ISOAsyncClient.java | 47 ++++++++-------- .../cloudstack/features/ISOClient.java | 8 +-- .../features/ISOAsyncClientTest.java | 53 ++++++++++--------- .../features/ISOClientLiveTest.java | 23 ++++++++ .../listipforwardingrulesresponse.json | 3 +- .../listportforwardingrulesresponse.json | 2 +- 8 files changed, 117 insertions(+), 76 deletions(-) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOPermissions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOPermissions.java index f10a2e506c..ac0214507f 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOPermissions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOPermissions.java @@ -18,6 +18,8 @@ */ package org.jclouds.cloudstack.domain; +import java.util.Set; + import com.google.gson.annotations.SerializedName; /** @@ -71,7 +73,8 @@ public class ISOPermissions implements Comparable { } private long id; - private String account; + @SerializedName("account") + private Set accounts; @SerializedName("domainid") private long domainId; @SerializedName("ispublic") @@ -93,8 +96,8 @@ public class ISOPermissions implements Comparable { /** * @return the list of accounts the template is available for */ - public String getAccount() { - return account; + public Set getAccounts() { + return accounts; } /** @@ -112,26 +115,36 @@ public class ISOPermissions implements Comparable { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ISOPermissions that = (ISOPermissions) o; - - if (domainId != that.domainId) return false; - if (id != that.id) return false; - if (isPublic != that.isPublic) return false; - if (account != null ? !account.equals(that.account) : that.account != null) return false; - + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ISOPermissions other = (ISOPermissions) obj; + if (accounts == null) { + if (other.accounts != null) + return false; + } else if (!accounts.equals(other.accounts)) + return false; + if (domainId != other.domainId) + return false; + if (id != other.id) + return false; + if (isPublic != other.isPublic) + return false; return true; } @Override public int hashCode() { - int result = (int) (id ^ (id >>> 32)); - result = 31 * result + (account != null ? account.hashCode() : 0); - result = 31 * result + (int) (domainId ^ (domainId >>> 32)); - result = 31 * result + (isPublic ? 1 : 0); + final int prime = 31; + int result = 1; + result = prime * result + ((accounts == null) ? 0 : accounts.hashCode()); + result = prime * result + (int) (domainId ^ (domainId >>> 32)); + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + (isPublic ? 1231 : 1237); return result; } @@ -139,7 +152,7 @@ public class ISOPermissions implements Comparable { public String toString() { return "ISOPermissions{" + "id=" + id + - ", account='" + account + '\'' + + ", accounts='" + accounts + '\'' + ", domainId=" + domainId + ", isPublic=" + isPublic + '}'; diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PortForwardingRule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PortForwardingRule.java index 105e926f9e..275e5cd3c4 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PortForwardingRule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PortForwardingRule.java @@ -137,7 +137,7 @@ public class PortForwardingRule implements Comparable { @SerializedName("virtualmachinename") private String virtualMachineName; @SerializedName("cidrlist") - private String CIDRs = ""; + private String CIDRs; @SerializedName("privateendport") private int privateEndPort; @SerializedName("publicendport") @@ -240,7 +240,7 @@ public class PortForwardingRule implements Comparable { * @return the cidr list to forward traffic from */ public Set getCIDRs() { - return ImmutableSet.copyOf(Splitter.on(' ').split(CIDRs)); + return CIDRs != null ? ImmutableSet.copyOf(Splitter.on(' ').split(CIDRs)) : ImmutableSet. of(); } /** @@ -334,7 +334,7 @@ public class PortForwardingRule implements Comparable { ", virtualMachineDisplayName='" + virtualMachineDisplayName + '\'' + ", virtualMachineId=" + virtualMachineId + ", virtualMachineName='" + virtualMachineName + '\'' + - ", CIDRs=" + CIDRs + + ", CIDRs=" + getCIDRs() + ", privateEndPort=" + privateEndPort + ", publicEndPort=" + publicEndPort + '}'; 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 f940f0832f..e8fb5f90d5 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 @@ -18,7 +18,13 @@ */ package org.jclouds.cloudstack.features; -import com.google.common.util.concurrent.ListenableFuture; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.ExtractMode; import org.jclouds.cloudstack.domain.ISO; @@ -31,16 +37,14 @@ 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.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 javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import java.util.Set; +import com.google.common.util.concurrent.ListenableFuture; /** * @@ -64,7 +68,7 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "attachISO") + @QueryParams(keys = "command", values = "attachIso") @Unwrap ListenableFuture attachISO(@QueryParam("id") long isoId, @QueryParam("virtualmachineid") long vmId); @@ -76,7 +80,7 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "detachISO") + @QueryParams(keys = "command", values = "detachIso") @Unwrap ListenableFuture detachISO(@QueryParam("virtualmachineid") long vmId); @@ -88,8 +92,9 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "listISOs") - @Unwrap + @QueryParams(keys = "command", values = "listIsos") + @SelectJson("iso") + @OnlyElement ListenableFuture getISO(@QueryParam("id") long id); /** @@ -100,8 +105,8 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "listISOs") - @Unwrap + @QueryParams(keys = "command", values = "listIsos") + @SelectJson("iso") ListenableFuture> listISOs(ListISOsOptions... options); /** @@ -116,7 +121,7 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "registerISO") + @QueryParams(keys = "command", values = "registerIso") @Unwrap ListenableFuture registerISO(@QueryParam("name") String name, @QueryParam("displaytext") String displayText, @QueryParam("url") String url, @QueryParam("zoneid") long zoneId, RegisterISOOptions... options); @@ -129,7 +134,7 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "updateISO") + @QueryParams(keys = "command", values = "updateIso") @Unwrap ListenableFuture updateISO(@QueryParam("id") long id, UpdateISOOptions... options); @@ -142,7 +147,7 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "deleteISO") + @QueryParams(keys = "command", values = "deleteIso") @Unwrap ListenableFuture deleteISO(@QueryParam("id") long id, DeleteISOOptions... options); @@ -156,7 +161,7 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "copyISO") + @QueryParams(keys = "command", values = "copyIso") @Unwrap ListenableFuture copyISO(@QueryParam("id") long isoId, @QueryParam("sourcezoneid") long sourceZoneId, @QueryParam("destzoneid") long destZoneId); @@ -169,7 +174,7 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "updateISOPermissions") + @QueryParams(keys = "command", values = "updateIsoPermissions") @Unwrap ListenableFuture updateISOPermissions(@QueryParam("id") long id, UpdateISOPermissionsOptions... options); @@ -182,9 +187,9 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "listISOPermissions") - @Unwrap - ListenableFuture> listISOPermissions(@QueryParam("id") long id, AccountInDomainOptions... options); + @QueryParams(keys = "command", values = "listIsoPermissions") + @SelectJson("templatepermission") + ListenableFuture listISOPermissions(@QueryParam("id") long id, AccountInDomainOptions... options); /** * Extracts an ISO @@ -197,7 +202,7 @@ public interface ISOAsyncClient { */ @GET @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "command", values = "extractISO") + @QueryParams(keys = "command", values = "extractIso") @Unwrap ListenableFuture extractISO(@QueryParam("id") long id, @QueryParam("mode") ExtractMode mode, @QueryParam("zoneid") long zoneId, ExtractISOOptions... options); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ISOClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ISOClient.java index 2e2e706a62..233d66acab 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ISOClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ISOClient.java @@ -18,6 +18,9 @@ */ package org.jclouds.cloudstack.features; +import java.util.Set; +import java.util.concurrent.TimeUnit; + import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.ExtractMode; import org.jclouds.cloudstack.domain.ISO; @@ -31,9 +34,6 @@ import org.jclouds.cloudstack.options.UpdateISOOptions; import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions; import org.jclouds.concurrent.Timeout; -import java.util.Set; -import java.util.concurrent.TimeUnit; - /** * *

@@ -134,7 +134,7 @@ public interface ISOClient { * @param options optional arguments * @return A set of the permissions on this ISO */ - Set listISOPermissions(long id, AccountInDomainOptions... options); + ISOPermissions listISOPermissions(long id, AccountInDomainOptions... options); /** * Extracts an ISO 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 a617baff7a..32a55a8d80 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 @@ -18,8 +18,8 @@ */ package org.jclouds.cloudstack.features; -import com.google.common.collect.ImmutableSet; -import com.google.inject.TypeLiteral; +import java.lang.reflect.Method; + import org.jclouds.cloudstack.domain.ExtractMode; import org.jclouds.cloudstack.domain.ISO; import org.jclouds.cloudstack.domain.PermissionOperation; @@ -31,13 +31,15 @@ import org.jclouds.cloudstack.options.RegisterISOOptions; import org.jclouds.cloudstack.options.UpdateISOOptions; import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions; import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; -import java.lang.reflect.Method; +import com.google.common.collect.ImmutableSet; +import com.google.inject.TypeLiteral; /** * Tests the behaviour of ISOAsyncClient. * @@ -54,7 +56,7 @@ public class ISOAsyncClientTest extends BaseCloudStackAsyncClientTestof("fred", "bob")).isExtractable(true).isFeatured(true).isPublic(true).operation(PermissionOperation.add)); assertRequestLineEquals(httpRequest, - "GET http://localhost:8080/client/api?response=json&command=updateISOPermissions&id=3&accounts=fred,bob&isextractable=true&isfeatured=true&ispublic=true&op=add HTTP/1.1"); + "GET http://localhost:8080/client/api?response=json&command=updateIsoPermissions&id=3&accounts=fred,bob&isextractable=true&isfeatured=true&ispublic=true&op=add HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertPayloadEquals(httpRequest, null, null, false); @@ -278,11 +279,11 @@ public class ISOAsyncClientTest extends BaseCloudStackAsyncClientTest response = client.getISOClient().listISOs(ListISOsOptions.Builder.isPublic()); assertNotNull(response); assertFalse(response.isEmpty()); + long isoCount = response.size(); + assertTrue(isoCount >= 0); + + for (ISO iso : response) { + ISO query = client.getISOClient().getISO(iso.getId()); + assertEquals(query.getId(), iso.getId()); + } + } + + public void testListISOPermissions() throws Exception { + Set response = client.getISOClient().listISOs(ListISOsOptions.Builder.isPublic()); + assertNotNull(response); + assertFalse(response.isEmpty()); + long isoCount = response.size(); + assertTrue(isoCount >= 0); + + for (ISO iso : response) { + ISOPermissions perms = client.getISOClient().listISOPermissions(iso.getId()); + assertNotNull(perms); + } } } diff --git a/apis/cloudstack/src/test/resources/listipforwardingrulesresponse.json b/apis/cloudstack/src/test/resources/listipforwardingrulesresponse.json index 8f1f4e2dfe..984f6ee4b6 100644 --- a/apis/cloudstack/src/test/resources/listipforwardingrulesresponse.json +++ b/apis/cloudstack/src/test/resources/listipforwardingrulesresponse.json @@ -11,8 +11,7 @@ "ipaddress": "10.27.27.64", "startport": 22, "endport": 22, - "state": "Active", - "cidrlist":"" + "state": "Active" }] } } diff --git a/apis/cloudstack/src/test/resources/listportforwardingrulesresponse.json b/apis/cloudstack/src/test/resources/listportforwardingrulesresponse.json index 54d5a076df..0f1373f089 100644 --- a/apis/cloudstack/src/test/resources/listportforwardingrulesresponse.json +++ b/apis/cloudstack/src/test/resources/listportforwardingrulesresponse.json @@ -1 +1 @@ -{ "listportforwardingrulesresponse" : { "portforwardingrule" : [ {"id":18,"privateport":"22","protocol":"tcp","publicport":"22","virtualmachineid":89,"virtualmachinename":"i-3-89-VM","ipaddressid":34,"ipaddress":"72.52.126.63","state":"Active"}, {"id":15,"privateport":"22","protocol":"tcp","publicport":"2022","virtualmachineid":3,"virtualmachinename":"i-3-3-VM","ipaddressid":3,"ipaddress":"72.52.126.32","state":"Active"} ] } } \ No newline at end of file +{ "listportforwardingrulesresponse" : { "portforwardingrule" : [ {"id":18,"privateport":"22","protocol":"tcp","publicport":"22","virtualmachineid":89,"virtualmachinename":"i-3-89-VM","ipaddressid":34,"ipaddress":"72.52.126.63","state":"Active"}, {"id":15,"privateport":"22","protocol":"tcp","publicport":"2022","virtualmachineid":3,"virtualmachinename":"i-3-3-VM","ipaddressid":3,"ipaddress":"72.52.126.32","state":"Active","cidrlist":""} ] } } \ No newline at end of file