mirror of https://github.com/apache/jclouds.git
Implement the Cloudstack "system capacity" API
This commit is contained in:
parent
120c907633
commit
a4ce36036a
|
@ -20,6 +20,7 @@ package org.jclouds.cloudstack;
|
|||
|
||||
import org.jclouds.cloudstack.features.GlobalAccountAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalCapacityAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
|
@ -48,6 +49,12 @@ public interface CloudStackGlobalAsyncClient extends CloudStackDomainAsyncClient
|
|||
@Delegate
|
||||
GlobalAlertAsyncClient getAlertClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Capacities
|
||||
*/
|
||||
@Delegate
|
||||
GlobalCapacityAsyncClient getCapacityClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Offerings
|
||||
*/
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.cloudstack.features.GlobalAccountClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertClient;
|
||||
import org.jclouds.cloudstack.features.GlobalCapacityClient;
|
||||
import org.jclouds.cloudstack.features.GlobalOfferingClient;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
@ -52,6 +53,12 @@ public interface CloudStackGlobalClient extends CloudStackDomainClient {
|
|||
@Delegate
|
||||
GlobalAlertClient getAlertClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Capacities
|
||||
*/
|
||||
@Delegate
|
||||
GlobalCapacityClient getCapacityClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Offerings
|
||||
*/
|
||||
|
|
|
@ -46,6 +46,8 @@ import org.jclouds.cloudstack.features.GlobalAccountAsyncClient;
|
|||
import org.jclouds.cloudstack.features.GlobalAccountClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertClient;
|
||||
import org.jclouds.cloudstack.features.GlobalCapacityAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalCapacityClient;
|
||||
import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalOfferingClient;
|
||||
import org.jclouds.cloudstack.features.GuestOSAsyncClient;
|
||||
|
@ -132,6 +134,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
|||
.put(VolumeClient.class, VolumeAsyncClient.class)//
|
||||
.put(SnapshotClient.class, SnapshotAsyncClient.class)//
|
||||
.put(GlobalAlertClient.class, GlobalAlertAsyncClient.class)//
|
||||
.put(GlobalCapacityClient.class, GlobalCapacityAsyncClient.class)//
|
||||
.put(GlobalOfferingClient.class, GlobalOfferingAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
|
|
|
@ -0,0 +1,241 @@
|
|||
/**
|
||||
* 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.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Information about a dimension of the capacity
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class Capacity implements Comparable<Capacity> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private long capacityTotal;
|
||||
private long capacityUsed;
|
||||
private double percentUsed;
|
||||
private long podId;
|
||||
private String podName;
|
||||
private Type type;
|
||||
private long zoneId;
|
||||
private String zoneName;
|
||||
|
||||
public Builder capacityTotal(long capacityTotal) {
|
||||
this.capacityTotal = capacityTotal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder capacityUsed(long capacityUsed) {
|
||||
this.capacityUsed = capacityUsed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder percentUsed(double percentUsed) {
|
||||
this.percentUsed = percentUsed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder podId(long podId) {
|
||||
this.podId = podId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder podName(String podName) {
|
||||
this.podName = podName;
|
||||
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 Capacity build() {
|
||||
return new Capacity(capacityTotal, capacityUsed, percentUsed, podId, podName, type, zoneId, zoneName);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
MEMORY_ALLOCATED_BYTES(0),
|
||||
CPU_ALLOCATED_MHZ(1),
|
||||
PRIMARY_STORAGE_USED_BYTES(2),
|
||||
PRIMARY_STORAGE_ALLOCATED_BYTES(3),
|
||||
PUBLIC_IP_ADDRESSES(4),
|
||||
PRIVATE_IP_ADDRESSES(5),
|
||||
SECONDARY_STORAGE_USED_BYTES(6),
|
||||
UNRECOGNIZED(Integer.MAX_VALUE);
|
||||
|
||||
private int code;
|
||||
|
||||
private static final Map<Integer, Type> INDEX = Maps.uniqueIndex(ImmutableSet.copyOf(Type.values()),
|
||||
new Function<Type, Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer apply(Type input) {
|
||||
return input.code;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Type(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static Type fromValue(String type) {
|
||||
Integer code = new Integer(checkNotNull(type, "type"));
|
||||
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
@SerializedName("capacitytotal")
|
||||
private long capacityTotal;
|
||||
@SerializedName("capacityused")
|
||||
private long capacityUsed;
|
||||
@SerializedName("percentused")
|
||||
private double percentUsed;
|
||||
@SerializedName("podid")
|
||||
private long podId = -1;
|
||||
@SerializedName("podname")
|
||||
private String podName;
|
||||
private Capacity.Type type;
|
||||
@SerializedName("zoneid")
|
||||
private long zoneId = -1;
|
||||
@SerializedName("zonename")
|
||||
private String zoneName;
|
||||
|
||||
/* exists for the deserializer, only */
|
||||
Capacity() {
|
||||
}
|
||||
|
||||
public Capacity(long capacityTotal, long capacityUsed, double percentUsed, long podId, String podName, Type type, long zoneId, String zoneName) {
|
||||
this.capacityTotal = capacityTotal;
|
||||
this.capacityUsed = capacityUsed;
|
||||
this.percentUsed = percentUsed;
|
||||
this.podId = podId;
|
||||
this.podName = podName;
|
||||
this.type = type;
|
||||
this.zoneId = zoneId;
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
public long getCapacityTotal() {
|
||||
return capacityTotal;
|
||||
}
|
||||
|
||||
public long getCapacityUsed() {
|
||||
return capacityUsed;
|
||||
}
|
||||
|
||||
public double getPercentUsed() {
|
||||
return percentUsed;
|
||||
}
|
||||
|
||||
public long getPodId() {
|
||||
return podId;
|
||||
}
|
||||
|
||||
public String getPodName() {
|
||||
return podName;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public String getZoneName() {
|
||||
return zoneName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Capacity capacity = (Capacity) o;
|
||||
|
||||
if (capacityTotal != capacity.capacityTotal) return false;
|
||||
if (capacityUsed != capacity.capacityUsed) return false;
|
||||
if (Double.compare(capacity.percentUsed, percentUsed) != 0) return false;
|
||||
if (podId != capacity.podId) return false;
|
||||
if (zoneId != capacity.zoneId) return false;
|
||||
if (podName != null ? !podName.equals(capacity.podName) : capacity.podName != null) return false;
|
||||
if (type != capacity.type) return false;
|
||||
if (zoneName != null ? !zoneName.equals(capacity.zoneName) : capacity.zoneName != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
result = (int) (capacityTotal ^ (capacityTotal >>> 32));
|
||||
result = 31 * result + (int) (capacityUsed ^ (capacityUsed >>> 32));
|
||||
temp = percentUsed != +0.0d ? Double.doubleToLongBits(percentUsed) : 0L;
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
result = 31 * result + (int) (podId ^ (podId >>> 32));
|
||||
result = 31 * result + (podName != null ? podName.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);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Capacity other) {
|
||||
int comparison = Long.valueOf(this.zoneId).compareTo(other.zoneId);
|
||||
if (comparison != 0) return comparison;
|
||||
comparison = Long.valueOf(this.podId).compareTo(other.podId);
|
||||
if (comparison != 0) return comparison;
|
||||
return Integer.valueOf(this.type.code).compareTo(other.type.code);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* 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.Capacity;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListCapacityOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
|
||||
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 Account features available to Global
|
||||
* Admin users.
|
||||
*
|
||||
* @author Richard Downer
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html"
|
||||
* />
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface GlobalCapacityAsyncClient {
|
||||
|
||||
/**
|
||||
* @see GlobalCapacityClient#listCapacity(org.jclouds.cloudstack.options.ListCapacityOptions...)
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listCapacity")
|
||||
@SelectJson("capacity")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Capacity>> listCapacity(ListCapacityOptions...options);
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* 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.Capacity;
|
||||
import org.jclouds.cloudstack.options.ListCapacityOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack Capacities features available to Global
|
||||
* Admin users.
|
||||
*
|
||||
* @author Richard Downer
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html"
|
||||
* />
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface GlobalCapacityClient {
|
||||
|
||||
/**
|
||||
* List Capacities
|
||||
*
|
||||
* @return alert list or null if not found
|
||||
*/
|
||||
Set<Capacity> listCapacity(ListCapacityOptions... options);
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* 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.cloudstack.domain.Capacity;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Options to the listCapacity command.
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class ListCapacityOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListCapacityOptions NONE = new ListCapacityOptions();
|
||||
|
||||
public ListCapacityOptions hostId(long hostId) {
|
||||
this.queryParameters.replaceValues("hostid", ImmutableSet.of(hostId + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListCapacityOptions keyword(String keyword) {
|
||||
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListCapacityOptions podId(long podId) {
|
||||
this.queryParameters.replaceValues("podid", ImmutableSet.of(podId + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListCapacityOptions type(Capacity.Type type) {
|
||||
this.queryParameters.replaceValues("type", ImmutableSet.of(type.ordinal() + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListCapacityOptions zoneId(long zoneId) {
|
||||
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
public static ListCapacityOptions hostId(long hostId) {
|
||||
final ListCapacityOptions options = new ListCapacityOptions();
|
||||
return options.hostId(hostId);
|
||||
}
|
||||
|
||||
public static ListCapacityOptions keyword(String keyword) {
|
||||
final ListCapacityOptions options = new ListCapacityOptions();
|
||||
return options.keyword(keyword);
|
||||
}
|
||||
|
||||
public static ListCapacityOptions podId(long podId) {
|
||||
final ListCapacityOptions options = new ListCapacityOptions();
|
||||
return options.podId(podId);
|
||||
}
|
||||
|
||||
public static ListCapacityOptions type(Capacity.Type type) {
|
||||
final ListCapacityOptions options = new ListCapacityOptions();
|
||||
return options.type(type);
|
||||
}
|
||||
|
||||
public static ListCapacityOptions zoneId(long zoneId) {
|
||||
final ListCapacityOptions options = new ListCapacityOptions();
|
||||
return options.zoneId(zoneId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* 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.domain.Capacity;
|
||||
import org.jclouds.cloudstack.options.ListCapacityOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobalCapacityAsyncClient}
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during
|
||||
// surefire
|
||||
@Test(groups = "unit", testName = "GlobalCapacityAsyncClientTest")
|
||||
public class GlobalCapacityAsyncClientTest extends BaseCloudStackAsyncClientTest<GlobalCapacityAsyncClient> {
|
||||
|
||||
public void testListCapacity() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = GlobalCapacityAsyncClient.class.getMethod("listCapacity", ListCapacityOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listCapacity HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testListCapacityOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = GlobalCapacityAsyncClient.class.getMethod("listCapacity", ListCapacityOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListCapacityOptions.Builder.hostId(3).keyword("fred").podId(4).type(Capacity.Type.CPU_ALLOCATED_MHZ).zoneId(6));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listCapacity&hostid=3&keyword=fred&podid=4&type=1&zoneid=6 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GlobalCapacityAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GlobalCapacityAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* 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.Capacity;
|
||||
import org.jclouds.cloudstack.options.ListCapacityOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobalCapacityClient}
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "GlobalCapacityClientLiveTest")
|
||||
public class GlobalCapacityClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
@Test(groups = "live", enabled = true)
|
||||
public void testListCapacity() throws Exception {
|
||||
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
|
||||
|
||||
final Set<Capacity> response = globalAdminClient.getCapacityClient().listCapacity();
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
int count = 0;
|
||||
for (Capacity capacity : response) {
|
||||
assertTrue(capacity.getCapacityTotal() > 0);
|
||||
assertTrue(capacity.getCapacityUsed() > 0);
|
||||
assertTrue(capacity.getPercentUsed() > 0);
|
||||
assertTrue(capacity.getType() != Capacity.Type.UNRECOGNIZED);
|
||||
assertNotNull(capacity.getZoneName());
|
||||
count++;
|
||||
}
|
||||
assertTrue(count > 0, "No capacities were returned, so I couldn't test");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* 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.jclouds.cloudstack.domain.Capacity;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListCapacityOptions.Builder.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListCapacityOptions}
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListCapacityOptionsTest {
|
||||
|
||||
public void testHostId() {
|
||||
ListCapacityOptions options = new ListCapacityOptions().hostId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("hostid"));
|
||||
}
|
||||
|
||||
public void testHostIdStatic() {
|
||||
ListCapacityOptions options = hostId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("hostid"));
|
||||
}
|
||||
|
||||
public void testKeyword() {
|
||||
ListCapacityOptions options = new ListCapacityOptions().keyword("fred");
|
||||
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword"));
|
||||
}
|
||||
|
||||
public void testKeywordStatic() {
|
||||
ListCapacityOptions options = keyword("fred");
|
||||
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword"));
|
||||
}
|
||||
|
||||
public void testPodId() {
|
||||
ListCapacityOptions options = new ListCapacityOptions().podId(5);
|
||||
assertEquals(ImmutableList.of("5"), options.buildQueryParameters().get("podid"));
|
||||
}
|
||||
|
||||
public void testPodIdStatic() {
|
||||
ListCapacityOptions options = podId(5);
|
||||
assertEquals(ImmutableList.of("5"), options.buildQueryParameters().get("podid"));
|
||||
}
|
||||
|
||||
public void testType() {
|
||||
ListCapacityOptions options = new ListCapacityOptions().type(Capacity.Type.PUBLIC_IP_ADDRESSES);
|
||||
assertEquals(ImmutableList.of("4"), options.buildQueryParameters().get("type"));
|
||||
}
|
||||
|
||||
public void testTypeStatic() {
|
||||
ListCapacityOptions options = type(Capacity.Type.PUBLIC_IP_ADDRESSES);
|
||||
assertEquals(ImmutableList.of("4"), options.buildQueryParameters().get("type"));
|
||||
}
|
||||
|
||||
public void testZoneId() {
|
||||
ListCapacityOptions options = new ListCapacityOptions().zoneId(4);
|
||||
assertEquals(ImmutableList.of("4"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
|
||||
public void testZoneIdStatic() {
|
||||
ListCapacityOptions options = zoneId(4);
|
||||
assertEquals(ImmutableList.of("4"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
}
|
|
@ -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.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jclouds.cloudstack.config.CloudStackParserModule;
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.Account.State;
|
||||
import org.jclouds.cloudstack.domain.Account.Type;
|
||||
import org.jclouds.cloudstack.domain.Capacity;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.json.BaseSetParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
import sun.util.resources.CalendarData;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListCapacityResponseTest extends BaseSetParserTest<Capacity> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/listcapacityresponse.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("capacity")
|
||||
public Set<Capacity> expected() {
|
||||
Capacity a = Capacity.builder().type(Capacity.Type.PRIMARY_STORAGE_ALLOCATED_BYTES)
|
||||
.zoneId(1).zoneName("Dev Zone 1").podId(-1).podName("All")
|
||||
.capacityUsed(34057748480L).capacityTotal(1796712955904L).percentUsed(1.9).build();
|
||||
Capacity b = Capacity.builder().type(Capacity.Type.PRIMARY_STORAGE_ALLOCATED_BYTES)
|
||||
.zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1")
|
||||
.capacityUsed(34057748480L).capacityTotal(1796712955904L).percentUsed(1.9).build();
|
||||
return ImmutableSet.of(a, b);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{ "listcapacityresponse" : { "count":2 ,"capacity" : [ {"type":3,"zoneid":1,"zonename":"Dev Zone 1","podid":-1,"podname":"All","capacityused":34057748480,"capacitytotal":1796712955904,"percentused":"1.9"}, {"type":3,"zoneid":1,"zonename":"Dev Zone 1","podid":1,"podname":"Dev Pod 1","capacityused":34057748480,"capacitytotal":1796712955904,"percentused":"1.9"} ] } }
|
Loading…
Reference in New Issue