diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java index b42611e49a..641ba83925 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java @@ -19,6 +19,8 @@ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Date; import java.util.Set; @@ -31,7 +33,73 @@ import com.google.gson.annotations.SerializedName; * * @author Adrian Cole */ -public class DiskOffering { +public class DiskOffering implements Comparable { + + 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 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 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 String name; @SerializedName("displaytext") @@ -47,7 +115,7 @@ public class DiskOffering { private String tags; public DiskOffering(long id, String name, String displayText, Date created, String domain, long domainId, - int diskSize, boolean customized, Set tags) { + int diskSize, boolean customized, Set tags) { this.id = id; this.name = name; this.displayText = displayText; @@ -56,7 +124,7 @@ public class DiskOffering { this.domainId = domainId; this.diskSize = diskSize; 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 public String toString() { return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created + ", diskSize=" - + diskSize + ", iscustomized=" + customized + ", domain=" + domain + ", domainId=" + domainId - + ", tags=" + tags + "]"; + + diskSize + ", iscustomized=" + customized + ", domain=" + domain + ", domainId=" + domainId + ", tags=" + + getTags() + "]"; + } + + @Override + public int compareTo(DiskOffering arg0) { + return new Long(id).compareTo(arg0.getId()); } } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java index 2c2cd443e8..c5ad45479e 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java @@ -29,14 +29,195 @@ import javax.annotation.Nullable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableList.Builder; import com.google.gson.annotations.SerializedName; /** * * @author Adrian Cole */ -public class Network { +public class Network implements Comparable { + 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 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 services = ImmutableSet. 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 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 services) { + this.services = ImmutableSet. 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 String account; @SerializedName("broadcastdomaintype") @@ -73,7 +254,7 @@ public class Network { private long networkOfferingId; @SerializedName("networkofferingname") private String networkOfferingName; - private String related; + private long related; @SerializedName("startip") private String startIP; private String name; @@ -100,7 +281,7 @@ public class Network { public Network(long id, String account, String broadcastDomainType, URI broadcastURI, String displayText, List DNS, String domain, long domainId, String endIP, String gateway, boolean isDefault, 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, long zoneId, Set services) { this.id = id; @@ -179,7 +360,7 @@ public class Network { * @return the external DNS for the network */ public List getDNS() { - Builder builder = ImmutableList.builder(); + ImmutableList.Builder builder = ImmutableList.builder(); if (DNS1 != null && !"".equals(DNS1)) builder.add(DNS1); if (DNS2 != null && !"".equals(DNS2)) @@ -336,7 +517,7 @@ public class Network { * * @return related to what other network configuration */ - public String getRelated() { + public long getRelated() { return related; } @@ -391,7 +572,7 @@ public class Network { result = prime * result + ((networkOfferingDisplayText == null) ? 0 : networkOfferingDisplayText.hashCode()); result = prime * result + (int) (networkOfferingId ^ (networkOfferingId >>> 32)); 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 + ((startIP == null) ? 0 : startIP.hashCode()); result = prime * result + ((state == null) ? 0 : state.hashCode()); @@ -503,10 +684,7 @@ public class Network { return false; } else if (!networkOfferingName.equals(other.networkOfferingName)) return false; - if (related == null) { - if (other.related != null) - return false; - } else if (!related.equals(other.related)) + if (related != other.related) return false; if (services == null) { if (other.services != null) @@ -543,4 +721,8 @@ public class Network { + ", networkOfferingName=" + networkOfferingName + "]"; } + @Override + public int compareTo(Network arg0) { + return new Long(id).compareTo(arg0.getId()); + } } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java index 78e49d3f16..c44b0b6740 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java @@ -19,6 +19,8 @@ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Date; import java.util.Set; @@ -33,7 +35,85 @@ import com.google.gson.annotations.SerializedName; * * @author Adrian Cole */ -public class NetworkOffering { +public class NetworkOffering implements Comparable { + 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 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 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 String name; @SerializedName("displaytext") @@ -48,11 +128,13 @@ public class NetworkOffering { private boolean supportsVLAN; @SerializedName("traffictype") private TrafficType trafficType; + @SerializedName("networkrate") + private int networkRate = -1; private String tags; public NetworkOffering(long id, String name, String displayText, @Nullable Date created, String availability, - boolean supportsVLAN, @Nullable Integer maxConnections, boolean isDefault, TrafficType trafficType, - Set tags) { + boolean supportsVLAN, @Nullable Integer maxConnections, boolean isDefault, TrafficType trafficType, + int networkRate, Set tags) { this.id = id; this.name = name; this.displayText = displayText; @@ -62,7 +144,8 @@ public class NetworkOffering { this.maxConnections = maxConnections; this.isDefault = isDefault; 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 data transfer rate in megabits per second allowed. + */ + public int getNetworkRate() { + return networkRate; + } + /** * * @return the tags for the network offering @@ -226,8 +317,13 @@ public class NetworkOffering { @Override public String toString() { return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created - + ", maxConnections=" + maxConnections + ", trafficType=" + trafficType + ", isDefault=" + isDefault - + ", availability=" + availability + ", supportsVLAN=" + supportsVLAN + ", tags=" + tags + "]"; + + ", maxConnections=" + maxConnections + ", trafficType=" + trafficType + ", isDefault=" + isDefault + + ", availability=" + availability + ", supportsVLAN=" + supportsVLAN + ", tags=" + getTags() + "]"; + } + + @Override + public int compareTo(NetworkOffering arg0) { + return new Long(id).compareTo(arg0.getId()); } } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkService.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkService.java index a1c4e6079e..02262ba3de 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkService.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkService.java @@ -21,8 +21,12 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Map; +import java.util.Map.Entry; 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.gson.annotations.SerializedName; @@ -31,26 +35,19 @@ import com.google.gson.annotations.SerializedName; * @author Adrian Cole */ public class NetworkService { - public static class Capability { + // internal only to match json type + private static class Capability { private String name; private String value; - Capability() { + private Capability() { } - public Capability(String name, String value) { - this.name = checkNotNull(name, "name"); - this.value = checkNotNull(value, "value"); - } - - public String getName() { - return name; - } - - public String getValue() { - return value; + private Capability(String name, String value) { + this.name = name; + this.value = value; } @Override @@ -99,17 +96,28 @@ public class NetworkService { } - public NetworkService(String name, Set capabilities) { + public NetworkService(String name) { + this(name, ImmutableMap. of()); + } + + public NetworkService(String name, Map capabilities) { this.name = checkNotNull(name, "name"); - this.capabilities = ImmutableSet.copyOf(checkNotNull(capabilities, "capabilities")); + ImmutableSet.Builder internal = ImmutableSet. builder(); + for (Entry capabililty : checkNotNull(capabilities, "capabilities").entrySet()) + internal.add(new Capability(capabililty.getKey(), capabililty.getValue())); + this.capabilities = internal.build(); } public String getName() { return name; } - public Set getCapabilities() { - return capabilities; + public Map getCapabilities() { + Builder returnVal = ImmutableMap. builder(); + for (Capability capability : capabilities) { + returnVal.put(capability.name, capability.value); + } + return returnVal.build(); } @Override diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java index 2883998d33..45ce8ffa4b 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java @@ -30,7 +30,7 @@ import com.google.gson.annotations.SerializedName; * * @author Adrian Cole */ -public class SecurityGroup { +public class SecurityGroup implements Comparable { private long id; private String account; private String name; @@ -178,4 +178,8 @@ public class SecurityGroup { + domain + ", domainId=" + domainId + ", ingressRules=" + ingressRules + "]"; } + @Override + public int compareTo(SecurityGroup arg0) { + return new Long(id).compareTo(arg0.getId()); + } } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java index 48a98bfe4c..9e63037ca7 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java @@ -19,6 +19,8 @@ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Date; import java.util.Set; @@ -31,7 +33,92 @@ import com.google.gson.annotations.SerializedName; * * @author Adrian Cole */ -public class ServiceOffering { +public class ServiceOffering implements Comparable { + 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 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 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 String name; @SerializedName("displaytext") @@ -52,7 +139,7 @@ public class ServiceOffering { private String tags; 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 tags) { + int cpuNumber, int cpuSpeed, int memory, boolean haSupport, StorageType storageType, Set tags) { this.id = id; this.name = name; this.displayText = displayText; @@ -64,7 +151,7 @@ public class ServiceOffering { this.memory = memory; this.haSupport = haSupport; 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 public String toString() { return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created + ", cpuNumber=" - + cpuNumber + ", cpuSpeed=" + cpuSpeed + ", memory=" + memory + ", storageType=" + storageType - + ", haSupport=" + haSupport + ", domain=" + domain + ", domainId=" + domainId + ", tags=" + tags + "]"; + + cpuNumber + ", cpuSpeed=" + cpuSpeed + ", memory=" + memory + ", storageType=" + storageType + + ", haSupport=" + haSupport + ", domain=" + domain + ", domainId=" + domainId + ", tags=" + getTags() + + "]"; + } + + @Override + public int compareTo(ServiceOffering arg0) { + return new Long(id).compareTo(arg0.getId()); } } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java index ed7f6ad0cb..79c69010d7 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java @@ -19,9 +19,10 @@ package org.jclouds.cloudstack.domain; -import java.util.Date; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Date; + import javax.annotation.Nullable; import com.google.gson.annotations.SerializedName; @@ -30,7 +31,200 @@ import com.google.gson.annotations.SerializedName; * * @author Adrian Cole */ -public class Template { +public class Template implements Comparable