Merge pull request #243 from richardcloudsoft/cloudstack-storagepools

Cloudstack listStoragePools operation
This commit is contained in:
Adrian Cole 2011-12-14 10:10:43 -08:00
commit db172d74d2
12 changed files with 956 additions and 0 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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<CloudStackClien
.put(GlobalCapacityClient.class, GlobalCapacityAsyncClient.class)//
.put(GlobalOfferingClient.class, GlobalOfferingAsyncClient.class)//
.put(GlobalHostClient.class, GlobalHostAsyncClient.class)//
.put(GlobalStoragePoolClient.class, GlobalStoragePoolAsyncClient.class)//
.build();
@Override

View File

@ -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<StoragePool> {
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);
}
}

View File

@ -0,0 +1,54 @@
/**
* 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.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.
* <p/>
*
* @see GlobalStoragePoolClient
* @see <a href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html" />
* @author Richard Downer
*/
@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<Set<StoragePool>> listStoragePools(ListStoragePoolsOptions... options);
}

View File

@ -0,0 +1,41 @@
/**
* 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.cloudstack.domain.StoragePool;
import org.jclouds.cloudstack.options.ListStoragePoolsOptions;
import org.jclouds.concurrent.Timeout;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to CloudStack storage pool features.
* <p/>
*
* @see GlobalStoragePoolClient
* @see <a href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html" />
* @author Richard Downer
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface GlobalStoragePoolClient {
Set<StoragePool> listStoragePools(ListStoragePoolsOptions... options);
}

View File

@ -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;
}
}

View File

@ -0,0 +1,76 @@
/**
* 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.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}
*
* @author Richard Downer
*/
@Test(groups = "unit", testName = "GlobalStoragePoolAsyncClientTest")
public class GlobalStoragePoolAsyncClientTest extends BaseCloudStackAsyncClientTest<GlobalStoragePoolAsyncClient> {
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<RestAnnotationProcessor<GlobalStoragePoolAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<GlobalStoragePoolAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,62 @@
/**
* 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.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}
*
* @author Richard Downer
*/
@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<StoragePool> 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);
}
}
}

View File

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

View File

@ -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<Set<StoragePool>> {
@Override
public String resource() {
return "/liststoragepoolsresponse.json";
}
@Override
@SelectJson("storagepool")
public Set<StoragePool> 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);
}
}

View File

@ -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"} ] } }