Basic functionality in place for listHosts feature

This commit is contained in:
andreisavu 2011-12-06 21:57:38 +02:00
parent cfecb84d75
commit 0f57247e58
10 changed files with 1106 additions and 0 deletions

View File

@ -21,6 +21,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.GlobalHostAsyncClient;
import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient;
import org.jclouds.rest.annotations.Delegate;
@ -62,4 +63,10 @@ public interface CloudStackGlobalAsyncClient extends CloudStackDomainAsyncClient
@Override
GlobalOfferingAsyncClient getOfferingClient();
/**
* Provides asynchronous access to Hosts
*/
@Delegate
GlobalHostAsyncClient getHostClient();
}

View File

@ -23,6 +23,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.GlobalHostClient;
import org.jclouds.cloudstack.features.GlobalOfferingClient;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
@ -66,4 +67,10 @@ public interface CloudStackGlobalClient extends CloudStackDomainClient {
@Override
GlobalOfferingClient getOfferingClient();
/**
* Provides synchronous access to Hosts
*/
@Delegate
GlobalHostClient getHostClient();
}

View File

@ -48,6 +48,8 @@ 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.GlobalHostAsyncClient;
import org.jclouds.cloudstack.features.GlobalHostClient;
import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient;
import org.jclouds.cloudstack.features.GlobalOfferingClient;
import org.jclouds.cloudstack.features.GuestOSAsyncClient;
@ -136,6 +138,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
.put(GlobalAlertClient.class, GlobalAlertAsyncClient.class)//
.put(GlobalCapacityClient.class, GlobalCapacityAsyncClient.class)//
.put(GlobalOfferingClient.class, GlobalOfferingAsyncClient.class)//
.put(GlobalHostClient.class, GlobalHostAsyncClient.class)//
.build();
@Override

View File

@ -0,0 +1,774 @@
/**
* 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.gson.annotations.SerializedName;
import java.util.Date;
/**
* Represents a host issued by Cloudstack
*
* @author Andrei Savu
*/
public class Host implements Comparable<Host> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String allocationState;
private int averageLoad;
private String capabilities;
private long clusterId;
private String clusterName;
private String clusterType;
private String cpuAllocated;
private int cpuNumber;
private int cpuSpeed;
private String cpuUsed;
private float cpuWithOverProvisioning;
private Date created;
private boolean disconnected;
private long diskSizeAllocated;
private long diskSizeTotal;
private String events;
private boolean hasEnoughCapacity;
private String hostTags;
private String hypervisor;
private String ipAddress;
private boolean localStorageActive;
private long jobId;
private AsyncJob.Status jobStatus;
private Date lastPinged;
private long managementServerId;
private long memoryAllocated;
private long memoryTotal;
private long memoryUsed;
private String name;
private long networkKbsRead;
private long networkKbsWrite;
private long osCategoryId;
private long osCategoryName;
private long podId;
private String podName;
private Date removed;
private String state;
private String type;
private String version;
private long zoneId;
private String zoneName;
public Builder id(long id) {
this.id = id;
return this;
}
public Builder allocationState(String allocationState) {
this.allocationState = allocationState;
return this;
}
public Builder averageLoad(int averageLoad) {
this.averageLoad = averageLoad;
return this;
}
public Builder capabilities(String capabilities) {
this.capabilities = capabilities;
return this;
}
public Builder clusterId(long clusterId) {
this.clusterId = clusterId;
return this;
}
public Builder clusterName(String clusterName) {
this.clusterName = clusterName;
return this;
}
public Builder clusterType(String clusterType) {
this.clusterType = clusterType;
return this;
}
public Builder cpuAllocated(String cpuAllocated) {
this.cpuAllocated = cpuAllocated;
return this;
}
public Builder cpuNumber(int cpuNumber) {
this.cpuNumber = cpuNumber;
return this;
}
public Builder cpuSpeed(int cpuSpeed) {
this.cpuSpeed = cpuSpeed;
return this;
}
public Builder cpuUsed(String cpuUsed) {
this.cpuUsed = cpuUsed;
return this;
}
public Builder cpuWithOverProvisioning(float cpuWithOverProvisioning) {
this.cpuWithOverProvisioning = cpuWithOverProvisioning;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Builder disconnected(boolean disconnected) {
this.disconnected = disconnected;
return this;
}
public Builder diskSizeAllocated(long diskSizeAllocated) {
this.diskSizeAllocated = diskSizeAllocated;
return this;
}
public Builder diskSizeTotal(long diskSizeTotal) {
this.diskSizeTotal = diskSizeTotal;
return this;
}
public Builder events(String events) {
this.events = events;
return this;
}
public Builder hasEnoughCapacity(boolean hasEnoughCapacity) {
this.hasEnoughCapacity = hasEnoughCapacity;
return this;
}
public Builder hostTags(String hostTags) {
this.hostTags = hostTags;
return this;
}
public Builder hypervisor(String hypervisor) {
this.hypervisor = hypervisor;
return this;
}
public Builder ipAddress(String ipAddress) {
this.ipAddress = ipAddress;
return this;
}
public Builder localStorageActive(boolean localStorageActive) {
this.localStorageActive = localStorageActive;
return this;
}
public Builder jobId(long jobId) {
this.jobId = jobId;
return this;
}
public Builder jobStatus(AsyncJob.Status jobStatus) {
this.jobStatus = jobStatus;
return this;
}
public Builder lastPinged(Date lastPinged) {
this.lastPinged = lastPinged;
return this;
}
public Builder managementServerId(long managementServerId) {
this.managementServerId = managementServerId;
return this;
}
public Builder memoryAllocated(long memoryAllocated) {
this.memoryAllocated = memoryAllocated;
return this;
}
public Builder memoryTotal(long memoryTotal) {
this.memoryTotal = memoryTotal;
return this;
}
public Builder memoryUsed(long memoryUsed) {
this.memoryUsed = memoryUsed;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder networkKbsRead(long networkKbsRead) {
this.networkKbsRead = networkKbsRead;
return this;
}
public Builder networkKbsWrite(long networkKbsWrite) {
this.networkKbsWrite = networkKbsWrite;
return this;
}
public Builder osCategoryId(long osCategoryId) {
this.osCategoryId = osCategoryId;
return this;
}
public Builder osCategoryName(long osCategoryName) {
this.osCategoryName = osCategoryName;
return this;
}
public Builder podId(long podId) {
this.podId = podId;
return this;
}
public Builder podName(String podName) {
this.podName = podName;
return this;
}
public Builder removed(Date removed) {
this.removed = removed;
return this;
}
public Builder state(String state) {
this.state = state;
return this;
}
public Builder type(String type) {
this.type = type;
return this;
}
public Builder version(String version) {
this.version = version;
return this;
}
public Builder zoneId(long zoneId) {
this.zoneId = zoneId;
return this;
}
public Builder zoneName(String zoneName) {
this.zoneName = zoneName;
return this;
}
public Host build() {
return new Host(id, allocationState, averageLoad, capabilities,
clusterId, clusterName, clusterType, cpuAllocated,
cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning,
created, disconnected, diskSizeAllocated, diskSizeTotal,
events, hasEnoughCapacity, hostTags, hypervisor,
ipAddress, localStorageActive, jobId, jobStatus,
lastPinged, managementServerId, memoryAllocated, memoryTotal,
memoryUsed, name, networkKbsRead, networkKbsWrite,
osCategoryId, osCategoryName, podId, podName, removed,
state, type, version, zoneId, zoneName);
}
}
private long id;
@SerializedName("allocationstate")
private String allocationState;
@SerializedName("averageload")
private int averageLoad;
@SerializedName("capabilities")
private String capabilities;
@SerializedName("clusterid")
private long clusterId;
@SerializedName("clustername")
private String clusterName;
@SerializedName("clustertype")
private String clusterType;
@SerializedName("cpuallocated")
private String cpuAllocated;
@SerializedName("cpunumber")
private int cpuNumber;
@SerializedName("cpuspeed")
private int cpuSpeed;
@SerializedName("cpuused")
private String cpuUsed;
@SerializedName("cpuwithoverprovisioning")
private float cpuWithOverProvisioning;
private Date created;
private boolean disconnected;
@SerializedName("disksizeallocated")
private long diskSizeAllocated;
@SerializedName("disksizetotal")
private long diskSizeTotal;
private String events;
@SerializedName("hasenoughcapacity")
private boolean hasEnoughCapacity;
@SerializedName("hosttags")
private String hostTags;
private String hypervisor;
@SerializedName("ipaddress")
private String ipAddress;
@SerializedName("islocalstorageactive")
private boolean localStorageActive;
@SerializedName("jobid")
private long jobId;
@SerializedName("jobstatus")
private AsyncJob.Status jobStatus;
@SerializedName("lastpinged")
private Date lastPinged;
@SerializedName("managementserverid")
private long managementServerId;
@SerializedName("memoryallocated")
private long memoryAllocated;
@SerializedName("memorytotal")
private long memoryTotal;
@SerializedName("memoryused")
private long memoryUsed;
private String name;
@SerializedName("networkkbsread")
private long networkKbsRead;
@SerializedName("networkkbswrite")
private long networkKbsWrite;
@SerializedName("oscategoryid")
private long osCategoryId;
@SerializedName("oscategoryname")
private long osCategoryName;
@SerializedName("podid")
private long podId;
@SerializedName("podname")
private String podName;
private Date removed;
private String state;
private String type;
private String version;
@SerializedName("zoneid")
private long zoneId;
@SerializedName("zonename")
private String zoneName;
/* exists for the deserializer, only */
Host() {
}
public Host(long id, String allocationState, int averageLoad, String capabilities,
long clusterId, String clusterName, String clusterType, String cpuAllocated,
int cpuNumber, int cpuSpeed, String cpuUsed, float cpuWithOverProvisioning,
Date created, boolean disconnected, long diskSizeAllocated, long diskSizeTotal,
String events, boolean hasEnoughCapacity, String hostTags, String hypervisor,
String ipAddress, boolean localStorageActive, long jobId, AsyncJob.Status jobStatus,
Date lastPinged, long managementServerId, long memoryAllocated, long memoryTotal,
long memoryUsed, String name, long networkKbsRead, long networkKbsWrite,
long osCategoryId, long osCategoryName, long podId, String podName, Date removed,
String state, String type, String version, long zoneId, String zoneName) {
this.id = id;
this.allocationState = allocationState;
this.averageLoad = averageLoad;
this.capabilities = capabilities;
this.clusterId = clusterId;
this.clusterName = clusterName;
this.clusterType = clusterType;
this.cpuAllocated = cpuAllocated;
this.cpuNumber = cpuNumber;
this.cpuSpeed = cpuSpeed;
this.cpuUsed = cpuUsed;
this.cpuWithOverProvisioning = cpuWithOverProvisioning;
this.created = created;
this.disconnected = disconnected;
this.diskSizeAllocated = diskSizeAllocated;
this.diskSizeTotal = diskSizeTotal;
this.events = events;
this.hasEnoughCapacity = hasEnoughCapacity;
this.hostTags = hostTags;
this.hypervisor = hypervisor;
this.ipAddress = ipAddress;
this.localStorageActive = localStorageActive;
this.jobId = jobId;
this.jobStatus = jobStatus;
this.lastPinged = lastPinged;
this.managementServerId = managementServerId;
this.memoryAllocated = memoryAllocated;
this.memoryTotal = memoryTotal;
this.memoryUsed = memoryUsed;
this.name = name;
this.networkKbsRead = networkKbsRead;
this.networkKbsWrite = networkKbsWrite;
this.osCategoryId = osCategoryId;
this.osCategoryName = osCategoryName;
this.podId = podId;
this.podName = podName;
this.removed = removed;
this.state = state;
this.type = type;
this.version = version;
this.zoneId = zoneId;
this.zoneName = zoneName;
}
public long getId() {
return id;
}
public String getAllocationState() {
return allocationState;
}
public int getAverageLoad() {
return averageLoad;
}
public String getCapabilities() {
return capabilities;
}
public long getClusterId() {
return clusterId;
}
public String getClusterName() {
return clusterName;
}
public String getClusterType() {
return clusterType;
}
public String getCpuAllocated() {
return cpuAllocated;
}
public int getCpuNumber() {
return cpuNumber;
}
public int getCpuSpeed() {
return cpuSpeed;
}
public String getCpuUsed() {
return cpuUsed;
}
public float getCpuWithOverProvisioning() {
return cpuWithOverProvisioning;
}
public Date getCreated() {
return created;
}
public boolean isDisconnected() {
return disconnected;
}
public long getDiskSizeAllocated() {
return diskSizeAllocated;
}
public long getDiskSizeTotal() {
return diskSizeTotal;
}
public String getEvents() {
return events;
}
public boolean isHasEnoughCapacity() {
return hasEnoughCapacity;
}
public String getHostTags() {
return hostTags;
}
public String getHypervisor() {
return hypervisor;
}
public String getIpAddress() {
return ipAddress;
}
public boolean isLocalStorageActive() {
return localStorageActive;
}
public long getJobId() {
return jobId;
}
public AsyncJob.Status getJobStatus() {
return jobStatus;
}
public Date getLastPinged() {
return lastPinged;
}
public long getManagementServerId() {
return managementServerId;
}
public long getMemoryAllocated() {
return memoryAllocated;
}
public long getMemoryTotal() {
return memoryTotal;
}
public long getMemoryUsed() {
return memoryUsed;
}
public String getName() {
return name;
}
public long getNetworkKbsRead() {
return networkKbsRead;
}
public long getNetworkKbsWrite() {
return networkKbsWrite;
}
public long getOsCategoryId() {
return osCategoryId;
}
public long getOsCategoryName() {
return osCategoryName;
}
public long getPodId() {
return podId;
}
public String getPodName() {
return podName;
}
public Date getRemoved() {
return removed;
}
public String getState() {
return state;
}
public String getType() {
return type;
}
public String getVersion() {
return version;
}
public long getZoneId() {
return zoneId;
}
public String getZoneName() {
return zoneName;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (allocationState != null ? allocationState.hashCode() : 0);
result = 31 * result + averageLoad;
result = 31 * result + (capabilities != null ? capabilities.hashCode() : 0);
result = 31 * result + (int) (clusterId ^ (clusterId >>> 32));
result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0);
result = 31 * result + (clusterType != null ? clusterType.hashCode() : 0);
result = 31 * result + (cpuAllocated != null ? cpuAllocated.hashCode() : 0);
result = 31 * result + cpuNumber;
result = 31 * result + cpuSpeed;
result = 31 * result + (cpuUsed != null ? cpuUsed.hashCode() : 0);
result = 31 * result + (int) cpuWithOverProvisioning;
result = 31 * result + (created != null ? created.hashCode() : 0);
result = 31 * result + (disconnected ? 1 : 0);
result = 31 * result + (int) (diskSizeAllocated ^ (diskSizeAllocated >>> 32));
result = 31 * result + (int) (diskSizeTotal ^ (diskSizeTotal >>> 32));
result = 31 * result + (events != null ? events.hashCode() : 0);
result = 31 * result + (hasEnoughCapacity ? 1 : 0);
result = 31 * result + (hostTags != null ? hostTags.hashCode() : 0);
result = 31 * result + (hypervisor != null ? hypervisor.hashCode() : 0);
result = 31 * result + (ipAddress != null ? ipAddress.hashCode() : 0);
result = 31 * result + (localStorageActive ? 1 : 0);
result = 31 * result + (int) (jobId ^ (jobId >>> 32));
result = 31 * result + (jobStatus != null ? jobStatus.hashCode() : 0);
result = 31 * result + (lastPinged != null ? lastPinged.hashCode() : 0);
result = 31 * result + (int) (managementServerId ^ (managementServerId >>> 32));
result = 31 * result + (int) (memoryAllocated ^ (memoryAllocated >>> 32));
result = 31 * result + (int) (memoryTotal ^ (memoryTotal >>> 32));
result = 31 * result + (int) (memoryUsed ^ (memoryUsed >>> 32));
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (int) (networkKbsRead ^ (networkKbsRead >>> 32));
result = 31 * result + (int) (networkKbsWrite ^ (networkKbsWrite >>> 32));
result = 31 * result + (int) (osCategoryId ^ (osCategoryId >>> 32));
result = 31 * result + (int) (osCategoryName ^ (osCategoryName >>> 32));
result = 31 * result + (int) (podId ^ (podId >>> 32));
result = 31 * result + (podName != null ? podName.hashCode() : 0);
result = 31 * result + (removed != null ? removed.hashCode() : 0);
result = 31 * result + (state != null ? state.hashCode() : 0);
result = 31 * result + (type != null ? type.hashCode() : 0);
result = 31 * result + (version != null ? version.hashCode() : 0);
result = 31 * result + (int) (zoneId ^ (zoneId >>> 32));
result = 31 * result + (zoneName != null ? zoneName.hashCode() : 0);
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Host host = (Host) o;
if (averageLoad != host.averageLoad) return false;
if (clusterId != host.clusterId) return false;
if (cpuAllocated != host.cpuAllocated) return false;
if (cpuNumber != host.cpuNumber) return false;
if (cpuSpeed != host.cpuSpeed) return false;
if (cpuUsed != host.cpuUsed) return false;
if (cpuWithOverProvisioning != host.cpuWithOverProvisioning) return false;
if (disconnected != host.disconnected) return false;
if (diskSizeAllocated != host.diskSizeAllocated) return false;
if (diskSizeTotal != host.diskSizeTotal) return false;
if (hasEnoughCapacity != host.hasEnoughCapacity) return false;
if (id != host.id) return false;
if (localStorageActive != host.localStorageActive) return false;
if (jobId != host.jobId) return false;
if (managementServerId != host.managementServerId) return false;
if (memoryAllocated != host.memoryAllocated) return false;
if (memoryTotal != host.memoryTotal) return false;
if (memoryUsed != host.memoryUsed) return false;
if (networkKbsRead != host.networkKbsRead) return false;
if (networkKbsWrite != host.networkKbsWrite) return false;
if (osCategoryId != host.osCategoryId) return false;
if (osCategoryName != host.osCategoryName) return false;
if (podId != host.podId) return false;
if (zoneId != host.zoneId) return false;
if (allocationState != null ? !allocationState.equals(host.allocationState) : host.allocationState != null)
return false;
if (capabilities != null ? !capabilities.equals(host.capabilities) : host.capabilities != null)
return false;
if (clusterName != null ? !clusterName.equals(host.clusterName) : host.clusterName != null)
return false;
if (clusterType != null ? !clusterType.equals(host.clusterType) : host.clusterType != null)
return false;
if (created != null ? !created.equals(host.created) : host.created != null)
return false;
if (events != null ? !events.equals(host.events) : host.events != null)
return false;
if (hostTags != null ? !hostTags.equals(host.hostTags) : host.hostTags != null)
return false;
if (hypervisor != null ? !hypervisor.equals(host.hypervisor) : host.hypervisor != null)
return false;
if (ipAddress != null ? !ipAddress.equals(host.ipAddress) : host.ipAddress != null)
return false;
if (jobStatus != host.jobStatus) return false;
if (lastPinged != null ? !lastPinged.equals(host.lastPinged) : host.lastPinged != null)
return false;
if (name != null ? !name.equals(host.name) : host.name != null)
return false;
if (podName != null ? !podName.equals(host.podName) : host.podName != null)
return false;
if (removed != null ? !removed.equals(host.removed) : host.removed != null)
return false;
if (state != null ? !state.equals(host.state) : host.state != null)
return false;
if (type != null ? !type.equals(host.type) : host.type != null)
return false;
if (version != null ? !version.equals(host.version) : host.version != null)
return false;
if (zoneName != null ? !zoneName.equals(host.zoneName) : host.zoneName != null)
return false;
return true;
}
@Override
public String toString() {
return "Host{" +
"id=" + id +
", allocationState='" + allocationState + '\'' +
", averageLoad=" + averageLoad +
", capabilities='" + capabilities + '\'' +
", clusterId=" + clusterId +
", clusterName='" + clusterName + '\'' +
", clusterType='" + clusterType + '\'' +
", cpuAllocated=" + cpuAllocated +
", cpuNumber=" + cpuNumber +
", cpuSpeed=" + cpuSpeed +
", cpuUsed=" + cpuUsed +
", cpuWithOverProvisioning=" + cpuWithOverProvisioning +
", created=" + created +
", disconnected=" + disconnected +
", diskSizeAllocated=" + diskSizeAllocated +
", diskSizeTotal=" + diskSizeTotal +
", events='" + events + '\'' +
", hasEnoughCapacity=" + hasEnoughCapacity +
", hostTags='" + hostTags + '\'' +
", hypervisor='" + hypervisor + '\'' +
", ipAddress='" + ipAddress + '\'' +
", localStorageActive=" + localStorageActive +
", jobId=" + jobId +
", jobStatus=" + jobStatus +
", lastPinged=" + lastPinged +
", managementServerId=" + managementServerId +
", memoryAllocated=" + memoryAllocated +
", memoryTotal=" + memoryTotal +
", memoryUsed=" + memoryUsed +
", name='" + name + '\'' +
", networkKbsRead=" + networkKbsRead +
", networkKbsWrite=" + networkKbsWrite +
", osCategoryId=" + osCategoryId +
", osCategoryName=" + osCategoryName +
", podId=" + podId +
", podName='" + podName + '\'' +
", removed=" + removed +
", state='" + state + '\'' +
", type='" + type + '\'' +
", version='" + version + '\'' +
", zoneId=" + zoneId +
", zoneName='" + zoneName + '\'' +
'}';
}
@Override
public int compareTo(Host other) {
return Long.valueOf(this.getId()).compareTo(other.getId());
}
}

View File

@ -0,0 +1,57 @@
/**
* 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.Host;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.ListHostsOptions;
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 via their REST API.
* <p/>
*
* @see GlobalHostClient
* @see <a href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html" />
* @author Andrei Savu
*/
@RequestFilters(QuerySigner.class)
@QueryParams(keys = "response", values = "json")
public interface GlobalHostAsyncClient {
/**
* @see GlobalHostClient#listHosts
*/
@GET
@QueryParams(keys = "command", values = "listHosts")
@SelectJson("host")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Host>> listHosts(ListHostsOptions... options);
}

View File

@ -0,0 +1,49 @@
/**
* 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.Host;
import org.jclouds.cloudstack.options.ListHostsOptions;
import org.jclouds.concurrent.Timeout;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to CloudStack host features.
* <p/>
*
* @see org.jclouds.cloudstack.features.GlobalOfferingAsyncClient
* @see <a href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html" />
* @author Andrei Savu
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface GlobalHostClient {
/**
* Lists hosts
*
* @param options
* if present, how to constrain the list.
* @return hosts matching query, or empty set, if no service
* offerings are found
*/
Set<Host> listHosts(ListHostsOptions... options);
}

View File

@ -0,0 +1,88 @@
/**
* 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.NetworkType;
import org.jclouds.cloudstack.domain.TrafficType;
/**
* Options used to control what hosts information is returned
*
* @see <a
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/global_admin/listHosts.html"
* />
* @author Andrei Savu
*/
public class ListHostsOptions extends AccountInDomainOptions {
public static final ListHostsOptions NONE = new ListHostsOptions();
/**
* @param isDefault
* true if network is default, false otherwise
*/
public ListHostsOptions isDefault(boolean isDefault) {
this.queryParameters.replaceValues("isdefault", ImmutableSet.of(isDefault + ""));
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ListHostsOptions accountInDomain(String account, long domain) {
return ListHostsOptions.class.cast(super.accountInDomain(account, domain));
}
/**
* {@inheritDoc}
*/
@Override
public ListHostsOptions domainId(long domainId) {
return ListHostsOptions.class.cast(super.domainId(domainId));
}
public static class Builder {
/**
* @see org.jclouds.cloudstack.options.ListHostsOptions#isDefault
*/
public static ListHostsOptions isDefault(boolean isDefault) {
ListHostsOptions options = new ListHostsOptions();
return options.isDefault(isDefault);
}
/**
* @see org.jclouds.cloudstack.options.ListHostsOptions#accountInDomain
*/
public static ListHostsOptions accountInDomain(String account, long domain) {
ListHostsOptions options = new ListHostsOptions();
return options.accountInDomain(account, domain);
}
/**
* @see org.jclouds.cloudstack.options.ListHostsOptions#domainId
*/
public static ListHostsOptions domainId(long domainId) {
ListHostsOptions options = new ListHostsOptions();
return options.domainId(domainId);
}
}
}

View File

@ -0,0 +1,55 @@
/**
* 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.Host;
import org.jclouds.logging.Logger;
import org.testng.annotations.Test;
import java.util.Set;
import static org.testng.Assert.assertTrue;
/**
* Tests behavior of {@code GlobalHostClient}
*
* @author Andrei Savu
*/
@Test(groups = "live", singleThreaded = true, testName = "GlobalHostClientLiveTest")
public class GlobalHostClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testListHosts() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
Set<Host> hosts = globalAdminClient.getHostClient().listHosts();
assert hosts.size() > 0 : hosts;
for(Host host : hosts) {
Logger.CONSOLE.info(host.toString());
checkHost(host);
}
}
private void checkHost(Host host) {
// assert host.getCpuNumber() > 0;
// assert host.getAverageLoad() >= 0;
}
}

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.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.cloudstack.config.CloudStackParserModule;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.json.BaseSetParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import java.util.Set;
/**
*
* @author Andrei Savu
*/
@Test(groups = "unit")
public class ListHostsResponseTest extends BaseSetParserTest<Host> {
@Override
protected Injector injector() {
return Guice.createInjector(new CloudStackParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
}
@Override
public String resource() {
return "/listhostsresponse.json";
}
@Override
@SelectJson("host")
public Set<Host> expected() {
return ImmutableSet.of();
}
}

View File

@ -0,0 +1 @@
{ "listhostsresponse" : { "count":4 ,"host" : [ {"id":1,"name":"cs2-xevsrv.alucloud.local","state":"Up","type":"Routing","ipaddress":"10.26.26.107","zoneid":1,"zonename":"Dev Zone 1","podid":1,"podname":"Dev Pod 1","version":"2.2.12.20110928142833","hypervisor":"XenServer","cpunumber":24,"cpuspeed":2266,"cpuallocated":"2.76%","cpuused":"0.1%","cpuwithoverprovisioning":"54384.0","networkkbsread":4443,"networkkbswrite":15048,"memorytotal":100549733760,"memoryallocated":3623878656,"memoryused":3623878656,"capabilities":"xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64","lastpinged":"1970-01-16T00:54:43+0200","managementserverid":223098941760041,"clusterid":1,"clustername":"Xen Clust 1","clustertype":"CloudManaged","islocalstorageactive":false,"created":"2011-11-26T23:28:36+0200","events":"PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping","hosttags":"","hasEnoughCapacity":false,"allocationstate":"Enabled"}, {"id":2,"name":"nfs://10.26.26.165/mnt/nfs/cs_sec","state":"Alert","disconnected":"2011-11-26T23:33:38+0200","type":"SecondaryStorage","ipaddress":"nfs","zoneid":1,"zonename":"Dev Zone 1","version":"2.2.12.20110928142833","hypervisor":"None","lastpinged":"1970-01-16T00:42:30+0200","islocalstorageactive":false,"created":"2011-11-26T23:33:38+0200","events":"ManagementServerDown; AgentDisconnected; Remove; MaintenanceRequested; AgentConnected; Ping","hasEnoughCapacity":false,"allocationstate":"Enabled"}, {"id":3,"name":"s-1-VM","state":"Up","type":"SecondaryStorageVM","ipaddress":"10.26.26.81","zoneid":1,"zonename":"Dev Zone 1","podid":1,"podname":"Dev Pod 1","version":"2.2.12.20110928142833","lastpinged":"1970-01-16T00:54:43+0200","managementserverid":223098941760041,"islocalstorageactive":false,"created":"2011-11-26T23:35:51+0200","events":"PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping","hasEnoughCapacity":false,"allocationstate":"Enabled"}, {"id":4,"name":"v-2-VM","state":"Up","type":"ConsoleProxy","ipaddress":"10.26.26.96","zoneid":1,"zonename":"Dev Zone 1","podid":1,"podname":"Dev Pod 1","version":"2.2.12.20110928142833","lastpinged":"1970-01-16T00:54:43+0200","managementserverid":223098941760041,"islocalstorageactive":false,"created":"2011-11-26T23:36:46+0200","events":"PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping","hasEnoughCapacity":false,"allocationstate":"Enabled"} ] } }