Merge pull request #313 from richardcloudsoft/cs-hosts

CloudStack 'hosts' API
This commit is contained in:
Adrian Cole 2012-01-12 09:03:23 -08:00
commit ce4a5d832e
24 changed files with 1656 additions and 77 deletions

View File

@ -707,6 +707,59 @@ public class Host implements Comparable<Host> {
return zoneName; return zoneName;
} }
@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 (cpuNumber != host.cpuNumber) return false;
if (cpuSpeed != host.cpuSpeed) return false;
if (Float.compare(host.cpuWithOverProvisioning, cpuWithOverProvisioning) != 0) 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 (jobId != host.jobId) return false;
if (localStorageActive != host.localStorageActive) 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 != host.allocationState) 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 != host.clusterType) return false;
if (cpuAllocated != null ? !cpuAllocated.equals(host.cpuAllocated) : host.cpuAllocated != null) return false;
if (cpuUsed != null ? !cpuUsed.equals(host.cpuUsed) : host.cpuUsed != null) return false;
if (created != null ? !created.equals(host.created) : host.created != null) return false;
if (disconnected != null ? !disconnected.equals(host.disconnected) : host.disconnected != 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 != host.state) return false;
if (type != host.type) 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 @Override
public int hashCode() { public int hashCode() {
int result = (int) (id ^ (id >>> 32)); int result = (int) (id ^ (id >>> 32));
@ -720,7 +773,7 @@ public class Host implements Comparable<Host> {
result = 31 * result + cpuNumber; result = 31 * result + cpuNumber;
result = 31 * result + cpuSpeed; result = 31 * result + cpuSpeed;
result = 31 * result + (cpuUsed != null ? cpuUsed.hashCode() : 0); result = 31 * result + (cpuUsed != null ? cpuUsed.hashCode() : 0);
result = 31 * result + (int) cpuWithOverProvisioning; result = 31 * result + (cpuWithOverProvisioning != +0.0f ? Float.floatToIntBits(cpuWithOverProvisioning) : 0);
result = 31 * result + (created != null ? created.hashCode() : 0); result = 31 * result + (created != null ? created.hashCode() : 0);
result = 31 * result + (disconnected != null ? disconnected.hashCode() : 0); result = 31 * result + (disconnected != null ? disconnected.hashCode() : 0);
result = 31 * result + (int) (diskSizeAllocated ^ (diskSizeAllocated >>> 32)); result = 31 * result + (int) (diskSizeAllocated ^ (diskSizeAllocated >>> 32));
@ -754,90 +807,20 @@ public class Host implements Comparable<Host> {
return result; 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 @Override
public String toString() { public String toString() {
return "Host{" + return "Host{" +
"id=" + id + "id=" + id +
", allocationState='" + allocationState + '\'' + ", allocationState=" + allocationState +
", averageLoad=" + averageLoad + ", averageLoad=" + averageLoad +
", capabilities='" + capabilities + '\'' + ", capabilities='" + capabilities + '\'' +
", clusterId=" + clusterId + ", clusterId=" + clusterId +
", clusterName='" + clusterName + '\'' + ", clusterName='" + clusterName + '\'' +
", clusterType='" + clusterType + '\'' + ", clusterType=" + clusterType +
", cpuAllocated=" + cpuAllocated + ", cpuAllocated='" + cpuAllocated + '\'' +
", cpuNumber=" + cpuNumber + ", cpuNumber=" + cpuNumber +
", cpuSpeed=" + cpuSpeed + ", cpuSpeed=" + cpuSpeed +
", cpuUsed=" + cpuUsed + ", cpuUsed='" + cpuUsed + '\'' +
", cpuWithOverProvisioning=" + cpuWithOverProvisioning + ", cpuWithOverProvisioning=" + cpuWithOverProvisioning +
", created=" + created + ", created=" + created +
", disconnected=" + disconnected + ", disconnected=" + disconnected +
@ -864,8 +847,8 @@ public class Host implements Comparable<Host> {
", podId=" + podId + ", podId=" + podId +
", podName='" + podName + '\'' + ", podName='" + podName + '\'' +
", removed=" + removed + ", removed=" + removed +
", state='" + state + '\'' + ", state=" + state +
", type='" + type + '\'' + ", type=" + type +
", version='" + version + '\'' + ", version='" + version + '\'' +
", zoneId=" + zoneId + ", zoneId=" + zoneId +
", zoneName='" + zoneName + '\'' + ", zoneName='" + zoneName + '\'' +

View File

@ -22,8 +22,14 @@ import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.cloudstack.domain.Cluster; import org.jclouds.cloudstack.domain.Cluster;
import org.jclouds.cloudstack.domain.Host; import org.jclouds.cloudstack.domain.Host;
import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.AddClusterOptions;
import org.jclouds.cloudstack.options.AddHostOptions;
import org.jclouds.cloudstack.options.AddSecondaryStorageOptions;
import org.jclouds.cloudstack.options.DeleteHostOptions;
import org.jclouds.cloudstack.options.ListClustersOptions; import org.jclouds.cloudstack.options.ListClustersOptions;
import org.jclouds.cloudstack.options.ListHostsOptions; import org.jclouds.cloudstack.options.ListHostsOptions;
import org.jclouds.cloudstack.options.UpdateClusterOptions;
import org.jclouds.cloudstack.options.UpdateHostOptions;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
@ -32,6 +38,7 @@ import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.Set; import java.util.Set;
@ -57,6 +64,108 @@ public interface GlobalHostAsyncClient {
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Host>> listHosts(ListHostsOptions... options); ListenableFuture<Set<Host>> listHosts(ListHostsOptions... options);
/**
* Adds a new host.
*
* @param zoneId the Zone ID for the host
* @param url the host URL
* @param hypervisor hypervisor type of the host
* @param username the username for the host
* @param password the password for the host
* @param options optional arguments
* @return the new host.
*/
@GET
@QueryParams(keys = "command", values = "addHost")
@SelectJson("host")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Host> addHost(@QueryParam("zoneid") long zoneId, @QueryParam("url") String url, @QueryParam("hypervisor") String hypervisor, @QueryParam("username") String username, @QueryParam("password") String password, AddHostOptions... options);
/**
* Updates a host.
*
* @param hostId the ID of the host to update
* @param options optional arguments
* @return the modified host.
*/
@GET
@QueryParams(keys = "command", values = "updateHost")
@SelectJson("host")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Host> updateHost(@QueryParam("id") long hostId, UpdateHostOptions... options);
/**
* Update password of a host on management server.
*
* @param hostId the host ID
* @param username the username for the host
* @param password the password for the host
*/
@GET
@QueryParams(keys = "command", values = "updateHostPassword")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> updateHostPassword(@QueryParam("hostid") long hostId, @QueryParam("username") String username, @QueryParam("password") String password);
/**
* Deletes a host.
*
* @param hostId the host ID
* @param options optional arguments
*/
@GET
@QueryParams(keys = "command", values = "deleteHost")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> deleteHost(@QueryParam("id") long hostId, DeleteHostOptions... options);
/**
* Prepares a host for maintenance.
*
* @param hostId the host ID
* @return a job reference number for tracking this asynchronous job.
*/
@GET
@QueryParams(keys = "command", values = "prepareHostForMaintenance")
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> prepareHostForMaintenance(@QueryParam("id") long hostId);
/**
* Cancels host maintenance.
*
* @param hostId the host ID
* @return a job reference number for tracking this asynchronous job.
*/
@GET
@QueryParams(keys = "command", values = "cancelHostMaintenance")
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> cancelHostMaintenance(@QueryParam("id") long hostId);
/**
* Reconnects a host.
*
* @param hostId
* @return a job reference number for tracking this asynchronous job.
*/
@GET
@QueryParams(keys = "command", values = "reconnectHost")
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> reconnectHost(@QueryParam("id") long hostId);
/**
* Adds secondary storage.
*
* @param url the URL for the secondary storage
* @param options optional arguments
* @return the host of the storage.
*/
@GET
@QueryParams(keys = "command", values = "addSecondaryStorage")
@SelectJson("host")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Host> addSecondaryStorage(@QueryParam("url") String url, AddSecondaryStorageOptions... options);
/** /**
* @see GlobalHostClient#listClusters * @see GlobalHostClient#listClusters
*/ */
@ -66,4 +175,57 @@ public interface GlobalHostAsyncClient {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Cluster>> listClusters(ListClustersOptions... options); ListenableFuture<Set<Cluster>> listClusters(ListClustersOptions... options);
/**
* Adds a new cluster.
*
* @param zoneId the Zone ID for the cluster
* @param clusterName the cluster name
* @param clusterType type of the cluster
* @param hypervisor hypervisor type of the cluster
* @param options optional arguments
* @return the new cluster.
*/
@GET
@QueryParams(keys = "command", values = "addCluster")
@SelectJson("cluster")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Cluster> addCluster(@QueryParam("zoneid") long zoneId, @QueryParam("clustername") String clusterName, @QueryParam("clustertype") Host.ClusterType clusterType, @QueryParam("hypervisor") String hypervisor, AddClusterOptions... options);
/**
* Updates an existing cluster.
*
* @param clusterId the ID of the cluster
* @param options optional arguments
* @return the modified cluster
*/
@GET
@QueryParams(keys = "command", values = "updateCluster")
@SelectJson("cluster")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Cluster> updateCluster(@QueryParam("id") long clusterId, UpdateClusterOptions... options);
/**
* Update password of a cluster on management server.
*
* @param clusterId the cluster ID
* @param username the username for the cluster
* @param password the password for the cluster
*/
@GET
@QueryParams(keys = "command", values = "updateHostPassword")
@SelectJson("cluster")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> updateClusterPassword(@QueryParam("clusterid") long clusterId, @QueryParam("username") String username, @QueryParam("password") String password);
/**
* Deletes a cluster.
*
* @param clusterId the cluster ID
*/
@GET
@QueryParams(keys = "command", values = "deleteCluster")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> deleteCluster(@QueryParam("id") long clusterId);
} }

View File

@ -20,8 +20,14 @@ package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.domain.Cluster; import org.jclouds.cloudstack.domain.Cluster;
import org.jclouds.cloudstack.domain.Host; import org.jclouds.cloudstack.domain.Host;
import org.jclouds.cloudstack.options.AddClusterOptions;
import org.jclouds.cloudstack.options.AddHostOptions;
import org.jclouds.cloudstack.options.AddSecondaryStorageOptions;
import org.jclouds.cloudstack.options.DeleteHostOptions;
import org.jclouds.cloudstack.options.ListClustersOptions; import org.jclouds.cloudstack.options.ListClustersOptions;
import org.jclouds.cloudstack.options.ListHostsOptions; import org.jclouds.cloudstack.options.ListHostsOptions;
import org.jclouds.cloudstack.options.UpdateClusterOptions;
import org.jclouds.cloudstack.options.UpdateHostOptions;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import java.util.Set; import java.util.Set;
@ -48,6 +54,78 @@ public interface GlobalHostClient {
*/ */
Set<Host> listHosts(ListHostsOptions... options); Set<Host> listHosts(ListHostsOptions... options);
/**
* Adds a new host.
*
* @param zoneId the Zone ID for the host
* @param url the host URL
* @param hypervisor hypervisor type of the host
* @param username the username for the host
* @param password the password for the host
* @param options optional arguments
* @return the new host.
*/
Host addHost(long zoneId, String url, String hypervisor, String username, String password, AddHostOptions... options);
/**
* Updates a host.
*
* @param hostId the ID of the host to update
* @param options optional arguments
* @return the modified host.
*/
Host updateHost(long hostId, UpdateHostOptions... options);
/**
* Update password of a host on management server.
*
* @param hostId the host ID
* @param username the username for the host
* @param password the password for the host
*/
void updateHostPassword(long hostId, String username, String password);
/**
* Deletes a host.
*
* @param hostId the host ID
* @param options optional arguments
*/
void deleteHost(long hostId, DeleteHostOptions... options);
/**
* Prepares a host for maintenance.
*
* @param hostId the host ID
* @return a job reference number for tracking this asynchronous job.
*/
Long prepareHostForMaintenance(long hostId);
/**
* Cancels host maintenance.
*
* @param hostId the host ID
* @return a job reference number for tracking this asynchronous job.
*/
Long cancelHostMaintenance(long hostId);
/**
* Reconnects a host.
*
* @param hostId
* @return a job reference number for tracking this asynchronous job.
*/
Long reconnectHost(long hostId);
/**
* Adds secondary storage.
*
* @param url the URL for the secondary storage
* @param options optional arguments
* @return the host of the storage.
*/
Host addSecondaryStorage(String url, AddSecondaryStorageOptions... options);
/** /**
* Lists clusters * Lists clusters
* *
@ -55,4 +133,42 @@ public interface GlobalHostClient {
* @return clusters matching query, or empty set if no clusters match * @return clusters matching query, or empty set if no clusters match
*/ */
Set<Cluster> listClusters(ListClustersOptions... options); Set<Cluster> listClusters(ListClustersOptions... options);
/**
* Adds a new cluster.
*
* @param zoneId the Zone ID for the cluster
* @param clusterName the cluster name
* @param clusterType type of the cluster
* @param hypervisor hypervisor type of the cluster
* @param options optional arguments
* @return the new cluster.
*/
Cluster addCluster(long zoneId, String clusterName, Host.ClusterType clusterType, String hypervisor, AddClusterOptions... options);
/**
* Updates an existing cluster.
*
* @param clusterId the ID of the cluster
* @param options optional arguments
* @return the modified cluster
*/
Cluster updateCluster(long clusterId, UpdateClusterOptions... options);
/**
* Update password of a cluster on management server.
*
* @param hostId the cluster ID
* @param username the username for the cluster
* @param password the password for the cluster
*/
void updateClusterPassword(long clusterId, String username, String password);
/**
* Deletes a cluster.
*
* @param clusterId the cluster ID
*/
void deleteCluster(long clusterId);
} }

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.ImmutableSet;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.functions.JoinOnComma;
import org.jclouds.http.options.BaseHttpRequestOptions;
import java.util.Set;
/**
* Options to the GlobalHostClient.addHost() API call
*
* @author Richard Downer
*/
public class AddClusterOptions extends BaseHttpRequestOptions {
public static final AddClusterOptions NONE = new AddClusterOptions();
/**
* @param allocationState Allocation state of this Host for allocation of new resources
*/
public AddClusterOptions allocationState(Host.AllocationState allocationState) {
this.queryParameters.replaceValues("allocationstate", ImmutableSet.of(allocationState.toString()));
return this;
}
/**
* @param password the password for the host
*/
public AddClusterOptions password(String password) {
this.queryParameters.replaceValues("password", ImmutableSet.of(password));
return this;
}
/**
* @param podId the Pod ID for the host
*/
public AddClusterOptions podId(long podId) {
this.queryParameters.replaceValues("podid", ImmutableSet.of(podId + ""));
return this;
}
/**
* @param url the URL
*/
public AddClusterOptions url(String url) {
this.queryParameters.replaceValues("url", ImmutableSet.of(url));
return this;
}
/**
* @param username the username for the cluster
*/
public AddClusterOptions username(String username) {
this.queryParameters.replaceValues("username", ImmutableSet.of(username));
return this;
}
public static class Builder {
/**
* @param allocationState Allocation state of this Host for allocation of new resources
*/
public static AddClusterOptions allocationState(Host.AllocationState allocationState) {
return new AddClusterOptions().allocationState(allocationState);
}
/**
* @param password the password for the host
*/
public static AddClusterOptions password(String password) {
return new AddClusterOptions().password(password);
}
/**
* @param podId the Pod ID for the host
*/
public static AddClusterOptions podId(long podId) {
return new AddClusterOptions().podId(podId);
}
/**
* @param url the URL
*/
public static AddClusterOptions url(String url) {
return new AddClusterOptions().url(url);
}
/**
* @param username the username for the cluster
*/
public static AddClusterOptions username(String username) {
return new AddClusterOptions().username(username);
}
}
}

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.base.Joiner;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.http.options.BaseHttpRequestOptions;
import java.util.Set;
/**
* Options to the GlobalHostClient.addHost() API call
*
* @author Richard Downer
*/
public class AddHostOptions extends BaseHttpRequestOptions {
public static final AddHostOptions NONE = new AddHostOptions();
/**
* @param allocationState Allocation state of this Host for allocation of new resources
*/
public AddHostOptions allocationState(Host.AllocationState allocationState) {
this.queryParameters.replaceValues("allocationstate", ImmutableSet.of(allocationState.toString()));
return this;
}
/**
* @param clusterId the cluster ID for the host
*/
public AddHostOptions clusterId(long clusterId) {
this.queryParameters.replaceValues("clusterid", ImmutableSet.of(clusterId + ""));
return this;
}
/**
* @param clusterName the cluster name for the host
*/
public AddHostOptions clusterName(String clusterName) {
this.queryParameters.replaceValues("clustername", ImmutableSet.of(clusterName));
return this;
}
/**
* @param hostTags list of tags to be added to the host
*/
public AddHostOptions hostTags(Set<String> hostTags) {
this.queryParameters.replaceValues("hosttags", ImmutableSet.of(Joiner.on(',').join(hostTags)));
return this;
}
/**
* @param podId the Pod ID for the host
*/
public AddHostOptions podId(long podId) {
this.queryParameters.replaceValues("podid", ImmutableSet.of(podId + ""));
return this;
}
public static class Builder {
/**
* @param allocationState Allocation state of this Host for allocation of new resources
*/
public static AddHostOptions allocationState(Host.AllocationState allocationState) {
return new AddHostOptions().allocationState(allocationState);
}
/**
* @param clusterId the cluster ID for the host
*/
public static AddHostOptions clusterId(long clusterId) {
return new AddHostOptions().clusterId(clusterId);
}
/**
* @param clusterName the cluster name for the host
*/
public static AddHostOptions clusterName(String clusterName) {
return new AddHostOptions().clusterName(clusterName);
}
/**
* @param hostTags list of tags to be added to the host
*/
public static AddHostOptions hostTags(Set<String> hostTags) {
return new AddHostOptions().hostTags(hostTags);
}
/**
* @param podId the Pod ID for the host
*/
public static AddHostOptions podId(long podId) {
return new AddHostOptions().podId(podId);
}
}
}

View File

@ -0,0 +1,53 @@
/**
* 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 for the GlobalHostClient.addSecondaryStorage() API call
*
* @author Richard Downer
*/
public class AddSecondaryStorageOptions extends BaseHttpRequestOptions {
public static final AddSecondaryStorageOptions NONE = new AddSecondaryStorageOptions();
/**
* @param zoneId
* the ID of the zone
*/
public AddSecondaryStorageOptions zoneId(long zoneId) {
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + ""));
return this;
}
public static class Builder {
/**
* @param zoneId
* the ID of the zone
*/
public static AddSecondaryStorageOptions zoneId(long zoneId) {
return new AddSecondaryStorageOptions().zoneId(zoneId);
}
}
}

View File

@ -0,0 +1,66 @@
/**
* 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 GlobalHostClient.deleteHost() API call
*
* @author Richard Downer
*/
public class DeleteHostOptions extends BaseHttpRequestOptions {
public static final DeleteHostOptions NONE = new DeleteHostOptions();
/**
* @param forced Force delete the host. All HA enabled vms running on the host will be put to HA; HA disabled ones will be stopped
*/
public DeleteHostOptions forced(boolean forced) {
this.queryParameters.replaceValues("forced", ImmutableSet.of(forced + ""));
return this;
}
/**
* @param forceDestroyLocalStorage Force destroy local storage on this host. All VMs created on this local storage will be destroyed
*/
public DeleteHostOptions forceDestroyLocalStorage(boolean forceDestroyLocalStorage) {
this.queryParameters.replaceValues("forcedestroylocalstorage", ImmutableSet.of(forceDestroyLocalStorage + ""));
return this;
}
public static class Builder {
/**
* @param forced Force delete the host. All HA enabled vms running on the host will be put to HA; HA disabled ones will be stopped
*/
public static DeleteHostOptions forced(boolean forced) {
return new DeleteHostOptions().forced(forced);
}
/**
* @param forceDestroyLocalStorage Force destroy local storage on this host. All VMs created on this local storage will be destroyed
*/
public static DeleteHostOptions forceDestroyLocalStorage(boolean forceDestroyLocalStorage) {
return new DeleteHostOptions().forceDestroyLocalStorage(forceDestroyLocalStorage);
}
}
}

View File

@ -0,0 +1,113 @@
/**
* 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.Cluster;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options for the GlobalHostClient.updateCluster() API call.
*
* @author Richard Downer
*/
public class UpdateClusterOptions extends BaseHttpRequestOptions {
public static final UpdateClusterOptions NONE = new UpdateClusterOptions();
/**
* @param allocationState Allocation state of this cluster for allocation of new resources
*/
public UpdateClusterOptions allocationState(Host.AllocationState allocationState) {
this.queryParameters.replaceValues("allocationstate", ImmutableSet.<String>of(allocationState.toString()));
return this;
}
/**
* @param clusterName the cluster name
*/
public UpdateClusterOptions clusterName(String clusterName) {
this.queryParameters.replaceValues("clustername", ImmutableSet.<String>of(clusterName));
return this;
}
/**
* @param clusterType type of the cluster
*/
public UpdateClusterOptions clusterType(Host.ClusterType clusterType) {
this.queryParameters.replaceValues("clustertype", ImmutableSet.<String>of(clusterType.toString()));
return this;
}
/**
* @param hypervisor hypervisor type of the cluster
*/
public UpdateClusterOptions hypervisor(String hypervisor) {
this.queryParameters.replaceValues("hypervisor", ImmutableSet.<String>of(hypervisor));
return this;
}
/**
* @param managedState whether this cluster is managed by cloudstack
*/
public UpdateClusterOptions managedState(Cluster.ManagedState managedState) {
this.queryParameters.replaceValues("managedstate", ImmutableSet.<String>of(managedState.toString()));
return this;
}
public static class Builder {
/**
* @param allocationState Allocation state of this cluster for allocation of new resources
*/
public static UpdateClusterOptions allocationState(Host.AllocationState allocationState) {
return new UpdateClusterOptions().allocationState(allocationState);
}
/**
* @param clusterName the cluster name
*/
public static UpdateClusterOptions clusterName(String clusterName) {
return new UpdateClusterOptions().clusterName(clusterName);
}
/**
* @param clusterType type of the cluster
*/
public static UpdateClusterOptions clusterType(Host.ClusterType clusterType) {
return new UpdateClusterOptions().clusterType(clusterType);
}
/**
* @param hypervisor hypervisor type of the cluster
*/
public static UpdateClusterOptions hypervisor(String hypervisor) {
return new UpdateClusterOptions().hypervisor(hypervisor);
}
/**
* @param managedState whether this cluster is managed by cloudstack
*/
public static UpdateClusterOptions managedState(Cluster.ManagedState managedState) {
return new UpdateClusterOptions().managedState(managedState);
}
}
}

View File

@ -0,0 +1,87 @@
/**
* 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.base.Joiner;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.functions.JoinOnComma;
import org.jclouds.http.options.BaseHttpRequestOptions;
import java.util.Set;
/**
* Options to the GlobalHostClient.addHost() API call
*
* @author Richard Downer
*/
public class UpdateHostOptions extends BaseHttpRequestOptions {
public static final UpdateHostOptions NONE = new UpdateHostOptions();
/**
* @param allocationState Allocation state of this Host for allocation of new resources
*/
public UpdateHostOptions allocationState(Host.AllocationState allocationState) {
this.queryParameters.replaceValues("allocationstate", ImmutableSet.of(allocationState.toString()));
return this;
}
/**
* @param hostTags list of tags to be added to the host
*/
public UpdateHostOptions hostTags(Set<String> hostTags) {
this.queryParameters.replaceValues("hosttags", ImmutableSet.of(Joiner.on(',').join(hostTags)));
return this;
}
/**
* @param osCategoryId the id of Os category to update the host with
*/
public UpdateHostOptions osCategoryId(long osCategoryId) {
this.queryParameters.replaceValues("oscategoryid", ImmutableSet.of(osCategoryId + ""));
return this;
}
public static class Builder {
/**
* @param allocationState Allocation state of this Host for allocation of new resources
*/
public static UpdateHostOptions allocationState(Host.AllocationState allocationState) {
return new UpdateHostOptions().allocationState(allocationState);
}
/**
* @param hostTags list of tags to be added to the host
*/
public static UpdateHostOptions hostTags(Set<String> hostTags) {
return new UpdateHostOptions().hostTags(hostTags);
}
/**
* @param podId the Pod ID for the host
*/
public static UpdateHostOptions osCategoryId(long osCategoryId) {
return new UpdateHostOptions().osCategoryId(osCategoryId);
}
}
}

View File

@ -0,0 +1,348 @@
/**
* 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 com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.CloudStackContext;
import org.jclouds.cloudstack.domain.Cluster;
import org.jclouds.cloudstack.domain.ConfigurationEntry;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.cloudstack.options.AddClusterOptions;
import org.jclouds.cloudstack.options.AddHostOptions;
import org.jclouds.cloudstack.options.AddSecondaryStorageOptions;
import org.jclouds.cloudstack.options.DeleteHostOptions;
import org.jclouds.cloudstack.options.UpdateClusterOptions;
import org.jclouds.cloudstack.options.UpdateHostOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
import java.net.URI;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Set;
import java.util.TimeZone;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
/**
* Test the CloudStack GlobalHostClient
*
* @author Richard Downer
*/
@Test(groups = "unit", testName = "GlobalConfigurationClientExpectTest")
public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTest<GlobalHostClient> {
@Test
public void testListHostsWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=listHosts&apiKey=identity&signature=wsv4UBgXxURW0pNlso4MT9E052s%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/listhostsresponse.json"))
.statusCode(200).build();
Set<Host> actual = requestSendsResponse(request, response).listHosts();
Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC");
Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "UTC");
Host host1 = Host.builder().id(1).name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.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.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).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(lastPinged).managementServerId(223098941760041L).clusterId(1).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build();
Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC");
lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "UTC");
created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC");
Host host2 = Host.builder().id(2).name("nfs://10.26.26.165/mnt/nfs/cs_sec").state(Host.State.ALERT).disconnected(disconnected).type(Host.Type.SECONDARY_STORAGE).ipAddress("nfs").zoneId(1).zoneName("Dev Zone 1").version("2.2.12.20110928142833").hypervisor("None").lastPinged(lastPinged).localStorageActive(false).created(created).events("ManagementServerDown; AgentDisconnected; Remove; MaintenanceRequested; AgentConnected; Ping").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build();
lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC");
created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 35, 51, "UTC");
Host host3 = Host.builder().id(3).name("s-1-VM").state(Host.State.UP).type(Host.Type.SECONDARY_STORAGE_VM).ipAddress("10.26.26.81").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").lastPinged(lastPinged).managementServerId(223098941760041L).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build();
lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC");
created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 36, 46, "UTC");
Host host4 = Host.builder().id(4).name("v-2-VM").state(Host.State.UP).type(Host.Type.CONSOLE_PROXY).ipAddress("10.26.26.96").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").lastPinged(lastPinged).managementServerId(223098941760041L).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build();
Set<Host> expected = ImmutableSet.of(host1, host2, host3, host4);
assertEquals(actual, expected);
}
@Test
public void testListHostsEmptyOn404() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=listHosts&apiKey=identity&signature=wsv4UBgXxURW0pNlso4MT9E052s%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
GlobalHostClient client = requestSendsResponse(request, response);
assertEquals(client.listHosts(), ImmutableSet.of());
}
@Test
public void testAddHostWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=addHost&zoneid=1&hypervisor=XenServer&url=http%3A%2F%2Fexample.com&username=fred&password=sekrit&hosttags=&allocationstate=Enabled&clusterid=1&clustername=Xen%20Clust%201&podid=1&apiKey=identity&signature=ExGaljKKQIlVbWk5hd0BnnjmBzs%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/addhostresponse.json"))
.statusCode(200).build();
Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC");
Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "UTC");
Host expected = Host.builder().id(1).name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.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.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).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(lastPinged).managementServerId(223098941760041L).clusterId(1).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build();
Host actual = requestSendsResponse(request, response).addHost(1, "http://example.com", "XenServer", "fred", "sekrit",
AddHostOptions.Builder.hostTags(Collections.<String>emptySet()).allocationState(Host.AllocationState.ENABLED).clusterId(1).clusterName("Xen Clust 1").podId(1));
assertEquals(actual, expected);
}
@Test
public void testUpdateHostWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=updateHost&id=1&allocationstate=Enabled&hosttags=&oscategoryid=5&apiKey=identity&signature=qTxNq9yQG8S108giqS%2FROFzgev8%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/updatehostresponse.json"))
.statusCode(200).build();
Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC");
Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "UTC");
Host expected = Host.builder().id(1).name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.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.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).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(lastPinged).managementServerId(223098941760041L).clusterId(1).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build();
Host actual = requestSendsResponse(request, response).updateHost(1, UpdateHostOptions.Builder.allocationState(Host.AllocationState.ENABLED).hostTags(Collections.<String>emptySet()).osCategoryId(5));
assertEquals(actual, expected);
}
@Test
public void testUpdateHostPasswordWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=updateHostPassword&hostid=1&password=sekrit&username=fred&apiKey=identity&signature=g9nMKDWoiU72y0HhaRFekZCgfJc%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.statusCode(200).build();
requestSendsResponse(request, response).updateHostPassword(1, "fred", "sekrit");
}
@Test
public void testDeleteHostWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=deleteHost&id=1&forced=true&forcedestroylocalstorage=true&apiKey=identity&signature=ZdvO1BWBkdPiDAjsVlKtqDe6N7k%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.statusCode(200).build();
requestSendsResponse(request, response).deleteHost(1, DeleteHostOptions.Builder.forced(true).forceDestroyLocalStorage(true));
}
@Test
public void testPrepareHostForMaintenanceWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=prepareHostForMaintenance&id=1&apiKey=identity&signature=9tDwdox%2FxAKmZr9kVrR6Ttnxf3U%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/preparehostformaintenanceresponse.json"))
.statusCode(200).build();
Long actual = requestSendsResponse(request, response).prepareHostForMaintenance(1);
assertEquals(actual, Long.valueOf(2036L));
}
@Test
public void testCancelHostMaintenanceWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=cancelHostMaintenance&id=1&apiKey=identity&signature=9RduzuBoyRZKNTzAoVqUo9gRTfk%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/cancelhostmaintenanceresponse.json"))
.statusCode(200).build();
Long actual = requestSendsResponse(request, response).cancelHostMaintenance(1);
assertEquals(actual, Long.valueOf(2036L));
}
@Test
public void testReconnectHostWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=reconnectHost&id=1&apiKey=identity&signature=wJEF02vwdyOnJOTa%2BWMMK906aRU%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/reconnecthostresponse.json"))
.statusCode(200).build();
Long actual = requestSendsResponse(request, response).reconnectHost(1);
assertEquals(actual, Long.valueOf(2036L));
}
@Test
public void testAddSecondaryStorageWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=addSecondaryStorage&url=nfs%3A%2F%2F10.26.26.165%2Fmnt%2Fnfs%2Fcs_sec&zoneid=1&apiKey=identity&signature=MccRKx1yPP43ImiO70WlhVDlAIA%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/addsecondarystorageresponse.json"))
.statusCode(200).build();
Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC");
Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "UTC");
Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC");
Host expected = Host.builder().id(2).name("nfs://10.26.26.165/mnt/nfs/cs_sec").state(Host.State.ALERT).disconnected(disconnected).type(Host.Type.SECONDARY_STORAGE).ipAddress("nfs").zoneId(1).zoneName("Dev Zone 1").version("2.2.12.20110928142833").hypervisor("None").lastPinged(lastPinged).localStorageActive(false).created(created).events("ManagementServerDown; AgentDisconnected; Remove; MaintenanceRequested; AgentConnected; Ping").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build();
Host actual = requestSendsResponse(request, response).addSecondaryStorage("nfs://10.26.26.165/mnt/nfs/cs_sec", AddSecondaryStorageOptions.Builder.zoneId(1));
assertEquals(actual, expected);
}
@Test
public void testListClustersWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=listClusters&apiKey=identity&signature=MWOOe7bm1J14DIfLjAGqsSVb8oo%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/listclustersresponse.json"))
.statusCode(200).build();
Set<Cluster> actual = requestSendsResponse(request, response).listClusters();
Cluster cluster1 = Cluster.builder().id(1).name("Xen Clust 1").podId(1).podName("Dev Pod 1").zoneId(1).zoneName("Dev Zone 1").hypervisor("XenServer").clusterType(Host.ClusterType.CLOUD_MANAGED).allocationState(Host.AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build();
Cluster cluster2 = Cluster.builder().id(2).name("Xen Clust 1").podId(2).podName("Dev Pod 2").zoneId(2).zoneName("Dev Zone 2").hypervisor("XenServer").clusterType(Host.ClusterType.CLOUD_MANAGED).allocationState(Host.AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build();
ImmutableSet<Cluster> expected = ImmutableSet.of(cluster1, cluster2);
assertEquals(actual, expected);
}
@Test
public void testListClustersEmptyOn404() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=listClusters&apiKey=identity&signature=MWOOe7bm1J14DIfLjAGqsSVb8oo%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
GlobalHostClient client = requestSendsResponse(request, response);
assertEquals(client.listClusters(), ImmutableSet.of());
}
@Test
public void testAddClusterWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=addCluster&zoneid=1&clustertype=CloudManaged&clustername=Xen%20Clust%201&hypervisor=XenServer&allocationstate=Enabled&podid=1&url=http%3A%2F%2Fexample.com%2Fcluster&username=fred&password=sekrit&apiKey=identity&signature=2uIQ5qF0bVycXK111wxvogWp1Yw%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/addclusterresponse.json"))
.statusCode(200).build();
Cluster expected = Cluster.builder().id(1).name("Xen Clust 1").podId(1).podName("Dev Pod 1").zoneId(1).zoneName("Dev Zone 1").hypervisor("XenServer").clusterType(Host.ClusterType.CLOUD_MANAGED).allocationState(Host.AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build();
Cluster actual = requestSendsResponse(request, response).addCluster(1, "Xen Clust 1", Host.ClusterType.CLOUD_MANAGED, "XenServer", AddClusterOptions.Builder.allocationState(Host.AllocationState.ENABLED).podId(1).url("http://example.com/cluster").username("fred").password("sekrit"));
assertEquals(actual, expected);
}
@Test
public void testUpdateClusterWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=updateCluster&id=1&allocationstate=Enabled&clustername=Xen%20Clust%201&clustertype=CloudManaged&hypervisor=XenServer&managedstate=Managed&apiKey=identity&signature=%2FwbuYKwInciSXWkUf05lEfJZShQ%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/updateclusterresponse.json"))
.statusCode(200).build();
Cluster expected = Cluster.builder().id(1).name("Xen Clust 1").podId(1).podName("Dev Pod 1").zoneId(1).zoneName("Dev Zone 1").hypervisor("XenServer").clusterType(Host.ClusterType.CLOUD_MANAGED).allocationState(Host.AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build();
Cluster actual = requestSendsResponse(request, response).updateCluster(1, UpdateClusterOptions.Builder.allocationState(Host.AllocationState.ENABLED).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).hypervisor("XenServer").managedState(Cluster.ManagedState.MANAGED));
assertEquals(actual, expected);
}
@Test
public void testUpdateClusterPasswordWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=updateHostPassword&clusterid=1&password=sekrit&username=fred&apiKey=identity&signature=xwc83%2BoYK0cuAiFQAlg%2F7%2F1IVHE%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.statusCode(200).build();
requestSendsResponse(request, response).updateClusterPassword(1, "fred", "sekrit");
}
@Test
public void testDeleteClusterWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=deleteCluster&id=1&apiKey=identity&signature=CKH26MFgKGY7Sosd17LjBMNa3AI%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.statusCode(200).build();
requestSendsResponse(request, response).deleteCluster(1);
}
private Date makeDate(int year, int month, int date, int hour, int minute, int second, String timeZoneName) {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneName));
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DATE, date);
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, minute);
cal.set(Calendar.SECOND, second);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
@Override
protected GlobalHostClient clientFrom(CloudStackContext context) {
return context.getGlobalContext().getApi().getHostClient();
}
}

View File

@ -0,0 +1,86 @@
/**
* 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.Host;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.AddClusterOptions.Builder.*;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code AddClusterOptions}
*
* @author Richard Downer
*/
@Test(groups = "unit")
public class AddClusterOptionsTest {
public void testAllocationState() {
AddClusterOptions options = new AddClusterOptions().allocationState(Host.AllocationState.ENABLED);
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
}
public void testAllocationStateStatic() {
AddClusterOptions options = allocationState(Host.AllocationState.ENABLED);
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
}
public void testPassword() {
AddClusterOptions options = new AddClusterOptions().password("sekrit");
assertEquals(ImmutableList.of("sekrit"), options.buildQueryParameters().get("password"));
}
public void testPasswordStatic() {
AddClusterOptions options = password("sekrit");
assertEquals(ImmutableList.of("sekrit"), options.buildQueryParameters().get("password"));
}
public void testPodId() {
AddClusterOptions options = new AddClusterOptions().podId(42L);
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("podid"));
}
public void testPodIdStatic() {
AddClusterOptions options = podId(42L);
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("podid"));
}
public void testUrl() {
AddClusterOptions options = new AddClusterOptions().url("http://example.com");
assertEquals(ImmutableList.of("http://example.com"), options.buildQueryParameters().get("url"));
}
public void testUrlStatic() {
AddClusterOptions options = url("http://example.com");
assertEquals(ImmutableList.of("http://example.com"), options.buildQueryParameters().get("url"));
}
public void testUsername() {
AddClusterOptions options = new AddClusterOptions().username("fred");
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("username"));
}
public void testUsernameStatic() {
AddClusterOptions options = username("fred");
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("username"));
}
}

View File

@ -0,0 +1,87 @@
/**
* 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 com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.Host;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.AddHostOptions.Builder.*;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code AddHostOptions}
*
* @author Richard Downer
*/
@Test(groups = "unit")
public class AddHostOptionsTest {
public void testAllocationState() {
AddHostOptions options = new AddHostOptions().allocationState(Host.AllocationState.ENABLED);
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
}
public void testAllocationStateStatic() {
AddHostOptions options = allocationState(Host.AllocationState.ENABLED);
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
}
public void testClusterId() {
AddHostOptions options = new AddHostOptions().clusterId(42L);
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("clusterid"));
}
public void testClusterIdStatic() {
AddHostOptions options = clusterId(42L);
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("clusterid"));
}
public void testClusterName() {
AddHostOptions options = new AddHostOptions().clusterName("Cluster Name");
assertEquals(ImmutableList.of("Cluster Name"), options.buildQueryParameters().get("clustername"));
}
public void testClusterNameStatic() {
AddHostOptions options = clusterName("Cluster Name");
assertEquals(ImmutableList.of("Cluster Name"), options.buildQueryParameters().get("clustername"));
}
public void testHostTags() {
AddHostOptions options = new AddHostOptions().hostTags(ImmutableSet.<String>of("foo", "bar", "baz"));
assertEquals(ImmutableList.of("foo,bar,baz"), options.buildQueryParameters().get("hosttags"));
}
public void testHostTagsStatic() {
AddHostOptions options = hostTags(ImmutableSet.<String>of("foo", "bar", "baz"));
assertEquals(ImmutableList.of("foo,bar,baz"), options.buildQueryParameters().get("hosttags"));
}
public void testPodId() {
AddHostOptions options = new AddHostOptions().podId(42L);
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("podid"));
}
public void testPodIdStatic() {
AddHostOptions options = podId(42L);
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("podid"));
}
}

View File

@ -0,0 +1,45 @@
/**
* 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.AddSecondaryStorageOptions.Builder.*;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code AddSecondaryStorageOptions}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class AddSecondaryStorageOptionsTest {
public void testZoneId() {
AddSecondaryStorageOptions options = new AddSecondaryStorageOptions().zoneId(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
}
public void testZoneIdStatic() {
AddSecondaryStorageOptions options = zoneId(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
}
}

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.options;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.Host;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.DeleteHostOptions.Builder.*;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code DeleteHostOptions}
*
* @author Richard Downer
*/
@Test(groups = "unit")
public class DeleteHostOptionsTest {
public void testForced() {
DeleteHostOptions options = new DeleteHostOptions().forced(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forced"));
}
public void testForcedStatic() {
DeleteHostOptions options = forced(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forced"));
}
public void testForceDestroyLocalStorage() {
DeleteHostOptions options = new DeleteHostOptions().forceDestroyLocalStorage(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forcedestroylocalstorage"));
}
public void testForceDestroyLocalStorageStatic() {
DeleteHostOptions options = forceDestroyLocalStorage(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forcedestroylocalstorage"));
}
}

View File

@ -0,0 +1,67 @@
/**
* 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.Cluster;
import org.jclouds.cloudstack.domain.Host;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.UpdateClusterOptions.Builder.allocationState;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code UpdateClusterOptions}
*
* @author Richard Downer
*/
@Test(groups = "unit")
public class UpdateClusterOptionsTest {
public void testAllocationState() {
UpdateClusterOptions options = new UpdateClusterOptions().allocationState(Host.AllocationState.ENABLED);
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
}
public void testAllocationStateStatic() {
UpdateClusterOptions options = allocationState(Host.AllocationState.ENABLED);
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
}
public void testClusterName() {
UpdateClusterOptions options = new UpdateClusterOptions().clusterName("My Cluster");
assertEquals(ImmutableList.of("My Cluster"), options.buildQueryParameters().get("clustername"));
}
public void testClusterType() {
UpdateClusterOptions options = new UpdateClusterOptions().clusterType(Host.ClusterType.CLOUD_MANAGED);
assertEquals(ImmutableList.of("CloudManaged"), options.buildQueryParameters().get("clustertype"));
}
public void testHypervisor() {
UpdateClusterOptions options = new UpdateClusterOptions().hypervisor("XenServer");
assertEquals(ImmutableList.of("XenServer"), options.buildQueryParameters().get("hypervisor"));
}
public void testManagedState() {
UpdateClusterOptions options = new UpdateClusterOptions().managedState(Cluster.ManagedState.PREPARE_UNMANAGED);
assertEquals(ImmutableList.of("PrepareUnmanaged"), options.buildQueryParameters().get("managedstate"));
}
}

View File

@ -0,0 +1,67 @@
/**
* 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 com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.Host;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.UpdateHostOptions.Builder.*;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code UpdateHostOptions}
*
* @author Richard Downer
*/
@Test(groups = "unit")
public class UpdateHostOptionsTest {
public void testAllocationState() {
UpdateHostOptions options = new UpdateHostOptions().allocationState(Host.AllocationState.ENABLED);
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
}
public void testAllocationStateStatic() {
UpdateHostOptions options = allocationState(Host.AllocationState.ENABLED);
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
}
public void testHostTags() {
UpdateHostOptions options = new UpdateHostOptions().hostTags(ImmutableSet.<String>of("foo", "bar", "baz"));
assertEquals(ImmutableList.of("foo,bar,baz"), options.buildQueryParameters().get("hosttags"));
}
public void testHostTagsStatic() {
UpdateHostOptions options = hostTags(ImmutableSet.<String>of("foo", "bar", "baz"));
assertEquals(ImmutableList.of("foo,bar,baz"), options.buildQueryParameters().get("hosttags"));
}
public void testOsCategoryId() {
UpdateHostOptions options = new UpdateHostOptions().osCategoryId(42L);
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("oscategoryid"));
}
public void testOsCategoryIdStatic() {
UpdateHostOptions options = osCategoryId(42L);
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("oscategoryid"));
}
}

View File

@ -0,0 +1 @@
{ "addclusterresponse" : { "cluster" : {"warning":"this test data is fabricated","id":1,"name":"Xen Clust 1","podid":1,"podname":"Dev Pod 1","zoneid":1,"zonename":"Dev Zone 1","hypervisortype":"XenServer","clustertype":"CloudManaged","allocationstate":"Enabled","managedstate":"Managed"} } }

View File

@ -0,0 +1,2 @@
{ "addhostresponse" : { "host" :
{"warning":"This test data is fabricated","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"} } }

View File

@ -0,0 +1,3 @@
{ "addsecondarystorageresponse" : { "host" :
{"warning":"this test data is fabricated","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"},
} }

View File

@ -0,0 +1 @@
{ "cancelhostmaintenanceresponse" : {"warning":"this test data is fabricated","jobid":2036,"id":2017} }

View File

@ -0,0 +1 @@
{ "preparehostformaintenanceresponse" : {"warning":"this test data is fabricated","jobid":2036,"id":2017} }

View File

@ -0,0 +1 @@
{ "reconnecthostresponse" : {"warning":"this test data is fabricated","jobid":2036,"id":2017} }

View File

@ -0,0 +1 @@
{ "updateclusterresponse" : { "cluster" : {"warning":"this test data is fabricated","id":1,"name":"Xen Clust 1","podid":1,"podname":"Dev Pod 1","zoneid":1,"zonename":"Dev Zone 1","hypervisortype":"XenServer","clustertype":"CloudManaged","allocationstate":"Enabled","managedstate":"Managed"} } }

View File

@ -0,0 +1,2 @@
{ "updatehostresponse" : { "host" :
{"warning":"This test data is fabricated","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"} } }