tested response parsing on cloudstack

This commit is contained in:
Adrian Cole 2011-02-19 10:06:59 -08:00
parent 63b6f21044
commit ee81a8ac43
24 changed files with 1468 additions and 85 deletions

View File

@ -19,6 +19,8 @@
package org.jclouds.cloudstack.domain; package org.jclouds.cloudstack.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
@ -31,7 +33,73 @@ import com.google.gson.annotations.SerializedName;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class DiskOffering { public class DiskOffering implements Comparable<DiskOffering> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String name;
private String displayText;
private Date created;
private String domain;
private long domainId;
private int diskSize;
private boolean customized;
private Set<String> tags = ImmutableSet.of();
public Builder id(long id) {
this.id = id;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder displayText(String displayText) {
this.displayText = displayText;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Builder domain(String domain) {
this.domain = domain;
return this;
}
public Builder domainId(long domainId) {
this.domainId = domainId;
return this;
}
public Builder diskSize(int diskSize) {
this.diskSize = diskSize;
return this;
}
public Builder customized(boolean customized) {
this.customized = customized;
return this;
}
public Builder tags(Set<String> tags) {
this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags"));
return this;
}
public DiskOffering build() {
return new DiskOffering(id, name, displayText, created, domain, domainId, diskSize, customized, tags);
}
}
private long id; private long id;
private String name; private String name;
@SerializedName("displaytext") @SerializedName("displaytext")
@ -47,7 +115,7 @@ public class DiskOffering {
private String tags; private String tags;
public DiskOffering(long id, String name, String displayText, Date created, String domain, long domainId, public DiskOffering(long id, String name, String displayText, Date created, String domain, long domainId,
int diskSize, boolean customized, Set<String> tags) { int diskSize, boolean customized, Set<String> tags) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.displayText = displayText; this.displayText = displayText;
@ -56,7 +124,7 @@ public class DiskOffering {
this.domainId = domainId; this.domainId = domainId;
this.diskSize = diskSize; this.diskSize = diskSize;
this.customized = customized; this.customized = customized;
this.tags = Joiner.on(',').join(tags); this.tags = tags.size() == 0 ? null : Joiner.on(',').join(tags);
} }
/** /**
@ -204,8 +272,13 @@ public class DiskOffering {
@Override @Override
public String toString() { public String toString() {
return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created + ", diskSize=" return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created + ", diskSize="
+ diskSize + ", iscustomized=" + customized + ", domain=" + domain + ", domainId=" + domainId + diskSize + ", iscustomized=" + customized + ", domain=" + domain + ", domainId=" + domainId + ", tags="
+ ", tags=" + tags + "]"; + getTags() + "]";
}
@Override
public int compareTo(DiskOffering arg0) {
return new Long(id).compareTo(arg0.getId());
} }
} }

View File

@ -29,14 +29,195 @@ import javax.annotation.Nullable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList.Builder;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class Network { public class Network implements Comparable<Network> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String account;
private String broadcastDomainType;
private URI broadcastURI;
private String displayText;
private List<String> DNS = ImmutableList.of();
private String domain;
private long domainId;
private String endIP;
private String gateway;
private boolean isDefault;
private boolean isShared;
private boolean isSystem;
private String netmask;
private String networkDomain;
private String networkOfferingAvailability;
private String networkOfferingDisplayText;
private long networkOfferingId;
private String networkOfferingName;
private long related;
private String startIP;
private String name;
private String state;
private GuestIPType guestIPType;
private String VLAN;
private TrafficType trafficType;
private long zoneId;
private Set<? extends NetworkService> services = ImmutableSet.<NetworkService> of();
public Builder id(long id) {
this.id = id;
return this;
}
public Builder account(String account) {
this.account = account;
return this;
}
public Builder broadcastDomainType(String broadcastDomainType) {
this.broadcastDomainType = broadcastDomainType;
return this;
}
public Builder broadcastURI(URI broadcastURI) {
this.broadcastURI = broadcastURI;
return this;
}
public Builder displayText(String displayText) {
this.displayText = displayText;
return this;
}
public Builder DNS(List<String> DNS) {
this.DNS = ImmutableList.copyOf(checkNotNull(DNS, "DNS"));
return this;
}
public Builder domain(String domain) {
this.domain = domain;
return this;
}
public Builder domainId(long domainId) {
this.domainId = domainId;
return this;
}
public Builder endIP(String endIP) {
this.endIP = endIP;
return this;
}
public Builder gateway(String gateway) {
this.gateway = gateway;
return this;
}
public Builder isDefault(boolean isDefault) {
this.isDefault = isDefault;
return this;
}
public Builder isShared(boolean isShared) {
this.isShared = isShared;
return this;
}
public Builder isSystem(boolean isSystem) {
this.isSystem = isSystem;
return this;
}
public Builder netmask(String netmask) {
this.netmask = netmask;
return this;
}
public Builder networkDomain(String networkDomain) {
this.networkDomain = networkDomain;
return this;
}
public Builder networkOfferingAvailability(String networkOfferingAvailability) {
this.networkOfferingAvailability = networkOfferingAvailability;
return this;
}
public Builder networkOfferingDisplayText(String networkOfferingDisplayText) {
this.networkOfferingDisplayText = networkOfferingDisplayText;
return this;
}
public Builder networkOfferingId(long networkOfferingId) {
this.networkOfferingId = networkOfferingId;
return this;
}
public Builder networkOfferingName(String networkOfferingName) {
this.networkOfferingName = networkOfferingName;
return this;
}
public Builder related(long related) {
this.related = related;
return this;
}
public Builder startIP(String startIP) {
this.startIP = startIP;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder state(String state) {
this.state = state;
return this;
}
public Builder guestIPType(GuestIPType guestIPType) {
this.guestIPType = guestIPType;
return this;
}
public Builder VLAN(String VLAN) {
this.VLAN = VLAN;
return this;
}
public Builder trafficType(TrafficType trafficType) {
this.trafficType = trafficType;
return this;
}
public Builder zoneId(long zoneId) {
this.zoneId = zoneId;
return this;
}
public Builder services(Set<? extends NetworkService> services) {
this.services = ImmutableSet.<NetworkService> copyOf(checkNotNull(services, "services"));
return this;
}
public Network build() {
return new Network(id, account, broadcastDomainType, broadcastURI, displayText, DNS, domain, domainId, endIP,
gateway, isDefault, isShared, isSystem, netmask, networkDomain, networkOfferingAvailability,
networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state,
guestIPType, VLAN, trafficType, zoneId, services);
}
}
private long id; private long id;
private String account; private String account;
@SerializedName("broadcastdomaintype") @SerializedName("broadcastdomaintype")
@ -73,7 +254,7 @@ public class Network {
private long networkOfferingId; private long networkOfferingId;
@SerializedName("networkofferingname") @SerializedName("networkofferingname")
private String networkOfferingName; private String networkOfferingName;
private String related; private long related;
@SerializedName("startip") @SerializedName("startip")
private String startIP; private String startIP;
private String name; private String name;
@ -100,7 +281,7 @@ public class Network {
public Network(long id, String account, String broadcastDomainType, URI broadcastURI, String displayText, public Network(long id, String account, String broadcastDomainType, URI broadcastURI, String displayText,
List<String> DNS, String domain, long domainId, String endIP, String gateway, boolean isDefault, List<String> DNS, String domain, long domainId, String endIP, String gateway, boolean isDefault,
boolean isShared, boolean isSystem, String netmask, String networkDomain, String networkOfferingAvailability, boolean isShared, boolean isSystem, String netmask, String networkDomain, String networkOfferingAvailability,
String networkOfferingDisplayText, long networkOfferingId, String networkOfferingName, String related, String networkOfferingDisplayText, long networkOfferingId, String networkOfferingName, long related,
String startIP, String name, String state, GuestIPType type, String vLAN, TrafficType trafficType, String startIP, String name, String state, GuestIPType type, String vLAN, TrafficType trafficType,
long zoneId, Set<? extends NetworkService> services) { long zoneId, Set<? extends NetworkService> services) {
this.id = id; this.id = id;
@ -179,7 +360,7 @@ public class Network {
* @return the external DNS for the network * @return the external DNS for the network
*/ */
public List<String> getDNS() { public List<String> getDNS() {
Builder<String> builder = ImmutableList.builder(); ImmutableList.Builder<String> builder = ImmutableList.builder();
if (DNS1 != null && !"".equals(DNS1)) if (DNS1 != null && !"".equals(DNS1))
builder.add(DNS1); builder.add(DNS1);
if (DNS2 != null && !"".equals(DNS2)) if (DNS2 != null && !"".equals(DNS2))
@ -336,7 +517,7 @@ public class Network {
* *
* @return related to what other network configuration * @return related to what other network configuration
*/ */
public String getRelated() { public long getRelated() {
return related; return related;
} }
@ -391,7 +572,7 @@ public class Network {
result = prime * result + ((networkOfferingDisplayText == null) ? 0 : networkOfferingDisplayText.hashCode()); result = prime * result + ((networkOfferingDisplayText == null) ? 0 : networkOfferingDisplayText.hashCode());
result = prime * result + (int) (networkOfferingId ^ (networkOfferingId >>> 32)); result = prime * result + (int) (networkOfferingId ^ (networkOfferingId >>> 32));
result = prime * result + ((networkOfferingName == null) ? 0 : networkOfferingName.hashCode()); result = prime * result + ((networkOfferingName == null) ? 0 : networkOfferingName.hashCode());
result = prime * result + ((related == null) ? 0 : related.hashCode()); result = prime * result + (int) (related ^ (related >>> 32));
result = prime * result + ((services == null) ? 0 : services.hashCode()); result = prime * result + ((services == null) ? 0 : services.hashCode());
result = prime * result + ((startIP == null) ? 0 : startIP.hashCode()); result = prime * result + ((startIP == null) ? 0 : startIP.hashCode());
result = prime * result + ((state == null) ? 0 : state.hashCode()); result = prime * result + ((state == null) ? 0 : state.hashCode());
@ -503,10 +684,7 @@ public class Network {
return false; return false;
} else if (!networkOfferingName.equals(other.networkOfferingName)) } else if (!networkOfferingName.equals(other.networkOfferingName))
return false; return false;
if (related == null) { if (related != other.related)
if (other.related != null)
return false;
} else if (!related.equals(other.related))
return false; return false;
if (services == null) { if (services == null) {
if (other.services != null) if (other.services != null)
@ -543,4 +721,8 @@ public class Network {
+ ", networkOfferingName=" + networkOfferingName + "]"; + ", networkOfferingName=" + networkOfferingName + "]";
} }
@Override
public int compareTo(Network arg0) {
return new Long(id).compareTo(arg0.getId());
}
} }

View File

@ -19,6 +19,8 @@
package org.jclouds.cloudstack.domain; package org.jclouds.cloudstack.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
@ -33,7 +35,85 @@ import com.google.gson.annotations.SerializedName;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class NetworkOffering { public class NetworkOffering implements Comparable<NetworkOffering> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String name;
private String displayText;
private Date created;
private String availability;
private Integer maxConnections;
private int networkRate;
private boolean isDefault;
private boolean supportsVLAN;
private TrafficType trafficType;
private Set<String> tags = ImmutableSet.of();
public Builder id(long id) {
this.id = id;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder displayText(String displayText) {
this.displayText = displayText;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Builder availability(String availability) {
this.availability = availability;
return this;
}
public Builder maxConnections(Integer maxConnections) {
this.maxConnections = maxConnections;
return this;
}
public Builder isDefault(boolean isDefault) {
this.isDefault = isDefault;
return this;
}
public Builder networkRate(int networkRate) {
this.networkRate = networkRate;
return this;
}
public Builder supportsVLAN(boolean supportsVLAN) {
this.supportsVLAN = supportsVLAN;
return this;
}
public Builder trafficType(TrafficType trafficType) {
this.trafficType = trafficType;
return this;
}
public Builder tags(Set<String> tags) {
this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags"));
return this;
}
public NetworkOffering build() {
return new NetworkOffering(id, name, displayText, created, availability, supportsVLAN, maxConnections,
isDefault, trafficType, networkRate, tags);
}
}
private long id; private long id;
private String name; private String name;
@SerializedName("displaytext") @SerializedName("displaytext")
@ -48,11 +128,13 @@ public class NetworkOffering {
private boolean supportsVLAN; private boolean supportsVLAN;
@SerializedName("traffictype") @SerializedName("traffictype")
private TrafficType trafficType; private TrafficType trafficType;
@SerializedName("networkrate")
private int networkRate = -1;
private String tags; private String tags;
public NetworkOffering(long id, String name, String displayText, @Nullable Date created, String availability, public NetworkOffering(long id, String name, String displayText, @Nullable Date created, String availability,
boolean supportsVLAN, @Nullable Integer maxConnections, boolean isDefault, TrafficType trafficType, boolean supportsVLAN, @Nullable Integer maxConnections, boolean isDefault, TrafficType trafficType,
Set<String> tags) { int networkRate, Set<String> tags) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.displayText = displayText; this.displayText = displayText;
@ -62,7 +144,8 @@ public class NetworkOffering {
this.maxConnections = maxConnections; this.maxConnections = maxConnections;
this.isDefault = isDefault; this.isDefault = isDefault;
this.trafficType = trafficType; this.trafficType = trafficType;
this.tags = Joiner.on(',').join(tags); this.networkRate = networkRate;
this.tags = tags.size() == 0 ? null : Joiner.on(',').join(tags);
} }
/** /**
@ -148,6 +231,14 @@ public class NetworkOffering {
return trafficType; return trafficType;
} }
/**
*
* @return data transfer rate in megabits per second allowed.
*/
public int getNetworkRate() {
return networkRate;
}
/** /**
* *
* @return the tags for the network offering * @return the tags for the network offering
@ -226,8 +317,13 @@ public class NetworkOffering {
@Override @Override
public String toString() { public String toString() {
return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created
+ ", maxConnections=" + maxConnections + ", trafficType=" + trafficType + ", isDefault=" + isDefault + ", maxConnections=" + maxConnections + ", trafficType=" + trafficType + ", isDefault=" + isDefault
+ ", availability=" + availability + ", supportsVLAN=" + supportsVLAN + ", tags=" + tags + "]"; + ", availability=" + availability + ", supportsVLAN=" + supportsVLAN + ", tags=" + getTags() + "]";
}
@Override
public int compareTo(NetworkOffering arg0) {
return new Long(id).compareTo(arg0.getId());
} }
} }

View File

@ -21,8 +21,12 @@ package org.jclouds.cloudstack.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -31,26 +35,19 @@ import com.google.gson.annotations.SerializedName;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class NetworkService { public class NetworkService {
public static class Capability { // internal only to match json type
private static class Capability {
private String name; private String name;
private String value; private String value;
Capability() { private Capability() {
} }
public Capability(String name, String value) { private Capability(String name, String value) {
this.name = checkNotNull(name, "name"); this.name = name;
this.value = checkNotNull(value, "value"); this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
} }
@Override @Override
@ -99,17 +96,28 @@ public class NetworkService {
} }
public NetworkService(String name, Set<? extends NetworkService.Capability> capabilities) { public NetworkService(String name) {
this(name, ImmutableMap.<String, String> of());
}
public NetworkService(String name, Map<String, String> capabilities) {
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
this.capabilities = ImmutableSet.copyOf(checkNotNull(capabilities, "capabilities")); ImmutableSet.Builder<Capability> internal = ImmutableSet.<Capability> builder();
for (Entry<String, String> capabililty : checkNotNull(capabilities, "capabilities").entrySet())
internal.add(new Capability(capabililty.getKey(), capabililty.getValue()));
this.capabilities = internal.build();
} }
public String getName() { public String getName() {
return name; return name;
} }
public Set<? extends NetworkService.Capability> getCapabilities() { public Map<String, String> getCapabilities() {
return capabilities; Builder<String, String> returnVal = ImmutableMap.<String, String> builder();
for (Capability capability : capabilities) {
returnVal.put(capability.name, capability.value);
}
return returnVal.build();
} }
@Override @Override

View File

@ -30,7 +30,7 @@ import com.google.gson.annotations.SerializedName;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class SecurityGroup { public class SecurityGroup implements Comparable<SecurityGroup> {
private long id; private long id;
private String account; private String account;
private String name; private String name;
@ -178,4 +178,8 @@ public class SecurityGroup {
+ domain + ", domainId=" + domainId + ", ingressRules=" + ingressRules + "]"; + domain + ", domainId=" + domainId + ", ingressRules=" + ingressRules + "]";
} }
@Override
public int compareTo(SecurityGroup arg0) {
return new Long(id).compareTo(arg0.getId());
}
} }

View File

@ -19,6 +19,8 @@
package org.jclouds.cloudstack.domain; package org.jclouds.cloudstack.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
@ -31,7 +33,92 @@ import com.google.gson.annotations.SerializedName;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class ServiceOffering { public class ServiceOffering implements Comparable<ServiceOffering> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String name;
private String displayText;
private Date created;
private String domain;
private long domainId;
private int cpuNumber;
private int cpuSpeed;
private int memory;
private boolean haSupport;
private StorageType storageType;
private Set<String> tags = ImmutableSet.of();
public Builder id(long id) {
this.id = id;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder displayText(String displayText) {
this.displayText = displayText;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Builder domain(String domain) {
this.domain = domain;
return this;
}
public Builder domainId(long domainId) {
this.domainId = domainId;
return this;
}
public Builder cpuNumber(int cpuNumber) {
this.cpuNumber = cpuNumber;
return this;
}
public Builder cpuSpeed(int cpuSpeed) {
this.cpuSpeed = cpuSpeed;
return this;
}
public Builder memory(int memory) {
this.memory = memory;
return this;
}
public Builder haSupport(boolean haSupport) {
this.haSupport = haSupport;
return this;
}
public Builder storageType(StorageType storageType) {
this.storageType = storageType;
return this;
}
public Builder tags(Set<String> tags) {
this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags"));
return this;
}
public ServiceOffering build() {
return new ServiceOffering(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory,
haSupport, storageType, tags);
}
}
private long id; private long id;
private String name; private String name;
@SerializedName("displaytext") @SerializedName("displaytext")
@ -52,7 +139,7 @@ public class ServiceOffering {
private String tags; private String tags;
public ServiceOffering(long id, String name, String displayText, Date created, String domain, long domainId, public ServiceOffering(long id, String name, String displayText, Date created, String domain, long domainId,
int cpuNumber, int cpuSpeed, int memory, boolean haSupport, StorageType storageType, Set<String> tags) { int cpuNumber, int cpuSpeed, int memory, boolean haSupport, StorageType storageType, Set<String> tags) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.displayText = displayText; this.displayText = displayText;
@ -64,7 +151,7 @@ public class ServiceOffering {
this.memory = memory; this.memory = memory;
this.haSupport = haSupport; this.haSupport = haSupport;
this.storageType = storageType; this.storageType = storageType;
this.tags = Joiner.on(',').join(tags); this.tags = tags.size() == 0 ? null : Joiner.on(',').join(tags);
} }
/** /**
@ -245,8 +332,14 @@ public class ServiceOffering {
@Override @Override
public String toString() { public String toString() {
return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created + ", cpuNumber=" return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created + ", cpuNumber="
+ cpuNumber + ", cpuSpeed=" + cpuSpeed + ", memory=" + memory + ", storageType=" + storageType + cpuNumber + ", cpuSpeed=" + cpuSpeed + ", memory=" + memory + ", storageType=" + storageType
+ ", haSupport=" + haSupport + ", domain=" + domain + ", domainId=" + domainId + ", tags=" + tags + "]"; + ", haSupport=" + haSupport + ", domain=" + domain + ", domainId=" + domainId + ", tags=" + getTags()
+ "]";
}
@Override
public int compareTo(ServiceOffering arg0) {
return new Long(id).compareTo(arg0.getId());
} }
} }

View File

@ -19,9 +19,10 @@
package org.jclouds.cloudstack.domain; package org.jclouds.cloudstack.domain;
import java.util.Date;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -30,7 +31,200 @@ import com.google.gson.annotations.SerializedName;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class Template { public class Template implements Comparable<Template> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
@SerializedName("displaytext")
private String displayText;
private String domain;
@SerializedName("domainid")
private long domainId;
private String account;
@SerializedName("accountid")
private long accountId;
@SerializedName("zonename")
private String zone;
@SerializedName("zoneid")
private long zoneId;
@SerializedName("ostypename")
private String OSType;
@SerializedName("ostypeid")
private long OSTypeId;
private String name;
@SerializedName("templatetype")
private Type type;
private String status;
private Format format;
private String hypervisor;
private Long size;
private Date created;
private Date removed;
@SerializedName("crossZones")
private boolean crossZones;
@SerializedName("bootable")
private boolean bootable;
@SerializedName("isextractable")
private boolean extractable;
@SerializedName("isfeatured")
private boolean featured;
@SerializedName("ispublic")
private boolean isPublic;
@SerializedName("isready")
private boolean ready;
@SerializedName("passwordenabled")
private boolean passwordEnabled;
@Nullable
@SerializedName("jobid")
private Long jobId;
@SerializedName("jobstatus")
private String jobStatus;
public Builder id(long id) {
this.id = id;
return this;
}
public Builder displayText(String displayText) {
this.displayText = displayText;
return this;
}
public Builder domain(String domain) {
this.domain = domain;
return this;
}
public Builder domainId(long domainId) {
this.domainId = domainId;
return this;
}
public Builder account(String account) {
this.account = account;
return this;
}
public Builder accountId(long accountId) {
this.accountId = accountId;
return this;
}
public Builder zone(String zone) {
this.zone = zone;
return this;
}
public Builder zoneId(long zoneId) {
this.zoneId = zoneId;
return this;
}
public Builder OSType(String OSType) {
this.OSType = OSType;
return this;
}
public Builder OSTypeId(long OSTypeId) {
this.OSTypeId = OSTypeId;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder type(Type type) {
this.type = type;
return this;
}
public Builder status(String status) {
this.status = status;
return this;
}
public Builder format(Format format) {
this.format = format;
return this;
}
public Builder hypervisor(String hypervisor) {
this.hypervisor = hypervisor;
return this;
}
public Builder size(Long size) {
this.size = size;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Builder removed(Date removed) {
this.removed = removed;
return this;
}
public Builder crossZones(boolean crossZones) {
this.crossZones = crossZones;
return this;
}
public Builder bootable(boolean bootable) {
this.bootable = bootable;
return this;
}
public Builder extractable(boolean extractable) {
this.extractable = extractable;
return this;
}
public Builder featured(boolean featured) {
this.featured = featured;
return this;
}
public Builder isPublic(boolean isPublic) {
this.isPublic = isPublic;
return this;
}
public Builder ready(boolean ready) {
this.ready = ready;
return this;
}
public Builder passwordEnabled(boolean passwordEnabled) {
this.passwordEnabled = passwordEnabled;
return this;
}
public Builder jobId(Long jobId) {
this.jobId = jobId;
return this;
}
public Builder jobStatus(String jobStatus) {
this.jobStatus = jobStatus;
return this;
}
public Template build() {
return new Template(id, displayText, domain, domainId, account, accountId, zone, zoneId, OSType, OSTypeId,
name, type, status, format, hypervisor, size, created, removed, crossZones, bootable, extractable,
featured, isPublic, ready, passwordEnabled, jobId, jobStatus);
}
}
public enum Type { public enum Type {
@ -105,10 +299,10 @@ public class Template {
private String jobStatus; private String jobStatus;
public Template(long id, String displayText, String domain, long domainId, String account, long accountId, public Template(long id, String displayText, String domain, long domainId, String account, long accountId,
String zone, long zoneId, String oSType, long oSTypeId, String name, Type type, String status, String zone, long zoneId, String oSType, long oSTypeId, String name, Type type, String status, Format format,
Format format, String hypervisor, Long size, Date created, Date removed, boolean crossZones, String hypervisor, Long size, Date created, Date removed, boolean crossZones, boolean bootable,
boolean bootable, boolean extractable, boolean featured, boolean ispublic, boolean ready, boolean extractable, boolean featured, boolean ispublic, boolean ready, boolean passwordEnabled, Long jobId,
boolean passwordEnabled, Long jobId, String jobStatus) { String jobStatus) {
this.id = id; this.id = id;
this.displayText = displayText; this.displayText = displayText;
this.domain = domain; this.domain = domain;
@ -506,12 +700,16 @@ public class Template {
@Override @Override
public String toString() { public String toString() {
return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", format=" + format + ", type=" + type return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", format=" + format + ", type=" + type
+ ", hypervisor=" + hypervisor + ", size=" + size + ", status=" + status + ", created=" + created + ", hypervisor=" + hypervisor + ", size=" + size + ", status=" + status + ", created=" + created
+ ", removed=" + removed + ", OSType=" + OSType + ", OSTypeId=" + OSTypeId + ", account=" + account + ", removed=" + removed + ", OSType=" + OSType + ", OSTypeId=" + OSTypeId + ", account=" + account
+ ", accountId=" + accountId + ", domain=" + domain + ", domainId=" + domainId + ", zone=" + zone + ", accountId=" + accountId + ", domain=" + domain + ", domainId=" + domainId + ", zone=" + zone
+ ", zoneId=" + zoneId + ", ready=" + ready + ", bootable=" + bootable + ", crossZones=" + crossZones + ", zoneId=" + zoneId + ", ready=" + ready + ", bootable=" + bootable + ", crossZones=" + crossZones
+ ", extractable=" + extractable + ", featured=" + featured + ", ispublic=" + ispublic + ", extractable=" + extractable + ", featured=" + featured + ", ispublic=" + ispublic
+ ", passwordEnabled=" + passwordEnabled + ", jobId=" + jobId + ", jobStatus=" + jobStatus + "]"; + ", passwordEnabled=" + passwordEnabled + ", jobId=" + jobId + ", jobStatus=" + jobStatus + "]";
} }
@Override
public int compareTo(Template arg0) {
return new Long(id).compareTo(arg0.getId());
}
} }

View File

@ -34,7 +34,7 @@ import com.google.gson.annotations.SerializedName;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class VirtualMachine { public class VirtualMachine implements Comparable<VirtualMachine> {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
@ -400,7 +400,7 @@ public class VirtualMachine {
this.account = account; this.account = account;
this.cpuCount = cpuCount; this.cpuCount = cpuCount;
this.cpuSpeed = cpuSpeed; this.cpuSpeed = cpuSpeed;
this.cpuUsed = cpuUsed + ""; this.cpuUsed = cpuUsed != null ? cpuUsed + "" : null;
this.displayName = displayName; this.displayName = displayName;
this.created = created; this.created = created;
this.domain = domain; this.domain = domain;
@ -777,7 +777,6 @@ public class VirtualMachine {
result = prime * result + ((securityGroups == null) ? 0 : securityGroups.hashCode()); result = prime * result + ((securityGroups == null) ? 0 : securityGroups.hashCode());
result = prime * result + (int) (serviceOfferingId ^ (serviceOfferingId >>> 32)); result = prime * result + (int) (serviceOfferingId ^ (serviceOfferingId >>> 32));
result = prime * result + ((serviceOfferingName == null) ? 0 : serviceOfferingName.hashCode()); result = prime * result + ((serviceOfferingName == null) ? 0 : serviceOfferingName.hashCode());
result = prime * result + ((state == null) ? 0 : state.hashCode());
result = prime * result + ((templateDisplayText == null) ? 0 : templateDisplayText.hashCode()); result = prime * result + ((templateDisplayText == null) ? 0 : templateDisplayText.hashCode());
result = prime * result + (int) (templateId ^ (templateId >>> 32)); result = prime * result + (int) (templateId ^ (templateId >>> 32));
result = prime * result + ((templateName == null) ? 0 : templateName.hashCode()); result = prime * result + ((templateName == null) ? 0 : templateName.hashCode());
@ -927,8 +926,6 @@ public class VirtualMachine {
return false; return false;
} else if (!serviceOfferingName.equals(other.serviceOfferingName)) } else if (!serviceOfferingName.equals(other.serviceOfferingName))
return false; return false;
if (state != other.state)
return false;
if (templateDisplayText == null) { if (templateDisplayText == null) {
if (other.templateDisplayText != null) if (other.templateDisplayText != null)
return false; return false;
@ -955,19 +952,22 @@ public class VirtualMachine {
@Override @Override
public String toString() { public String toString() {
return "[id=" + id + ", account=" + account + ", cpuCount=" + cpuCount + ", cpuSpeed=" + cpuSpeed return "[id=" + id + ", account=" + account + ", cpuCount=" + cpuCount + ", cpuSpeed=" + cpuSpeed + ", cpuUsed="
+ ", cpuUsed=" + cpuUsed + ", displayName=" + displayName + ", created=" + created + ", domain=" + domain + cpuUsed + ", displayName=" + displayName + ", created=" + created + ", domain=" + domain + ", domainId="
+ ", domainId=" + domainId + ", usesVirtualNetwork=" + usesVirtualNetwork + ", group=" + group + domainId + ", usesVirtualNetwork=" + usesVirtualNetwork + ", group=" + group + ", groupId=" + groupId
+ ", groupId=" + groupId + ", guestOSId=" + guestOSId + ", HAEnabled=" + HAEnabled + ", hostId=" + hostId + ", guestOSId=" + guestOSId + ", HAEnabled=" + HAEnabled + ", hostId=" + hostId + ", hostname=" + hostname
+ ", hostname=" + hostname + ", IPAddress=" + IPAddress + ", ISODisplayText=" + ISODisplayText + ", ISOId=" + ", IPAddress=" + IPAddress + ", ISODisplayText=" + ISODisplayText + ", ISOId=" + ISOId + ", ISOName="
+ ISOId + ", ISOName=" + ISOName + ", jobId=" + jobId + ", jobStatus=" + jobStatus + ", memory=" + memory + ISOName + ", jobId=" + jobId + ", jobStatus=" + jobStatus + ", memory=" + memory + ", name=" + name
+ ", name=" + name + ", networkKbsRead=" + networkKbsRead + ", networkKbsWrite=" + networkKbsWrite + ", networkKbsRead=" + networkKbsRead + ", networkKbsWrite=" + networkKbsWrite + ", password=" + password
+ ", password=" + password + ", passwordEnabled=" + passwordEnabled + ", rootDeviceId=" + rootDeviceId + ", passwordEnabled=" + passwordEnabled + ", rootDeviceId=" + rootDeviceId + ", rootDeviceType="
+ ", rootDeviceType=" + rootDeviceType + ", serviceOfferingId=" + serviceOfferingId + rootDeviceType + ", serviceOfferingId=" + serviceOfferingId + ", serviceOfferingName="
+ ", serviceOfferingName=" + serviceOfferingName + ", state=" + state + ", templateDisplayText=" + serviceOfferingName + ", state=" + state + ", templateDisplayText=" + templateDisplayText
+ templateDisplayText + ", templateId=" + templateId + ", templateName=" + templateName + ", zoneId=" + ", templateId=" + templateId + ", templateName=" + templateName + ", zoneId=" + zoneId + ", zoneName="
+ zoneId + ", zoneName=" + zoneName + ", nics=" + nics + ", hypervisor=" + hypervisor + ", securityGroups=" + zoneName + ", nics=" + nics + ", hypervisor=" + hypervisor + ", securityGroups=" + securityGroups + "]";
+ securityGroups + "]";
} }
@Override
public int compareTo(VirtualMachine arg0) {
return new Long(id).compareTo(arg0.getId());
}
} }

View File

@ -26,14 +26,97 @@ import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class Zone { public class Zone implements Comparable<Zone> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String description;
private String displayText;
private List<String> DNS = ImmutableList.of();
private String domain;
private long domainId;
private String guestCIDRAddress;
private List<String> internalDNS = ImmutableList.of();
private String name;
private NetworkType networkType;
private String status;
private String VLAN;
public Builder id(long id) {
this.id = id;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Builder displayText(String displayText) {
this.displayText = displayText;
return this;
}
public Builder DNS(List<String> DNS) {
this.DNS = ImmutableList.copyOf(checkNotNull(DNS, "DNS"));
return this;
}
public Builder domain(String domain) {
this.domain = domain;
return this;
}
public Builder domainId(long domainId) {
this.domainId = domainId;
return this;
}
public Builder guestCIDRAddress(String guestCIDRAddress) {
this.guestCIDRAddress = guestCIDRAddress;
return this;
}
public Builder internalDNS(List<String> internalDNS) {
this.internalDNS = ImmutableList.copyOf(checkNotNull(internalDNS, "internalDNS"));
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder networkType(NetworkType networkType) {
this.networkType = networkType;
return this;
}
public Builder status(String status) {
this.status = status;
return this;
}
public Builder VLAN(String VLAN) {
this.VLAN = VLAN;
return this;
}
public Zone build() {
return new Zone(id, description, displayText, DNS, domain, domainId, guestCIDRAddress, internalDNS, name,
networkType, status, VLAN);
}
}
private long id; private long id;
private String description; private String description;
@SerializedName("displaytext") @SerializedName("displaytext")
@ -68,8 +151,8 @@ public class Zone {
} }
public Zone(long id, String description, String displayText, List<String> DNS, String domain, long domainId, public Zone(long id, String description, String displayText, List<String> DNS, String domain, long domainId,
String guestCIDRAddress, List<String> internalDNS, String name, NetworkType networkType, String status, String guestCIDRAddress, List<String> internalDNS, String name, NetworkType networkType, String status,
String vLAN) { String vLAN) {
this.id = id; this.id = id;
this.description = description; this.description = description;
this.displayText = displayText; this.displayText = displayText;
@ -115,7 +198,7 @@ public class Zone {
* @return the external DNS for the Zone * @return the external DNS for the Zone
*/ */
public List<String> getDNS() { public List<String> getDNS() {
Builder<String> builder = ImmutableList.builder(); ImmutableList.Builder<String> builder = ImmutableList.builder();
if (DNS1 != null && !"".equals(DNS1)) if (DNS1 != null && !"".equals(DNS1))
builder.add(DNS1); builder.add(DNS1);
if (DNS2 != null && !"".equals(DNS2)) if (DNS2 != null && !"".equals(DNS2))
@ -153,7 +236,7 @@ public class Zone {
* @return the internal DNS for the Zone * @return the internal DNS for the Zone
*/ */
public List<String> getInternalDNS() { public List<String> getInternalDNS() {
Builder<String> builder = ImmutableList.builder(); ImmutableList.Builder<String> builder = ImmutableList.builder();
if (internalDNS1 != null && !"".equals(internalDNS1)) if (internalDNS1 != null && !"".equals(internalDNS1))
builder.add(internalDNS1); builder.add(internalDNS1);
if (internalDNS2 != null && !"".equals(internalDNS2)) if (internalDNS2 != null && !"".equals(internalDNS2))
@ -290,8 +373,13 @@ public class Zone {
@Override @Override
public String toString() { public String toString() {
return "[id=" + id + ", status=" + status + ", name=" + name + ", description=" + description + ", displayText=" return "[id=" + id + ", status=" + status + ", name=" + name + ", description=" + description + ", displayText="
+ displayText + ", domain=" + domain + ", domainId=" + domainId + ", networkType=" + networkType + displayText + ", domain=" + domain + ", domainId=" + domainId + ", networkType=" + networkType
+ ", guestCIDRAddress=" + guestCIDRAddress + ", VLAN=" + VLAN + ", DNS=" + getDNS() + ", internalDNS=" + ", guestCIDRAddress=" + guestCIDRAddress + ", VLAN=" + VLAN + ", DNS=" + getDNS() + ", internalDNS="
+ getInternalDNS() + "]"; + getInternalDNS() + "]";
}
@Override
public int compareTo(Zone arg0) {
return new Long(id).compareTo(arg0.getId());
} }
} }

View File

@ -47,6 +47,9 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
assert syncClient.getTemplateClient() != null; assert syncClient.getTemplateClient() != null;
assert syncClient.getOfferingClient() != null; assert syncClient.getOfferingClient() != null;
assert syncClient.getNetworkClient() != null; assert syncClient.getNetworkClient() != null;
assert syncClient.getVirtualMachineClient() != null;
assert syncClient.getSecurityGroupClient() != null;
assert syncClient.getAsyncJobClient() != null;
} }
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
@ -54,6 +57,9 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
assert asyncClient.getTemplateClient() != null; assert asyncClient.getTemplateClient() != null;
assert asyncClient.getOfferingClient() != null; assert asyncClient.getOfferingClient() != null;
assert asyncClient.getNetworkClient() != null; assert asyncClient.getNetworkClient() != null;
assert asyncClient.getVirtualMachineClient() != null;
assert asyncClient.getSecurityGroupClient() != null;
assert asyncClient.getAsyncJobClient() != null;
} }
@Override @Override

View File

@ -61,7 +61,7 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
assert network.getNetworkOfferingDisplayText() != null : network; assert network.getNetworkOfferingDisplayText() != null : network;
assert network.getNetworkOfferingId() > 0 : network; assert network.getNetworkOfferingId() > 0 : network;
assert network.getNetworkOfferingName() != null : network; assert network.getNetworkOfferingName() != null : network;
assert network.getRelated() != null : network; assert network.getRelated() > 0 : network;
assert network.getServices().size() != 0 : network; assert network.getServices().size() != 0 : network;
assert network.getState() != null : network; assert network.getState() != null : network;
assert network.getTrafficType() != null : network; assert network.getTrafficType() != null : network;

View File

@ -0,0 +1,84 @@
/**
*
* Copyright (C) 2010 Cloud Conscious) LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.cloudstack.domain.DiskOffering;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ListDiskOfferingsResponseTest {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
public void test() {
InputStream is = getClass().getResourceAsStream("/listdiskofferingsresponse.json");
Set<DiskOffering> expects = ImmutableSet.<DiskOffering> of(
DiskOffering.builder().id(3).domainId(1).domain("ROOT").name("Small").displayText("Small Disk, 5 GB")
.diskSize(5)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T15:22:32-0800"))
.customized(false).build(),
DiskOffering.builder().id(4).domainId(1).domain("ROOT").name("Medium").displayText("Medium Disk, 20 GB")
.diskSize(20)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T15:22:32-0800"))
.customized(false).build(),
DiskOffering.builder().id(5).domainId(1).domain("ROOT").name("Large").displayText("Large Disk, 100 GB")
.diskSize(100)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T15:22:32-0800"))
.customized(false).build());
UnwrapOnlyNestedJsonValue<Set<DiskOffering>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyNestedJsonValue<Set<DiskOffering>>>() {
}));
Set<DiskOffering> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(Sets.newHashSet(response), expects);
}
}

View File

@ -0,0 +1,77 @@
/**
*
* Copyright (C) 2010 Cloud Conscious) LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.cloudstack.domain.NetworkOffering;
import org.jclouds.cloudstack.domain.TrafficType;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ListNetworkOfferingsResponseTest {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
public void test() {
InputStream is = getClass().getResourceAsStream("/listnetworkofferingsresponse.json");
Set<NetworkOffering> expects = ImmutableSortedSet.<NetworkOffering> of(
NetworkOffering.builder().id(6).name("DefaultVirtualizedNetworkOffering").displayText("Virtual Vlan")
.trafficType(TrafficType.GUEST).isDefault(true).supportsVLAN(false).availability("Required")
.networkRate(200).build(), NetworkOffering.builder().id(7).name("DefaultDirectNetworkOffering")
.displayText("Direct").trafficType(TrafficType.PUBLIC).isDefault(true).supportsVLAN(false)
.availability("Required").networkRate(200).build());
UnwrapOnlyNestedJsonValue<Set<NetworkOffering>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyNestedJsonValue<Set<NetworkOffering>>>() {
}));
Set<NetworkOffering> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(Sets.newTreeSet(response), expects);
}
}

View File

@ -0,0 +1,114 @@
/**
*
* Copyright (C) 2010 Cloud Conscious) LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.Set;
import org.jclouds.cloudstack.domain.GuestIPType;
import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.NetworkService;
import org.jclouds.cloudstack.domain.TrafficType;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ListNetworksResponseTest {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
public void test() {
InputStream is = getClass().getResourceAsStream("/listnetworksresponse.json");
Set<Network> expects = ImmutableSet
.<Network> of(Network
.builder()
.id(204)
.name("Virtual Network")
.displayText(
"A dedicated virtualized network for your account. The broadcast domain is contained within a VLAN and all public network access is routed out by a virtual router.")
.broadcastDomainType("Vlan")
.trafficType(TrafficType.GUEST)
.zoneId(1)
.networkOfferingId(6)
.networkOfferingName("DefaultVirtualizedNetworkOffering")
.networkOfferingDisplayText("Virtual Vlan")
.networkOfferingAvailability("Required")
.isShared(false)
.isSystem(false)
.state("Implemented")
.related(204)
.broadcastURI(URI.create("vlan://240"))
.DNS(ImmutableList.of("8.8.8.8"))
.guestIPType(GuestIPType.VIRTUAL)
.account("adrian")
.domainId(1)
.domain("ROOT")
.isDefault(true)
.services(
ImmutableSet.of(
new NetworkService("Vpn", ImmutableMap.of("SupportedVpnTypes", "pptp,l2tp,ipsec")),
new NetworkService("Gateway"),
new NetworkService("UserData"),
new NetworkService("Dhcp"),
new NetworkService("Firewall", ImmutableMap.<String, String> builder()
.put("SupportedSourceNatTypes", "per account").put("StaticNat", "true")
.put("TrafficStatistics", "per public ip").put("PortForwarding", "true")
.put("MultipleIps", "true").put("SupportedProtocols", "tcp,udp").build()),
new NetworkService("Dns"),
new NetworkService("Lb", ImmutableMap.of("SupportedLbAlgorithms",
"roundrobin,leastconn,source", "SupportedProtocols", "tcp, udp"))))
.networkDomain("cs3cloud.internal").build());
UnwrapOnlyNestedJsonValue<Set<Network>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyNestedJsonValue<Set<Network>>>() {
}));
Set<Network> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(Sets.newHashSet(response), expects);
}
}

View File

@ -0,0 +1,83 @@
/**
*
* Copyright (C) 2010 Cloud Conscious) LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.cloudstack.domain.ServiceOffering;
import org.jclouds.cloudstack.domain.StorageType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ListServiceOfferingsResponseTest {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
public void test() {
InputStream is = getClass().getResourceAsStream("/listserviceofferingsresponse.json");
Set<ServiceOffering> expects = ImmutableSortedSet.<ServiceOffering> of(
ServiceOffering.builder().id(1).name("Small Instance")
.displayText("Small Instance - 500 MhZ CPU, 512 MB RAM - $0.05 per hour").cpuNumber(1).cpuSpeed(500)
.memory(512)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T15:22:32-0800"))
.storageType(StorageType.SHARED).haSupport(false).build(),
ServiceOffering.builder().id(2).name("Medium Instance")
.displayText("Medium Instance, 1 GhZ CPU, 1 GB RAM - $0.10 per hour").cpuNumber(1).cpuSpeed(1000)
.memory(1024)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T15:22:32-0800"))
.storageType(StorageType.SHARED).haSupport(false).build());
UnwrapOnlyNestedJsonValue<Set<ServiceOffering>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyNestedJsonValue<Set<ServiceOffering>>>() {
}));
Set<ServiceOffering> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(Sets.newTreeSet(response), expects);
}
}

View File

@ -0,0 +1,94 @@
/**
*
* Copyright (C) 2010 Cloud Conscious) LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.cloudstack.domain.Template;
import org.jclouds.cloudstack.domain.Template.Format;
import org.jclouds.cloudstack.domain.Template.Type;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ListTemplatesResponseTest {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
public void test() {
InputStream is = getClass().getResourceAsStream("/listtemplatesresponse.json");
Set<Template> expects = ImmutableSortedSet.<Template> of(
Template.builder().id(2).name("CentOS 5.3(64-bit) no GUI (XenServer)")
.displayText("CentOS 5.3(64-bit) no GUI (XenServer)").isPublic(true)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T18:45:54-0800"))
.ready(true).passwordEnabled(false).format(Format.VHD).featured(true).crossZones(true).OSTypeId(11)
.OSType("CentOS 5.3 (32-bit)").account("system").zoneId(1).zone("San Jose 1").size(8589934592l)
.type(Template.Type.BUILTIN).hypervisor("XenServer").domain("ROOT").domainId(1).extractable(true)
.build(),
Template.builder().id(4).name("CentOS 5.5(64-bit) no GUI (KVM)")
.displayText("CentOS 5.5(64-bit) no GUI (KVM)").isPublic(true)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T18:45:54-0800"))
.ready(true).passwordEnabled(false).format(Format.QCOW2).featured(true).crossZones(true)
.OSTypeId(112).OSType("CentOS 5.5 (64-bit)").account("system").zoneId(1).zone("San Jose 1")
.size(8589934592l).type(Type.BUILTIN).hypervisor("KVM").domain("ROOT").domainId(1).extractable(true)
.build(),
Template.builder().id(7).name("CentOS 5.3(64-bit) no GUI (vSphere)")
.displayText("CentOS 5.3(64-bit) no GUI (vSphere)").isPublic(true)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T18:45:54-0800"))
.ready(true).passwordEnabled(false).format(Format.OVA).featured(true).crossZones(true).OSTypeId(12)
.OSType("CentOS 5.3 (64-bit)").account("system").zoneId(1).zone("San Jose 1").size(459320832l)
.type(Type.BUILTIN).hypervisor("VMware").domain("ROOT").domainId(1).extractable(true).build());
UnwrapOnlyNestedJsonValue<Set<Template>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyNestedJsonValue<Set<Template>>>() {
}));
Set<Template> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(Sets.newTreeSet(response), expects);
}
}

View File

@ -0,0 +1,104 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.cloudstack.domain.GuestIPType;
import org.jclouds.cloudstack.domain.NIC;
import org.jclouds.cloudstack.domain.TrafficType;
import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ListVirtualMachinesResponseTest {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
public void test() {
InputStream is = getClass().getResourceAsStream("/listvirtualmachinesresponse.json");
VirtualMachine expects = VirtualMachine
.builder()
.id(54)
.name("i-3-54-VM")
.displayName("i-3-54-VM")
.account("adrian")
.domainId(1)
.domain("ROOT")
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-16T14:28:37-0800"))
.state(VirtualMachine.State.STARTING)
.isHAEnabled(false)
.zoneId(1)
.zoneName("San Jose 1")
.templateId(2)
.templateName("CentOS 5.3(64-bit) no GUI (XenServer)")
.templateDisplayText("CentOS 5.3(64-bit) no GUI (XenServer)")
.passwordEnabled(false)
.serviceOfferingId(1)
.serviceOfferingName("Small Instance")
.cpuCount(1)
.cpuSpeed(500)
.memory(512)
.guestOSId(11)
.rootDeviceId(0)
.rootDeviceType("NetworkFilesystem")
.jobId(63l)
.jobStatus(0)
.nics(ImmutableSet.of(NIC.builder().id(72).networkId(204).netmask("255.255.255.0").gateway("10.1.1.1")
.IPAddress("10.1.1.18").trafficType(TrafficType.GUEST).guestIPType(GuestIPType.VIRTUAL)
.isDefault(true).build())).hypervisor("XenServer").build();
UnwrapOnlyNestedJsonValue<Set<VirtualMachine>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyNestedJsonValue<Set<VirtualMachine>>>() {
}));
Set<VirtualMachine> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(Iterables.getOnlyElement(response), expects);
}
}

View File

@ -0,0 +1,73 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import org.jclouds.cloudstack.domain.NetworkType;
import org.jclouds.cloudstack.domain.Zone;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ListZonesResponseTest {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
public void testAdvanced() {
Zone expects = Zone.builder().id(1).name("San Jose 1").networkType(NetworkType.ADVANCED).build();
UnwrapOnlyNestedJsonValue<Set<Zone>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyNestedJsonValue<Set<Zone>>>() {
}));
Set<Zone> response = parser
.apply(new HttpResponse(
200,
"ok",
Payloads
.newStringPayload("{ \"listzonesresponse\" : { \"zone\" : [ {\"id\":1,\"name\":\"San Jose 1\",\"networktype\":\"Advanced\"} ] } }")));
assertEquals(Iterables.getOnlyElement(response), expects);
}
}

View File

@ -0,0 +1 @@
{ "listdiskofferingsresponse" : { "diskoffering" : [ {"id":3,"domainid":1,"domain":"ROOT","name":"Small","displaytext":"Small Disk, 5 GB","disksize":5,"created":"2011-02-11T15:22:32-0800","iscustomized":false}, {"id":4,"domainid":1,"domain":"ROOT","name":"Medium","displaytext":"Medium Disk, 20 GB","disksize":20,"created":"2011-02-11T15:22:32-0800","iscustomized":false}, {"id":5,"domainid":1,"domain":"ROOT","name":"Large","displaytext":"Large Disk, 100 GB","disksize":100,"created":"2011-02-11T15:22:32-0800","iscustomized":false} ] } }

View File

@ -0,0 +1 @@
{ "listnetworkofferingsresponse" : { "networkoffering" : [ {"id":6,"name":"DefaultVirtualizedNetworkOffering","displaytext":"Virtual Vlan","traffictype":"Guest","isdefault":true,"specifyvlan":false,"availability":"Required","networkrate":200}, {"id":7,"name":"DefaultDirectNetworkOffering","displaytext":"Direct","traffictype":"Public","isdefault":true,"specifyvlan":false,"availability":"Required","networkrate":200} ] } }

View File

@ -0,0 +1 @@
{ "listnetworksresponse" : { "network" : [ {"id":204,"name":"Virtual Network","displaytext":"A dedicated virtualized network for your account. The broadcast domain is contained within a VLAN and all public network access is routed out by a virtual router.","broadcastdomaintype":"Vlan","traffictype":"Guest","zoneid":1,"networkofferingid":6,"networkofferingname":"DefaultVirtualizedNetworkOffering","networkofferingdisplaytext":"Virtual Vlan","networkofferingavailability":"Required","isshared":false,"issystem":false,"state":"Implemented","related":204,"broadcasturi":"vlan://240","dns1":"8.8.8.8","type":"Virtual","account":"adrian","domainid":1,"domain":"ROOT","isdefault":true,"service":[{"name":"Vpn","capability":[{"name":"SupportedVpnTypes","value":"pptp,l2tp,ipsec"}]},{"name":"Gateway"},{"name":"UserData"},{"name":"Dhcp"},{"name":"Firewall","capability":[{"name":"SupportedSourceNatTypes","value":"per account"},{"name":"StaticNat","value":"true"},{"name":"TrafficStatistics","value":"per public ip"},{"name":"PortForwarding","value":"true"},{"name":"MultipleIps","value":"true"},{"name":"SupportedProtocols","value":"tcp,udp"}]},{"name":"Dns"},{"name":"Lb","capability":[{"name":"SupportedLbAlgorithms","value":"roundrobin,leastconn,source"},{"name":"SupportedProtocols","value":"tcp, udp"}]}],"networkdomain":"cs3cloud.internal"} ] } }

View File

@ -0,0 +1 @@
{ "listserviceofferingsresponse" : { "serviceoffering" : [ {"id":1,"name":"Small Instance","displaytext":"Small Instance - 500 MhZ CPU, 512 MB RAM - $0.05 per hour","cpunumber":1,"cpuspeed":500,"memory":512,"created":"2011-02-11T15:22:32-0800","storagetype":"shared","offerha":false}, {"id":2,"name":"Medium Instance","displaytext":"Medium Instance, 1 GhZ CPU, 1 GB RAM - $0.10 per hour","cpunumber":1,"cpuspeed":1000,"memory":1024,"created":"2011-02-11T15:22:32-0800","storagetype":"shared","offerha":false} ] } }

View File

@ -0,0 +1 @@
{ "listtemplatesresponse" : { "template" : [ {"id":2,"name":"CentOS 5.3(64-bit) no GUI (XenServer)","displaytext":"CentOS 5.3(64-bit) no GUI (XenServer)","ispublic":true,"created":"2011-02-11T18:45:54-0800","isready":true,"passwordenabled":false,"format":"VHD","isfeatured":true,"crossZones":true,"ostypeid":11,"ostypename":"CentOS 5.3 (32-bit)","account":"system","zoneid":1,"zonename":"San Jose 1","size":8589934592,"templatetype":"BUILTIN","hypervisor":"XenServer","domain":"ROOT","domainid":1,"isextractable":true}, {"id":4,"name":"CentOS 5.5(64-bit) no GUI (KVM)","displaytext":"CentOS 5.5(64-bit) no GUI (KVM)","ispublic":true,"created":"2011-02-11T18:45:54-0800","isready":true,"passwordenabled":false,"format":"QCOW2","isfeatured":true,"crossZones":true,"ostypeid":112,"ostypename":"CentOS 5.5 (64-bit)","account":"system","zoneid":1,"zonename":"San Jose 1","size":8589934592,"templatetype":"BUILTIN","hypervisor":"KVM","domain":"ROOT","domainid":1,"isextractable":true}, {"id":7,"name":"CentOS 5.3(64-bit) no GUI (vSphere)","displaytext":"CentOS 5.3(64-bit) no GUI (vSphere)","ispublic":true,"created":"2011-02-11T18:45:54-0800","isready":true,"passwordenabled":false,"format":"OVA","isfeatured":true,"crossZones":true,"ostypeid":12,"ostypename":"CentOS 5.3 (64-bit)","account":"system","zoneid":1,"zonename":"San Jose 1","size":459320832,"templatetype":"BUILTIN","hypervisor":"VMware","domain":"ROOT","domainid":1,"isextractable":true} ] } }

View File

@ -0,0 +1 @@
{ "listvirtualmachinesresponse" : { "virtualmachine" : [ {"id":54,"name":"i-3-54-VM","displayname":"i-3-54-VM","account":"adrian","domainid":1,"domain":"ROOT","created":"2011-02-16T14:28:37-0800","state":"Starting","haenable":false,"zoneid":1,"zonename":"San Jose 1","templateid":2,"templatename":"CentOS 5.3(64-bit) no GUI (XenServer)","templatedisplaytext":"CentOS 5.3(64-bit) no GUI (XenServer)","passwordenabled":false,"serviceofferingid":1,"serviceofferingname":"Small Instance","cpunumber":1,"cpuspeed":500,"memory":512,"guestosid":11,"rootdeviceid":0,"rootdevicetype":"NetworkFilesystem","securitygroup":[],"jobid":63,"jobstatus":0,"nic":[{"id":72,"networkid":204,"netmask":"255.255.255.0","gateway":"10.1.1.1","ipaddress":"10.1.1.18","traffictype":"Guest","type":"Virtual","isdefault":true}],"hypervisor":"XenServer"} ] } }