From c8bc318fbaea4f144fbed24ba2c9a32df4192eb5 Mon Sep 17 00:00:00 2001 From: Richard Downer Date: Wed, 14 Dec 2011 15:42:27 +0000 Subject: [PATCH 1/4] Add empty feature classes for Storage Pool API --- .../CloudStackGlobalAsyncClient.java | 7 ++++ .../cloudstack/CloudStackGlobalClient.java | 7 ++++ .../config/CloudStackRestClientModule.java | 3 ++ .../GlobalStoragePoolAsyncClient.java | 36 ++++++++++++++++++ .../features/GlobalStoragePoolClient.java | 35 +++++++++++++++++ .../GlobalStoragePoolAsyncClientTest.java | 38 +++++++++++++++++++ .../GlobalStoragePoolClientLiveTest.java | 31 +++++++++++++++ 7 files changed, 157 insertions(+) create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClient.java create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolClient.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClientTest.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalAsyncClient.java index f41bd5776a..fe7af3cff1 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalAsyncClient.java @@ -23,6 +23,7 @@ import org.jclouds.cloudstack.features.GlobalAlertAsyncClient; import org.jclouds.cloudstack.features.GlobalCapacityAsyncClient; import org.jclouds.cloudstack.features.GlobalHostAsyncClient; import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient; +import org.jclouds.cloudstack.features.GlobalStoragePoolAsyncClient; import org.jclouds.cloudstack.features.GlobalUserAsyncClient; import org.jclouds.rest.annotations.Delegate; @@ -77,4 +78,10 @@ public interface CloudStackGlobalAsyncClient extends CloudStackDomainAsyncClient @Delegate GlobalHostAsyncClient getHostClient(); + /** + * Provides synchronous access to Storage Pools + */ + @Delegate + GlobalStoragePoolAsyncClient getStoragePoolClient(); + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalClient.java index 53e3f5dd99..fa05591ad6 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalClient.java @@ -25,6 +25,7 @@ import org.jclouds.cloudstack.features.GlobalAlertClient; import org.jclouds.cloudstack.features.GlobalCapacityClient; import org.jclouds.cloudstack.features.GlobalHostClient; import org.jclouds.cloudstack.features.GlobalOfferingClient; +import org.jclouds.cloudstack.features.GlobalStoragePoolClient; import org.jclouds.cloudstack.features.GlobalUserClient; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; @@ -81,4 +82,10 @@ public interface CloudStackGlobalClient extends CloudStackDomainClient { @Delegate GlobalHostClient getHostClient(); + /** + * Provides synchronous access to Storage Pools + */ + @Delegate + GlobalStoragePoolClient getStoragePoolClient(); + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java index 537561f7e3..92a2f1fe60 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java @@ -58,6 +58,8 @@ import org.jclouds.cloudstack.features.GlobalHostAsyncClient; import org.jclouds.cloudstack.features.GlobalHostClient; import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient; import org.jclouds.cloudstack.features.GlobalOfferingClient; +import org.jclouds.cloudstack.features.GlobalStoragePoolAsyncClient; +import org.jclouds.cloudstack.features.GlobalStoragePoolClient; import org.jclouds.cloudstack.features.GlobalUserAsyncClient; import org.jclouds.cloudstack.features.GlobalUserClient; import org.jclouds.cloudstack.features.GuestOSAsyncClient; @@ -152,6 +154,7 @@ public class CloudStackRestClientModule extends RestClientModule + * + * @see GlobalStoragePoolClient + * @see + * @author Richard Downer + */ +@RequestFilters(QuerySigner.class) +@QueryParams(keys = "response", values = "json") +public interface GlobalStoragePoolAsyncClient { +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolClient.java new file mode 100644 index 0000000000..51257cd492 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolClient.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.features; + +import org.jclouds.concurrent.Timeout; + +import java.util.concurrent.TimeUnit; + +/** + * Provides synchronous access to CloudStack storage pool features. + *

+ * + * @see GlobalStoragePoolClient + * @see + * @author Richard Downer + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface GlobalStoragePoolClient { +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClientTest.java new file mode 100644 index 0000000000..efb77076ae --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClientTest.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.features; + +import com.google.inject.TypeLiteral; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code GlobalStoragePoolAsyncClient} + * + * @author Richard Downer + */ +@Test(groups = "unit", testName = "GlobalStoragePoolAsyncClientTest") +public class GlobalStoragePoolAsyncClientTest extends BaseCloudStackAsyncClientTest { + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java new file mode 100644 index 0000000000..37a60edf93 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java @@ -0,0 +1,31 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.features; + +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code GlobalStoragePoolClient} + * + * @author Richard Downer + */ +@Test(groups = "live", singleThreaded = true, testName = "GlobalStoragePoolClientLiveTest") +public class GlobalStoragePoolClientLiveTest extends BaseCloudStackClientLiveTest { + +} From 56baa1977f0431d3db4124108812f2aa4aa09aab Mon Sep 17 00:00:00 2001 From: Richard Downer Date: Tue, 13 Dec 2011 16:42:54 +0000 Subject: [PATCH 2/4] Add domain object for StoragePool --- .../cloudstack/domain/StoragePool.java | 406 ++++++++++++++++++ .../parse/ListStoragePoolsResponseTest.java | 65 +++ .../resources/liststoragepoolsresponse.json | 1 + 3 files changed, 472 insertions(+) create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java create mode 100644 apis/cloudstack/src/test/resources/liststoragepoolsresponse.json diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java new file mode 100644 index 0000000000..fc7234c1f4 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java @@ -0,0 +1,406 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.domain; + +import com.google.common.base.CaseFormat; +import com.google.gson.annotations.SerializedName; + +import java.util.Date; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Represents a storage pool in CloudStack + * + * @author Richard Downer + */ +public class StoragePool implements Comparable { + + public enum State { + UP, + PREPARE_FOR_MAINTENANCE, + ERROR_IN_MAINTENANCE, + CANCEL_MAINTENANCE, + MAINTENANCE, + REMOVED, + UNRECOGNIZED; + + @Override + public String toString() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + public static State fromValue(String type) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public static enum Type { + FILESYSTEM, + NETWORK_FILESYSTEM, + ISCSI_LUN, + ISCSI, + ISO, + LVM, + CLVM, + SHARED_MOUNT_POINT, + VMFS, + PRE_SETUP, + EXT, + OCFS2, + UNRECOGNIZED; + + @Override + public String toString() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + public static Type fromValue(String type) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private Builder() { + } + + private long id; + private String name; + private String path; + private String tags; + private State state; + private Type type; + private long zoneId; + private String zoneName; + private long podId; + private String podName; + private long clusterId; + private String clusterName; + private Date created; + private long diskSizeAllocated; + private long diskSizeTotal; + private String ipAddress; + private Long jobId; + private String jobStatus; + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder path(String path) { + this.path = path; + return this; + } + + public Builder tags(String tags) { + this.tags = tags; + return this; + } + + public Builder state(State state) { + this.state = state; + return this; + } + + public Builder type(Type type) { + this.type = type; + return this; + } + + public Builder zoneId(long zoneId) { + this.zoneId = zoneId; + return this; + } + + public Builder zoneName(String zoneName) { + this.zoneName = zoneName; + return this; + } + + public Builder podId(long podId) { + this.podId = podId; + return this; + } + + public Builder podName(String podName) { + this.podName = podName; + return this; + } + + public Builder clusterId(long clusterId) { + this.clusterId = clusterId; + return this; + } + + public Builder clusterName(String clusterName) { + this.clusterName = clusterName; + return this; + } + + public Builder created(Date created) { + this.created = created; + return this; + } + + public Builder diskSizeAllocated(long diskSizeAllocated) { + this.diskSizeAllocated = diskSizeAllocated; + return this; + } + + public Builder diskSizeTotal(long diskSizeTotal) { + this.diskSizeTotal = diskSizeTotal; + return this; + } + + public Builder ipAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + public Builder jobId(Long jobId) { + this.jobId = jobId; + return this; + } + + public Builder jobStatus(String jobStatus) { + this.jobStatus = jobStatus; + return this; + } + + public StoragePool build() { + return new StoragePool(id, name, path, tags, state, type, zoneId, zoneName, podId, podName, clusterId, clusterName, created, diskSizeAllocated, diskSizeTotal, ipAddress, jobId, jobStatus); + } + } + + private long id; + private String name; + private String path; + private String tags; + private State state; + private Type type; + @SerializedName("zoneid") private long zoneId; + @SerializedName("zonename") private String zoneName; + @SerializedName("podid") private long podId; + @SerializedName("podname") private String podName; + @SerializedName("clusterid") private long clusterId; + @SerializedName("clustername") private String clusterName; + private Date created; + @SerializedName("disksizeallocated") private long diskSizeAllocated; + @SerializedName("disksizetotal") private long diskSizeTotal; + @SerializedName("ipaddress") private String ipAddress; + @SerializedName("jobid") private Long jobId; + @SerializedName("jobstatus") private String jobStatus; + + /* Exists only for the serializer */ + StoragePool() { + } + + public StoragePool(long id, String name, String path, String tags, State state, Type type, long zoneId, String zoneName, long podId, String podName, long clusterId, String clusterName, Date created, long diskSizeAllocated, long diskSizeTotal, String ipAddress, Long jobId, String jobStatus) { + this.id = id; + this.name = name; + this.path = path; + this.tags = tags; + this.state = state; + this.type = type; + this.zoneId = zoneId; + this.zoneName = zoneName; + this.podId = podId; + this.podName = podName; + this.clusterId = clusterId; + this.clusterName = clusterName; + this.created = created; + this.diskSizeAllocated = diskSizeAllocated; + this.diskSizeTotal = diskSizeTotal; + this.ipAddress = ipAddress; + this.jobId = jobId; + this.jobStatus = jobStatus; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getPath() { + return path; + } + + public String getTags() { + return tags; + } + + public State getState() { + return state; + } + + public Type getType() { + return type; + } + + public long getZoneId() { + return zoneId; + } + + public String getZoneName() { + return zoneName; + } + + public long getPodId() { + return podId; + } + + public String getPodName() { + return podName; + } + + public long getClusterId() { + return clusterId; + } + + public String getClusterName() { + return clusterName; + } + + public Date getCreated() { + return created; + } + + public long getDiskSizeAllocated() { + return diskSizeAllocated; + } + + public long getDiskSizeTotal() { + return diskSizeTotal; + } + + public String getIpAddress() { + return ipAddress; + } + + public Long getJobId() { + return jobId; + } + + public String getJobStatus() { + return jobStatus; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + StoragePool that = (StoragePool) o; + + if (clusterId != that.clusterId) return false; + if (diskSizeAllocated != that.diskSizeAllocated) return false; + if (diskSizeTotal != that.diskSizeTotal) return false; + if (id != that.id) return false; + if (podId != that.podId) return false; + if (zoneId != that.zoneId) return false; + if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false; + if (created != null ? !created.equals(that.created) : that.created != null) return false; + if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) return false; + if (jobId != null ? !jobId.equals(that.jobId) : that.jobId != null) return false; + if (jobStatus != null ? !jobStatus.equals(that.jobStatus) : that.jobStatus != null) return false; + if (name != null ? !name.equals(that.name) : that.name != null) return false; + if (path != null ? !path.equals(that.path) : that.path != null) return false; + if (podName != null ? !podName.equals(that.podName) : that.podName != null) return false; + if (state != that.state) return false; + if (tags != null ? !tags.equals(that.tags) : that.tags != null) return false; + if (type != that.type) return false; + if (zoneName != null ? !zoneName.equals(that.zoneName) : that.zoneName != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (path != null ? path.hashCode() : 0); + result = 31 * result + (tags != null ? tags.hashCode() : 0); + result = 31 * result + (state != null ? state.hashCode() : 0); + result = 31 * result + (type != null ? type.hashCode() : 0); + result = 31 * result + (int) (zoneId ^ (zoneId >>> 32)); + result = 31 * result + (zoneName != null ? zoneName.hashCode() : 0); + result = 31 * result + (int) (podId ^ (podId >>> 32)); + result = 31 * result + (podName != null ? podName.hashCode() : 0); + result = 31 * result + (int) (clusterId ^ (clusterId >>> 32)); + result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0); + result = 31 * result + (created != null ? created.hashCode() : 0); + result = 31 * result + (int) (diskSizeAllocated ^ (diskSizeAllocated >>> 32)); + result = 31 * result + (int) (diskSizeTotal ^ (diskSizeTotal >>> 32)); + result = 31 * result + (ipAddress != null ? ipAddress.hashCode() : 0); + result = 31 * result + (jobId != null ? jobId.hashCode() : 0); + result = 31 * result + (jobStatus != null ? jobStatus.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "StoragePool{" + + "id=" + id + + ", name='" + name + '\'' + + ", path='" + path + '\'' + + ", tags='" + tags + '\'' + + ", state=" + state + + ", type=" + type + + ", zoneId=" + zoneId + + ", zoneName='" + zoneName + '\'' + + ", podId=" + podId + + ", podName='" + podName + '\'' + + ", clusterId=" + clusterId + + ", clusterName='" + clusterName + '\'' + + ", created=" + created + + ", diskSizeAllocated=" + diskSizeAllocated + + ", diskSizeTotal=" + diskSizeTotal + + ", ipAddress='" + ipAddress + '\'' + + ", jobId=" + jobId + + ", jobStatus='" + jobStatus + '\'' + + '}'; + } + + @Override + public int compareTo(StoragePool other) { + return Long.valueOf(this.id).compareTo(other.id); + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java new file mode 100644 index 0000000000..b560633c82 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.parse; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Injector; +import org.jclouds.cloudstack.domain.StoragePool; +import org.jclouds.cloudstack.functions.ParseIdToNameFromHttpResponse; +import org.jclouds.http.HttpResponse; +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import java.util.Calendar; +import java.util.Date; +import java.util.Map; +import java.util.Set; +import java.util.TimeZone; + +/** + * + * @author Richard Downer + */ +@Test(groups = "unit") +public class ListStoragePoolsResponseTest extends BaseItemParserTest> { + + @Override + public String resource() { + return "/liststoragepoolsresponse.json"; + } + + @Override + @SelectJson("storagepool") + public Set expected() { + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + c.set(Calendar.YEAR, 2011); + c.set(Calendar.MONTH, Calendar.NOVEMBER); + c.set(Calendar.DAY_OF_MONTH, 26); + c.set(Calendar.HOUR_OF_DAY, 23); + c.set(Calendar.MINUTE, 33); + c.set(Calendar.SECOND, 6); + Date created = c.getTime(); + + StoragePool storagePool = StoragePool.builder().id(201).zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").name("NFS Pri 1").ipAddress("10.26.26.165").path("/mnt/nfs/cs_pri").created(created).type(StoragePool.Type.NETWORK_FILESYSTEM).clusterId(1).clusterName("Xen Clust 1").diskSizeTotal(898356445184L).diskSizeAllocated(18276679680L).tags("").state(StoragePool.State.UP).build(); + return ImmutableSet.of(storagePool); + } +} diff --git a/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json b/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json new file mode 100644 index 0000000000..deca7a28c7 --- /dev/null +++ b/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json @@ -0,0 +1 @@ +{ "liststoragepoolsresponse" : { "count":1 ,"storagepool" : [ {"id":201,"zoneid":1,"zonename":"Dev Zone 1","podid":1,"podname":"Dev Pod 1","name":"NFS Pri 1","ipaddress":"10.26.26.165","path":"/mnt/nfs/cs_pri","created":"2011-11-26T23:33:06+0200","type":"NetworkFilesystem","clusterid":1,"clustername":"Xen Clust 1","disksizetotal":898356445184,"disksizeallocated":18276679680,"tags":"","state":"Up"} ] } } \ No newline at end of file From ec46da8b594f37855eab3c686baf448b842d43f2 Mon Sep 17 00:00:00 2001 From: Richard Downer Date: Wed, 14 Dec 2011 15:13:10 +0000 Subject: [PATCH 3/4] Add ListStoragePoolsOptions + test --- .../options/ListStoragePoolsOptions.java | 119 ++++++++++++++++++ .../options/ListStoragePoolsOptionsTest.java | 115 +++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListStoragePoolsOptions.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListStoragePoolsOptionsTest.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListStoragePoolsOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListStoragePoolsOptions.java new file mode 100644 index 0000000000..a8657e10e7 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListStoragePoolsOptions.java @@ -0,0 +1,119 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Options to the GlobalStoragePools[Async]Client.listStoragePools API call + * + * @author Richard Downer + */ +public class ListStoragePoolsOptions extends BaseHttpRequestOptions { + + public static ListStoragePoolsOptions NONE = new ListStoragePoolsOptions(); + + public static class Builder { + + private Builder() {} + + public static ListStoragePoolsOptions clusterId(long clusterId) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.clusterId(clusterId); + } + + public static ListStoragePoolsOptions id(long id) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.id(id); + } + + public static ListStoragePoolsOptions ipAddress(String ipAddress) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.ipAddress(ipAddress); + } + + public static ListStoragePoolsOptions keyword(String keyword) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.keyword(keyword); + } + + public static ListStoragePoolsOptions name(String name) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.name(name); + } + + public static ListStoragePoolsOptions path(String path) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.path(path); + } + + public static ListStoragePoolsOptions podId(long podId) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.podId(podId); + } + + public static ListStoragePoolsOptions zoneId(long zoneId) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.zoneId(zoneId); + } + } + + ListStoragePoolsOptions() {} + + public ListStoragePoolsOptions clusterId(long clusterId) { + this.queryParameters.replaceValues("clusterid", ImmutableSet.of(clusterId + "")); + return this; + } + + public ListStoragePoolsOptions id(long id) { + this.queryParameters.replaceValues("id", ImmutableSet.of(id + "")); + return this; + } + + public ListStoragePoolsOptions ipAddress(String ipAddress) { + this.queryParameters.replaceValues("ipaddress", ImmutableSet.of(ipAddress)); + return this; + } + + public ListStoragePoolsOptions keyword(String keyword) { + this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword)); + return this; + } + + public ListStoragePoolsOptions name(String name) { + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); + return this; + } + public ListStoragePoolsOptions path(String path) { + this.queryParameters.replaceValues("path", ImmutableSet.of(path)); + return this; + } + + public ListStoragePoolsOptions podId(long podId) { + this.queryParameters.replaceValues("podid", ImmutableSet.of(podId + "")); + return this; + } + + public ListStoragePoolsOptions zoneId(long zoneId) { + this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + "")); + return this; + } + +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListStoragePoolsOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListStoragePoolsOptionsTest.java new file mode 100644 index 0000000000..38eb811bbf --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListStoragePoolsOptionsTest.java @@ -0,0 +1,115 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.options; + +import com.google.common.collect.ImmutableList; +import org.testng.annotations.Test; + +import static org.jclouds.cloudstack.options.ListStoragePoolsOptions.Builder.*; +import static org.testng.Assert.assertEquals; + +/** + * Test for the ListStoragePoolsOptions class. + * + * @author Richard Downer + */ +@Test(groups = "unit") +public class ListStoragePoolsOptionsTest { + + public void testClusterId() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().clusterId(14); + assertEquals(ImmutableList.of(14 + ""), options.buildQueryParameters().get("clusterid")); + } + + public void testClusterIdStatic() { + ListStoragePoolsOptions options = clusterId(14); + assertEquals(ImmutableList.of(14 + ""), options.buildQueryParameters().get("clusterid")); + } + + public void testId() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().id(15); + assertEquals(ImmutableList.of(15 + ""), options.buildQueryParameters().get("id")); + } + + public void testIdStatic() { + ListStoragePoolsOptions options = id(15); + assertEquals(ImmutableList.of(15 + ""), options.buildQueryParameters().get("id")); + } + + public void testIpAddress() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().ipAddress("192.168.42.42"); + assertEquals(ImmutableList.of("192.168.42.42"), options.buildQueryParameters().get("ipaddress")); + } + + public void testIpAddressStatic() { + ListStoragePoolsOptions options = ipAddress("192.168.42.42"); + assertEquals(ImmutableList.of("192.168.42.42"), options.buildQueryParameters().get("ipaddress")); + } + + public void testKeyword() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().keyword("fred"); + assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword")); + } + + public void testKeywordStatic() { + ListStoragePoolsOptions options = keyword("fred"); + assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword")); + } + + public void testName() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().name("bob"); + assertEquals(ImmutableList.of("bob"), options.buildQueryParameters().get("name")); + } + + public void testNameStatic() { + ListStoragePoolsOptions options = name("bob"); + assertEquals(ImmutableList.of("bob"), options.buildQueryParameters().get("name")); + } + + public void testPath() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().path("/foo/bar"); + assertEquals(ImmutableList.of("/foo/bar"), options.buildQueryParameters().get("path")); + } + + public void testPathStatic() { + ListStoragePoolsOptions options = path("/foo/bar"); + assertEquals(ImmutableList.of("/foo/bar"), options.buildQueryParameters().get("path")); + } + + public void testPodId() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().podId(16); + assertEquals(ImmutableList.of(16 + ""), options.buildQueryParameters().get("podid")); + } + + public void testPodIdStatic() { + ListStoragePoolsOptions options = podId(16); + assertEquals(ImmutableList.of(16 + ""), options.buildQueryParameters().get("podid")); + } + + public void testZoneId() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().zoneId(17); + assertEquals(ImmutableList.of(17 + ""), options.buildQueryParameters().get("zoneid")); + } + + public void testZoneIdStatic() { + ListStoragePoolsOptions options = zoneId(17); + assertEquals(ImmutableList.of(17 + ""), options.buildQueryParameters().get("zoneid")); + } + +} From c000db598dc012f933a4e8f044539a743710195e Mon Sep 17 00:00:00 2001 From: Richard Downer Date: Wed, 14 Dec 2011 16:45:41 +0000 Subject: [PATCH 4/4] Add listStoragePools to the GlobalStoragePool[Async]Client, with tests --- .../GlobalStoragePoolAsyncClient.java | 18 +++++++++ .../features/GlobalStoragePoolClient.java | 6 +++ .../GlobalStoragePoolAsyncClientTest.java | 38 +++++++++++++++++++ .../GlobalStoragePoolClientLiveTest.java | 31 +++++++++++++++ 4 files changed, 93 insertions(+) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClient.java index db572cd025..a3d13c5852 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClient.java @@ -18,9 +18,19 @@ */ package org.jclouds.cloudstack.features; +import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.cloudstack.domain.StoragePool; import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.options.ListStoragePoolsOptions; 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 javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.core.MediaType; +import java.util.Set; /** * Provides asynchronous access to CloudStack storage pool features. @@ -32,5 +42,13 @@ import org.jclouds.rest.annotations.RequestFilters; */ @RequestFilters(QuerySigner.class) @QueryParams(keys = "response", values = "json") +@SkipEncoding({'/'}) public interface GlobalStoragePoolAsyncClient { + + @GET + @QueryParams(keys = "command", values = "listStoragePools") + @SelectJson("storagepool") + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture> listStoragePools(ListStoragePoolsOptions... options); + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolClient.java index 51257cd492..6a7e48970b 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalStoragePoolClient.java @@ -18,8 +18,11 @@ */ package org.jclouds.cloudstack.features; +import org.jclouds.cloudstack.domain.StoragePool; +import org.jclouds.cloudstack.options.ListStoragePoolsOptions; import org.jclouds.concurrent.Timeout; +import java.util.Set; import java.util.concurrent.TimeUnit; /** @@ -32,4 +35,7 @@ import java.util.concurrent.TimeUnit; */ @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface GlobalStoragePoolClient { + + Set listStoragePools(ListStoragePoolsOptions... options); + } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClientTest.java index efb77076ae..22932b9a19 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolAsyncClientTest.java @@ -19,9 +19,15 @@ package org.jclouds.cloudstack.features; import com.google.inject.TypeLiteral; +import org.jclouds.cloudstack.options.ListStoragePoolsOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; +import java.lang.reflect.Method; + /** * Tests behavior of {@code GlobalStoragePoolAsyncClient} * @@ -30,6 +36,38 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "GlobalStoragePoolAsyncClientTest") public class GlobalStoragePoolAsyncClientTest extends BaseCloudStackAsyncClientTest { + public void testListStoragePools() throws NoSuchMethodException { + Method method = GlobalStoragePoolAsyncClient.class.getMethod("listStoragePools", ListStoragePoolsOptions[].class); + HttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listStoragePools HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + } + + public void testListStoragePoolsOptions() throws NoSuchMethodException { + Method method = GlobalStoragePoolAsyncClient.class.getMethod("listStoragePools", ListStoragePoolsOptions[].class); + HttpRequest httpRequest = processor.createRequest(method, ListStoragePoolsOptions.Builder.clusterId(3).id(4).ipAddress("192.168.42.42").keyword("fred").name("bob").path("/mnt/store42").podId(4).zoneId(5)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listStoragePools&clusterid=3&id=4&ipaddress=192.168.42.42&keyword=fred&name=bob&path=/mnt/store42&podid=4&zoneid=5 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + } + @Override protected TypeLiteral> createTypeLiteral() { return new TypeLiteral>() { diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java index 37a60edf93..f44d7e9846 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java @@ -18,8 +18,14 @@ */ package org.jclouds.cloudstack.features; +import com.google.common.base.Strings; +import org.jclouds.cloudstack.domain.StoragePool; import org.testng.annotations.Test; +import java.util.Set; + +import static org.testng.Assert.*; + /** * Tests behavior of {@code GlobalStoragePoolClient} * @@ -28,4 +34,29 @@ import org.testng.annotations.Test; @Test(groups = "live", singleThreaded = true, testName = "GlobalStoragePoolClientLiveTest") public class GlobalStoragePoolClientLiveTest extends BaseCloudStackClientLiveTest { + @Test(groups = "live", enabled = true) + public void testListStoragePools() throws Exception { + assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + + Set result = globalAdminClient.getStoragePoolClient().listStoragePools(); + assertNotNull(result); + assertTrue(result.size() > 0); + for(StoragePool pool : result) { + assertTrue(pool.getId() > 0); + assertFalse(Strings.isNullOrEmpty(pool.getName())); + assertFalse(Strings.isNullOrEmpty(pool.getPath())); + assertNotNull(pool.getTags()); + assertTrue(pool.getState() != StoragePool.State.UNRECOGNIZED); + assertTrue(pool.getType() != StoragePool.Type.UNRECOGNIZED); + assertTrue(pool.getZoneId() > 0); + assertFalse(Strings.isNullOrEmpty(pool.getZoneName())); + assertTrue(pool.getPodId() > 0); + assertFalse(Strings.isNullOrEmpty(pool.getPodName())); + assertTrue(pool.getClusterId() > 0); + assertFalse(Strings.isNullOrEmpty(pool.getClusterName())); + assertNotNull(pool.getCreated()); + assertTrue(pool.getDiskSizeTotal() > 0); + } + } + }