diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindTemplateMetadataToQueryParams.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindTemplateMetadataToQueryParams.java index db265ce7a9..11c39078e5 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindTemplateMetadataToQueryParams.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindTemplateMetadataToQueryParams.java @@ -57,8 +57,8 @@ public class BindTemplateMetadataToQueryParams implements Binder { if (metadata.getVirtualMachineId() != null) { request = ModifyRequest.addQueryParam(request, "virtualmachineid", metadata.getVirtualMachineId(), uriBuilderProvider.get()); } - if (metadata.getPasswordEnabled() != null) { - request = ModifyRequest.addQueryParam(request, "passwordenabled", metadata.getPasswordEnabled(), uriBuilderProvider.get()); + if (metadata.isPasswordEnabled() != null) { + request = ModifyRequest.addQueryParam(request, "passwordenabled", metadata.isPasswordEnabled(), uriBuilderProvider.get()); } return request; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Account.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Account.java index 33dae7d1ca..0cd19c6f5c 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Account.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Account.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,207 +20,31 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Map; import java.util.Set; -import javax.annotation.Nullable; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; import com.google.common.base.CaseFormat; import com.google.common.base.Function; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ForwardingSet; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; -import com.google.gson.annotations.SerializedName; /** + * Class Account + * * @author Adrian Cole */ -public class Account extends ForwardingSet implements Comparable { - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String id; - private Type type; - private String networkDomain; - private String domain; - private String domainId; - private Long IPsAvailable; - private Long IPLimit; - private long IPs; - private boolean cleanupRequired; - private String name; - private long receivedBytes; - private long sentBytes; - private Long snapshotsAvailable; - private Long snapshotLimit; - private long snapshots; - private State state; - private Long templatesAvailable; - private Long templateLimit; - private long templates; - private Long VMsAvailable; - private Long VMLimit; - private long VMsRunning; - private long VMsStopped; - private long VMs; - private Long volumesAvailable; - private Long volumeLimit; - private long volumes; - private Set users = ImmutableSet.of(); - - public Builder id(String id) { - this.id = id; - return this; - } - - public Builder type(Type type) { - this.type = type; - return this; - } - - public Builder networkDomain(String networkDomain) { - this.networkDomain = networkDomain; - return this; - } - - public Builder domain(String domain) { - this.domain = domain; - return this; - } - - public Builder domainId(String domainId) { - this.domainId = domainId; - return this; - } - - public Builder IPsAvailable(Long IPsAvailable) { - this.IPsAvailable = IPsAvailable; - return this; - } - - public Builder IPLimit(Long IPLimit) { - this.IPLimit = IPLimit; - return this; - } - - public Builder IPs(long IPs) { - this.IPs = IPs; - return this; - } - - public Builder cleanupRequired(boolean cleanupRequired) { - this.cleanupRequired = cleanupRequired; - return this; - } - - public Builder name(String name) { - this.name = name; - return this; - } - - public Builder receivedBytes(long receivedBytes) { - this.receivedBytes = receivedBytes; - return this; - } - - public Builder sentBytes(long sentBytes) { - this.sentBytes = sentBytes; - return this; - } - - public Builder snapshotsAvailable(Long snapshotsAvailable) { - this.snapshotsAvailable = snapshotsAvailable; - return this; - } - - public Builder snapshotLimit(Long snapshotLimit) { - this.snapshotLimit = snapshotLimit; - return this; - } - - public Builder snapshots(long snapshots) { - this.snapshots = snapshots; - return this; - } - - public Builder state(State state) { - this.state = state; - return this; - } - - public Builder templatesAvailable(Long templatesAvailable) { - this.templatesAvailable = templatesAvailable; - return this; - } - - public Builder templateLimit(Long templateLimit) { - this.templateLimit = templateLimit; - return this; - } - - public Builder templates(long templates) { - this.templates = templates; - return this; - } - - public Builder VMsAvailable(Long VMsAvailable) { - this.VMsAvailable = VMsAvailable; - return this; - } - - public Builder VMLimit(Long VMLimit) { - this.VMLimit = VMLimit; - return this; - } - - public Builder VMsRunning(long VMsRunning) { - this.VMsRunning = VMsRunning; - return this; - } - - public Builder VMsStopped(long VMsStopped) { - this.VMsStopped = VMsStopped; - return this; - } - - public Builder VMs(long VMs) { - this.VMs = VMs; - return this; - } - - public Builder volumesAvailable(Long volumesAvailable) { - this.volumesAvailable = volumesAvailable; - return this; - } - - public Builder volumeLimit(Long volumeLimit) { - this.volumeLimit = volumeLimit; - return this; - } - - public Builder volumes(long volumes) { - this.volumes = volumes; - return this; - } - - public Builder users(Set users) { - this.users = ImmutableSet.copyOf(checkNotNull(users, "users")); - return this; - } - - public Account build() { - return new Account(id, type, networkDomain, domain, domainId, IPsAvailable, IPLimit, IPs, cleanupRequired, name, - receivedBytes, sentBytes, snapshotsAvailable, snapshotLimit, snapshots, state, templatesAvailable, - templateLimit, templates, VMsAvailable, VMLimit, VMsRunning, VMsStopped, VMs, volumesAvailable, - volumeLimit, volumes, users); - } - - } +public class Account extends ForwardingSet { + /** + */ public static enum State { ENABLED, DISABLED, LOCKED, UNRECOGNIZED; @@ -239,6 +63,8 @@ public class Account extends ForwardingSet implements Comparable } + /** + */ public static enum Type { /** * API access for all the resources associated with their account. There @@ -285,71 +111,386 @@ public class Account extends ForwardingSet implements Comparable } - private String id; - @SerializedName("accounttype") - private Type type; - @SerializedName("networkdomain") - private String networkDomain; - private String domain; - @SerializedName("domainId") - private String domainId; - @SerializedName("ipsavailable") - private Long IPsAvailable; - @SerializedName("iplimit") - private Long IPLimit; - @SerializedName("iptotal") - private long IPs; - @SerializedName("iscleanuprequired") - private boolean cleanupRequired; - private String name; - @SerializedName("receivedbytes") - private long receivedBytes; - @SerializedName("sentbytes") - private long sentBytes; - @SerializedName("snapshotavailable") - private Long snapshotsAvailable; - @SerializedName("snapshotLimit") - private Long snapshotLimit; - @SerializedName("snapshottotal") - private long snapshots; - private State state; - @SerializedName("templateavailable") - private Long templatesAvailable; - @SerializedName("templatelimit") - private Long templateLimit; - @SerializedName("templatetotal") - private long templates; - @SerializedName("vmavailable") - private Long VMsAvailable; - @SerializedName("vmlimit") - private Long VMLimit; - @SerializedName("vmrunning") - private long VMsRunning; - @SerializedName("vmstopped") - private long VMsStopped; - @SerializedName("vmtotal") - private long VMs; - @SerializedName("volumeavailable") - private Long volumesAvailable; - @SerializedName("volumelimit") - private Long volumeLimit; - @SerializedName("volumetotal") - private long volumes; - private Set users; + public static Builder builder() { + return new ConcreteBuilder(); + } - public Account(String id, Type type, String networkDomain, String domain, String domainId, Long IPsAvailable, Long IPLimit, long iPs, - boolean cleanupRequired, String name, long receivedBytes, long sentBytes, Long snapshotsAvailable, - Long snapshotLimit, long snapshots, org.jclouds.cloudstack.domain.Account.State state, - Long templatesAvailable, Long templateLimit, long templates, Long VMsAvailable, Long VMLimit, long vMsRunning, - long vMsStopped, long vMs, Long volumesAvailable, Long volumeLimit, long volumes, Set users) { - this.id = id; + public Builder toBuilder() { + return new ConcreteBuilder().fromAccount(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected Account.Type type; + protected String networkDomain; + protected String domain; + protected String domainId; + protected Long IPsAvailable; + protected Long IPLimit; + protected long IPs; + protected boolean cleanupRequired; + protected String name; + protected long receivedBytes; + protected long sentBytes; + protected Long snapshotsAvailable; + protected Long snapshotLimit; + protected long snapshots; + protected Account.State state; + protected Long templatesAvailable; + protected Long templateLimit; + protected long templates; + protected Long VMsAvailable; + protected Long VMLimit; + protected long VMsRunning; + protected long VMsStopped; + protected long VMs; + protected Long volumesAvailable; + protected Long volumeLimit; + protected long volumes; + protected Set users = ImmutableSet.of(); + + /** + * @see Account#getId() + */ + public T id(String id) { + this.id = id; + return self(); + } + + /** + * @see Account#getType() + */ + public T type(Account.Type type) { + this.type = type; + return self(); + } + + /** + * @see Account#getNetworkDomain() + */ + public T networkDomain(String networkDomain) { + this.networkDomain = networkDomain; + return self(); + } + + /** + * @see Account#getDomain() + */ + public T domain(String domain) { + this.domain = domain; + return self(); + } + + /** + * @see Account#getDomainId() + */ + public T domainId(String domainId) { + this.domainId = domainId; + return self(); + } + + /** + * @see Account#getIPsAvailable() + */ + public T IPsAvailable(Long IPsAvailable) { + this.IPsAvailable = IPsAvailable; + return self(); + } + + /** + * @see Account#getIPLimit() + */ + public T IPLimit(Long IPLimit) { + this.IPLimit = IPLimit; + return self(); + } + + /** + * @see Account#getIPs() + */ + public T IPs(long IPs) { + this.IPs = IPs; + return self(); + } + + /** + * @see Account#isCleanupRequired() + */ + public T cleanupRequired(boolean cleanupRequired) { + this.cleanupRequired = cleanupRequired; + return self(); + } + + /** + * @see Account#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + /** + * @see Account#getReceivedBytes() + */ + public T receivedBytes(long receivedBytes) { + this.receivedBytes = receivedBytes; + return self(); + } + + /** + * @see Account#getSentBytes() + */ + public T sentBytes(long sentBytes) { + this.sentBytes = sentBytes; + return self(); + } + + /** + * @see Account#getSnapshotsAvailable() + */ + public T snapshotsAvailable(Long snapshotsAvailable) { + this.snapshotsAvailable = snapshotsAvailable; + return self(); + } + + /** + * @see Account#getSnapshotLimit() + */ + public T snapshotLimit(Long snapshotLimit) { + this.snapshotLimit = snapshotLimit; + return self(); + } + + /** + * @see Account#getSnapshots() + */ + public T snapshots(long snapshots) { + this.snapshots = snapshots; + return self(); + } + + /** + * @see Account#getState() + */ + public T state(Account.State state) { + this.state = state; + return self(); + } + + /** + * @see Account#getTemplatesAvailable() + */ + public T templatesAvailable(Long templatesAvailable) { + this.templatesAvailable = templatesAvailable; + return self(); + } + + /** + * @see Account#getTemplateLimit() + */ + public T templateLimit(Long templateLimit) { + this.templateLimit = templateLimit; + return self(); + } + + /** + * @see Account#getTemplates() + */ + public T templates(long templates) { + this.templates = templates; + return self(); + } + + /** + * @see Account#getVMsAvailable() + */ + public T VMsAvailable(Long VMsAvailable) { + this.VMsAvailable = VMsAvailable; + return self(); + } + + /** + * @see Account#getVMLimit() + */ + public T VMLimit(Long VMLimit) { + this.VMLimit = VMLimit; + return self(); + } + + /** + * @see Account#getVMsRunning() + */ + public T VMsRunning(long VMsRunning) { + this.VMsRunning = VMsRunning; + return self(); + } + + /** + * @see Account#getVMsStopped() + */ + public T VMsStopped(long VMsStopped) { + this.VMsStopped = VMsStopped; + return self(); + } + + /** + * @see Account#getVMs() + */ + public T VMs(long VMs) { + this.VMs = VMs; + return self(); + } + + /** + * @see Account#getVolumesAvailable() + */ + public T volumesAvailable(Long volumesAvailable) { + this.volumesAvailable = volumesAvailable; + return self(); + } + + /** + * @see Account#getVolumeLimit() + */ + public T volumeLimit(Long volumeLimit) { + this.volumeLimit = volumeLimit; + return self(); + } + + /** + * @see Account#getVolumes() + */ + public T volumes(long volumes) { + this.volumes = volumes; + return self(); + } + + /** + * @see Account#getUsers() + */ + public T users(Set users) { + this.users = ImmutableSet.copyOf(checkNotNull(users, "users")); + return self(); + } + + public T users(User... in) { + return users(ImmutableSet.copyOf(in)); + } + + public Account build() { + return new Account(id, type, networkDomain, domain, domainId, IPsAvailable, IPLimit, IPs, cleanupRequired, name, receivedBytes, sentBytes, snapshotsAvailable, snapshotLimit, snapshots, state, templatesAvailable, templateLimit, templates, VMsAvailable, VMLimit, VMsRunning, VMsStopped, VMs, volumesAvailable, volumeLimit, volumes, users); + } + + public T fromAccount(Account in) { + return this + .id(in.getId()) + .type(in.getType()) + .networkDomain(in.getNetworkDomain()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .IPsAvailable(in.getIPsAvailable()) + .IPLimit(in.getIPLimit()) + .IPs(in.getIPs()) + .cleanupRequired(in.isCleanupRequired()) + .name(in.getName()) + .receivedBytes(in.getReceivedBytes()) + .sentBytes(in.getSentBytes()) + .snapshotsAvailable(in.getSnapshotsAvailable()) + .snapshotLimit(in.getSnapshotLimit()) + .snapshots(in.getSnapshots()) + .state(in.getState()) + .templatesAvailable(in.getTemplatesAvailable()) + .templateLimit(in.getTemplateLimit()) + .templates(in.getTemplates()) + .VMsAvailable(in.getVMsAvailable()) + .VMLimit(in.getVMLimit()) + .VMsRunning(in.getVMsRunning()) + .VMsStopped(in.getVMsStopped()) + .VMs(in.getVMs()) + .volumesAvailable(in.getVolumesAvailable()) + .volumeLimit(in.getVolumeLimit()) + .volumes(in.getVolumes()) + .users(in.getUsers()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + @Named("accounttype") + private final Account.Type type; + @Named("networkdomain") + private final String networkDomain; + private final String domain; + private final String domainId; + @Named("ipsavailable") + private final Long IPsAvailable; + @Named("iplimit") + private final Long IPLimit; + @Named("iptotal") + private final long IPs; + @Named("iscleanuprequired") + private final boolean cleanupRequired; + private final String name; + @Named("receivedbytes") + private final long receivedBytes; + @Named("sentbytes") + private final long sentBytes; + @Named("snapshotavailable") + private final Long snapshotsAvailable; + private final Long snapshotLimit; + @Named("snapshottotal") + private final long snapshots; + private final Account.State state; + @Named("templateavailable") + private final Long templatesAvailable; + @Named("templatelimit") + private final Long templateLimit; + @Named("templatetotal") + private final long templates; + @Named("vmavailable") + private final Long VMsAvailable; + @Named("vmlimit") + private final Long VMLimit; + @Named("vmrunning") + private final long VMsRunning; + @Named("vmstopped") + private final long VMsStopped; + @Named("vmtotal") + private final long VMs; + @Named("volumeavailable") + private final Long volumesAvailable; + @Named("volumelimit") + private final Long volumeLimit; + @Named("volumetotal") + private final long volumes; + private final Set users; + + @ConstructorProperties({ + "id", "accounttype", "networkdomain", "domain", "domainId", "ipsavailable", "iplimit", "iptotal", "iscleanuprequired", "name", "receivedbytes", "sentbytes", "snapshotavailable", "snapshotLimit", "snapshottotal", "state", "templateavailable", "templatelimit", "templatetotal", "vmavailable", "vmlimit", "vmrunning", "vmstopped", "vmtotal", "volumeavailable", "volumelimit", "volumetotal", "users" + }) + protected Account(String id, @Nullable Account.Type type, @Nullable String networkDomain, @Nullable String domain, + @Nullable String domainId, @Nullable Long IPsAvailable, @Nullable Long IPLimit, long IPs, + boolean cleanupRequired, @Nullable String name, long receivedBytes, long sentBytes, @Nullable Long snapshotsAvailable, + @Nullable Long snapshotLimit, long snapshots, @Nullable Account.State state, @Nullable Long templatesAvailable, + @Nullable Long templateLimit, long templates, @Nullable Long VMsAvailable, @Nullable Long VMLimit, long VMsRunning, + long VMsStopped, long VMs, @Nullable Long volumesAvailable, @Nullable Long volumeLimit, long volumes, + @Nullable Set users) { + this.id = checkNotNull(id, "id"); this.type = type; this.networkDomain = networkDomain; this.domain = domain; this.domainId = domainId; this.IPsAvailable = IPsAvailable; this.IPLimit = IPLimit; - this.IPs = iPs; + this.IPs = IPs; this.cleanupRequired = cleanupRequired; this.name = name; this.receivedBytes = receivedBytes; @@ -363,213 +504,204 @@ public class Account extends ForwardingSet implements Comparable this.templates = templates; this.VMsAvailable = VMsAvailable; this.VMLimit = VMLimit; - this.VMsRunning = vMsRunning; - this.VMsStopped = vMsStopped; - this.VMs = vMs; + this.VMsRunning = VMsRunning; + this.VMsStopped = VMsStopped; + this.VMs = VMs; this.volumesAvailable = volumesAvailable; this.volumeLimit = volumeLimit; this.volumes = volumes; - this.users = ImmutableSet.copyOf(checkNotNull(users, "users")); - } - - /** - * present only for serializer - */ - Account() { - + this.users = users == null ? ImmutableSet.of() : ImmutableSet.copyOf(users); } /** * @return the id of the account */ public String getId() { - return id; - } - - /** - * @return the name of the account - */ - - public String getName() { - return name; + return this.id; } /** * @return account type (admin, domain-admin, user) */ - public Type getType() { - return type; + @Nullable + public Account.Type getType() { + return this.type; } /** * @return the network domain */ + @Nullable public String getNetworkDomain() { - return networkDomain; + return this.networkDomain; } /** * @return name of the Domain the account belongs to */ + @Nullable public String getDomain() { - return domain; + return this.domain; } /** * @return id of the Domain the account belongs to */ + @Nullable public String getDomainId() { - return domainId; - } - - /** - * @return true if the account requires cleanup - */ - public boolean isCleanupRequired() { - return cleanupRequired; - } - - /** - * @return the list of users associated with account - */ - public Set getUsers() { - return users; + return this.domainId; } /** * @return the total number of public ip addresses available for this account - * to acquire, or null if unlimited + to acquire, or null if unlimited */ @Nullable public Long getIPsAvailable() { - return IPsAvailable; + return this.IPsAvailable; } /** * @return the total number of public ip addresses this account can acquire, - * or null if unlimited + or null if unlimited */ @Nullable public Long getIPLimit() { - return IPLimit; + return this.IPLimit; } /** * @return the total number of public ip addresses allocated for this account */ public long getIPs() { - return IPs; + return this.IPs; + } + + /** + * @return true if the account requires cleanup + */ + public boolean isCleanupRequired() { + return this.cleanupRequired; + } + + /** + * @return the name of the account + */ + @Nullable + public String getName() { + return this.name; } /** * @return the total number of network traffic bytes received */ public long getReceivedBytes() { - return receivedBytes; + return this.receivedBytes; } /** * @return the total number of network traffic bytes sent */ public long getSentBytes() { - return sentBytes; + return this.sentBytes; } /** * @return the total number of snapshots available for this account, or null - * if unlimited + if unlimited */ @Nullable public Long getSnapshotsAvailable() { - return snapshotsAvailable; + return this.snapshotsAvailable; } /** * @return the total number of snapshots which can be stored by this account, - * or null if unlimited + or null if unlimited */ @Nullable public Long getSnapshotLimit() { - return snapshotLimit; + return this.snapshotLimit; } /** * @return the total number of snapshots stored by this account */ public long getSnapshots() { - return snapshots; + return this.snapshots; } /** * @return the state of the account */ + @Nullable public State getState() { - return state; + return this.state; } /** * @return the total number of templates available to be created by this - * account, or null if unlimited + account, or null if unlimited */ @Nullable public Long getTemplatesAvailable() { - return templatesAvailable; + return this.templatesAvailable; } /** * @return the total number of templates which can be created by this - * account, or null if unlimited + account, or null if unlimited */ @Nullable public Long getTemplateLimit() { - return templateLimit; + return this.templateLimit; } /** * @return the total number of templates which have been created by this - * account + account */ public long getTemplates() { - return templates; + return this.templates; } /** * @return the total number of virtual machines available for this account to - * acquire, or null if unlimited + acquire, or null if unlimited */ @Nullable public Long getVMsAvailable() { - return VMsAvailable; + return this.VMsAvailable; } /** * @return the total number of virtual machines that can be deployed by this - * account, or null if unlimited + account, or null if unlimited */ @Nullable public Long getVMLimit() { - return VMLimit; + return this.VMLimit; } /** * @return the total number of virtual machines running for this account */ public long getVMsRunning() { - return VMsRunning; + return this.VMsRunning; } /** * @return the total number of virtual machines stopped for this account */ public long getVMsStopped() { - return VMsStopped; + return this.VMsStopped; } /** * @return the total number of virtual machines deployed by this account */ public long getVMs() { - return VMs; + return this.VMs; } /** @@ -577,88 +709,85 @@ public class Account extends ForwardingSet implements Comparable */ @Nullable public Long getVolumesAvailable() { - return volumesAvailable; + return this.volumesAvailable; } /** * @return the total volume which can be used by this account, or null if - * unlimited + unlimited */ @Nullable public Long getVolumeLimit() { - return volumeLimit; + return this.volumeLimit; } /** * @return the total volume being used by this account */ public long getVolumes() { - return volumes; + return this.volumes; } - @Override - public int compareTo(Account arg0) { - return id.compareTo(arg0.getId()); - } - - - @Override - public String toString() { - return "Account{" + - "id=" + id + - ", type=" + type + - ", networkDomain='" + networkDomain + '\'' + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", IPsAvailable=" + IPsAvailable + - ", IPLimit=" + IPLimit + - ", IPs=" + IPs + - ", cleanupRequired=" + cleanupRequired + - ", name='" + name + '\'' + - ", receivedBytes=" + receivedBytes + - ", sentBytes=" + sentBytes + - ", snapshotsAvailable=" + snapshotsAvailable + - ", snapshotLimit=" + snapshotLimit + - ", snapshots=" + snapshots + - ", state=" + state + - ", templatesAvailable=" + templatesAvailable + - ", templateLimit=" + templateLimit + - ", templates=" + templates + - ", VMsAvailable=" + VMsAvailable + - ", VMLimit=" + VMLimit + - ", VMsRunning=" + VMsRunning + - ", VMsStopped=" + VMsStopped + - ", VMs=" + VMs + - ", volumesAvailable=" + volumesAvailable + - ", volumeLimit=" + volumeLimit + - ", volumes=" + volumes + - ", users=" + users + - '}'; - } - - @Override - public int hashCode() { - return Objects.hashCode(domainId, id, name); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Account that = (Account) obj; - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(name, that.name)) return false; - - return true; + /** + * @return the list of users associated with account + */ + public Set getUsers() { + return this.users; } @Override protected Set delegate() { - return users; + return this.users; } + + @Override + public int hashCode() { + return Objects.hashCode(id, type, networkDomain, domain, domainId, IPsAvailable, IPLimit, IPs, cleanupRequired, name, receivedBytes, sentBytes, snapshotsAvailable, snapshotLimit, snapshots, state, templatesAvailable, templateLimit, templates, VMsAvailable, VMLimit, VMsRunning, VMsStopped, VMs, volumesAvailable, volumeLimit, volumes, users); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Account that = Account.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.type, that.type) + && Objects.equal(this.networkDomain, that.networkDomain) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.IPsAvailable, that.IPsAvailable) + && Objects.equal(this.IPLimit, that.IPLimit) + && Objects.equal(this.IPs, that.IPs) + && Objects.equal(this.cleanupRequired, that.cleanupRequired) + && Objects.equal(this.name, that.name) + && Objects.equal(this.receivedBytes, that.receivedBytes) + && Objects.equal(this.sentBytes, that.sentBytes) + && Objects.equal(this.snapshotsAvailable, that.snapshotsAvailable) + && Objects.equal(this.snapshotLimit, that.snapshotLimit) + && Objects.equal(this.snapshots, that.snapshots) + && Objects.equal(this.state, that.state) + && Objects.equal(this.templatesAvailable, that.templatesAvailable) + && Objects.equal(this.templateLimit, that.templateLimit) + && Objects.equal(this.templates, that.templates) + && Objects.equal(this.VMsAvailable, that.VMsAvailable) + && Objects.equal(this.VMLimit, that.VMLimit) + && Objects.equal(this.VMsRunning, that.VMsRunning) + && Objects.equal(this.VMsStopped, that.VMsStopped) + && Objects.equal(this.VMs, that.VMs) + && Objects.equal(this.volumesAvailable, that.volumesAvailable) + && Objects.equal(this.volumeLimit, that.volumeLimit) + && Objects.equal(this.volumes, that.volumes) + && Objects.equal(this.users, that.users); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("type", type).add("networkDomain", networkDomain).add("domain", domain).add("domainId", domainId).add("IPsAvailable", IPsAvailable).add("IPLimit", IPLimit).add("IPs", IPs).add("cleanupRequired", cleanupRequired).add("name", name).add("receivedBytes", receivedBytes).add("sentBytes", sentBytes).add("snapshotsAvailable", snapshotsAvailable).add("snapshotLimit", snapshotLimit).add("snapshots", snapshots).add("state", state).add("templatesAvailable", templatesAvailable).add("templateLimit", templateLimit).add("templates", templates).add("VMsAvailable", VMsAvailable).add("VMLimit", VMLimit).add("VMsRunning", VMsRunning).add("VMsStopped", VMsStopped).add("VMs", VMs).add("volumesAvailable", volumesAvailable).add("volumeLimit", volumeLimit).add("volumes", volumes).add("users", users); + } + + @Override + public String toString() { + return string().toString(); + } + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Alert.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Alert.java index 88ee6bb564..c28d0e0cd9 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Alert.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Alert.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,117 +18,149 @@ */ package org.jclouds.cloudstack.domain; -import com.google.common.base.Objects; +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + /** * Represents an alert issued by Cloudstack * * @author Richard Downer */ -public class Alert implements Comparable { +public class Alert { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { - private String id; - private String description; - private Date sent; - private String type; + public Builder toBuilder() { + return new ConcreteBuilder().fromAlert(this); + } - public Builder id(String id) { + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected String description; + protected Date sent; + protected String type; + + /** + * @see Alert#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder description(String description) { + /** + * @see Alert#getDescription() + */ + public T description(String description) { this.description = description; - return this; + return self(); } - public Builder sent(Date sent) { + /** + * @see Alert#getSent() + */ + public T sent(Date sent) { this.sent = sent; - return this; + return self(); } - public Builder type(String type) { + /** + * @see Alert#getType() + */ + public T type(String type) { this.type = type; - return this; + return self(); } public Alert build() { return new Alert(id, description, sent, type); } + + public T fromAlert(Alert in) { + return this + .id(in.getId()) + .description(in.getDescription()) + .sent(in.getSent()) + .type(in.getType()); + } } - private String id; - private String description; - private Date sent; - private String type; - - /* exists for the deserializer, only */ - Alert() { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - private Alert(String id, String description, Date sent, String type) { - this.id = id; + private final String id; + private final String description; + private final Date sent; + private final String type; + + @ConstructorProperties({ + "id", "description", "sent", "type" + }) + protected Alert(String id, @Nullable String description, @Nullable Date sent, @Nullable String type) { + this.id = checkNotNull(id, "id"); this.description = description; this.sent = sent; this.type = type; } public String getId() { - return id; + return this.id; } + @Nullable public String getDescription() { - return description; + return this.description; } + @Nullable public Date getSent() { - return sent; + return this.sent; } + @Nullable public String getType() { - return type; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Alert that = (Alert) o; - - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(description, that.description)) return false; - if (!Objects.equal(sent, that.sent)) return false; - if (!Objects.equal(type, that.type)) return false; - - return true; + return this.type; } @Override public int hashCode() { - return Objects.hashCode(id, description, sent, type); + return Objects.hashCode(id, description, sent, type); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Alert that = Alert.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.description, that.description) + && Objects.equal(this.sent, that.sent) + && Objects.equal(this.type, that.type); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("description", description).add("sent", sent).add("type", type); + } @Override public String toString() { - return "Alert{" + - "id=" + id + - ", description='" + description + '\'' + - ", sent=" + sent + - ", type='" + type + '\'' + - '}'; + return string().toString(); } - @Override - public int compareTo(Alert other) { - return this.getId().compareTo(other.getId()); - } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ApiKeyPair.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ApiKeyPair.java index 4851c133a3..659e4f837e 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ApiKeyPair.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ApiKeyPair.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,94 +16,117 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.cloudstack.domain; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * Representation of the API keypair response * * @author Andrei Savu */ -public class ApiKeyPair implements Comparable { +public class ApiKeyPair { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { + public Builder toBuilder() { + return new ConcreteBuilder().fromApiKeyPair(this); + } - private String apiKey; - private String secretKey; + public static abstract class Builder> { + protected abstract T self(); - public Builder apiKey(String apiKey) { + protected String apiKey; + protected String secretKey; + + /** + * @see ApiKeyPair#getApiKey() + */ + public T apiKey(String apiKey) { this.apiKey = apiKey; - return this; + return self(); } - public Builder secretKey(String secretKey) { + /** + * @see ApiKeyPair#getSecretKey() + */ + public T secretKey(String secretKey) { this.secretKey = secretKey; - return this; + return self(); } public ApiKeyPair build() { return new ApiKeyPair(apiKey, secretKey); } + + public T fromApiKeyPair(ApiKeyPair in) { + return this + .apiKey(in.getApiKey()) + .secretKey(in.getSecretKey()); + } } - // for deserialization - ApiKeyPair() { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - @SerializedName("apikey") - private String apiKey; - @SerializedName("secretkey") - private String secretKey; + @Named("apikey") + private final String apiKey; + @Named("secretkey") + private final String secretKey; - public ApiKeyPair(String apiKey, String secretKey) { + @ConstructorProperties({ + "apikey", "secretkey" + }) + protected ApiKeyPair(@Nullable String apiKey, @Nullable String secretKey) { this.apiKey = apiKey; this.secretKey = secretKey; } - public String getSecretKey() { - return secretKey; - } - + @Nullable public String getApiKey() { - return apiKey; + return this.apiKey; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ApiKeyPair that = (ApiKeyPair) o; - - if (!Objects.equal(apiKey, that.apiKey)) return false; - if (!Objects.equal(secretKey, that.secretKey)) return false; - - return true; + @Nullable + public String getSecretKey() { + return this.secretKey; } @Override public int hashCode() { - return Objects.hashCode(apiKey, secretKey); + return Objects.hashCode(apiKey, secretKey); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ApiKeyPair that = ApiKeyPair.class.cast(obj); + return Objects.equal(this.apiKey, that.apiKey) + && Objects.equal(this.secretKey, that.secretKey); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("apiKey", apiKey).add("secretKey", secretKey); } @Override public String toString() { - return "ApiKeyPair{" + - "apiKey='" + apiKey + '\'' + - ", secretKey='" + secretKey + '\'' + - '}'; - } - - @Override - public int compareTo(ApiKeyPair arg0) { - return apiKey.compareTo(arg0.getApiKey()); + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncCreateResponse.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncCreateResponse.java index 3c2ed009ca..613adfc9bc 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncCreateResponse.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncCreateResponse.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,29 +18,79 @@ */ package org.jclouds.cloudstack.domain; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** - * + * Class AsyncCreateResponse + * * @author Adrian Cole */ public class AsyncCreateResponse { - public static final AsyncCreateResponse UNINITIALIZED = new AsyncCreateResponse(); - - private String id; - @SerializedName("jobid") - private String jobId; - - /** - * present only for serializer - * - */ - AsyncCreateResponse() { + public static final AsyncCreateResponse UNINITIALIZED = new AsyncCreateResponse(null, null); + public static Builder builder() { + return new ConcreteBuilder(); } - public AsyncCreateResponse(String id, String jobId) { + public Builder toBuilder() { + return new ConcreteBuilder().fromAsyncCreateResponse(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected String jobId; + + /** + * @see AsyncCreateResponse#getId() + */ + public T id(String id) { + this.id = id; + return self(); + } + + /** + * @see AsyncCreateResponse#getJobId() + */ + public T jobId(String jobId) { + this.jobId = jobId; + return self(); + } + + public AsyncCreateResponse build() { + return new AsyncCreateResponse(id, jobId); + } + + public T fromAsyncCreateResponse(AsyncCreateResponse in) { + return this + .id(in.getId()) + .jobId(in.getJobId()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + @Named("jobid") + private final String jobId; + + @ConstructorProperties({ + "id", "jobid" + }) + protected AsyncCreateResponse(@Nullable String id, @Nullable String jobId) { this.id = id; this.jobId = jobId; } @@ -48,44 +98,41 @@ public class AsyncCreateResponse { /** * @return id of the resource being created */ + @Nullable public String getId() { - return id; + return this.id; } /** * @return id of the job in progress */ + @Nullable public String getJobId() { - return jobId; + return this.jobId; } @Override public int hashCode() { - return Objects.hashCode(id, jobId); + return Objects.hashCode(id, jobId); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AsyncCreateResponse that = (AsyncCreateResponse) obj; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + AsyncCreateResponse that = AsyncCreateResponse.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.jobId, that.jobId); + } - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(jobId, that.jobId)) return false; - - return true; + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("jobId", jobId); } @Override public String toString() { - return "AsyncCreateResponse{" + - "id=" + id + - ", jobId=" + jobId + - '}'; + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJob.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJob.java index 93551fc603..0ecb1e9e97 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJob.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJob.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,16 +18,24 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.util.Date; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** - * + * Class AsyncJob + * * @author Adrian Cole */ -public class AsyncJob { +public class AsyncJob { /** * Valid job result codes @@ -98,132 +106,205 @@ public class AsyncJob { } } - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { - private String accountId; - private String cmd; - private Date created; - private String id; - private String instanceId; - private String instanceType; - private int progress; - private T result; - private ResultCode resultCode = ResultCode.UNKNOWN; - private String resultType; - private AsyncJobError error; - private Status status = Status.UNKNOWN; - private String userId; + public Builder toBuilder() { + return new ConcreteBuilder().fromAsyncJob(this); + } - public Builder accountId(String accountId) { + public static abstract class Builder, S> { + protected abstract T self(); + + protected String accountId; + protected String cmd; + protected Date created; + protected String id; + protected String instanceId; + protected String instanceType; + protected int progress; + protected S result; + protected AsyncJob.ResultCode resultCode; + protected String resultType; + protected AsyncJob.Status status; + protected String userId; + protected AsyncJobError error; + + /** + * @see AsyncJob#getAccountId() + */ + public T accountId(String accountId) { this.accountId = accountId; - return this; + return self(); } - public Builder cmd(String cmd) { + /** + * @see AsyncJob#getCmd() + */ + public T cmd(String cmd) { this.cmd = cmd; - return this; + return self(); } - public Builder created(Date created) { + /** + * @see AsyncJob#getCreated() + */ + public T created(Date created) { this.created = created; - return this; + return self(); } - public Builder id(String id) { + /** + * @see AsyncJob#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder instanceId(String instanceId) { + /** + * @see AsyncJob#getInstanceId() + */ + public T instanceId(String instanceId) { this.instanceId = instanceId; - return this; + return self(); } - public Builder error(AsyncJobError error) { - this.error = error; - return this; - } - - public Builder instanceType(String instanceType) { + /** + * @see AsyncJob#getInstanceType() + */ + public T instanceType(String instanceType) { this.instanceType = instanceType; - return this; + return self(); } - public Builder progress(int progress) { + /** + * @see AsyncJob#getProgress() + */ + public T progress(int progress) { this.progress = progress; - return this; + return self(); } - public Builder result(T result) { + /** + * @see AsyncJob#getResult() + */ + public T result(S result) { this.result = result; - return this; + return self(); } - public Builder resultCode(ResultCode resultCode) { + /** + * @see AsyncJob#getResultCode() + */ + public T resultCode(AsyncJob.ResultCode resultCode) { this.resultCode = resultCode; - return this; + return self(); } - public Builder resultType(String resultType) { + /** + * @see AsyncJob#getResultType() + */ + public T resultType(String resultType) { this.resultType = resultType; - return this; + return self(); } - public Builder status(Status status) { + /** + * @see AsyncJob#getStatus() + */ + public T status(AsyncJob.Status status) { this.status = status; - return this; + return self(); } - public Builder userId(String userId) { + /** + * @see AsyncJob#getUserId() + */ + public T userId(String userId) { this.userId = userId; - return this; + return self(); } - public AsyncJob build() { - return new AsyncJob(accountId, cmd, created, id, instanceId, instanceType, progress, result, resultCode, + /** + * @see AsyncJob#getError() + */ + public T error(AsyncJobError error) { + this.error = error; + return self(); + } + + public AsyncJob build() { + return new AsyncJob(accountId, cmd, created, id, instanceId, instanceType, progress, result, resultCode, resultType, status, userId, error); } - public static Builder fromAsyncJobUntyped(AsyncJob in) { - return new Builder().accountId(in.accountId).cmd(in.cmd).created(in.created).id(in.id) - .instanceId(in.instanceId).instanceType(in.instanceType).progress(in.progress).result(in.result) - .resultCode(in.resultCode).resultType(in.resultType).status(in.status).userId(in.userId).error(in.error); + public T fromAsyncJob(AsyncJob in) { + return this + .accountId(in.getAccountId()) + .cmd(in.getCmd()) + .created(in.getCreated()) + .id(in.getId()) + .instanceId(in.getInstanceId()) + .instanceType(in.getInstanceType()) + .progress(in.getProgress()) + .result(in.getResult()) + .resultCode(in.getResultCode()) + .resultType(in.getResultType()) + .status(in.getStatus()) + .userId(in.getUserId()) + .error(in.getError()); + } + + public static Builder fromAsyncJobUntyped(AsyncJob in) { + return new ConcreteBuilder().fromAsyncJob(in); } } - @SerializedName("accountid") - private String accountId; - private String cmd; - private Date created; - @SerializedName("jobid") - private String id; - @SerializedName("jobinstanceid") - private String instanceId; - @SerializedName("jobinstancetype") - private String instanceType; - @SerializedName("jobprocstatus") - private int progress; - @SerializedName("jobresult") - private T result; - @SerializedName("jobresultcode") - private ResultCode resultCode = ResultCode.UNKNOWN; - @SerializedName("jobresulttype") - private String resultType; - @SerializedName("jobstatus") - private Status status = Status.UNKNOWN; - @SerializedName("userid") - private String userId; - private AsyncJobError error; + private static class ConcreteBuilder extends Builder,T> { + @Override + protected ConcreteBuilder self() { + return this; + } + } - public AsyncJob(String accountId, String cmd, Date created, String id, String instanceId, String instanceType, - int progress, T result, ResultCode resultCode, String resultType, Status status, String userId, AsyncJobError error) { + @Named("accountid") + private final String accountId; + private final String cmd; + private final Date created; + @Named("jobid") + private final String id; + @Named("jobinstanceid") + private final String instanceId; + @Named("jobinstancetype") + private final String instanceType; + @Named("jobprocstatus") + private final int progress; + @Named("jobresult") + private final S result; + @Named("jobresultcode") + private final AsyncJob.ResultCode resultCode; + @Named("jobresulttype") + private final String resultType; + @Named("jobstatus") + private final AsyncJob.Status status; + @Named("userid") + private final String userId; + private final AsyncJobError error; + + @ConstructorProperties({ + "accountid", "cmd", "created", "jobid", "jobinstanceid", "jobinstancetype", "jobprocstatus", "jobresult", + "jobresultcode", "jobresulttype", "jobstatus", "userid", "error" + }) + protected AsyncJob(@Nullable String accountId, @Nullable String cmd, @Nullable Date created, String id, + @Nullable String instanceId, @Nullable String instanceType, int progress, @Nullable S result, + @Nullable AsyncJob.ResultCode resultCode, @Nullable String resultType, @Nullable AsyncJob.Status status, + @Nullable String userId, @Nullable AsyncJobError error) { this.accountId = accountId; this.cmd = cmd; this.created = created; - this.id = id; + this.id = checkNotNull(id, "id"); this.instanceId = instanceId; this.instanceType = instanceType; this.progress = progress; @@ -235,106 +316,107 @@ public class AsyncJob { this.error = error; } - /** - * present only for serializer - * - */ - AsyncJob() { - - } - /** * @return the account that executed the async command */ + @Nullable public String getAccountId() { - return accountId; + return this.accountId; } /** * @return the async command executed */ + @Nullable public String getCmd() { - return cmd; + return this.cmd; } /** * @return the created date of the job */ + @Nullable public Date getCreated() { - return created; + return this.created; } /** * @return async job ID */ public String getId() { - return id; + return this.id; } /** * @return the unique ID of the instance/entity object related to the job */ + @Nullable public String getInstanceId() { - return instanceId; + return this.instanceId; } /** * @return the instance/entity object related to the job */ + @Nullable public String getInstanceType() { - return instanceType; + return this.instanceType; } /** * @return the progress information of the PENDING job */ public int getProgress() { - return progress; + return this.progress; } /** * @return the result reason */ - public T getResult() { - return result; + @Nullable + public S getResult() { + return this.result; } /** * @return the result code for the job */ - public ResultCode getResultCode() { - return resultCode; + @Nullable + public AsyncJob.ResultCode getResultCode() { + return this.resultCode; } /** * @return the result type */ + @Nullable public String getResultType() { - return resultType; + return this.resultType; } /** * @return the current job status-should be 0 for PENDING */ - public Status getStatus() { - return status; + @Nullable + public AsyncJob.Status getStatus() { + return this.status; } /** * @return the user that executed the async command */ + @Nullable public String getUserId() { - return userId; + return this.userId; } /** - * - * * @return the error related to this command, or null if no error or error - * not yet encountered. + not yet encountered. */ + @Nullable public AsyncJobError getError() { - return error; + return this.error; } public boolean hasFailed() { @@ -347,55 +429,39 @@ public class AsyncJob { @Override public int hashCode() { - return Objects.hashCode(accountId, cmd, created, id, instanceId, instanceType, error, progress, - result, resultCode, resultType, status, userId); + return Objects.hashCode(accountId, cmd, created, id, instanceId, instanceType, progress, result, resultCode, resultType, status, userId, error); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + AsyncJob that = AsyncJob.class.cast(obj); + return Objects.equal(this.accountId, that.accountId) + && Objects.equal(this.cmd, that.cmd) + && Objects.equal(this.created, that.created) + && Objects.equal(this.id, that.id) + && Objects.equal(this.instanceId, that.instanceId) + && Objects.equal(this.instanceType, that.instanceType) + && Objects.equal(this.progress, that.progress) + && Objects.equal(this.result, that.result) + && Objects.equal(this.resultCode, that.resultCode) + && Objects.equal(this.resultType, that.resultType) + && Objects.equal(this.status, that.status) + && Objects.equal(this.userId, that.userId) + && Objects.equal(this.error, that.error); + } - AsyncJob that = (AsyncJob) obj; - - if (!Objects.equal(accountId, that.accountId)) return false; - if (!Objects.equal(cmd, that.cmd)) return false; - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(instanceId, that.instanceId)) return false; - if (!Objects.equal(instanceType, that.instanceType)) return false; - if (!Objects.equal(error, that.error)) return false; - if (!Objects.equal(progress, that.progress)) return false; - if (!Objects.equal(result, that.result)) return false; - if (!Objects.equal(resultCode, that.resultCode)) return false; - if (!Objects.equal(resultType, that.resultType)) return false; - if (!Objects.equal(status, that.status)) return false; - if (!Objects.equal(userId, that.userId)) return false; - - return true; + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("accountId", accountId).add("cmd", cmd).add("created", created).add("id", id).add("instanceId", instanceId) + .add("instanceType", instanceType).add("progress", progress).add("result", result).add("resultCode", resultCode) + .add("resultType", resultType).add("status", status).add("userId", userId).add("error", error); } @Override public String toString() { - return "AsyncJob{" + - "accountId=" + accountId + - ", cmd='" + cmd + '\'' + - ", created=" + created + - ", id=" + id + - ", instanceId=" + instanceId + - ", instanceType='" + instanceType + '\'' + - ", progress=" + progress + - ", result=" + result + - ", resultCode=" + resultCode + - ", resultType='" + resultType + '\'' + - ", status=" + status + - ", userId=" + userId + - ", error=" + error + - '}'; + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJobError.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJobError.java index f57fbd5e22..5e9b14a0b2 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJobError.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJobError.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,8 +18,14 @@ */ package org.jclouds.cloudstack.domain; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * @@ -65,59 +71,99 @@ public class AsyncJobError { } } - @SerializedName("errorcode") - private ErrorCode errorCode; - @SerializedName("errortext") - private String errorText; - - /** - * present only for serializer - * - */ - AsyncJobError() { - + public static Builder builder() { + return new ConcreteBuilder(); } - public AsyncJobError(ErrorCode errorCode, String errorText) { + public Builder toBuilder() { + return new ConcreteBuilder().fromAsyncJobError(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected AsyncJobError.ErrorCode errorCode; + protected String errorText; + + /** + * @see AsyncJobError#getErrorCode() + */ + public T errorCode(ErrorCode errorCode) { + this.errorCode = errorCode; + return self(); + } + + /** + * @see AsyncJobError#getErrorText() + */ + public T errorText(String errorText) { + this.errorText = errorText; + return self(); + } + + public AsyncJobError build() { + return new AsyncJobError(errorCode, errorText); + } + + public T fromAsyncJobError(AsyncJobError in) { + return this + .errorCode(in.getErrorCode()) + .errorText(in.getErrorText()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + @Named("errorcode") + private final ErrorCode errorCode; + @Named("errortext") + private final String errorText; + + @ConstructorProperties({ + "errorcode", "errortext" + }) + protected AsyncJobError(@Nullable ErrorCode errorCode, @Nullable String errorText) { this.errorCode = errorCode; this.errorText = errorText; } + @Nullable public ErrorCode getErrorCode() { - return errorCode; + return this.errorCode; } + @Nullable public String getErrorText() { - return errorText; + return this.errorText; } @Override public int hashCode() { - return Objects.hashCode(errorCode, errorText); + return Objects.hashCode(errorCode, errorText); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AsyncJobError that = (AsyncJobError) obj; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + AsyncJobError that = AsyncJobError.class.cast(obj); + return Objects.equal(this.errorCode, that.errorCode) + && Objects.equal(this.errorText, that.errorText); + } - if (!Objects.equal(errorCode, that.errorCode)) return false; - if (!Objects.equal(errorText, that.errorText)) return false; - - return true; + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("errorCode", errorCode).add("errorText", errorText); } @Override public String toString() { - return "AsyncJobError{" + - "errorCode=" + errorCode + - ", errorText='" + errorText + '\'' + - '}'; + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capabilities.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capabilities.java index 4d83b8bca1..ab0a92decd 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capabilities.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capabilities.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,73 +18,114 @@ */ package org.jclouds.cloudstack.domain; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** + * Class Capabilities + * * @author Adrian Cole */ public class Capabilities { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { - private String cloudStackVersion; - private boolean securityGroupsEnabled; - private boolean canShareTemplates; - private boolean firewallRuleUiEnabled; - private boolean supportELB; + public Builder toBuilder() { + return new ConcreteBuilder().fromCapabilities(this); + } - public Builder cloudStackVersion(String cloudStackVersion) { + public static abstract class Builder> { + protected abstract T self(); + + protected String cloudStackVersion; + protected boolean securityGroupsEnabled; + protected boolean canShareTemplates; + protected boolean firewallRuleUiEnabled; + protected boolean supportELB; + + /** + * @see Capabilities#getCloudStackVersion() + */ + public T cloudStackVersion(String cloudStackVersion) { this.cloudStackVersion = cloudStackVersion; - return this; + return self(); } - public Builder securityGroupsEnabled(boolean securityGroupsEnabled) { + /** + * @see Capabilities#isSecurityGroupsEnabled() + */ + public T securityGroupsEnabled(boolean securityGroupsEnabled) { this.securityGroupsEnabled = securityGroupsEnabled; - return this; + return self(); } - public Builder sharedTemplatesEnabled(boolean canShareTemplates) { + /** + * @see Capabilities#canShareTemplates() + */ + public T canShareTemplates(boolean canShareTemplates) { this.canShareTemplates = canShareTemplates; - return this; + return self(); } - public Builder firewallRuleUiEnabled(boolean firewallRuleUiEnabled) { + /** + * @see Capabilities#isFirewallRuleUiEnabled() + */ + public T firewallRuleUiEnabled(boolean firewallRuleUiEnabled) { this.firewallRuleUiEnabled = firewallRuleUiEnabled; - return this; + return self(); } - public Builder supportELB(boolean supportELB) { + /** + * @see Capabilities#isSupportELB() + */ + public T supportELB(boolean supportELB) { this.supportELB = supportELB; - return this; + return self(); } public Capabilities build() { return new Capabilities(cloudStackVersion, securityGroupsEnabled, canShareTemplates, firewallRuleUiEnabled, supportELB); } + + public T fromCapabilities(Capabilities in) { + return this + .cloudStackVersion(in.getCloudStackVersion()) + .securityGroupsEnabled(in.isSecurityGroupsEnabled()) + .canShareTemplates(in.canShareTemplates()) + .firewallRuleUiEnabled(in.isFirewallRuleUiEnabled()) + .supportELB(in.isSupportELB()); + } } - @SerializedName("cloudstackversion") - private String cloudStackVersion; - @SerializedName("securitygroupsenabled") - private boolean securityGroupsEnabled; - @SerializedName("userpublictemplateenabled") - private boolean canShareTemplates; - private boolean firewallRuleUiEnabled; - private boolean supportELB; - - - /** - * present only for serializer - */ - Capabilities() { - + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public Capabilities(String cloudStackVersion, boolean securityGroupsEnabled, boolean canShareTemplates, - boolean firewallRuleUiEnabled, boolean supportELB) { + @Named("cloudstackversion") + private final String cloudStackVersion; + @Named("securitygroupsenabled") + private final boolean securityGroupsEnabled; + @Named("userpublictemplateenabled") + private final boolean canShareTemplates; + private final boolean firewallRuleUiEnabled; + private final boolean supportELB; + + @ConstructorProperties({ + "cloudstackversion", "securitygroupsenabled", "userpublictemplateenabled", "firewallRuleUiEnabled", "supportELB" + }) + protected Capabilities(@Nullable String cloudStackVersion, boolean securityGroupsEnabled, boolean canShareTemplates, + boolean firewallRuleUiEnabled, boolean supportELB) { this.cloudStackVersion = cloudStackVersion; this.securityGroupsEnabled = securityGroupsEnabled; this.canShareTemplates = canShareTemplates; @@ -95,71 +136,61 @@ public class Capabilities { /** * @return version of the cloud stack */ + @Nullable public String getCloudStackVersion() { - return cloudStackVersion; + return this.cloudStackVersion; } /** * @return true if security groups support is enabled, false otherwise */ public boolean isSecurityGroupsEnabled() { - return securityGroupsEnabled; + return this.securityGroupsEnabled; } - /** - * @return true if user and domain admins can set templates to be shared, - * false otherwise - */ - public boolean isSharedTemplatesEnabled() { - return canShareTemplates; + public boolean canShareTemplates() { + return this.canShareTemplates; } /** * @return true if the firewall rule UI is enabled */ public boolean isFirewallRuleUiEnabled() { - return firewallRuleUiEnabled; + return this.firewallRuleUiEnabled; } /** * @return true if region supports elastic load balancer on basic zones */ public boolean isSupportELB() { - return supportELB; + return this.supportELB; } @Override public int hashCode() { - return Objects.hashCode(canShareTemplates, cloudStackVersion, securityGroupsEnabled, firewallRuleUiEnabled, supportELB); + return Objects.hashCode(cloudStackVersion, securityGroupsEnabled, canShareTemplates, firewallRuleUiEnabled, supportELB); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Capabilities that = (Capabilities) obj; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Capabilities that = Capabilities.class.cast(obj); + return Objects.equal(this.cloudStackVersion, that.cloudStackVersion) + && Objects.equal(this.securityGroupsEnabled, that.securityGroupsEnabled) + && Objects.equal(this.canShareTemplates, that.canShareTemplates) + && Objects.equal(this.firewallRuleUiEnabled, that.firewallRuleUiEnabled) + && Objects.equal(this.supportELB, that.supportELB); + } - if (!Objects.equal(canShareTemplates, that.canShareTemplates)) return false; - if (!Objects.equal(cloudStackVersion, that.cloudStackVersion)) return false; - if (!Objects.equal(securityGroupsEnabled, that.securityGroupsEnabled)) return false; - if (!Objects.equal(firewallRuleUiEnabled, that.firewallRuleUiEnabled)) return false; - if (!Objects.equal(supportELB, that.supportELB)) return false; - - return true; + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("cloudStackVersion", cloudStackVersion).add("securityGroupsEnabled", securityGroupsEnabled).add("canShareTemplates", canShareTemplates).add("firewallRuleUiEnabled", firewallRuleUiEnabled).add("supportELB", supportELB); } @Override public String toString() { - return "Capabilities{" + - "cloudStackVersion='" + cloudStackVersion + '\'' + - ", securityGroupsEnabled=" + securityGroupsEnabled + - ", canShareTemplates=" + canShareTemplates + - ", firewallRuleUiEnabled=" + firewallRuleUiEnabled + - ", supportELB=" + supportELB + - '}'; + return string().toString(); } + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capacity.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capacity.java index 1f39af815f..c2852fbf54 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capacity.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capacity.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,13 +20,18 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Map; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Function; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; -import com.google.gson.annotations.SerializedName; /** * Information about a dimension of the capacity @@ -35,67 +40,9 @@ import com.google.gson.annotations.SerializedName; */ public class Capacity implements Comparable { - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private long capacityTotal; - private long capacityUsed; - private double percentUsed; - private String podId; - private String podName; - private Type type; - private String zoneId; - private String zoneName; - - public Builder capacityTotal(long capacityTotal) { - this.capacityTotal = capacityTotal; - return this; - } - - public Builder capacityUsed(long capacityUsed) { - this.capacityUsed = capacityUsed; - return this; - } - - public Builder percentUsed(double percentUsed) { - this.percentUsed = percentUsed; - return this; - } - - public Builder podId(String podId) { - this.podId = podId; - return this; - } - - public Builder podName(String podName) { - this.podName = podName; - return this; - } - - public Builder type(Type type) { - this.type = type; - return this; - } - - public Builder zoneId(String zoneId) { - this.zoneId = zoneId; - return this; - } - - public Builder zoneName(String zoneName) { - this.zoneName = zoneName; - return this; - } - - public Capacity build() { - return new Capacity(capacityTotal, capacityUsed, percentUsed, podId, podName, type, zoneId, zoneName); - } - } - - public enum Type { + /** + */ + public static enum Type { MEMORY_ALLOCATED_BYTES(0), CPU_ALLOCATED_MHZ(1), PRIMARY_STORAGE_USED_BYTES(2), @@ -111,14 +58,14 @@ public class Capacity implements Comparable { private int code; private static final Map INDEX = Maps.uniqueIndex(ImmutableSet.copyOf(Type.values()), - new Function() { + new Function() { - @Override - public Integer apply(Type input) { - return input.code; - } + @Override + public Integer apply(Type input) { + return input.code; + } - }); + }); Type(int code) { this.code = code; @@ -135,27 +82,135 @@ public class Capacity implements Comparable { } } - @SerializedName("capacitytotal") - private long capacityTotal; - @SerializedName("capacityused") - private long capacityUsed; - @SerializedName("percentused") - private double percentUsed; - @SerializedName("podid") - private String podId; - @SerializedName("podname") - private String podName; - private Capacity.Type type; - @SerializedName("zoneid") - private String zoneId; - @SerializedName("zonename") - private String zoneName; - - /* exists for the deserializer, only */ - Capacity() { + public static Builder builder() { + return new ConcreteBuilder(); } - public Capacity(long capacityTotal, long capacityUsed, double percentUsed, String podId, String podName, Type type, String zoneId, String zoneName) { + public Builder toBuilder() { + return new ConcreteBuilder().fromCapacity(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected long capacityTotal; + protected long capacityUsed; + protected double percentUsed; + protected String podId; + protected String podName; + protected Capacity.Type type; + protected String zoneId; + protected String zoneName; + + /** + * @see Capacity#getCapacityTotal() + */ + public T capacityTotal(long capacityTotal) { + this.capacityTotal = capacityTotal; + return self(); + } + + /** + * @see Capacity#getCapacityUsed() + */ + public T capacityUsed(long capacityUsed) { + this.capacityUsed = capacityUsed; + return self(); + } + + /** + * @see Capacity#getPercentUsed() + */ + public T percentUsed(double percentUsed) { + this.percentUsed = percentUsed; + return self(); + } + + /** + * @see Capacity#getPodId() + */ + public T podId(String podId) { + this.podId = podId; + return self(); + } + + /** + * @see Capacity#getPodName() + */ + public T podName(String podName) { + this.podName = podName; + return self(); + } + + /** + * @see Capacity#getType() + */ + public T type(Capacity.Type type) { + this.type = type; + return self(); + } + + /** + * @see Capacity#getZoneId() + */ + public T zoneId(String zoneId) { + this.zoneId = zoneId; + return self(); + } + + /** + * @see Capacity#getZoneName() + */ + public T zoneName(String zoneName) { + this.zoneName = zoneName; + return self(); + } + + public Capacity build() { + return new Capacity(capacityTotal, capacityUsed, percentUsed, podId, podName, type, zoneId, zoneName); + } + + public T fromCapacity(Capacity in) { + return this + .capacityTotal(in.getCapacityTotal()) + .capacityUsed(in.getCapacityUsed()) + .percentUsed(in.getPercentUsed()) + .podId(in.getPodId()) + .podName(in.getPodName()) + .type(in.getType()) + .zoneId(in.getZoneId()) + .zoneName(in.getZoneName()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + @Named("capacitytotal") + private final long capacityTotal; + @Named("capacityused") + private final long capacityUsed; + @Named("percentused") + private final double percentUsed; + @Named("podid") + private final String podId; + @Named("podname") + private final String podName; + private final Capacity.Type type; + @Named("zoneid") + private final String zoneId; + @Named("zonename") + private final String zoneName; + + @ConstructorProperties({ + "capacitytotal", "capacityused", "percentused", "podid", "podname", "type", "zoneid", "zonename" + }) + protected Capacity(long capacityTotal, long capacityUsed, double percentUsed, @Nullable String podId, + @Nullable String podName, @Nullable Capacity.Type type, @Nullable String zoneId, @Nullable String zoneName) { this.capacityTotal = capacityTotal; this.capacityUsed = capacityUsed; this.percentUsed = percentUsed; @@ -167,83 +222,78 @@ public class Capacity implements Comparable { } public long getCapacityTotal() { - return capacityTotal; + return this.capacityTotal; } public long getCapacityUsed() { - return capacityUsed; + return this.capacityUsed; } public double getPercentUsed() { - return percentUsed; + return this.percentUsed; } + @Nullable public String getPodId() { - return podId; + return this.podId; } + @Nullable public String getPodName() { - return podName; + return this.podName; } - public Type getType() { - return type; + @Nullable + public Capacity.Type getType() { + return this.type; } + @Nullable public String getZoneId() { - return zoneId; + return this.zoneId; } + @Nullable public String getZoneName() { - return zoneName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Capacity that = (Capacity) o; - - if (!Objects.equal(capacityTotal, that.capacityTotal)) return false; - if (!Objects.equal(capacityUsed, that.capacityUsed)) return false; - if (!Objects.equal(percentUsed, that.percentUsed)) return false; - if (!Objects.equal(podId, that.podId)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(podName, that.podName)) return false; - if (!Objects.equal(type, that.type)) return false; - if (!Objects.equal(zoneName, that.zoneName)) return false; - - return true; + return this.zoneName; } @Override public int hashCode() { - return Objects.hashCode(capacityTotal, capacityUsed, percentUsed, podId, podName, - type, zoneId, zoneName); + return Objects.hashCode(capacityTotal, capacityUsed, percentUsed, podId, podName, type, zoneId, zoneName); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Capacity that = Capacity.class.cast(obj); + return Objects.equal(this.capacityTotal, that.capacityTotal) + && Objects.equal(this.capacityUsed, that.capacityUsed) + && Objects.equal(this.percentUsed, that.percentUsed) + && Objects.equal(this.podId, that.podId) + && Objects.equal(this.podName, that.podName) + && Objects.equal(this.type, that.type) + && Objects.equal(this.zoneId, that.zoneId) + && Objects.equal(this.zoneName, that.zoneName); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("capacityTotal", capacityTotal).add("capacityUsed", capacityUsed).add("percentUsed", percentUsed) + .add("podId", podId).add("podName", podName).add("type", type).add("zoneId", zoneId).add("zoneName", zoneName); } @Override public String toString() { - return "Capacity{" + - "capacityTotal=" + capacityTotal + - ", capacityUsed=" + capacityUsed + - ", percentUsed=" + percentUsed + - ", podId=" + podId + - ", podName='" + podName + '\'' + - ", type=" + type + - ", zoneId=" + zoneId + - ", zoneName='" + zoneName + '\'' + - '}'; + return string().toString(); } @Override public int compareTo(Capacity other) { int comparison = this.zoneId.compareTo(other.zoneId); - if (comparison != 0) return comparison; - comparison = this.podId.compareTo(other.podId); - if (comparison != 0) return comparison; - return Integer.valueOf(this.type.code).compareTo(other.type.code); + if (comparison == 0) comparison = this.podId.compareTo(other.podId); + if (comparison == 0) Integer.valueOf(this.type.code).compareTo(other.type.code); + return comparison; } - } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Cluster.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Cluster.java index cb167a9af1..969dce1d0f 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Cluster.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Cluster.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,9 +20,16 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.CaseFormat.UPPER_CAMEL; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * Represents a CloudStack Cluster. @@ -31,7 +38,9 @@ import com.google.gson.annotations.SerializedName; */ public class Cluster implements Comparable { - public enum ManagedState { + /** + */ + public static enum ManagedState { MANAGED, PREPARE_UNMANAGED, UNMANAGED, @@ -52,93 +61,160 @@ public class Cluster implements Comparable { } } - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { - private String id; - private AllocationState allocationState; - private Host.ClusterType clusterType; - private String hypervisor; - private ManagedState managedState; - private String name; - private String podId; - private String podName; - private String zoneId; - private String zoneName; + public Builder toBuilder() { + return new ConcreteBuilder().fromCluster(this); + } - public Builder id(String id) { + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected AllocationState allocationState; + protected Host.ClusterType clusterType; + protected String hypervisor; + protected Cluster.ManagedState managedState; + protected String name; + protected String podId; + protected String podName; + protected String zoneId; + protected String zoneName; + + /** + * @see Cluster#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder allocationState(AllocationState allocationState) { + /** + * @see Cluster#getAllocationState() + */ + public T allocationState(AllocationState allocationState) { this.allocationState = allocationState; - return this; + return self(); } - public Builder clusterType(Host.ClusterType clusterType) { + /** + * @see Cluster#getClusterType() + */ + public T clusterType(Host.ClusterType clusterType) { this.clusterType = clusterType; - return this; + return self(); } - public Builder hypervisor(String hypervisor) { + /** + * @see Cluster#getHypervisor() + */ + public T hypervisor(String hypervisor) { this.hypervisor = hypervisor; - return this; + return self(); } - public Builder managedState(ManagedState managedState) { + /** + * @see Cluster#getManagedState() + */ + public T managedState(Cluster.ManagedState managedState) { this.managedState = managedState; - return this; + return self(); } - public Builder name(String name) { + /** + * @see Cluster#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder podId(String podId) { + /** + * @see Cluster#getPodId() + */ + public T podId(String podId) { this.podId = podId; - return this; + return self(); } - public Builder podName(String podName) { + /** + * @see Cluster#getPodName() + */ + public T podName(String podName) { this.podName = podName; - return this; + return self(); } - public Builder zoneId(String zoneId) { + /** + * @see Cluster#getZoneId() + */ + public T zoneId(String zoneId) { this.zoneId = zoneId; - return this; + return self(); } - public Builder zoneName(String zoneName) { + /** + * @see Cluster#getZoneName() + */ + public T zoneName(String zoneName) { this.zoneName = zoneName; - return this; + return self(); } public Cluster build() { return new Cluster(id, allocationState, clusterType, hypervisor, managedState, name, podId, podName, zoneId, zoneName); } + + public T fromCluster(Cluster in) { + return this + .id(in.getId()) + .allocationState(in.getAllocationState()) + .clusterType(in.getClusterType()) + .hypervisor(in.getHypervisor()) + .managedState(in.getManagedState()) + .name(in.getName()) + .podId(in.getPodId()) + .podName(in.getPodName()) + .zoneId(in.getZoneId()) + .zoneName(in.getZoneName()); + } } - private String id; - @SerializedName("allocationstate") private AllocationState allocationState; - @SerializedName("clustertype") private Host.ClusterType clusterType; - @SerializedName("hypervisortype") private String hypervisor; - @SerializedName("managedstate") private ManagedState managedState; - private String name; - @SerializedName("podid") private String podId; - @SerializedName("podname") private String podName; - @SerializedName("zoneid") private String zoneId; - @SerializedName("zonename") private String zoneName; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - // Just for the serializer - Cluster() {} + private final String id; + @Named("allocationstate") + private final AllocationState allocationState; + @Named("clustertype") + private final Host.ClusterType clusterType; + @Named("hypervisortype") + private final String hypervisor; + @Named("managedstate") + private final Cluster.ManagedState managedState; + private final String name; + @Named("podid") + private final String podId; + @Named("podname") + private final String podName; + @Named("zoneid") + private final String zoneId; + @Named("zonename") + private final String zoneName; - public Cluster(String id, AllocationState allocationState, Host.ClusterType clusterType, String hypervisor, ManagedState managedState, String name, String podId, String podName, String zoneId, String zoneName) { - this.id = id; + @ConstructorProperties({ + "id", "allocationstate", "clustertype", "hypervisortype", "managedstate", "name", "podid", "podname", "zoneid", "zonename" + }) + protected Cluster(String id, @Nullable AllocationState allocationState, @Nullable Host.ClusterType clusterType, + @Nullable String hypervisor, @Nullable Cluster.ManagedState managedState, @Nullable String name, + @Nullable String podId, @Nullable String podName, @Nullable String zoneId, @Nullable String zoneName) { + this.id = checkNotNull(id, "id"); this.allocationState = allocationState; this.clusterType = clusterType; this.hypervisor = hypervisor; @@ -151,86 +227,85 @@ public class Cluster implements Comparable { } public String getId() { - return id; + return this.id; } + @Nullable public AllocationState getAllocationState() { - return allocationState; + return this.allocationState; } + @Nullable public Host.ClusterType getClusterType() { - return clusterType; + return this.clusterType; } + @Nullable public String getHypervisor() { - return hypervisor; + return this.hypervisor; } - public ManagedState getManagedState() { - return managedState; + @Nullable + public Cluster.ManagedState getManagedState() { + return this.managedState; } + @Nullable public String getName() { - return name; + return this.name; } + @Nullable public String getPodId() { - return podId; + return this.podId; } + @Nullable public String getPodName() { - return podName; + return this.podName; } + @Nullable public String getZoneId() { - return zoneId; + return this.zoneId; } + @Nullable public String getZoneName() { - return zoneName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Cluster that = (Cluster) o; - - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(podId, that.podId)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(allocationState, that.allocationState)) return false; - if (!Objects.equal(clusterType, that.clusterType)) return false; - if (!Objects.equal(hypervisor, that.hypervisor)) return false; - if (!Objects.equal(managedState, that.managedState)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(podName, that.podName)) return false; - if (!Objects.equal(zoneName, that.zoneName)) return false; - - return true; + return this.zoneName; } @Override public int hashCode() { - return Objects.hashCode(id, allocationState, clusterType, hypervisor, managedState, name, podId, podName, - zoneId, zoneName); + return Objects.hashCode(id, allocationState, clusterType, hypervisor, managedState, name, podId, podName, zoneId, zoneName); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Cluster that = Cluster.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.allocationState, that.allocationState) + && Objects.equal(this.clusterType, that.clusterType) + && Objects.equal(this.hypervisor, that.hypervisor) + && Objects.equal(this.managedState, that.managedState) + && Objects.equal(this.name, that.name) + && Objects.equal(this.podId, that.podId) + && Objects.equal(this.podName, that.podName) + && Objects.equal(this.zoneId, that.zoneId) + && Objects.equal(this.zoneName, that.zoneName); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("allocationState", allocationState).add("clusterType", clusterType).add("hypervisor", hypervisor) + .add("managedState", managedState).add("name", name).add("podId", podId).add("podName", podName).add("zoneId", zoneId).add("zoneName", zoneName); } @Override public String toString() { - return "Cluster{" + - "id=" + id + - ", allocationState=" + allocationState + - ", clusterType=" + clusterType + - ", hypervisor='" + hypervisor + '\'' + - ", managedState=" + managedState + - ", name='" + name + '\'' + - ", podId=" + podId + - ", podName='" + podName + '\'' + - ", zoneId=" + zoneId + - ", zoneName='" + zoneName + '\'' + - '}'; + return string().toString(); } @Override diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ConfigurationEntry.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ConfigurationEntry.java index d3a655bf1b..129c911c01 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ConfigurationEntry.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ConfigurationEntry.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,10 +16,16 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** * Representation of the API configuration entry response @@ -28,106 +34,136 @@ import com.google.common.base.Objects; */ public class ConfigurationEntry implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { + public Builder toBuilder() { + return new ConcreteBuilder().fromConfigurationEntry(this); + } - private String category; - private String description; - private String name; - private String value; + public static abstract class Builder> { + protected abstract T self(); - public Builder category(String category) { + protected String category; + protected String description; + protected String name; + protected String value; + + /** + * @see ConfigurationEntry#getCategory() + */ + public T category(String category) { this.category = category; - return this; + return self(); } - public Builder description(String description) { + /** + * @see ConfigurationEntry#getDescription() + */ + public T description(String description) { this.description = description; - return this; + return self(); } - public Builder name(String name) { + /** + * @see ConfigurationEntry#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder value(String value) { + /** + * @see ConfigurationEntry#getValue() + */ + public T value(String value) { this.value = value; - return this; + return self(); } public ConfigurationEntry build() { return new ConfigurationEntry(category, description, name, value); } + + public T fromConfigurationEntry(ConfigurationEntry in) { + return this + .category(in.getCategory()) + .description(in.getDescription()) + .name(in.getName()) + .value(in.getValue()); + } } - // for deserialization - ConfigurationEntry() { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - private String category; - private String description; - private String name; - private String value; + private final String category; + private final String description; + private final String name; + private final String value; - public ConfigurationEntry(String category, String description, String name, String value) { + @ConstructorProperties({ + "category", "description", "name", "value" + }) + protected ConfigurationEntry(@Nullable String category, @Nullable String description, String name, @Nullable String value) { this.category = category; this.description = description; - this.name = name; + this.name = checkNotNull(name, "name"); this.value = value; } - @Override - public int compareTo(ConfigurationEntry arg0) { - return name.compareTo(arg0.getName()); - } - + @Nullable public String getCategory() { - return category; + return this.category; } + @Nullable public String getDescription() { - return description; + return this.description; } public String getName() { - return name; + return this.name; } + @Nullable public String getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ConfigurationEntry that = (ConfigurationEntry) o; - - if (!Objects.equal(category, that.category)) return false; - if (!Objects.equal(description, that.description)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(value, that.value)) return false; - - return true; + return this.value; } @Override public int hashCode() { - return Objects.hashCode(category, description, name, value); + return Objects.hashCode(category, description, name, value); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ConfigurationEntry that = ConfigurationEntry.class.cast(obj); + return Objects.equal(this.category, that.category) + && Objects.equal(this.description, that.description) + && Objects.equal(this.name, that.name) + && Objects.equal(this.value, that.value); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("category", category).add("description", description).add("name", name).add("value", value); } @Override public String toString() { - return "ConfigurationEntry{" + - "category='" + category + '\'' + - ", description='" + description + '\'' + - ", name='" + name + '\'' + - ", value='" + value + '\'' + - '}'; + return string().toString(); + } + + @Override + public int compareTo(ConfigurationEntry other) { + return name.compareTo(other.getName()); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java index 5128faeb63..262a36c079 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,103 +20,162 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; -import java.util.Set; -import com.google.common.base.Joiner; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** - * + * Class DiskOffering + * * @author Adrian Cole */ public class DiskOffering implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { - private String id; - private String name; - private String displayText; - private Date created; - private String domain; - private String domainId; - private int diskSize; - private boolean customized; - private Set tags = ImmutableSet.of(); + public Builder toBuilder() { + return new ConcreteBuilder().fromDiskOffering(this); + } - public Builder id(String id) { + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected String name; + protected String displayText; + protected Date created; + protected String domain; + protected String domainId; + protected int diskSize; + protected boolean customized; + protected String tags; + + /** + * @see DiskOffering#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder name(String name) { + /** + * @see DiskOffering#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder displayText(String displayText) { + /** + * @see DiskOffering#getDisplayText() + */ + public T displayText(String displayText) { this.displayText = displayText; - return this; + return self(); } - public Builder created(Date created) { + /** + * @see DiskOffering#getCreated() + */ + public T created(Date created) { this.created = created; - return this; + return self(); } - public Builder domain(String domain) { + /** + * @see DiskOffering#getDomain() + */ + public T domain(String domain) { this.domain = domain; - return this; + return self(); } - public Builder domainId(String domainId) { + /** + * @see DiskOffering#getDomainId() + */ + public T domainId(String domainId) { this.domainId = domainId; - return this; + return self(); } - public Builder diskSize(int diskSize) { + /** + * @see DiskOffering#getDiskSize() + */ + public T diskSize(int diskSize) { this.diskSize = diskSize; - return this; + return self(); } - public Builder customized(boolean customized) { + /** + * @see DiskOffering#isCustomized() + */ + public T customized(boolean customized) { this.customized = customized; - return this; + return self(); } - public Builder tags(Set tags) { - this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); - return this; + /** + * @see DiskOffering#getTags() + */ + public T tags(String tags) { + this.tags = tags; + return self(); } public DiskOffering build() { return new DiskOffering(id, name, displayText, created, domain, domainId, diskSize, customized, tags); } + + public T fromDiskOffering(DiskOffering in) { + return this + .id(in.getId()) + .name(in.getName()) + .displayText(in.getDisplayText()) + .created(in.getCreated()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .diskSize(in.getDiskSize()) + .customized(in.isCustomized()) + .tags(in.getTags()); + } } - private String id; - private String name; - @SerializedName("displaytext") - private String displayText; - private Date created; - private String domain; - @SerializedName("domainid") - private String domainId; - @SerializedName("disksize") - private int diskSize; - @SerializedName("iscustomized") - private boolean customized; - private String tags; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - public DiskOffering(String id, String name, String displayText, Date created, String domain, String domainId, - int diskSize, boolean customized, Set tags) { - this.id = id; + private final String id; + private final String name; + @Named("displaytext") + private final String displayText; + private final Date created; + private final String domain; + @Named("domainid") + private final String domainId; + @Named("disksize") + private final int diskSize; + @Named("iscustomized") + private final boolean customized; + private final String tags; + + @ConstructorProperties({ + "id", "name", "displaytext", "created", "domain", "domainid", "disksize", "iscustomized", "tags" + }) + protected DiskOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, + @Nullable String domain, @Nullable String domainId, int diskSize, boolean customized, + @Nullable String tags) { + this.id = checkNotNull(id, "id"); this.name = name; this.displayText = displayText; this.created = created; @@ -124,136 +183,113 @@ public class DiskOffering implements Comparable { this.domainId = domainId; this.diskSize = diskSize; this.customized = customized; - this.tags = tags.size() == 0 ? null : Joiner.on(',').join(tags); + this.tags = tags; } /** - * present only for serializer - * - */ - DiskOffering() { - - } - - /** - * * @return the id of the disk offering */ public String getId() { - return id; + return this.id; } /** - * * @return the name of the disk offering */ - + @Nullable public String getName() { - return name; + return this.name; } /** - * * @return an alternate display text of the disk offering. */ + @Nullable public String getDisplayText() { - return displayText; + return this.displayText; } /** - * * @return the date this disk offering was created */ + @Nullable public Date getCreated() { - return created; + return this.created; } /** - * * @return Domain name for the offering */ + @Nullable public String getDomain() { - return domain; + return this.domain; } /** - * * @return the domain id of the disk offering */ + @Nullable public String getDomainId() { - return domainId; + return this.domainId; } /** - * * @return the size of the disk offering in GB */ public int getDiskSize() { - return diskSize; + return this.diskSize; } /** - * * @return the ha support in the disk offering */ public boolean isCustomized() { - return customized; + return this.customized; } /** - * * @return the tags for the disk offering */ - public Set getTags() { - return tags != null ? ImmutableSet.copyOf(Splitter.on(',').split(tags)) : ImmutableSet. of(); + @Nullable + public String getTags() { + return this.tags; } @Override public int hashCode() { - return Objects.hashCode(created, customized, diskSize, displayText, domain, domainId, id, name, tags); + return Objects.hashCode(id, name, displayText, created, domain, domainId, diskSize, customized, tags); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - DiskOffering that = (DiskOffering) obj; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + DiskOffering that = DiskOffering.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.name, that.name) + && Objects.equal(this.displayText, that.displayText) + && Objects.equal(this.created, that.created) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.diskSize, that.diskSize) + && Objects.equal(this.customized, that.customized) + && Objects.equal(this.tags, that.tags); + } - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(customized, that.customized)) return false; - if (!Objects.equal(diskSize, that.diskSize)) return false; - if (!Objects.equal(displayText, that.displayText)) return false; - if (!Objects.equal(domain, that.domain)) return false; - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(tags, that.tags)) return false; - - return true; + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("displayText", displayText).add("created", created).add("domain", domain) + .add("domainId", domainId).add("diskSize", diskSize).add("customized", customized).add("tags", tags); } @Override public String toString() { - return "DiskOffering{" + - "id=" + id + - ", name='" + name + '\'' + - ", displayText='" + displayText + '\'' + - ", created=" + created + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", diskSize=" + diskSize + - ", customized=" + customized + - ", tags='" + tags + '\'' + - '}'; + return string().toString(); } @Override - public int compareTo(DiskOffering arg0) { - return id.compareTo(arg0.getId()); + public int compareTo(DiskOffering other) { + return id.compareTo(other.getId()); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Domain.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Domain.java index 565e1f6c19..c127bc998c 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Domain.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Domain.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,11 +16,18 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * Representation of the API domain response @@ -29,80 +36,122 @@ import com.google.gson.annotations.SerializedName; */ public class Domain implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { + public Builder toBuilder() { + return new ConcreteBuilder().fromDomain(this); + } - private String id; - private boolean hasChild; - private long level; - private String name; - private String networkDomain; - private String parentDomainId; - private String parentDomainName; + public static abstract class Builder> { + protected abstract T self(); - public Builder id(String id) { + protected String id; + protected boolean hasChild; + protected long level; + protected String name; + protected String networkDomain; + protected String parentDomainId; + protected String parentDomainName; + + /** + * @see Domain#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder hasChild(boolean hasChild) { + /** + * @see Domain#hasChild() + */ + public T hasChild(boolean hasChild) { this.hasChild = hasChild; - return this; + return self(); } - public Builder level(long level) { + /** + * @see Domain#getLevel() + */ + public T level(long level) { this.level = level; - return this; + return self(); } - public Builder name(String name) { + /** + * @see Domain#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder networkDomain(String networkDomain) { + /** + * @see Domain#getNetworkDomain() + */ + public T networkDomain(String networkDomain) { this.networkDomain = networkDomain; - return this; + return self(); } - public Builder parentDomainId(String parentDomainId) { + /** + * @see Domain#getParentDomainId() + */ + public T parentDomainId(String parentDomainId) { this.parentDomainId = parentDomainId; - return this; + return self(); } - public Builder parentDomainName(String parentDomainName) { + /** + * @see Domain#getParentDomainName() + */ + public T parentDomainName(String parentDomainName) { this.parentDomainName = parentDomainName; - return this; + return self(); } public Domain build() { - return new Domain(id, hasChild, level, name, networkDomain, - parentDomainId, parentDomainName); + return new Domain(id, hasChild, level, name, networkDomain, parentDomainId, parentDomainName); + } + + public T fromDomain(Domain in) { + return this + .id(in.getId()) + .hasChild(in.hasChild()) + .level(in.getLevel()) + .name(in.getName()) + .networkDomain(in.getNetworkDomain()) + .parentDomainId(in.getParentDomainId()) + .parentDomainName(in.getParentDomainName()); } } - // for deserialization - Domain() { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - private String id; - @SerializedName("haschild") - private boolean hasChild; - private long level; - private String name; - @SerializedName("networkdomain") - private String networkDomain; - @SerializedName("parentdomainid") - private String parentDomainId; - @SerializedName("parentdomainname") - private String parentDomainName; + private final String id; + @Named("haschild") + private final boolean hasChild; + private final long level; + private final String name; + @Named("networkdomain") + private final String networkDomain; + @Named("parentdomainid") + private final String parentDomainId; + @Named("parentdomainname") + private final String parentDomainName; - public Domain(String id, boolean hasChild, long level, String name, String networkDomain, - String parentDomainId, String parentDomainName) { - this.id = id; + @ConstructorProperties({ + "id", "haschild", "level", "name", "networkdomain", "parentdomainid", "parentdomainname" + }) + protected Domain(String id, boolean hasChild, long level, @Nullable String name, @Nullable String networkDomain, + @Nullable String parentDomainId, @Nullable String parentDomainName) { + this.id = checkNotNull(id, "id"); this.hasChild = hasChild; this.level = level; this.name = name; @@ -112,72 +161,69 @@ public class Domain implements Comparable { } public String getId() { - return id; + return this.id; } public boolean hasChild() { - return hasChild; + return this.hasChild; } public long getLevel() { - return level; + return this.level; } + @Nullable public String getName() { - return name; + return this.name; } + @Nullable public String getNetworkDomain() { - return networkDomain; + return this.networkDomain; } + @Nullable public String getParentDomainId() { - return parentDomainId; + return this.parentDomainId; } + @Nullable public String getParentDomainName() { - return parentDomainName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Domain that = (Domain) o; - - if (!Objects.equal(hasChild, that.hasChild)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(level, that.level)) return false; - if (!Objects.equal(parentDomainId, that.parentDomainId)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(networkDomain, that.networkDomain)) return false; - if (!Objects.equal(parentDomainName, that.parentDomainName)) return false; - - return true; + return this.parentDomainName; } @Override public int hashCode() { - return Objects.hashCode(id, hasChild, level, name, networkDomain, parentDomainId, parentDomainName); + return Objects.hashCode(id, hasChild, level, name, networkDomain, parentDomainId, parentDomainName); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Domain that = Domain.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.hasChild, that.hasChild) + && Objects.equal(this.level, that.level) + && Objects.equal(this.name, that.name) + && Objects.equal(this.networkDomain, that.networkDomain) + && Objects.equal(this.parentDomainId, that.parentDomainId) + && Objects.equal(this.parentDomainName, that.parentDomainName); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("hasChild", hasChild).add("level", level).add("name", name).add("networkDomain", networkDomain).add("parentDomainId", parentDomainId).add("parentDomainName", parentDomainName); } @Override public String toString() { - return "Domain{" + - "id='" + id + '\'' + - ", hasChild=" + hasChild + - ", level=" + level + - ", name='" + name + '\'' + - ", networkDomain='" + networkDomain + '\'' + - ", parentDomainId='" + parentDomainId + '\'' + - ", parentDomainName='" + parentDomainName + '\'' + - '}'; + return string().toString(); } @Override - public int compareTo(Domain arg0) { - return id.compareTo(arg0.getId()); + public int compareTo(Domain other) { + return id.compareTo(other.getId()); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPasswordAndPrivateKey.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPasswordAndPrivateKey.java index fcec6d9174..cf2ae210dd 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPasswordAndPrivateKey.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPasswordAndPrivateKey.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,17 +18,75 @@ */ package org.jclouds.cloudstack.domain; +import java.beans.ConstructorProperties; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** + * Class EncryptedPasswordAndPrivateKey + * * @author Andrei Savu */ public class EncryptedPasswordAndPrivateKey { + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromEncryptedPasswordAndPrivateKey(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String encryptedPassword; + protected String privateKey; + + /** + * @see EncryptedPasswordAndPrivateKey#getEncryptedPassword() + */ + public T encryptedPassword(String encryptedPassword) { + this.encryptedPassword = encryptedPassword; + return self(); + } + + /** + * @see EncryptedPasswordAndPrivateKey#getPrivateKey() + */ + public T privateKey(String privateKey) { + this.privateKey = privateKey; + return self(); + } + + public EncryptedPasswordAndPrivateKey build() { + return new EncryptedPasswordAndPrivateKey(encryptedPassword, privateKey); + } + + public T fromEncryptedPasswordAndPrivateKey(EncryptedPasswordAndPrivateKey in) { + return this + .encryptedPassword(in.getEncryptedPassword()) + .privateKey(in.getPrivateKey()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + private final String encryptedPassword; private final String privateKey; - public EncryptedPasswordAndPrivateKey(String encryptedPassword, String privateKey) { + @ConstructorProperties({ + "encryptedPassword", "privateKey" + }) + protected EncryptedPasswordAndPrivateKey(@Nullable String encryptedPassword, @Nullable String privateKey) { this.encryptedPassword = encryptedPassword; this.privateKey = privateKey; } @@ -36,40 +94,41 @@ public class EncryptedPasswordAndPrivateKey { /** * @return the encrypted password String representation */ + @Nullable public String getEncryptedPassword() { - return encryptedPassword; + return this.encryptedPassword; } /** * @return get the string representation of the private key */ + @Nullable public String getPrivateKey() { - return privateKey; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - EncryptedPasswordAndPrivateKey that = (EncryptedPasswordAndPrivateKey) o; - - if (!Objects.equal(encryptedPassword, that.encryptedPassword)) return false; - if (!Objects.equal(privateKey, that.privateKey)) return false; - - return true; + return this.privateKey; } @Override public int hashCode() { - return Objects.hashCode(encryptedPassword, privateKey); + return Objects.hashCode(encryptedPassword, privateKey); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + EncryptedPasswordAndPrivateKey that = EncryptedPasswordAndPrivateKey.class.cast(obj); + return Objects.equal(this.encryptedPassword, that.encryptedPassword) + && Objects.equal(this.privateKey, that.privateKey); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("encryptedPassword", encryptedPassword).add("privateKey", privateKey); } @Override public String toString() { - return "EncryptedPasswordAndPrivateKey{" + - "encryptedPassword='" + encryptedPassword + '\'' + - ", privateKey='" + privateKey + '\'' + - '}'; + return string().toString(); } + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Event.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Event.java index c1b6c1a7b6..27645bbb27 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Event.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Event.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,112 +18,180 @@ */ package org.jclouds.cloudstack.domain; -import com.google.common.base.Objects; +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + /** + * Class Event + * * @author Vijay Kiran */ public class Event implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { - private String id; - private String account; - private String description; - private Date created; - private String domain; - private String domainId; - //TODO Change to enum : the event level (INFO, WARN, ERROR) - private String level; - private String parentId; - private String state; - //Event Type - private String type; - private String username; + public Builder toBuilder() { + return new ConcreteBuilder().fromEvent(this); + } - public Builder id(String id) { + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected String account; + protected String description; + protected Date created; + protected String domain; + protected String domainId; + protected String level; + protected String parentId; + protected String state; + protected String type; + protected String username; + + /** + * @see Event#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder account(String account) { + /** + * @see Event#getAccount() + */ + public T account(String account) { this.account = account; - return this; + return self(); } - public Builder description(String description) { + /** + * @see Event#getDescription() + */ + public T description(String description) { this.description = description; - return this; + return self(); } - public Builder created(Date created) { + /** + * @see Event#getCreated() + */ + public T created(Date created) { this.created = created; - return this; + return self(); } - public Builder domain(String domain) { + /** + * @see Event#getDomain() + */ + public T domain(String domain) { this.domain = domain; - return this; + return self(); } - public Builder domainId(String domainId) { + /** + * @see Event#getDomainId() + */ + public T domainId(String domainId) { this.domainId = domainId; - return this; + return self(); } - public Builder level(String level) { + /** + * @see Event#getLevel() + */ + public T level(String level) { this.level = level; - return this; + return self(); } - public Builder parentId(String parentId) { + /** + * @see Event#getParentId() + */ + public T parentId(String parentId) { this.parentId = parentId; - return this; + return self(); } - public Builder state(String state) { + /** + * @see Event#getState() + */ + public T state(String state) { this.state = state; - return this; + return self(); } - public Builder type(String type) { + /** + * @see Event#getType() + */ + public T type(String type) { this.type = type; - return this; + return self(); } - public Builder username(String username) { + /** + * @see Event#getUsername() + */ + public T username(String username) { this.username = username; - return this; + return self(); } public Event build() { return new Event(id, account, description, created, domain, domainId, level, parentId, state, type, username); } + public T fromEvent(Event in) { + return this + .id(in.getId()) + .account(in.getAccount()) + .description(in.getDescription()) + .created(in.getCreated()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .level(in.getLevel()) + .parentId(in.getParentId()) + .state(in.getState()) + .type(in.getType()) + .username(in.getUsername()); + } } - private String id; - private String account; - private String description; - private Date created; - private String domain; - private String domainId; - //TODO Change to enum : the event level (INFO, WARN, ERROR) - private String level; - private String parentId; - private String state; - //Event Type - private String type; - private String username; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - public Event(String id, String account, String description, Date created, String domain, String domainId, String level, - String parentId, String state, String type, String username) { - this.id = id; + private final String id; + private final String account; + private final String description; + private final Date created; + private final String domain; + private final String domainId; + private final String level; + private final String parentId; + private final String state; + private final String type; + private final String username; + + @ConstructorProperties({ + "id", "account", "description", "created", "domain", "domainId", "level", "parentId", "state", "type", "username" + }) + protected Event(String id, @Nullable String account, @Nullable String description, @Nullable Date created, + @Nullable String domain, @Nullable String domainId, @Nullable String level, @Nullable String parentId, + @Nullable String state, @Nullable String type, @Nullable String username) { + this.id = checkNotNull(id, "id"); this.account = account; this.description = description; this.created = created; @@ -136,140 +204,133 @@ public class Event implements Comparable { this.username = username; } - /** - * present only for serializer - */ - Event() { - - } - /** * @return the ID of the event */ public String getId() { - return id; + return this.id; } /** * @return the account name for the account that owns the object being acted on in the event - * (e.g. the owner of the virtual machine, ip address, or security group) + (e.g. the owner of the virtual machine, ip address, or security group) */ + @Nullable public String getAccount() { - return account; - } - - /** - * @return the date the event was created - */ - public Date getCreated() { - return created; + return this.account; } /** * @return the description of the event */ + @Nullable public String getDescription() { - return description; + return this.description; + } + + /** + * @return the date the event was created + */ + @Nullable + public Date getCreated() { + return this.created; } /** * @return the name of the account's domain */ + @Nullable public String getDomain() { - return domain; + return this.domain; } /** * @return the id of the account's domain */ + @Nullable public String getDomainId() { - return domainId; + return this.domainId; } /** * @return the event level (INFO, WARN, ERROR) */ + @Nullable public String getLevel() { - return level; + return this.level; } /** * @return whether the event is parented */ + @Nullable public String getParentId() { - return parentId; + return this.parentId; } /** * @return the state of the event */ + @Nullable public String getState() { - return state; + return this.state; } /** * @return the type of the event (see event types) */ + @Nullable public String getType() { - return type; + return this.type; } /** * @return the name of the user who performed the action (can be different from the account if - * an admin is performing an action for a user, e.g. starting/stopping a user's virtual machine) + an admin is performing an action for a user, e.g. starting/stopping a user's virtual machine) */ + @Nullable public String getUsername() { - return username; - } - - @Override - public int compareTo(Event arg0) { - return id.compareTo(arg0.getId()); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Event that = (Event) o; - - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(account, that.account)) return false; - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(description, that.description)) return false; - if (!Objects.equal(domain, that.domain)) return false; - if (!Objects.equal(level, that.level)) return false; - if (!Objects.equal(parentId, that.parentId)) return false; - if (!Objects.equal(state, that.state)) return false; - if (!Objects.equal(type, that.type)) return false; - if (!Objects.equal(username, that.username)) return false; - - return true; + return this.username; } @Override public int hashCode() { - return Objects.hashCode(id, account, description, created, domain, domainId, level, parentId, state, type, username); + return Objects.hashCode(id, account, description, created, domain, domainId, level, parentId, state, type, username); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Event that = Event.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.account, that.account) + && Objects.equal(this.description, that.description) + && Objects.equal(this.created, that.created) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.level, that.level) + && Objects.equal(this.parentId, that.parentId) + && Objects.equal(this.state, that.state) + && Objects.equal(this.type, that.type) + && Objects.equal(this.username, that.username); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("account", account).add("description", description).add("created", created) + .add("domain", domain).add("domainId", domainId).add("level", level).add("parentId", parentId) + .add("state", state).add("type", type).add("username", username); } @Override public String toString() { - return "Event{" + - "id=" + id + - ", account='" + account + '\'' + - ", description='" + description + '\'' + - ", created=" + created + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", level='" + level + '\'' + - ", parentId='" + parentId + '\'' + - ", state='" + state + '\'' + - ", type='" + type + '\'' + - ", username='" + username + '\'' + - '}'; + return string().toString(); } + @Override + public int compareTo(Event other) { + return id.compareTo(other.getId()); + } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/FirewallRule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/FirewallRule.java index 8b94d6796a..12c43e7d5f 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/FirewallRule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/FirewallRule.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,18 +18,29 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.util.Set; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.CaseFormat; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; -import com.google.gson.annotations.SerializedName; /** + * Class FirewallRule + * * @author Andrei Savu */ public class FirewallRule implements Comparable { + /** + */ public static enum Protocol { TCP, UDP, @@ -73,105 +84,164 @@ public class FirewallRule implements Comparable { } } - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { - private String id; - private Set CIDRs; + public Builder toBuilder() { + return new ConcreteBuilder().fromFirewallRule(this); + } - private int startPort; - private int endPort; + public static abstract class Builder> { + protected abstract T self(); - private String icmpCode; - private String icmpType; + protected String id; + protected Set CIDRs = ImmutableSet.of(); + protected int startPort; + protected int endPort; + protected String icmpCode; + protected String icmpType; + protected String ipAddress; + protected String ipAddressId; + protected FirewallRule.Protocol protocol; + protected FirewallRule.State state; - private String ipAddress; - private String ipAddressId; - - private Protocol protocol; - private State state; - - public Builder id(String id) { + /** + * @see FirewallRule#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder CIDRs(Set CIDRs) { - this.CIDRs = ImmutableSet.copyOf(CIDRs); - return this; + /** + * @see FirewallRule#getCIDRs() + */ + public T CIDRs(Set CIDRs) { + this.CIDRs = ImmutableSet.copyOf(checkNotNull(CIDRs, "CIDRs")); + return self(); } - public Builder startPort(int startPort) { + public T CIDRs(String... in) { + return CIDRs(ImmutableSet.copyOf(in)); + } + + /** + * @see FirewallRule#getStartPort() + */ + public T startPort(int startPort) { this.startPort = startPort; - return this; + return self(); } - public Builder endPort(int endPort) { + /** + * @see FirewallRule#getEndPort() + */ + public T endPort(int endPort) { this.endPort = endPort; - return this; + return self(); } - public Builder icmpCode(String icmpCode) { + /** + * @see FirewallRule#getIcmpCode() + */ + public T icmpCode(String icmpCode) { this.icmpCode = icmpCode; - return this; + return self(); } - public Builder icmpType(String icmpType) { + /** + * @see FirewallRule#getIcmpType() + */ + public T icmpType(String icmpType) { this.icmpType = icmpType; - return this; + return self(); } - public Builder ipAddress(String ipAddress) { + /** + * @see FirewallRule#getIpAddress() + */ + public T ipAddress(String ipAddress) { this.ipAddress = ipAddress; - return this; + return self(); } - public Builder ipAddressId(String ipAddressId) { + /** + * @see FirewallRule#getIpAddressId() + */ + public T ipAddressId(String ipAddressId) { this.ipAddressId = ipAddressId; - return this; + return self(); } - public Builder protocol(Protocol protocol) { + /** + * @see FirewallRule#getProtocol() + */ + public T protocol(FirewallRule.Protocol protocol) { this.protocol = protocol; - return this; + return self(); } - public Builder state(State state) { + /** + * @see FirewallRule#getState() + */ + public T state(FirewallRule.State state) { this.state = state; - return this; + return self(); } public FirewallRule build() { - return new FirewallRule(id, CIDRs, startPort, endPort, icmpCode, - icmpType, ipAddress, ipAddressId, protocol, state); + return new FirewallRule(id, CIDRs, startPort, endPort, icmpCode, icmpType, ipAddress, ipAddressId, protocol, state); + } + + public T fromFirewallRule(FirewallRule in) { + return this + .id(in.getId()) + .CIDRs(in.getCIDRs()) + .startPort(in.getStartPort()) + .endPort(in.getEndPort()) + .icmpCode(in.getIcmpCode()) + .icmpType(in.getIcmpType()) + .ipAddress(in.getIpAddress()) + .ipAddressId(in.getIpAddressId()) + .protocol(in.getProtocol()) + .state(in.getState()); } } - private String id; - @SerializedName("cidrlist") - private Set CIDRs; - @SerializedName("startport") - private int startPort; - @SerializedName("endport") - private int endPort; - @SerializedName("icmpcode") - private String icmpCode; - @SerializedName("icmptype") - private String icmpType; - @SerializedName("ipaddress") - private String ipAddress; - @SerializedName("ipaddressid") - private String ipAddressId; - private Protocol protocol; - private State state; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - public FirewallRule(String id, Set CIDRs, int startPort, int endPort, - String icmpCode, String icmpType, String ipAddress, String ipAddressId, - Protocol protocol, State state) { - this.id = id; - this.CIDRs = ImmutableSet.copyOf(CIDRs); + private final String id; + @Named("cidrlist") + private final Set CIDRs; + @Named("startport") + private final int startPort; + @Named("endport") + private final int endPort; + @Named("icmpcode") + private final String icmpCode; + @Named("icmptype") + private final String icmpType; + @Named("ipaddress") + private final String ipAddress; + @Named("ipaddressid") + private final String ipAddressId; + private final FirewallRule.Protocol protocol; + private final FirewallRule.State state; + + @ConstructorProperties({ + "id", "cidrlist", "startport", "endport", "icmpcode", "icmptype", "ipaddress", "ipaddressid", "protocol", "state" + }) + protected FirewallRule(String id, @Nullable Set CIDRs, int startPort, int endPort, @Nullable String icmpCode, + @Nullable String icmpType, @Nullable String ipAddress, @Nullable String ipAddressId, + @Nullable FirewallRule.Protocol protocol, @Nullable FirewallRule.State state) { + this.id = checkNotNull(id, "id"); + this.CIDRs = CIDRs == null ? ImmutableSet.of() : ImmutableSet.copyOf(CIDRs); this.startPort = startPort; this.endPort = endPort; this.icmpCode = icmpCode; @@ -182,90 +252,88 @@ public class FirewallRule implements Comparable { this.state = state; } - @Override - public int compareTo(FirewallRule arg0) { - return id.compareTo(arg0.getId()); - } - public String getId() { - return id; + return this.id; } public Set getCIDRs() { - return CIDRs; + return this.CIDRs; } public int getStartPort() { - return startPort; + return this.startPort; } public int getEndPort() { - return endPort; + return this.endPort; } + @Nullable public String getIcmpCode() { - return icmpCode; + return this.icmpCode; } + @Nullable public String getIcmpType() { - return icmpType; + return this.icmpType; } + @Nullable public String getIpAddress() { - return ipAddress; + return this.ipAddress; } + @Nullable public String getIpAddressId() { - return ipAddressId; + return this.ipAddressId; } - public Protocol getProtocol() { - return protocol; + @Nullable + public FirewallRule.Protocol getProtocol() { + return this.protocol; } - public State getState() { - return state; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - FirewallRule that = (FirewallRule) o; - - if (!Objects.equal(endPort, that.endPort)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(startPort, that.startPort)) return false; - if (!Objects.equal(CIDRs, that.CIDRs)) return false; - if (!Objects.equal(icmpCode, that.icmpCode)) return false; - if (!Objects.equal(icmpType, that.icmpType)) return false; - if (!Objects.equal(ipAddress, that.ipAddress)) return false; - if (!Objects.equal(ipAddressId, that.ipAddressId)) return false; - if (!Objects.equal(protocol, that.protocol)) return false; - if (!Objects.equal(state, that.state)) return false; - - return true; + @Nullable + public FirewallRule.State getState() { + return this.state; } @Override public int hashCode() { - return Objects.hashCode(endPort, id, startPort, CIDRs, icmpCode, icmpType, ipAddress, ipAddressId, protocol, state); + return Objects.hashCode(id, CIDRs, startPort, endPort, icmpCode, icmpType, ipAddress, ipAddressId, protocol, state); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + FirewallRule that = FirewallRule.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.CIDRs, that.CIDRs) + && Objects.equal(this.startPort, that.startPort) + && Objects.equal(this.endPort, that.endPort) + && Objects.equal(this.icmpCode, that.icmpCode) + && Objects.equal(this.icmpType, that.icmpType) + && Objects.equal(this.ipAddress, that.ipAddress) + && Objects.equal(this.ipAddressId, that.ipAddressId) + && Objects.equal(this.protocol, that.protocol) + && Objects.equal(this.state, that.state); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("CIDRs", CIDRs).add("startPort", startPort).add("endPort", endPort).add("icmpCode", icmpCode) + .add("icmpType", icmpType).add("ipAddress", ipAddress).add("ipAddressId", ipAddressId).add("protocol", protocol).add("state", state); } @Override public String toString() { - return "FirewallRule{" + - "id=" + id + - ", CIDRs='" + CIDRs + '\'' + - ", startPort=" + startPort + - ", endPort=" + endPort + - ", icmpCode='" + icmpCode + '\'' + - ", icmpType='" + icmpType + '\'' + - ", ipAddress='" + ipAddress + '\'' + - ", ipAddressId='" + ipAddressId + '\'' + - ", protocol='" + protocol + '\'' + - ", state='" + state + '\'' + - '}'; + return string().toString(); } + + @Override + public int compareTo(FirewallRule other) { + return id.compareTo(other.getId()); + } + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/GuestIPType.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/GuestIPType.java index 60f378f9ce..76f12744e9 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/GuestIPType.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/GuestIPType.java @@ -25,7 +25,7 @@ import com.google.common.base.CaseFormat; /** * * @author Adrian Cole - * @see NetworkOfferingClient#listNetworkOfferings + * @see org.jclouds.cloudstack.features.OfferingClient#listNetworkOfferings */ public enum GuestIPType { diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java index a92ba74b19..00f822fad2 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,11 +20,17 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.CaseFormat.UPPER_CAMEL; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * Represents a host issued by Cloudstack @@ -41,7 +47,7 @@ public class Host implements Comparable { public static ClusterType fromValue(String value) { try { return valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, value)); - } catch(IllegalArgumentException e) { + } catch (IllegalArgumentException e) { return UNKNOWN; } } @@ -116,368 +122,544 @@ public class Host implements Comparable { } } - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { - private String id; - private AllocationState allocationState; - private int averageLoad; - private String capabilities; - private String clusterId; - private String clusterName; - private ClusterType clusterType; - private String cpuAllocated; - private int cpuNumber; - private int cpuSpeed; - private String cpuUsed; - private float cpuWithOverProvisioning; - private Date created; - private Date disconnected; - private long diskSizeAllocated; - private long diskSizeTotal; - private String events; - private boolean hasEnoughCapacity; - private String hostTags; - private String hypervisor; - private String ipAddress; - private boolean localStorageActive; - private String jobId; - private AsyncJob.Status jobStatus; - private Date lastPinged; - private String managementServerId; - private long memoryAllocated; - private long memoryTotal; - private long memoryUsed; - private String name; - private long networkKbsRead; - private long networkKbsWrite; - private String osCategoryId; - private String osCategoryName; - private String podId; - private String podName; - private Date removed; - private State state; - private Type type; - private String version; - private String zoneId; - private String zoneName; + public Builder toBuilder() { + return new ConcreteBuilder().fromHost(this); + } - public Builder id(String id) { + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected AllocationState allocationState; + protected int averageLoad; + protected String capabilities; + protected String clusterId; + protected String clusterName; + protected Host.ClusterType clusterType; + protected String cpuAllocated; + protected int cpuNumber; + protected int cpuSpeed; + protected String cpuUsed; + protected float cpuWithOverProvisioning; + protected Date created; + protected Date disconnected; + protected long diskSizeAllocated; + protected long diskSizeTotal; + protected String events; + protected boolean hasEnoughCapacity; + protected String hostTags; + protected String hypervisor; + protected String ipAddress; + protected boolean localStorageActive; + protected String jobId; + protected AsyncJob.Status jobStatus; + protected Date lastPinged; + protected String managementServerId; + protected long memoryAllocated; + protected long memoryTotal; + protected long memoryUsed; + protected String name; + protected long networkKbsRead; + protected long networkKbsWrite; + protected String osCategoryId; + protected String osCategoryName; + protected String podId; + protected String podName; + protected Date removed; + protected Host.State state; + protected Host.Type type; + protected String version; + protected String zoneId; + protected String zoneName; + + /** + * @see Host#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder allocationState(AllocationState allocationState) { + /** + * @see Host#getAllocationState() + */ + public T allocationState(AllocationState allocationState) { this.allocationState = allocationState; - return this; + return self(); } - public Builder averageLoad(int averageLoad) { + /** + * @see Host#getAverageLoad() + */ + public T averageLoad(int averageLoad) { this.averageLoad = averageLoad; - return this; + return self(); } - public Builder capabilities(String capabilities) { + /** + * @see Host#getCapabilities() + */ + public T capabilities(String capabilities) { this.capabilities = capabilities; - return this; + return self(); } - public Builder clusterId(String clusterId) { + /** + * @see Host#getClusterId() + */ + public T clusterId(String clusterId) { this.clusterId = clusterId; - return this; + return self(); } - public Builder clusterName(String clusterName) { + /** + * @see Host#getClusterName() + */ + public T clusterName(String clusterName) { this.clusterName = clusterName; - return this; + return self(); } - public Builder clusterType(ClusterType clusterType) { + /** + * @see Host#getClusterType() + */ + public T clusterType(Host.ClusterType clusterType) { this.clusterType = clusterType; - return this; + return self(); } - public Builder cpuAllocated(String cpuAllocated) { + /** + * @see Host#getCpuAllocated() + */ + public T cpuAllocated(String cpuAllocated) { this.cpuAllocated = cpuAllocated; - return this; + return self(); } - public Builder cpuNumber(int cpuNumber) { + /** + * @see Host#getCpuNumber() + */ + public T cpuNumber(int cpuNumber) { this.cpuNumber = cpuNumber; - return this; + return self(); } - public Builder cpuSpeed(int cpuSpeed) { + /** + * @see Host#getCpuSpeed() + */ + public T cpuSpeed(int cpuSpeed) { this.cpuSpeed = cpuSpeed; - return this; + return self(); } - public Builder cpuUsed(String cpuUsed) { + /** + * @see Host#getCpuUsed() + */ + public T cpuUsed(String cpuUsed) { this.cpuUsed = cpuUsed; - return this; + return self(); } - public Builder cpuWithOverProvisioning(float cpuWithOverProvisioning) { + /** + * @see Host#getCpuWithOverProvisioning() + */ + public T cpuWithOverProvisioning(float cpuWithOverProvisioning) { this.cpuWithOverProvisioning = cpuWithOverProvisioning; - return this; + return self(); } - public Builder created(Date created) { + /** + * @see Host#getCreated() + */ + public T created(Date created) { this.created = created; - return this; + return self(); } - public Builder disconnected(Date disconnected) { + /** + * @see Host#getDisconnected() + */ + public T disconnected(Date disconnected) { this.disconnected = disconnected; - return this; + return self(); } - public Builder diskSizeAllocated(long diskSizeAllocated) { + /** + * @see Host#getDiskSizeAllocated() + */ + public T diskSizeAllocated(long diskSizeAllocated) { this.diskSizeAllocated = diskSizeAllocated; - return this; + return self(); } - public Builder diskSizeTotal(long diskSizeTotal) { + /** + * @see Host#getDiskSizeTotal() + */ + public T diskSizeTotal(long diskSizeTotal) { this.diskSizeTotal = diskSizeTotal; - return this; + return self(); } - public Builder events(String events) { + /** + * @see Host#getEvents() + */ + public T events(String events) { this.events = events; - return this; + return self(); } - public Builder hasEnoughCapacity(boolean hasEnoughCapacity) { + /** + * @see Host#isHasEnoughCapacity() + */ + public T hasEnoughCapacity(boolean hasEnoughCapacity) { this.hasEnoughCapacity = hasEnoughCapacity; - return this; + return self(); } - public Builder hostTags(String hostTags) { + /** + * @see Host#getHostTags() + */ + public T hostTags(String hostTags) { this.hostTags = hostTags; - return this; + return self(); } - public Builder hypervisor(String hypervisor) { + /** + * @see Host#getHypervisor() + */ + public T hypervisor(String hypervisor) { this.hypervisor = hypervisor; - return this; + return self(); } - public Builder ipAddress(String ipAddress) { + /** + * @see Host#getIpAddress() + */ + public T ipAddress(String ipAddress) { this.ipAddress = ipAddress; - return this; + return self(); } - public Builder localStorageActive(boolean localStorageActive) { + /** + * @see Host#isLocalStorageActive() + */ + public T localStorageActive(boolean localStorageActive) { this.localStorageActive = localStorageActive; - return this; + return self(); } - public Builder jobId(String jobId) { + /** + * @see Host#getJobId() + */ + public T jobId(String jobId) { this.jobId = jobId; - return this; + return self(); } - public Builder jobStatus(AsyncJob.Status jobStatus) { + /** + * @see Host#getJobStatus() + */ + public T jobStatus(AsyncJob.Status jobStatus) { this.jobStatus = jobStatus; - return this; + return self(); } - public Builder lastPinged(Date lastPinged) { + /** + * @see Host#getLastPinged() + */ + public T lastPinged(Date lastPinged) { this.lastPinged = lastPinged; - return this; + return self(); } - public Builder managementServerId(String managementServerId) { + /** + * @see Host#getManagementServerId() + */ + public T managementServerId(String managementServerId) { this.managementServerId = managementServerId; - return this; + return self(); } - public Builder memoryAllocated(long memoryAllocated) { + /** + * @see Host#getMemoryAllocated() + */ + public T memoryAllocated(long memoryAllocated) { this.memoryAllocated = memoryAllocated; - return this; + return self(); } - public Builder memoryTotal(long memoryTotal) { + /** + * @see Host#getMemoryTotal() + */ + public T memoryTotal(long memoryTotal) { this.memoryTotal = memoryTotal; - return this; + return self(); } - public Builder memoryUsed(long memoryUsed) { + /** + * @see Host#getMemoryUsed() + */ + public T memoryUsed(long memoryUsed) { this.memoryUsed = memoryUsed; - return this; + return self(); } - public Builder name(String name) { + /** + * @see Host#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder networkKbsRead(long networkKbsRead) { + /** + * @see Host#getNetworkKbsRead() + */ + public T networkKbsRead(long networkKbsRead) { this.networkKbsRead = networkKbsRead; - return this; + return self(); } - public Builder networkKbsWrite(long networkKbsWrite) { + /** + * @see Host#getNetworkKbsWrite() + */ + public T networkKbsWrite(long networkKbsWrite) { this.networkKbsWrite = networkKbsWrite; - return this; + return self(); } - public Builder osCategoryId(String osCategoryId) { + /** + * @see Host#getOsCategoryId() + */ + public T osCategoryId(String osCategoryId) { this.osCategoryId = osCategoryId; - return this; + return self(); } - public Builder osCategoryName(String osCategoryName) { + /** + * @see Host#getOsCategoryName() + */ + public T osCategoryName(String osCategoryName) { this.osCategoryName = osCategoryName; - return this; + return self(); } - public Builder podId(String podId) { + /** + * @see Host#getPodId() + */ + public T podId(String podId) { this.podId = podId; - return this; + return self(); } - public Builder podName(String podName) { + /** + * @see Host#getPodName() + */ + public T podName(String podName) { this.podName = podName; - return this; + return self(); } - public Builder removed(Date removed) { + /** + * @see Host#getRemoved() + */ + public T removed(Date removed) { this.removed = removed; - return this; + return self(); } - public Builder state(State state) { + /** + * @see Host#getState() + */ + public T state(Host.State state) { this.state = state; - return this; + return self(); } - public Builder type(Type type) { + /** + * @see Host#getType() + */ + public T type(Host.Type type) { this.type = type; - return this; + return self(); } - public Builder version(String version) { + /** + * @see Host#getVersion() + */ + public T version(String version) { this.version = version; - return this; + return self(); } - public Builder zoneId(String zoneId) { + /** + * @see Host#getZoneId() + */ + public T zoneId(String zoneId) { this.zoneId = zoneId; - return this; + return self(); } - public Builder zoneName(String zoneName) { + /** + * @see Host#getZoneName() + */ + public T zoneName(String zoneName) { this.zoneName = zoneName; - return this; + return self(); } + public Host build() { - return new Host(id, allocationState, averageLoad, capabilities, - clusterId, clusterName, clusterType, cpuAllocated, - cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, - created, disconnected, diskSizeAllocated, diskSizeTotal, - events, hasEnoughCapacity, hostTags, hypervisor, - ipAddress, localStorageActive, jobId, jobStatus, - lastPinged, managementServerId, memoryAllocated, memoryTotal, - memoryUsed, name, networkKbsRead, networkKbsWrite, - osCategoryId, osCategoryName, podId, podName, removed, - state, type, version, zoneId, zoneName); + return new Host(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, hostTags, hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); + } + + public T fromHost(Host in) { + return this + .id(in.getId()) + .allocationState(in.getAllocationState()) + .averageLoad(in.getAverageLoad()) + .capabilities(in.getCapabilities()) + .clusterId(in.getClusterId()) + .clusterName(in.getClusterName()) + .clusterType(in.getClusterType()) + .cpuAllocated(in.getCpuAllocated()) + .cpuNumber(in.getCpuNumber()) + .cpuSpeed(in.getCpuSpeed()) + .cpuUsed(in.getCpuUsed()) + .cpuWithOverProvisioning(in.getCpuWithOverProvisioning()) + .created(in.getCreated()) + .disconnected(in.getDisconnected()) + .diskSizeAllocated(in.getDiskSizeAllocated()) + .diskSizeTotal(in.getDiskSizeTotal()) + .events(in.getEvents()) + .hasEnoughCapacity(in.isHasEnoughCapacity()) + .hostTags(in.getHostTags()) + .hypervisor(in.getHypervisor()) + .ipAddress(in.getIpAddress()) + .localStorageActive(in.isLocalStorageActive()) + .jobId(in.getJobId()) + .jobStatus(in.getJobStatus()) + .lastPinged(in.getLastPinged()) + .managementServerId(in.getManagementServerId()) + .memoryAllocated(in.getMemoryAllocated()) + .memoryTotal(in.getMemoryTotal()) + .memoryUsed(in.getMemoryUsed()) + .name(in.getName()) + .networkKbsRead(in.getNetworkKbsRead()) + .networkKbsWrite(in.getNetworkKbsWrite()) + .osCategoryId(in.getOsCategoryId()) + .osCategoryName(in.getOsCategoryName()) + .podId(in.getPodId()) + .podName(in.getPodName()) + .removed(in.getRemoved()) + .state(in.getState()) + .type(in.getType()) + .version(in.getVersion()) + .zoneId(in.getZoneId()) + .zoneName(in.getZoneName()); } } - private String id; - @SerializedName("allocationstate") - private AllocationState allocationState; - @SerializedName("averageload") - private int averageLoad; - @SerializedName("capabilities") - private String capabilities; - @SerializedName("clusterid") - private String clusterId; - @SerializedName("clustername") - private String clusterName; - @SerializedName("clustertype") - private ClusterType clusterType; - @SerializedName("cpuallocated") - private String cpuAllocated; - @SerializedName("cpunumber") - private int cpuNumber; - @SerializedName("cpuspeed") - private int cpuSpeed; - @SerializedName("cpuused") - private String cpuUsed; - @SerializedName("cpuwithoverprovisioning") - private float cpuWithOverProvisioning; - private Date created; - private Date disconnected; - @SerializedName("disksizeallocated") - private long diskSizeAllocated; - @SerializedName("disksizetotal") - private long diskSizeTotal; - private String events; - @SerializedName("hasenoughcapacity") - private boolean hasEnoughCapacity; - @SerializedName("hosttags") - private String hostTags; - private String hypervisor; - @SerializedName("ipaddress") - private String ipAddress; - @SerializedName("islocalstorageactive") - private boolean localStorageActive; - @SerializedName("jobid") - private String jobId; - @SerializedName("jobstatus") - private AsyncJob.Status jobStatus; - @SerializedName("lastpinged") - private Date lastPinged; - @SerializedName("managementserverid") - private String managementServerId; - @SerializedName("memoryallocated") - private long memoryAllocated; - @SerializedName("memorytotal") - private long memoryTotal; - @SerializedName("memoryused") - private long memoryUsed; - private String name; - @SerializedName("networkkbsread") - private long networkKbsRead; - @SerializedName("networkkbswrite") - private long networkKbsWrite; - @SerializedName("oscategoryid") - private String osCategoryId; - @SerializedName("oscategoryname") - private String osCategoryName; - @SerializedName("podid") - private String podId; - @SerializedName("podname") - private String podName; - private Date removed; - private State state; - private Type type; - private String version; - @SerializedName("zoneid") - private String zoneId; - @SerializedName("zonename") - private String zoneName; - - /* exists for the deserializer, only */ - Host() { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public Host(String id, AllocationState allocationState, int averageLoad, String capabilities, - String clusterId, String clusterName, ClusterType clusterType, String cpuAllocated, - int cpuNumber, int cpuSpeed, String cpuUsed, float cpuWithOverProvisioning, - Date created, Date disconnected, long diskSizeAllocated, long diskSizeTotal, - String events, boolean hasEnoughCapacity, String hostTags, String hypervisor, - String ipAddress, boolean localStorageActive, String jobId, AsyncJob.Status jobStatus, - Date lastPinged, String managementServerId, long memoryAllocated, long memoryTotal, - long memoryUsed, String name, long networkKbsRead, long networkKbsWrite, - String osCategoryId, String osCategoryName, String podId, String podName, Date removed, - State state, Type type, String version, String zoneId, String zoneName) { - this.id = id; + private final String id; + @Named("allocationstate") + private final AllocationState allocationState; + @Named("averageload") + private final int averageLoad; + private final String capabilities; + @Named("clusterid") + private final String clusterId; + @Named("clustername") + private final String clusterName; + @Named("clustertype") + private final Host.ClusterType clusterType; + @Named("cpuallocated") + private final String cpuAllocated; + @Named("cpunumber") + private final int cpuNumber; + @Named("cpuspeed") + private final int cpuSpeed; + @Named("cpuused") + private final String cpuUsed; + @Named("cpuwithoverprovisioning") + private final float cpuWithOverProvisioning; + private final Date created; + private final Date disconnected; + @Named("disksizeallocated") + private final long diskSizeAllocated; + @Named("disksizetotal") + private final long diskSizeTotal; + private final String events; + @Named("hasenoughcapacity") + private final boolean hasEnoughCapacity; + @Named("hosttags") + private final String hostTags; + private final String hypervisor; + @Named("ipaddress") + private final String ipAddress; + @Named("islocalstorageactive") + private final boolean localStorageActive; + @Named("jobid") + private final String jobId; + @Named("jobstatus") + private final AsyncJob.Status jobStatus; + @Named("lastpinged") + private final Date lastPinged; + @Named("managementserverid") + private final String managementServerId; + @Named("memoryallocated") + private final long memoryAllocated; + @Named("memorytotal") + private final long memoryTotal; + @Named("memoryused") + private final long memoryUsed; + private final String name; + @Named("networkkbsread") + private final long networkKbsRead; + @Named("networkkbswrite") + private final long networkKbsWrite; + @Named("oscategoryid") + private final String osCategoryId; + @Named("oscategoryname") + private final String osCategoryName; + @Named("podid") + private final String podId; + @Named("podname") + private final String podName; + private final Date removed; + private final Host.State state; + private final Host.Type type; + private final String version; + @Named("zoneid") + private final String zoneId; + @Named("zonename") + private final String zoneName; + + @ConstructorProperties({ + "id", "allocationstate", "averageload", "capabilities", "clusterid", "clustername", "clustertype", "cpuallocated", "cpunumber", "cpuspeed", "cpuused", "cpuwithoverprovisioning", "created", "disconnected", "disksizeallocated", "disksizetotal", "events", "hasenoughcapacity", "hosttags", "hypervisor", "ipaddress", "islocalstorageactive", "jobid", "jobstatus", "lastpinged", "managementserverid", "memoryallocated", "memorytotal", "memoryused", "name", "networkkbsread", "networkkbswrite", "oscategoryid", "oscategoryname", "podid", "podname", "removed", "state", "type", "version", "zoneid", "zonename" + }) + protected Host(String id, @Nullable AllocationState allocationState, int averageLoad, @Nullable String capabilities, + @Nullable String clusterId, @Nullable String clusterName, @Nullable Host.ClusterType clusterType, + @Nullable String cpuAllocated, int cpuNumber, int cpuSpeed, @Nullable String cpuUsed, + float cpuWithOverProvisioning, @Nullable Date created, @Nullable Date disconnected, long diskSizeAllocated, + long diskSizeTotal, @Nullable String events, boolean hasEnoughCapacity, @Nullable String hostTags, + @Nullable String hypervisor, @Nullable String ipAddress, boolean localStorageActive, @Nullable String jobId, + @Nullable AsyncJob.Status jobStatus, @Nullable Date lastPinged, @Nullable String managementServerId, + long memoryAllocated, long memoryTotal, long memoryUsed, @Nullable String name, long networkKbsRead, long networkKbsWrite, + @Nullable String osCategoryId, @Nullable String osCategoryName, @Nullable String podId, @Nullable String podName, + @Nullable Date removed, @Nullable Host.State state, @Nullable Host.Type type, @Nullable String version, @Nullable String zoneId, + @Nullable String zoneName) { + this.id = checkNotNull(id, "id"); this.allocationState = allocationState; this.averageLoad = averageLoad; this.capabilities = capabilities; @@ -522,282 +704,275 @@ public class Host implements Comparable { } public String getId() { - return id; + return this.id; } + @Nullable public AllocationState getAllocationState() { - return allocationState; + return this.allocationState; } public int getAverageLoad() { - return averageLoad; + return this.averageLoad; } + @Nullable public String getCapabilities() { - return capabilities; + return this.capabilities; } + @Nullable public String getClusterId() { - return clusterId; + return this.clusterId; } + @Nullable public String getClusterName() { - return clusterName; + return this.clusterName; } - public ClusterType getClusterType() { - return clusterType; + @Nullable + public Host.ClusterType getClusterType() { + return this.clusterType; } + @Nullable public String getCpuAllocated() { - return cpuAllocated; + return this.cpuAllocated; } public int getCpuNumber() { - return cpuNumber; + return this.cpuNumber; } public int getCpuSpeed() { - return cpuSpeed; + return this.cpuSpeed; } + @Nullable public String getCpuUsed() { - return cpuUsed; + return this.cpuUsed; } public float getCpuWithOverProvisioning() { - return cpuWithOverProvisioning; + return this.cpuWithOverProvisioning; } + @Nullable public Date getCreated() { - return created; + return this.created; } + @Nullable public Date getDisconnected() { - return disconnected; + return this.disconnected; } public long getDiskSizeAllocated() { - return diskSizeAllocated; + return this.diskSizeAllocated; } public long getDiskSizeTotal() { - return diskSizeTotal; + return this.diskSizeTotal; } + @Nullable public String getEvents() { - return events; + return this.events; } public boolean isHasEnoughCapacity() { - return hasEnoughCapacity; + return this.hasEnoughCapacity; } + @Nullable public String getHostTags() { - return hostTags; + return this.hostTags; } + @Nullable public String getHypervisor() { - return hypervisor; + return this.hypervisor; } + @Nullable public String getIpAddress() { - return ipAddress; + return this.ipAddress; } public boolean isLocalStorageActive() { - return localStorageActive; + return this.localStorageActive; } + @Nullable public String getJobId() { - return jobId; + return this.jobId; } + @Nullable public AsyncJob.Status getJobStatus() { - return jobStatus; + return this.jobStatus; } + @Nullable public Date getLastPinged() { - return lastPinged; + return this.lastPinged; } + @Nullable public String getManagementServerId() { - return managementServerId; + return this.managementServerId; } public long getMemoryAllocated() { - return memoryAllocated; + return this.memoryAllocated; } public long getMemoryTotal() { - return memoryTotal; + return this.memoryTotal; } public long getMemoryUsed() { - return memoryUsed; + return this.memoryUsed; } - + + @Nullable public String getName() { - return name; + return this.name; } public long getNetworkKbsRead() { - return networkKbsRead; + return this.networkKbsRead; } public long getNetworkKbsWrite() { - return networkKbsWrite; + return this.networkKbsWrite; } + @Nullable public String getOsCategoryId() { - return osCategoryId; + return this.osCategoryId; } + @Nullable public String getOsCategoryName() { - return osCategoryName; + return this.osCategoryName; } + @Nullable public String getPodId() { - return podId; + return this.podId; } + @Nullable public String getPodName() { - return podName; + return this.podName; } + @Nullable public Date getRemoved() { - return removed; + return this.removed; } - public State getState() { - return state; + @Nullable + public Host.State getState() { + return this.state; } - public Type getType() { - return type; + @Nullable + public Host.Type getType() { + return this.type; } + @Nullable public String getVersion() { - return version; + return this.version; } + @Nullable public String getZoneId() { - return zoneId; + return this.zoneId; } + @Nullable public String getZoneName() { - return zoneName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Host that = (Host) o; - - if (!Objects.equal(averageLoad, that.averageLoad)) return false; - if (!Objects.equal(clusterId, that.clusterId)) return false; - if (!Objects.equal(cpuNumber, that.cpuNumber)) return false; - if (!Objects.equal(cpuSpeed, that.cpuSpeed)) return false; - if (!Objects.equal(cpuWithOverProvisioning, that.cpuWithOverProvisioning)) return false; - if (!Objects.equal(diskSizeAllocated, that.diskSizeAllocated)) return false; - if (!Objects.equal(diskSizeTotal, that.diskSizeTotal)) return false; - if (!Objects.equal(hasEnoughCapacity, that.hasEnoughCapacity)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(jobId, that.jobId)) return false; - if (!Objects.equal(localStorageActive, that.localStorageActive)) return false; - if (!Objects.equal(managementServerId, that.managementServerId)) return false; - if (!Objects.equal(memoryAllocated, that.memoryAllocated)) return false; - if (!Objects.equal(memoryTotal, that.memoryTotal)) return false; - if (!Objects.equal(memoryUsed, that.memoryUsed)) return false; - if (!Objects.equal(networkKbsRead, that.networkKbsRead)) return false; - if (!Objects.equal(networkKbsWrite, that.networkKbsWrite)) return false; - if (!Objects.equal(osCategoryId, that.osCategoryId)) return false; - if (!Objects.equal(osCategoryName, that.osCategoryName)) return false; - if (!Objects.equal(podId, that.podId)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(allocationState, that.allocationState)) return false; - if (!Objects.equal(capabilities, that.capabilities)) return false; - if (!Objects.equal(clusterName, that.clusterName)) return false; - if (!Objects.equal(clusterType, that.clusterType)) return false; - if (!Objects.equal(cpuAllocated, that.cpuAllocated)) return false; - if (!Objects.equal(cpuUsed, that.cpuUsed)) return false; - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(disconnected, that.disconnected)) return false; - if (!Objects.equal(events, that.events)) return false; - if (!Objects.equal(hostTags, that.hostTags)) return false; - if (!Objects.equal(hypervisor, that.hypervisor)) return false; - if (!Objects.equal(ipAddress, that.ipAddress)) return false; - if (!Objects.equal(jobStatus, that.jobStatus)) return false; - if (!Objects.equal(lastPinged, that.lastPinged)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(podName, that.podName)) return false; - if (!Objects.equal(removed, that.removed)) return false; - if (!Objects.equal(state, that.state)) return false; - if (!Objects.equal(type, that.type)) return false; - if (!Objects.equal(version, that.version)) return false; - if (!Objects.equal(zoneName, that.zoneName)) return false; - - return true; + return this.zoneName; } @Override public int hashCode() { - return Objects.hashCode(averageLoad, clusterId, cpuNumber, cpuSpeed, cpuWithOverProvisioning, diskSizeAllocated, - diskSizeTotal, hasEnoughCapacity, id, jobId, localStorageActive, managementServerId, - memoryAllocated, memoryTotal, memoryUsed, networkKbsRead, networkKbsWrite, osCategoryId, - osCategoryName, podId, zoneId, allocationState, capabilities, clusterName, clusterType, - cpuAllocated, cpuUsed, created, disconnected, events, hostTags, hypervisor, ipAddress, - jobStatus, lastPinged, name, podName, removed, state, type, version, zoneName); + return Objects.hashCode(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, hostTags, hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); } - + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Host that = Host.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.allocationState, that.allocationState) + && Objects.equal(this.averageLoad, that.averageLoad) + && Objects.equal(this.capabilities, that.capabilities) + && Objects.equal(this.clusterId, that.clusterId) + && Objects.equal(this.clusterName, that.clusterName) + && Objects.equal(this.clusterType, that.clusterType) + && Objects.equal(this.cpuAllocated, that.cpuAllocated) + && Objects.equal(this.cpuNumber, that.cpuNumber) + && Objects.equal(this.cpuSpeed, that.cpuSpeed) + && Objects.equal(this.cpuUsed, that.cpuUsed) + && Objects.equal(this.cpuWithOverProvisioning, that.cpuWithOverProvisioning) + && Objects.equal(this.created, that.created) + && Objects.equal(this.disconnected, that.disconnected) + && Objects.equal(this.diskSizeAllocated, that.diskSizeAllocated) + && Objects.equal(this.diskSizeTotal, that.diskSizeTotal) + && Objects.equal(this.events, that.events) + && Objects.equal(this.hasEnoughCapacity, that.hasEnoughCapacity) + && Objects.equal(this.hostTags, that.hostTags) + && Objects.equal(this.hypervisor, that.hypervisor) + && Objects.equal(this.ipAddress, that.ipAddress) + && Objects.equal(this.localStorageActive, that.localStorageActive) + && Objects.equal(this.jobId, that.jobId) + && Objects.equal(this.jobStatus, that.jobStatus) + && Objects.equal(this.lastPinged, that.lastPinged) + && Objects.equal(this.managementServerId, that.managementServerId) + && Objects.equal(this.memoryAllocated, that.memoryAllocated) + && Objects.equal(this.memoryTotal, that.memoryTotal) + && Objects.equal(this.memoryUsed, that.memoryUsed) + && Objects.equal(this.name, that.name) + && Objects.equal(this.networkKbsRead, that.networkKbsRead) + && Objects.equal(this.networkKbsWrite, that.networkKbsWrite) + && Objects.equal(this.osCategoryId, that.osCategoryId) + && Objects.equal(this.osCategoryName, that.osCategoryName) + && Objects.equal(this.podId, that.podId) + && Objects.equal(this.podName, that.podName) + && Objects.equal(this.removed, that.removed) + && Objects.equal(this.state, that.state) + && Objects.equal(this.type, that.type) + && Objects.equal(this.version, that.version) + && Objects.equal(this.zoneId, that.zoneId) + && Objects.equal(this.zoneName, that.zoneName); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("allocationState", allocationState).add("averageLoad", averageLoad) + .add("capabilities", capabilities).add("clusterId", clusterId).add("clusterName", clusterName) + .add("clusterType", clusterType).add("cpuAllocated", cpuAllocated).add("cpuNumber", cpuNumber) + .add("cpuSpeed", cpuSpeed).add("cpuUsed", cpuUsed).add("cpuWithOverProvisioning", cpuWithOverProvisioning) + .add("created", created).add("disconnected", disconnected).add("diskSizeAllocated", diskSizeAllocated) + .add("diskSizeTotal", diskSizeTotal).add("events", events).add("hasEnoughCapacity", hasEnoughCapacity) + .add("hostTags", hostTags).add("hypervisor", hypervisor).add("ipAddress", ipAddress) + .add("localStorageActive", localStorageActive).add("jobId", jobId).add("jobStatus", jobStatus) + .add("lastPinged", lastPinged).add("managementServerId", managementServerId).add("memoryAllocated", memoryAllocated) + .add("memoryTotal", memoryTotal).add("memoryUsed", memoryUsed).add("name", name).add("networkKbsRead", networkKbsRead) + .add("networkKbsWrite", networkKbsWrite).add("osCategoryId", osCategoryId).add("osCategoryName", osCategoryName) + .add("podId", podId).add("podName", podName).add("removed", removed).add("state", state).add("type", type) + .add("version", version).add("zoneId", zoneId).add("zoneName", zoneName); + } + @Override public String toString() { - return "Host{" + - "id=" + id + - ", allocationState=" + allocationState + - ", averageLoad=" + averageLoad + - ", capabilities='" + capabilities + '\'' + - ", clusterId=" + clusterId + - ", clusterName='" + clusterName + '\'' + - ", clusterType=" + clusterType + - ", cpuAllocated='" + cpuAllocated + '\'' + - ", cpuNumber=" + cpuNumber + - ", cpuSpeed=" + cpuSpeed + - ", cpuUsed='" + cpuUsed + '\'' + - ", cpuWithOverProvisioning=" + cpuWithOverProvisioning + - ", created=" + created + - ", disconnected=" + disconnected + - ", diskSizeAllocated=" + diskSizeAllocated + - ", diskSizeTotal=" + diskSizeTotal + - ", events='" + events + '\'' + - ", hasEnoughCapacity=" + hasEnoughCapacity + - ", hostTags='" + hostTags + '\'' + - ", hypervisor='" + hypervisor + '\'' + - ", ipAddress='" + ipAddress + '\'' + - ", localStorageActive=" + localStorageActive + - ", jobId=" + jobId + - ", jobStatus=" + jobStatus + - ", lastPinged=" + lastPinged + - ", managementServerId=" + managementServerId + - ", memoryAllocated=" + memoryAllocated + - ", memoryTotal=" + memoryTotal + - ", memoryUsed=" + memoryUsed + - ", name='" + name + '\'' + - ", networkKbsRead=" + networkKbsRead + - ", networkKbsWrite=" + networkKbsWrite + - ", osCategoryId=" + osCategoryId + - ", osCategoryName=" + osCategoryName + - ", podId=" + podId + - ", podName='" + podName + '\'' + - ", removed=" + removed + - ", state=" + state + - ", type=" + type + - ", version='" + version + '\'' + - ", zoneId=" + zoneId + - ", zoneName='" + zoneName + '\'' + - '}'; + return string().toString(); } @Override diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IPForwardingRule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IPForwardingRule.java index 46a0b1133b..f11ff41fcf 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IPForwardingRule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IPForwardingRule.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,151 +18,236 @@ */ package org.jclouds.cloudstack.domain; -import java.util.Collections; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.util.Set; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import com.google.gson.annotations.SerializedName; /** + * Class IPForwardingRule + * * @author Adrian Cole - */ +*/ public class IPForwardingRule implements Comparable { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromIPForwardingRule(this); } - public static class Builder { - private String id; - private String IPAddress; - private String IPAddressId; - private int startPort; - private String protocol; - public int endPort; - private String state; - private String virtualMachineDisplayName; - public String virtualMachineId; - private String virtualMachineName; - private Set CIDRs = ImmutableSet.of(); - private int privateEndPort; - private int publicEndPort; - public int publicPort; + public static abstract class Builder> { + protected abstract T self(); - public Builder id(String id) { + protected String id; + protected String IPAddress; + protected String IPAddressId; + protected int startPort; + protected String protocol; + protected int endPort; + protected String state; + protected String virtualMachineDisplayName; + protected String virtualMachineId; + protected String virtualMachineName; + protected int publicPort; + protected Set CIDRs = ImmutableSet.of(); + protected int privateEndPort; + protected int publicEndPort; + + /** + * @see IPForwardingRule#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder IPAddress(String IPAddress) { + /** + * @see IPForwardingRule#getIPAddress() + */ + public T IPAddress(String IPAddress) { this.IPAddress = IPAddress; - return this; + return self(); } - public Builder IPAddressId(String IPAddressId) { + /** + * @see IPForwardingRule#getIPAddressId() + */ + public T IPAddressId(String IPAddressId) { this.IPAddressId = IPAddressId; - return this; + return self(); } - public Builder startPort(int startPort) { + /** + * @see IPForwardingRule#getStartPort() + */ + public T startPort(int startPort) { this.startPort = startPort; - return this; + return self(); } - public Builder protocol(String protocol) { + /** + * @see IPForwardingRule#getProtocol() + */ + public T protocol(String protocol) { this.protocol = protocol; - return this; + return self(); } - public Builder endPort(int endPort) { + /** + * @see IPForwardingRule#getEndPort() + */ + public T endPort(int endPort) { this.endPort = endPort; - return this; + return self(); } - public Builder state(String state) { + /** + * @see IPForwardingRule#getState() + */ + public T state(String state) { this.state = state; - return this; + return self(); } - public Builder virtualMachineDisplayName(String virtualMachineDisplayName) { + /** + * @see IPForwardingRule#getVirtualMachineDisplayName() + */ + public T virtualMachineDisplayName(String virtualMachineDisplayName) { this.virtualMachineDisplayName = virtualMachineDisplayName; - return this; + return self(); } - public Builder virtualMachineId(String virtualMachineId) { + /** + * @see IPForwardingRule#getVirtualMachineId() + */ + public T virtualMachineId(String virtualMachineId) { this.virtualMachineId = virtualMachineId; - return this; + return self(); } - public Builder virtualMachineName(String virtualMachineName) { + /** + * @see IPForwardingRule#getVirtualMachineName() + */ + public T virtualMachineName(String virtualMachineName) { this.virtualMachineName = virtualMachineName; - return this; + return self(); } - public Builder publicPort(int publicPort) { + /** + * @see IPForwardingRule#getPublicPort() + */ + public T publicPort(int publicPort) { this.publicPort = publicPort; - return this; + return self(); } - public Builder CIDRs(Set CIDRs) { - this.CIDRs = CIDRs; - return this; + /** + * @see IPForwardingRule#getCIDRs() + */ + public T CIDRs(Set CIDRs) { + this.CIDRs = ImmutableSet.copyOf(checkNotNull(CIDRs, "CIDRs")); + return self(); } - public Builder privateEndPort(int privateEndPort) { + public T CIDRs(String... in) { + return CIDRs(ImmutableSet.copyOf(in)); + } + + /** + * @see IPForwardingRule#getPrivateEndPort() + */ + public T privateEndPort(int privateEndPort) { this.privateEndPort = privateEndPort; - return this; + return self(); } - public Builder publicEndPort(int publicEndPort) { + /** + * @see IPForwardingRule#getPublicEndPort() + */ + public T publicEndPort(int publicEndPort) { this.publicEndPort = publicEndPort; - return this; + return self(); } public IPForwardingRule build() { - return new IPForwardingRule(id, IPAddress, IPAddressId, startPort, protocol, endPort, state, - virtualMachineDisplayName, virtualMachineId, virtualMachineName, publicEndPort, publicPort, CIDRs, privateEndPort); + return new IPForwardingRule(id, IPAddress, IPAddressId, startPort, protocol, endPort, state, virtualMachineDisplayName, + virtualMachineId, virtualMachineName, publicPort, CIDRs, privateEndPort, publicEndPort); + } + + public T fromIPForwardingRule(IPForwardingRule in) { + return this + .id(in.getId()) + .IPAddress(in.getIPAddress()) + .IPAddressId(in.getIPAddressId()) + .startPort(in.getStartPort()) + .protocol(in.getProtocol()) + .endPort(in.getEndPort()) + .state(in.getState()) + .virtualMachineDisplayName(in.getVirtualMachineDisplayName()) + .virtualMachineId(in.getVirtualMachineId()) + .virtualMachineName(in.getVirtualMachineName()) + .publicPort(in.getPublicPort()) + .CIDRs(in.getCIDRs()) + .privateEndPort(in.getPrivateEndPort()) + .publicEndPort(in.getPublicEndPort()); } } - private String id; - @SerializedName("ipaddress") - private String IPAddress; - @SerializedName("ipaddressid") - private String IPAddressId; - @SerializedName("startport") - private int startPort; - private String protocol; - @SerializedName("endport") - public int endPort; - private String state; - @SerializedName("virtualmachinedisplayname") - private String virtualMachineDisplayName; - @SerializedName("virtualmachineid") - public String virtualMachineId; - @SerializedName("virtualmachinename") - private String virtualMachineName; - @SerializedName("publicport") - public int publicPort; - @SerializedName("cidrlist") - private Set CIDRs; - @SerializedName("privateendport") - private int privateEndPort; - @SerializedName("publicendport") - private int publicEndPort; - - // for deserializer - IPForwardingRule() { - + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public IPForwardingRule(String id, String iPAddress, String iPAddressId, int startPort, String protocol, int endPort, - String state, String virtualMachineDisplayName, String virtualMachineId, String virtualMachineName, - int publicEndPort, int publicPort, Set CIDRs, int privateEndPort) { - this.id = id; - this.IPAddress = iPAddress; - this.IPAddressId = iPAddressId; + private final String id; + @Named("ipaddress") + private final String IPAddress; + @Named("ipaddressid") + private final String IPAddressId; + @Named("startport") + private final int startPort; + private final String protocol; + @Named("endport") + private final int endPort; + private final String state; + @Named("virtualmachinedisplayname") + private final String virtualMachineDisplayName; + @Named("virtualmachineid") + private final String virtualMachineId; + @Named("virtualmachinename") + private final String virtualMachineName; + @Named("publicport") + private final int publicPort; + @Named("cidrlist") + private final Set CIDRs; + @Named("privateendport") + private final int privateEndPort; + @Named("publicendport") + private final int publicEndPort; + + @ConstructorProperties({ + "id", "ipaddress", "ipaddressid", "startport", "protocol", "endport", "state", "virtualmachinedisplayname", + "virtualmachineid", "virtualmachinename", "publicport", "cidrlist", "privateendport", "publicendport" + }) + protected IPForwardingRule(String id, String IPAddress, String IPAddressId, int startPort, @Nullable String protocol, + int endPort, @Nullable String state, @Nullable String virtualMachineDisplayName, + @Nullable String virtualMachineId, @Nullable String virtualMachineName, int publicPort, + @Nullable Set CIDRs, int privateEndPort, int publicEndPort) { + this.id = checkNotNull(id, "id"); + this.IPAddress = IPAddress; + this.IPAddressId = IPAddressId; this.startPort = startPort; this.protocol = protocol; this.endPort = endPort; @@ -170,153 +255,158 @@ public class IPForwardingRule implements Comparable { this.virtualMachineDisplayName = virtualMachineDisplayName; this.virtualMachineId = virtualMachineId; this.virtualMachineName = virtualMachineName; - this.CIDRs = Sets.newHashSet(CIDRs); + this.publicPort = publicPort; + this.CIDRs = CIDRs == null ? ImmutableSet.of() : ImmutableSet.copyOf(CIDRs); this.privateEndPort = privateEndPort; this.publicEndPort = publicEndPort; - this.publicPort = publicPort; - - } - - @Override - public int compareTo(IPForwardingRule arg0) { - return id.compareTo(arg0.getId()); } /** * @return the ID of the ip forwarding rule */ public String getId() { - return id; + return this.id; } /** * @return the public ip address for the ip forwarding rule */ + @Nullable public String getIPAddress() { - return IPAddress; + return this.IPAddress; } /** * @return the public ip address id for the ip forwarding rule */ + @Nullable public String getIPAddressId() { - return IPAddressId; + return this.IPAddressId; } /** * @return the private port for the ip forwarding rule */ public int getStartPort() { - return startPort; + return this.startPort; } /** * @return the protocol of the ip forwarding rule */ + @Nullable public String getProtocol() { - return protocol; + return this.protocol; } /** * @return the public port for the ip forwarding rule */ public int getEndPort() { - return endPort; + return this.endPort; } /** * @return the state of the rule */ + @Nullable public String getState() { - return state; + return this.state; } /** * @return the VM display name for the ip forwarding rule */ + @Nullable public String getVirtualMachineDisplayName() { - return virtualMachineDisplayName; + return this.virtualMachineDisplayName; } /** * @return the VM ID for the ip forwarding rule */ + @Nullable public String getVirtualMachineId() { - return virtualMachineId; + return this.virtualMachineId; } /** * @return the VM name for the ip forwarding rule */ + @Nullable public String getVirtualMachineName() { - return virtualMachineName; + return this.virtualMachineName; } /** * @return the starting port of port forwarding rule's public port range */ public int getPublicPort() { - return publicPort; + return this.publicPort; } /** * @return the cidr list to forward traffic from */ public Set getCIDRs() { - return Collections.unmodifiableSet(CIDRs); + return this.CIDRs; } /** * @return the ending port of port forwarding rule's private port range */ public int getPrivateEndPort() { - return privateEndPort; + return this.privateEndPort; } /** * @return the ending port of port forwarding rule's private port range */ public int getPublicEndPort() { - return publicEndPort; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - IPForwardingRule that = (IPForwardingRule) o; - - if (!Objects.equal(IPAddress, that.IPAddress)) return false; - if (!Objects.equal(IPAddressId, that.IPAddressId)) return false; - if (!Objects.equal(endPort, that.endPort)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(protocol, that.protocol)) return false; - if (!Objects.equal(startPort, that.startPort)) return false; - if (!Objects.equal(publicEndPort, that.publicEndPort)) return false; - if (!Objects.equal(privateEndPort, that.privateEndPort)) return false; - if (!Objects.equal(publicPort, that.publicPort)) return false; - if (!Objects.equal(state, that.state)) return false; - if (!Objects.equal(virtualMachineDisplayName, that.virtualMachineDisplayName)) return false; - if (!Objects.equal(virtualMachineId, that.virtualMachineId)) return false; - if (!Objects.equal(virtualMachineName, that.virtualMachineName)) return false; - - return true; + return this.publicEndPort; } @Override public int hashCode() { - return Objects.hashCode(IPAddress, IPAddressId, endPort, id, protocol, startPort, publicEndPort, - privateEndPort, publicPort, state, virtualMachineDisplayName, - virtualMachineId, virtualMachineName); + return Objects.hashCode(id, IPAddress, IPAddressId, startPort, protocol, endPort, state, virtualMachineDisplayName, virtualMachineId, virtualMachineName, publicPort, CIDRs, privateEndPort, publicEndPort); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + IPForwardingRule that = IPForwardingRule.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.IPAddress, that.IPAddress) + && Objects.equal(this.IPAddressId, that.IPAddressId) + && Objects.equal(this.startPort, that.startPort) + && Objects.equal(this.protocol, that.protocol) + && Objects.equal(this.endPort, that.endPort) + && Objects.equal(this.state, that.state) + && Objects.equal(this.virtualMachineDisplayName, that.virtualMachineDisplayName) + && Objects.equal(this.virtualMachineId, that.virtualMachineId) + && Objects.equal(this.virtualMachineName, that.virtualMachineName) + && Objects.equal(this.publicPort, that.publicPort) + && Objects.equal(this.CIDRs, that.CIDRs) + && Objects.equal(this.privateEndPort, that.privateEndPort) + && Objects.equal(this.publicEndPort, that.publicEndPort); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("IPAddress", IPAddress).add("IPAddressId", IPAddressId).add("startPort", startPort) + .add("protocol", protocol).add("endPort", endPort).add("state", state).add("virtualMachineDisplayName", virtualMachineDisplayName) + .add("virtualMachineId", virtualMachineId).add("virtualMachineName", virtualMachineName).add("publicPort", publicPort) + .add("CIDRs", CIDRs).add("privateEndPort", privateEndPort).add("publicEndPort", publicEndPort); + } + @Override public String toString() { - return "[IPAddress=" + IPAddress + ", IPAddressId=" + IPAddressId + ", id=" + id + ", startPort=" + startPort - + ", protocol=" + protocol + ", endPort=" + endPort + ", state=" + state + ", virtualMachineDisplayName=" - + virtualMachineDisplayName + ", virtualMachineId=" + virtualMachineId + ", virtualMachineName=" - + virtualMachineName + "]"; + return string().toString(); } + @Override + public int compareTo(IPForwardingRule o) { + return id.compareTo(o.getId()); + } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java index 6ed2242ec3..d5a942e078 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,699 +20,772 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** + * Class ISO + * * @author Richard Downer - */ -public class ISO implements Comparable { - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String id; - private String account; - private String accountId; - private boolean bootable; - private String checksum; - private Date created; - private boolean crossZones; - private String displayText; - private String domain; - private String domainid; - private String format; - private String hostId; - private String hostName; - private String hypervisor; - private boolean isExtractable; - private boolean isFeatured; - private boolean isPublic; - private boolean isReady; - private String jobId; - private String jobStatus; - private String name; - private String osTypeId; - private String osTypeName; - private boolean passwordEnabled; - private Date removed; - private long size; - private String sourceTemplateId; - private String status; - private String templateTag; - private String templateType; - private String zoneId; - private String zoneName; - - /** - * @param id the template ID - */ - public Builder id(String id) { - this.id = id; - return this; - } - - /** - * @param account the account name to which the template belongs - */ - public Builder account(String account) { - this.account = account; - return this; - } - - /** - * @param accountId the account id to which the template belongs - */ - public Builder accountId(String accountId) { - this.accountId = accountId; - return this; - } - - /** - * @param bootable true if the ISO is bootable, false otherwise - */ - public Builder bootable(boolean bootable) { - this.bootable = bootable; - return this; - } - - /** - * @param checksum checksum of the template - */ - public Builder checksum(String checksum) { - this.checksum = checksum; - return this; - } - - /** - * @param created the date this template was created - */ - public Builder created(Date created) { - this.created = created; - return this; - } - - /** - * @param crossZones true if the template is managed across all Zones, false otherwise - */ - public Builder crossZones(boolean crossZones) { - this.crossZones = crossZones; - return this; - } - - /** - * @param displayText the template display text - */ - public Builder displayText(String displayText) { - this.displayText = displayText; - return this; - } - - /** - * @param domain the name of the domain to which the template belongs - */ - public Builder domain(String domain) { - this.domain = domain; - return this; - } - - /** - * @param domainid the ID of the domain to which the template belongs - */ - public Builder domainid(String domainid) { - this.domainid = domainid; - return this; - } - - /** - * @param format the format of the template. - */ - public Builder format(String format) { - this.format = format; - return this; - } - - /** - * @param hostId the ID of the secondary storage host for the template - */ - public Builder hostId(String hostId) { - this.hostId = hostId; - return this; - } - - /** - * @param hostName the name of the secondary storage host for the template - */ - public Builder hostName(String hostName) { - this.hostName = hostName; - return this; - } - - /** - * @param hypervisor the hypervisor on which the template runs - */ - public Builder hypervisor(String hypervisor) { - this.hypervisor = hypervisor; - return this; - } - - /** - * @param isExtractable true if the template is extractable, false otherwise - */ - public Builder isExtractable(boolean isExtractable) { - this.isExtractable = isExtractable; - return this; - } - - /** - * @param isFeatured true if this template is a featured template, false otherwise - */ - public Builder isFeatured(boolean isFeatured) { - this.isFeatured = isFeatured; - return this; - } - - /** - * @param isPublic true if this template is a public template, false otherwise - */ - public Builder isPublic(boolean isPublic) { - this.isPublic = isPublic; - return this; - } - - /** - * @param isReady true if the template is ready to be deployed from, false otherwise. - */ - public Builder isReady(boolean isReady) { - this.isReady = isReady; - return this; - } - - /** - * @param jobId shows the current pending asynchronous job ID. This tag is not returned if no current pending jobs are acting on the template - */ - public Builder jobId(String jobId) { - this.jobId = jobId; - return this; - } - - /** - * @param jobStatus shows the current pending asynchronous job status - */ - public Builder jobStatus(String jobStatus) { - this.jobStatus = jobStatus; - return this; - } - - /** - * @param name the template name - */ - public Builder name(String name) { - this.name = name; - return this; - } - - /** - * @param osTypeId the ID of the OS type for this template. - */ - public Builder osTypeId(String osTypeId) { - this.osTypeId = osTypeId; - return this; - } - - /** - * @param osTypeName the name of the OS type for this template. - */ - public Builder osTypeName(String osTypeName) { - this.osTypeName = osTypeName; - return this; - } - - /** - * @param passwordEnabled true if the reset password feature is enabled, false otherwise - */ - public Builder passwordEnabled(boolean passwordEnabled) { - this.passwordEnabled = passwordEnabled; - return this; - } - - /** - * @param removed the date this template was removed - */ - public Builder removed(Date removed) { - this.removed = removed; - return this; - } - - /** - * @param size the size of the template - */ - public Builder size(long size) { - this.size = size; - return this; - } - - /** - * @param sourceTemplateId the template ID of the parent template if present - */ - public Builder sourceTemplateId(String sourceTemplateId) { - this.sourceTemplateId = sourceTemplateId; - return this; - } - - /** - * @param status the status of the template - */ - public Builder status(String status) { - this.status = status; - return this; - } - - /** - * @param templateTag the tag of this template - */ - public Builder templateTag(String templateTag) { - this.templateTag = templateTag; - return this; - } - - /** - * @param templateType the type of the template - */ - public Builder templateType(String templateType) { - this.templateType = templateType; - return this; - } - - /** - * @param zoneId the ID of the zone for this template - */ - public Builder zoneId(String zoneId) { - this.zoneId = zoneId; - return this; - } - - /** - * @param zoneName the name of the zone for this template - */ - public Builder zoneName(String zoneName) { - this.zoneName = zoneName; - return this; - } - - } - - private String id; - private String account; - @SerializedName("accountid") - private String accountId; - private boolean bootable; - private String checksum; - private Date created; - private boolean crossZones; - @SerializedName("displaytext") - private String displayText; - private String domain; - @SerializedName("domainId") - private String domainid; - private String format; - @SerializedName("hostid") - private String hostId; - @SerializedName("hostname") - private String hostName; - private String hypervisor; - @SerializedName("isextractable") - private boolean isExtractable; - @SerializedName("isfeatured") - private boolean isFeatured; - @SerializedName("ispublic") - private boolean isPublic; - @SerializedName("isready") - private boolean isReady; - @SerializedName("jobid") - private String jobId; - @SerializedName("jobstatus") - private String jobStatus; - private String name; - @SerializedName("ostypeid") - private String osTypeId; - @SerializedName("ostypename") - private String osTypeName; - @SerializedName("passwordenabled") - private boolean passwordEnabled; - private Date removed; - private long size; - @SerializedName("sourcetemplateid") - private String sourceTemplateId; - private String status; - @SerializedName("templatetag") - private String templateTag; - @SerializedName("templatetype") - private String templateType; - @SerializedName("zoneid") - private String zoneId; - @SerializedName("zonename") - private String zoneName; +*/ +public class ISO { /** - * present only for serializer */ - ISO() { + public static enum ISOFilter { + + featured, self, self_executable, executable, community, UNRECOGNIZED; + + public static ISOFilter fromValue(String format) { + try { + return valueOf(checkNotNull(format, "format")); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromISO(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected String account; + protected String accountId; + protected boolean bootable; + protected String checksum; + protected Date created; + protected boolean crossZones; + protected String displayText; + protected String domain; + protected String domainid; + protected String format; + protected String hostId; + protected String hostName; + protected String hypervisor; + protected boolean isExtractable; + protected boolean isFeatured; + protected boolean isPublic; + protected boolean isReady; + protected String jobId; + protected String jobStatus; + protected String name; + protected String osTypeId; + protected String osTypeName; + protected boolean passwordEnabled; + protected Date removed; + protected long size; + protected String sourceTemplateId; + protected String status; + protected String templateTag; + protected String templateType; + protected String zoneId; + protected String zoneName; + + /** + * @see ISO#getId() + */ + public T id(String id) { + this.id = id; + return self(); + } + + /** + * @see ISO#getAccount() + */ + public T account(String account) { + this.account = account; + return self(); + } + + /** + * @see ISO#getAccountId() + */ + public T accountId(String accountId) { + this.accountId = accountId; + return self(); + } + + /** + * @see ISO#isBootable() + */ + public T bootable(boolean bootable) { + this.bootable = bootable; + return self(); + } + + /** + * @see ISO#getChecksum() + */ + public T checksum(String checksum) { + this.checksum = checksum; + return self(); + } + + /** + * @see ISO#getCreated() + */ + public T created(Date created) { + this.created = created; + return self(); + } + + /** + * @see ISO#isCrossZones() + */ + public T crossZones(boolean crossZones) { + this.crossZones = crossZones; + return self(); + } + + /** + * @see ISO#getDisplayText() + */ + public T displayText(String displayText) { + this.displayText = displayText; + return self(); + } + + /** + * @see ISO#getDomain() + */ + public T domain(String domain) { + this.domain = domain; + return self(); + } + + /** + * @see ISO#getDomainid() + */ + public T domainid(String domainid) { + this.domainid = domainid; + return self(); + } + + /** + * @see ISO#getFormat() + */ + public T format(String format) { + this.format = format; + return self(); + } + + /** + * @see ISO#getHostId() + */ + public T hostId(String hostId) { + this.hostId = hostId; + return self(); + } + + /** + * @see ISO#getHostName() + */ + public T hostName(String hostName) { + this.hostName = hostName; + return self(); + } + + /** + * @see ISO#getHypervisor() + */ + public T hypervisor(String hypervisor) { + this.hypervisor = hypervisor; + return self(); + } + + /** + * @see ISO#isExtractable() + */ + public T isExtractable(boolean isExtractable) { + this.isExtractable = isExtractable; + return self(); + } + + /** + * @see ISO#isFeatured() + */ + public T isFeatured(boolean isFeatured) { + this.isFeatured = isFeatured; + return self(); + } + + /** + * @see ISO#isPublic() + */ + public T isPublic(boolean isPublic) { + this.isPublic = isPublic; + return self(); + } + + /** + * @see ISO#isReady() + */ + public T isReady(boolean isReady) { + this.isReady = isReady; + return self(); + } + + /** + * @see ISO#getJobId() + */ + public T jobId(String jobId) { + this.jobId = jobId; + return self(); + } + + /** + * @see ISO#getJobStatus() + */ + public T jobStatus(String jobStatus) { + this.jobStatus = jobStatus; + return self(); + } + + /** + * @see ISO#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + /** + * @see ISO#getOsTypeId() + */ + public T osTypeId(String osTypeId) { + this.osTypeId = osTypeId; + return self(); + } + + /** + * @see ISO#getOsTypeName() + */ + public T osTypeName(String osTypeName) { + this.osTypeName = osTypeName; + return self(); + } + + /** + * @see ISO#isPasswordEnabled() + */ + public T passwordEnabled(boolean passwordEnabled) { + this.passwordEnabled = passwordEnabled; + return self(); + } + + /** + * @see ISO#getRemoved() + */ + public T removed(Date removed) { + this.removed = removed; + return self(); + } + + /** + * @see ISO#getSize() + */ + public T size(long size) { + this.size = size; + return self(); + } + + /** + * @see ISO#getSourceTemplateId() + */ + public T sourceTemplateId(String sourceTemplateId) { + this.sourceTemplateId = sourceTemplateId; + return self(); + } + + /** + * @see ISO#getStatus() + */ + public T status(String status) { + this.status = status; + return self(); + } + + /** + * @see ISO#getTemplateTag() + */ + public T templateTag(String templateTag) { + this.templateTag = templateTag; + return self(); + } + + /** + * @see ISO#getTemplateType() + */ + public T templateType(String templateType) { + this.templateType = templateType; + return self(); + } + + /** + * @see ISO#getZoneId() + */ + public T zoneId(String zoneId) { + this.zoneId = zoneId; + return self(); + } + + /** + * @see ISO#getZoneName() + */ + public T zoneName(String zoneName) { + this.zoneName = zoneName; + return self(); + } + + public ISO build() { + return new ISO(id, account, accountId, bootable, checksum, created, crossZones, displayText, domain, domainid, + format, hostId, hostName, hypervisor, isExtractable, isFeatured, isPublic, isReady, jobId, jobStatus, name, + osTypeId, osTypeName, passwordEnabled, removed, size, sourceTemplateId, status, templateTag, templateType, + zoneId, zoneName); + } + + public T fromISO(ISO in) { + return this + .id(in.getId()) + .account(in.getAccount()) + .accountId(in.getAccountId()) + .bootable(in.isBootable()) + .checksum(in.getChecksum()) + .created(in.getCreated()) + .crossZones(in.isCrossZones()) + .displayText(in.getDisplayText()) + .domain(in.getDomain()) + .domainid(in.getDomainid()) + .format(in.getFormat()) + .hostId(in.getHostId()) + .hostName(in.getHostName()) + .hypervisor(in.getHypervisor()) + .isExtractable(in.isExtractable()) + .isFeatured(in.isFeatured()) + .isPublic(in.isPublic()) + .isReady(in.isReady()) + .jobId(in.getJobId()) + .jobStatus(in.getJobStatus()) + .name(in.getName()) + .osTypeId(in.getOsTypeId()) + .osTypeName(in.getOsTypeName()) + .passwordEnabled(in.isPasswordEnabled()) + .removed(in.getRemoved()) + .size(in.getSize()) + .sourceTemplateId(in.getSourceTemplateId()) + .status(in.getStatus()) + .templateTag(in.getTemplateTag()) + .templateType(in.getTemplateType()) + .zoneId(in.getZoneId()) + .zoneName(in.getZoneName()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + private final String account; + @Named("accountid") + private final String accountId; + private final boolean bootable; + private final String checksum; + private final Date created; + private final boolean crossZones; + @Named("displaytext") + private final String displayText; + private final String domain; + @Named("domainId") + private final String domainid; + private final String format; + @Named("hostid") + private final String hostId; + @Named("hostname") + private final String hostName; + private final String hypervisor; + @Named("isextractable") + private final boolean isExtractable; + @Named("isfeatured") + private final boolean isFeatured; + @Named("ispublic") + private final boolean isPublic; + @Named("isready") + private final boolean isReady; + @Named("jobid") + private final String jobId; + @Named("jobstatus") + private final String jobStatus; + private final String name; + @Named("ostypeid") + private final String osTypeId; + @Named("ostypename") + private final String osTypeName; + @Named("passwordenabled") + private final boolean passwordEnabled; + private final Date removed; + private final long size; + @Named("sourcetemplateid") + private final String sourceTemplateId; + private final String status; + @Named("templatetag") + private final String templateTag; + @Named("templatetype") + private final String templateType; + @Named("zoneid") + private final String zoneId; + @Named("zonename") + private final String zoneName; + + @ConstructorProperties({ + "id", "account", "accountid", "bootable", "checksum", "created", "crossZones", "displaytext", "domain", "domainId", "format", "hostid", "hostname", "hypervisor", "isextractable", "isfeatured", "ispublic", "isready", "jobid", "jobstatus", "name", "ostypeid", "ostypename", "passwordenabled", "removed", "size", "sourcetemplateid", "status", "templatetag", "templatetype", "zoneid", "zonename" + }) + protected ISO(String id, @Nullable String account, @Nullable String accountId, boolean bootable, @Nullable String checksum, + @Nullable Date created, boolean crossZones, @Nullable String displayText, @Nullable String domain, + @Nullable String domainid, @Nullable String format, @Nullable String hostId, @Nullable String hostName, + @Nullable String hypervisor, boolean isExtractable, boolean isFeatured, boolean isPublic, boolean isReady, + @Nullable String jobId, @Nullable String jobStatus, @Nullable String name, @Nullable String osTypeId, + @Nullable String osTypeName, boolean passwordEnabled, @Nullable Date removed, long size, @Nullable String sourceTemplateId, + @Nullable String status, @Nullable String templateTag, @Nullable String templateType, @Nullable String zoneId, @Nullable String zoneName) { + this.id = checkNotNull(id, "id"); + this.account = account; + this.accountId = accountId; + this.bootable = bootable; + this.checksum = checksum; + this.created = created; + this.crossZones = crossZones; + this.displayText = displayText; + this.domain = domain; + this.domainid = domainid; + this.format = format; + this.hostId = hostId; + this.hostName = hostName; + this.hypervisor = hypervisor; + this.isExtractable = isExtractable; + this.isFeatured = isFeatured; + this.isPublic = isPublic; + this.isReady = isReady; + this.jobId = jobId; + this.jobStatus = jobStatus; + this.name = name; + this.osTypeId = osTypeId; + this.osTypeName = osTypeName; + this.passwordEnabled = passwordEnabled; + this.removed = removed; + this.size = size; + this.sourceTemplateId = sourceTemplateId; + this.status = status; + this.templateTag = templateTag; + this.templateType = templateType; + this.zoneId = zoneId; + this.zoneName = zoneName; } /** * @return the template ID */ public String getId() { - return id; + return this.id; } /** * @return the account name to which the template belongs */ + @Nullable public String getAccount() { - return account; + return this.account; } /** * @return the account id to which the template belongs */ + @Nullable public String getAccountId() { - return accountId; + return this.accountId; } - /** - * @return true if the ISO is bootable, false otherwise - */ - public boolean getBootable() { - return bootable; + public boolean isBootable() { + return this.bootable; } /** * @return checksum of the template */ + @Nullable public String getChecksum() { - return checksum; + return this.checksum; } /** * @return the date this template was created */ + @Nullable public Date getCreated() { - return created; + return this.created; } - /** - * @return true if the template is managed across all Zones, false otherwise - */ - public boolean getCrossZones() { - return crossZones; + public boolean isCrossZones() { + return this.crossZones; } /** * @return the template display text */ + @Nullable public String getDisplayText() { - return displayText; + return this.displayText; } /** * @return the name of the domain to which the template belongs */ + @Nullable public String getDomain() { - return domain; + return this.domain; } /** * @return the ID of the domain to which the template belongs */ + @Nullable public String getDomainid() { - return domainid; + return this.domainid; } /** * @return the format of the template. */ + @Nullable public String getFormat() { - return format; + return this.format; } /** * @return the ID of the secondary storage host for the template */ + @Nullable public String getHostId() { - return hostId; + return this.hostId; } /** * @return the name of the secondary storage host for the template */ + @Nullable public String getHostName() { - return hostName; + return this.hostName; } /** * @return the hypervisor on which the template runs */ + @Nullable public String getHypervisor() { - return hypervisor; + return this.hypervisor; } - /** - * @return true if the template is extractable, false otherwise - */ - public boolean getIsExtractable() { - return isExtractable; + public boolean isExtractable() { + return this.isExtractable; } - /** - * @return true if this template is a featured template, false otherwise - */ - public boolean getIsFeatured() { - return isFeatured; + public boolean isFeatured() { + return this.isFeatured; } - /** - * @return true if this template is a public template, false otherwise - */ - public boolean getIsPublic() { - return isPublic; + public boolean isPublic() { + return this.isPublic; } - /** - * @return true if the template is ready to be deployed from, false otherwise. - */ - public boolean getIsReady() { - return isReady; + public boolean isReady() { + return this.isReady; } /** * @return shows the current pending asynchronous job ID. This tag is not returned if no current pending jobs are acting on the template */ + @Nullable public String getJobId() { - return jobId; + return this.jobId; } /** * @return shows the current pending asynchronous job status */ + @Nullable public String getJobStatus() { - return jobStatus; + return this.jobStatus; } /** * @return the template name */ + @Nullable public String getName() { - return name; + return this.name; } /** * @return the ID of the OS type for this template. */ + @Nullable public String getOsTypeId() { - return osTypeId; + return this.osTypeId; } /** * @return the name of the OS type for this template. */ + @Nullable public String getOsTypeName() { - return osTypeName; + return this.osTypeName; } - /** - * @return true if the reset password feature is enabled, false otherwise - */ - public boolean getPasswordEnabled() { - return passwordEnabled; + public boolean isPasswordEnabled() { + return this.passwordEnabled; } /** * @return the date this template was removed */ + @Nullable public Date getRemoved() { - return removed; + return this.removed; } /** * @return the size of the template */ public long getSize() { - return size; + return this.size; } /** * @return the template ID of the parent template if present */ + @Nullable public String getSourceTemplateId() { - return sourceTemplateId; + return this.sourceTemplateId; } /** * @return the status of the template */ + @Nullable public String getStatus() { - return status; + return this.status; } /** * @return the tag of this template */ + @Nullable public String getTemplateTag() { - return templateTag; + return this.templateTag; } /** * @return the type of the template */ + @Nullable public String getTemplateType() { - return templateType; + return this.templateType; } /** * @return the ID of the zone for this template */ + @Nullable public String getZoneId() { - return zoneId; + return this.zoneId; } /** * @return the name of the zone for this template */ + @Nullable public String getZoneName() { - return zoneName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ISO that = (ISO) o; - - if (!Objects.equal(accountId, that.accountId)) return false; - if (!Objects.equal(bootable, that.bootable)) return false; - if (!Objects.equal(crossZones, that.crossZones)) return false; - if (!Objects.equal(domainid, that.domainid)) return false; - if (!Objects.equal(hostId, that.hostId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(isExtractable, that.isExtractable)) return false; - if (!Objects.equal(isPublic, that.isPublic)) return false; - if (!Objects.equal(isReady, that.isReady)) return false; - if (!Objects.equal(jobId, that.jobId)) return false; - if (!Objects.equal(osTypeId, that.osTypeId)) return false; - if (!Objects.equal(passwordEnabled, that.passwordEnabled)) return false; - if (!Objects.equal(size, that.size)) return false; - if (!Objects.equal(sourceTemplateId, that.sourceTemplateId)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(account, that.account)) return false; - if (!Objects.equal(checksum, that.checksum)) return false; - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(displayText, that.displayText)) return false; - if (!Objects.equal(domain, that.domain)) return false; - if (!Objects.equal(format, that.format)) return false; - if (!Objects.equal(hostName, that.hostName)) return false; - if (!Objects.equal(hypervisor, that.hypervisor)) return false; - if (!Objects.equal(jobStatus, that.jobStatus)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(osTypeName, that.osTypeName)) return false; - if (!Objects.equal(removed, that.removed)) return false; - if (!Objects.equal(status, that.status)) return false; - if (!Objects.equal(templateTag, that.templateTag)) return false; - if (!Objects.equal(templateType, that.templateType)) return false; - if (!Objects.equal(zoneName, that.zoneName)) return false; - - return true; + return this.zoneName; } @Override public int hashCode() { - return Objects.hashCode(accountId, bootable, crossZones, domainid, hostId, id, isExtractable, - isPublic, isReady, jobId, osTypeId, passwordEnabled, size, sourceTemplateId, - zoneId, account, checksum, created, displayText, domain, format, hostName, - hypervisor, jobStatus, name, osTypeName, removed, status, templateTag, - templateType, zoneName); + return Objects.hashCode(id, account, accountId, bootable, checksum, created, crossZones, displayText, domain, + domainid, format, hostId, hostName, hypervisor, isExtractable, isFeatured, isPublic, isReady, jobId, jobStatus, + name, osTypeId, osTypeName, passwordEnabled, removed, size, sourceTemplateId, status, templateTag, templateType, zoneId, zoneName); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ISO that = ISO.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.account, that.account) + && Objects.equal(this.accountId, that.accountId) + && Objects.equal(this.bootable, that.bootable) + && Objects.equal(this.checksum, that.checksum) + && Objects.equal(this.created, that.created) + && Objects.equal(this.crossZones, that.crossZones) + && Objects.equal(this.displayText, that.displayText) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainid, that.domainid) + && Objects.equal(this.format, that.format) + && Objects.equal(this.hostId, that.hostId) + && Objects.equal(this.hostName, that.hostName) + && Objects.equal(this.hypervisor, that.hypervisor) + && Objects.equal(this.isExtractable, that.isExtractable) + && Objects.equal(this.isFeatured, that.isFeatured) + && Objects.equal(this.isPublic, that.isPublic) + && Objects.equal(this.isReady, that.isReady) + && Objects.equal(this.jobId, that.jobId) + && Objects.equal(this.jobStatus, that.jobStatus) + && Objects.equal(this.name, that.name) + && Objects.equal(this.osTypeId, that.osTypeId) + && Objects.equal(this.osTypeName, that.osTypeName) + && Objects.equal(this.passwordEnabled, that.passwordEnabled) + && Objects.equal(this.removed, that.removed) + && Objects.equal(this.size, that.size) + && Objects.equal(this.sourceTemplateId, that.sourceTemplateId) + && Objects.equal(this.status, that.status) + && Objects.equal(this.templateTag, that.templateTag) + && Objects.equal(this.templateType, that.templateType) + && Objects.equal(this.zoneId, that.zoneId) + && Objects.equal(this.zoneName, that.zoneName); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("account", account).add("accountId", accountId).add("bootable", bootable) + .add("checksum", checksum).add("created", created).add("crossZones", crossZones).add("displayText", displayText) + .add("domain", domain).add("domainid", domainid).add("format", format).add("hostId", hostId).add("hostName", hostName) + .add("hypervisor", hypervisor).add("isExtractable", isExtractable).add("isFeatured", isFeatured).add("isPublic", isPublic) + .add("isReady", isReady).add("jobId", jobId).add("jobStatus", jobStatus).add("name", name).add("osTypeId", osTypeId) + .add("osTypeName", osTypeName).add("passwordEnabled", passwordEnabled).add("removed", removed).add("size", size) + .add("sourceTemplateId", sourceTemplateId).add("status", status).add("templateTag", templateTag).add("templateType", templateType) + .add("zoneId", zoneId).add("zoneName", zoneName); + } + @Override public String toString() { - return "ISO{" + - "id=" + id + - ", account='" + account + '\'' + - ", accountId=" + accountId + - ", bootable=" + bootable + - ", checksum='" + checksum + '\'' + - ", created=" + created + - ", crossZones=" + crossZones + - ", displayText='" + displayText + '\'' + - ", domain='" + domain + '\'' + - ", domainid=" + domainid + - ", format='" + format + '\'' + - ", hostId=" + hostId + - ", hostName='" + hostName + '\'' + - ", hypervisor='" + hypervisor + '\'' + - ", isExtractable=" + isExtractable + - ", isFeatured=" + isFeatured + - ", isPublic=" + isPublic + - ", isReady=" + isReady + - ", jobId=" + jobId + - ", jobStatus='" + jobStatus + '\'' + - ", name='" + name + '\'' + - ", osTypeId=" + osTypeId + - ", osTypeName='" + osTypeName + '\'' + - ", passwordEnabled=" + passwordEnabled + - ", removed=" + removed + - ", size=" + size + - ", sourceTemplateId=" + sourceTemplateId + - ", status='" + status + '\'' + - ", templateTag='" + templateTag + '\'' + - ", templateType='" + templateType + '\'' + - ", zoneId=" + zoneId + - ", zoneName='" + zoneName + '\'' + - '}'; + return string().toString(); } - @Override - public int compareTo(ISO other) { - return id.compareTo(other.getId()); - } - - public enum ISOFilter { - - featured, self, self_executable, executable, community, UNRECOGNIZED; - - public static ISOFilter fromValue(String format) { - try { - return valueOf(checkNotNull(format, "format")); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } - } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOExtraction.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOExtraction.java index 13e79e4048..5b8604293a 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOExtraction.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOExtraction.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,309 +18,361 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.util.Date; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** + * Class ISOExtraction + * * @author Richard Downer - */ -public class ISOExtraction implements Comparable { +*/ +public class ISOExtraction { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromISOExtraction(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); - private String id; - private String accountId; - private Date created; - private String extractId; - private ExtractMode extractMode; - private String name; - private String state; - private String status; - private String storageType; - private int uploadPercentage; - private String url; - private String zoneId; - private String zoneName; - - /** - * @param id the id of extracted object + protected String id; + protected String accountId; + protected Date created; + protected String extractId; + protected ExtractMode extractMode; + protected String name; + protected String state; + protected String status; + protected String storageType; + protected int uploadPercentage; + protected String url; + protected String zoneId; + protected String zoneName; + + /** + * @see ISOExtraction#getId() */ - public Builder id(String id) { + public T id(String id) { this.id = id; - return this; + return self(); } - /** - * @param accountId the account id to which the extracted object belongs + /** + * @see ISOExtraction#getAccountId() */ - public Builder accountId(String accountId) { + public T accountId(String accountId) { this.accountId = accountId; - return this; + return self(); } - /** - * @param created the time and date the object was created + /** + * @see ISOExtraction#getCreated() */ - public Builder created(Date created) { + public T created(Date created) { this.created = created; - return this; + return self(); } - /** - * @param extractId the upload id of extracted object + /** + * @see ISOExtraction#getExtractId() */ - public Builder extractId(String extractId) { + public T extractId(String extractId) { this.extractId = extractId; - return this; + return self(); } - /** - * @param extractMode the mode of extraction - upload or download + /** + * @see ISOExtraction#getExtractMode() */ - public Builder extractMode(ExtractMode extractMode) { + public T extractMode(ExtractMode extractMode) { this.extractMode = extractMode; - return this; + return self(); } - /** - * @param name the name of the extracted object + /** + * @see ISOExtraction#getName() */ - public Builder name(String name) { + public T name(String name) { this.name = name; - return this; + return self(); } - /** - * @param state the state of the extracted object + /** + * @see ISOExtraction#getState() */ - public Builder state(String state) { + public T state(String state) { this.state = state; - return this; + return self(); } - /** - * @param status the status of the extraction + /** + * @see ISOExtraction#getStatus() */ - public Builder status(String status) { + public T status(String status) { this.status = status; - return this; + return self(); } - /** - * @param storageType type of the storage + /** + * @see ISOExtraction#getStorageType() */ - public Builder storageType(String storageType) { + public T storageType(String storageType) { this.storageType = storageType; - return this; + return self(); } - /** - * @param uploadPercentage the percentage of the entity uploaded to the specified location + /** + * @see ISOExtraction#getUploadPercentage() */ - public Builder uploadPercentage(int uploadPercentage) { + public T uploadPercentage(int uploadPercentage) { this.uploadPercentage = uploadPercentage; - return this; + return self(); } - /** - * @param url if mode = upload then url of the uploaded entity. if mode = download the url from which the entity can be downloaded + /** + * @see ISOExtraction#getUrl() */ - public Builder url(String url) { + public T url(String url) { this.url = url; - return this; + return self(); } - /** - * @param zoneId zone ID the object was extracted from + /** + * @see ISOExtraction#getZoneId() */ - public Builder zoneId(String zoneId) { + public T zoneId(String zoneId) { this.zoneId = zoneId; - return this; + return self(); } - /** - * @param zoneName zone name the object was extracted from + /** + * @see ISOExtraction#getZoneName() */ - public Builder zoneName(String zoneName) { + public T zoneName(String zoneName) { this.zoneName = zoneName; - return this; + return self(); } + public ISOExtraction build() { + return new ISOExtraction(id, accountId, created, extractId, extractMode, name, state, status, storageType, uploadPercentage, url, zoneId, zoneName); + } + + public T fromISOExtraction(ISOExtraction in) { + return this + .id(in.getId()) + .accountId(in.getAccountId()) + .created(in.getCreated()) + .extractId(in.getExtractId()) + .extractMode(in.getExtractMode()) + .name(in.getName()) + .state(in.getState()) + .status(in.getStatus()) + .storageType(in.getStorageType()) + .uploadPercentage(in.getUploadPercentage()) + .url(in.getUrl()) + .zoneId(in.getZoneId()) + .zoneName(in.getZoneName()); + } } - private String id; - @SerializedName("accountid") - private String accountId; - private Date created; - private String extractId; - private ExtractMode extractMode; - private String name; - private String state; - private String status; - @SerializedName("storagetype") - private String storageType; - @SerializedName("uploadpercentage") - private int uploadPercentage; - private String url; - @SerializedName("zoneid") - private String zoneId; - @SerializedName("zonename") - private String zoneName; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - /** - * present only for serializer - */ - ISOExtraction() { + private final String id; + @Named("accountid") + private final String accountId; + private final Date created; + private final String extractId; + private final ExtractMode extractMode; + private final String name; + private final String state; + private final String status; + @Named("storagetype") + private final String storageType; + @Named("uploadpercentage") + private final int uploadPercentage; + private final String url; + @Named("zoneid") + private final String zoneId; + @Named("zonename") + private final String zoneName; + + @ConstructorProperties({ + "id", "accountid", "created", "extractId", "extractMode", "name", "state", "status", "storagetype", "uploadpercentage", "url", "zoneid", "zonename" + }) + protected ISOExtraction(String id, @Nullable String accountId, @Nullable Date created, @Nullable String extractId, + @Nullable ExtractMode extractMode, @Nullable String name, @Nullable String state, @Nullable String status, + @Nullable String storageType, int uploadPercentage, @Nullable String url, @Nullable String zoneId, + @Nullable String zoneName) { + this.id = checkNotNull(id, "id"); + this.accountId = accountId; + this.created = created; + this.extractId = extractId; + this.extractMode = extractMode; + this.name = name; + this.state = state; + this.status = status; + this.storageType = storageType; + this.uploadPercentage = uploadPercentage; + this.url = url; + this.zoneId = zoneId; + this.zoneName = zoneName; } /** * @return the id of extracted object */ public String getId() { - return id; + return this.id; } /** * @return the account id to which the extracted object belongs */ + @Nullable public String getAccountId() { - return accountId; + return this.accountId; } /** * @return the time and date the object was created */ + @Nullable public Date getCreated() { - return created; + return this.created; } /** * @return the upload id of extracted object */ + @Nullable public String getExtractId() { - return extractId; + return this.extractId; } /** * @return the mode of extraction - upload or download */ + @Nullable public ExtractMode getExtractMode() { - return extractMode; + return this.extractMode; } /** * @return the name of the extracted object */ + @Nullable public String getName() { - return name; + return this.name; } /** * @return the state of the extracted object */ + @Nullable public String getState() { - return state; + return this.state; } /** * @return the status of the extraction */ + @Nullable public String getStatus() { - return status; + return this.status; } /** * @return type of the storage */ + @Nullable public String getStorageType() { - return storageType; + return this.storageType; } /** * @return the percentage of the entity uploaded to the specified location */ public int getUploadPercentage() { - return uploadPercentage; + return this.uploadPercentage; } /** * @return if mode = upload then url of the uploaded entity. if mode = download the url from which the entity can be downloaded */ + @Nullable public String getUrl() { - return url; + return this.url; } /** * @return zone ID the object was extracted from */ + @Nullable public String getZoneId() { - return zoneId; + return this.zoneId; } /** * @return zone name the object was extracted from */ + @Nullable public String getZoneName() { - return zoneName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ISOExtraction that = (ISOExtraction) o; - - if (!Objects.equal(accountId, that.accountId)) return false; - if (!Objects.equal(extractId, that.extractId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(uploadPercentage, that.uploadPercentage)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(extractMode, that.extractMode)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(state, that.state)) return false; - if (!Objects.equal(status, that.status)) return false; - if (!Objects.equal(storageType, that.storageType)) return false; - if (!Objects.equal(url, that.url)) return false; - if (!Objects.equal(zoneName, that.zoneName)) return false; - - return true; + return this.zoneName; } @Override public int hashCode() { - return Objects.hashCode(accountId, extractId, id, uploadPercentage, zoneId, created, extractMode, name, state, status, storageType, url, zoneName); + return Objects.hashCode(id, accountId, created, extractId, extractMode, name, state, status, storageType, uploadPercentage, url, zoneId, zoneName); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ISOExtraction that = ISOExtraction.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.accountId, that.accountId) + && Objects.equal(this.created, that.created) + && Objects.equal(this.extractId, that.extractId) + && Objects.equal(this.extractMode, that.extractMode) + && Objects.equal(this.name, that.name) + && Objects.equal(this.state, that.state) + && Objects.equal(this.status, that.status) + && Objects.equal(this.storageType, that.storageType) + && Objects.equal(this.uploadPercentage, that.uploadPercentage) + && Objects.equal(this.url, that.url) + && Objects.equal(this.zoneId, that.zoneId) + && Objects.equal(this.zoneName, that.zoneName); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("accountId", accountId).add("created", created).add("extractId", extractId).add("extractMode", extractMode) + .add("name", name).add("state", state).add("status", status).add("storageType", storageType).add("uploadPercentage", uploadPercentage) + .add("url", url).add("zoneId", zoneId).add("zoneName", zoneName); + } + @Override public String toString() { - return "ISOExtraction{" + - "id=" + id + - ", accountId=" + accountId + - ", created=" + created + - ", extractId=" + extractId + - ", extractMode=" + extractMode + - ", name='" + name + '\'' + - ", state='" + state + '\'' + - ", status='" + status + '\'' + - ", storageType='" + storageType + '\'' + - ", uploadPercentage=" + uploadPercentage + - ", url='" + url + '\'' + - ", zoneId=" + zoneId + - ", zoneName='" + zoneName + '\'' + - '}'; - } - - @Override - public int compareTo(ISOExtraction other) { - return id.compareTo(other.getId()); + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOPermissions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOPermissions.java index 79d1efe929..03dbda69d3 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOPermissions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOPermissions.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,136 +18,169 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.util.Set; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** + * Class ISOPermissions + * * @author Richard Downer - */ -public class ISOPermissions implements Comparable { +*/ +public class ISOPermissions { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromISOPermissions(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); - private String id; - private String account; - private String domainId; - private boolean isPublic; - - /** - * @param id the template ID + protected String id; + protected Set accounts = ImmutableSet.of(); + protected String domainId; + protected boolean isPublic; + + /** + * @see ISOPermissions#getId() */ - public Builder id(String id) { + public T id(String id) { this.id = id; - return this; + return self(); } - /** - * @param account the list of accounts the template is available for + /** + * @see ISOPermissions#getAccounts() */ - public Builder account(String account) { - this.account = account; - return this; + public T accounts(Set accounts) { + this.accounts = ImmutableSet.copyOf(checkNotNull(accounts, "accounts")); + return self(); } - /** - * @param domainId the ID of the domain to which the template belongs + public T accounts(String... in) { + return accounts(ImmutableSet.copyOf(in)); + } + + /** + * @see ISOPermissions#getDomainId() */ - public Builder domainId(String domainId) { + public T domainId(String domainId) { this.domainId = domainId; - return this; + return self(); } - /** - * @param isPublic true if this template is a public template, false otherwise + /** + * @see ISOPermissions#isPublic() */ - public Builder isPublic(boolean isPublic) { + public T isPublic(boolean isPublic) { this.isPublic = isPublic; - return this; + return self(); } + public ISOPermissions build() { + return new ISOPermissions(id, accounts, domainId, isPublic); + } + + public T fromISOPermissions(ISOPermissions in) { + return this + .id(in.getId()) + .accounts(in.getAccounts()) + .domainId(in.getDomainId()) + .isPublic(in.isPublic()); + } } - private String id; - @SerializedName("account") - private Set accounts; - @SerializedName("domainid") - private String domainId; - @SerializedName("ispublic") - private boolean isPublic; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - /** - * present only for serializer - */ - ISOPermissions() { + private final String id; + @Named("account") + private final Set accounts; + @Named("domainid") + private final String domainId; + @Named("ispublic") + private final boolean isPublic; + + @ConstructorProperties({ + "id", "account", "domainid", "ispublic" + }) + protected ISOPermissions(String id, @Nullable Set accounts, @Nullable String domainId, boolean isPublic) { + this.id = checkNotNull(id, "id"); + this.accounts = accounts == null ? ImmutableSet.of() : ImmutableSet.copyOf(accounts); + this.domainId = domainId; + this.isPublic = isPublic; } /** * @return the template ID */ public String getId() { - return id; + return this.id; } /** * @return the list of accounts the template is available for */ public Set getAccounts() { - return accounts; + return this.accounts; } /** * @return the ID of the domain to which the template belongs */ + @Nullable public String getDomainId() { - return domainId; + return this.domainId; } /** * @return true if this template is a public template, false otherwise */ - public boolean getIsPublic() { - return isPublic; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ISOPermissions that = (ISOPermissions) o; - - if (!Objects.equal(accounts, that.accounts)) return false; - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(isPublic, that.isPublic)) return false; - - return true; + public boolean isPublic() { + return this.isPublic; } @Override public int hashCode() { - return Objects.hashCode(accounts, domainId, id, isPublic); + return Objects.hashCode(id, accounts, domainId, isPublic); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ISOPermissions that = ISOPermissions.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.accounts, that.accounts) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.isPublic, that.isPublic); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("accounts", accounts).add("domainId", domainId).add("isPublic", isPublic); + } + @Override public String toString() { - return "ISOPermissions{" + - "id=" + id + - ", accounts='" + accounts + '\'' + - ", domainId=" + domainId + - ", isPublic=" + isPublic + - '}'; - } - - @Override - public int compareTo(ISOPermissions other) { - return id.compareTo(other.getId()); + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java index ebff971c4a..e400ca39a2 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,118 +18,170 @@ */ package org.jclouds.cloudstack.domain; -import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * * @author Adrian Cole - */ +*/ public class IngressRule implements Comparable { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromIngressRule(this); } - public static class Builder { - private String account; - private String CIDR; - private int endPort = -1; - private int ICMPCode = -1; - private int ICMPType = -1; - private String protocol; - private String id; - private String securityGroupName; - private int startPort = -1; + public static abstract class Builder> { + protected abstract T self(); - public Builder account(String account) { + protected String account; + protected String CIDR; + protected int endPort; + protected int ICMPCode; + protected int ICMPType; + protected String protocol; + protected String id; + protected String securityGroupName; + protected int startPort; + + /** + * @see IngressRule#getAccount() + */ + public T account(String account) { this.account = account; - return this; + return self(); } - public Builder CIDR(String CIDR) { + /** + * @see IngressRule#getCIDR() + */ + public T CIDR(String CIDR) { this.CIDR = CIDR; - return this; + return self(); } - public Builder endPort(int endPort) { + /** + * @see IngressRule#getEndPort() + */ + public T endPort(int endPort) { this.endPort = endPort; - return this; + return self(); } - public Builder ICMPCode(int ICMPCode) { + /** + * @see IngressRule#getICMPCode() + */ + public T ICMPCode(int ICMPCode) { this.ICMPCode = ICMPCode; - return this; + return self(); } - public Builder ICMPType(int ICMPType) { + /** + * @see IngressRule#getICMPType() + */ + public T ICMPType(int ICMPType) { this.ICMPType = ICMPType; - return this; + return self(); } - public Builder protocol(String protocol) { + /** + * @see IngressRule#getProtocol() + */ + public T protocol(String protocol) { this.protocol = protocol; - return this; + return self(); } - public Builder id(String id) { + /** + * @see IngressRule#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder securityGroupName(String securityGroupName) { + /** + * @see IngressRule#getSecurityGroupName() + */ + public T securityGroupName(String securityGroupName) { this.securityGroupName = securityGroupName; - return this; + return self(); } - public Builder startPort(int startPort) { + /** + * @see IngressRule#getStartPort() + */ + public T startPort(int startPort) { this.startPort = startPort; - return this; + return self(); } public IngressRule build() { return new IngressRule(account, CIDR, endPort, ICMPCode, ICMPType, protocol, id, securityGroupName, startPort); } + + public T fromIngressRule(IngressRule in) { + return this + .account(in.getAccount()) + .CIDR(in.getCIDR()) + .endPort(in.getEndPort()) + .ICMPCode(in.getICMPCode()) + .ICMPType(in.getICMPType()) + .protocol(in.getProtocol()) + .id(in.getId()) + .securityGroupName(in.getSecurityGroupName()) + .startPort(in.getStartPort()); + } } - private String account; - @SerializedName("cidr") - private String CIDR; - @SerializedName("endport") - private int endPort = -1; - @SerializedName("icmpcode") - private int ICMPCode = -1; - @SerializedName("icmptype") - private int ICMPType = -1; - private String protocol; - @SerializedName("ruleid") - private String id; - @SerializedName("securitygroupname") - private String securityGroupName; - @SerializedName("startport") - private int startPort = -1; - - // for serialization - IngressRule() { - + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public IngressRule(String account, String CIDR, int endPort, int iCMPCode, int iCMPType, String protocol, String id, - String securityGroupName, int startPort) { - if (account == null) - checkArgument(securityGroupName == null && CIDR != null, - "if you do not specify an account and security group, you must specify a CIDR range"); - if (CIDR == null) - checkArgument(account != null && securityGroupName != null, - "if you do not specify an account and security group, you must specify a CIDR range"); + private final String account; + @Named("cidr") + private final String CIDR; + @Named("endport") + private final int endPort; + @Named("icmpcode") + private final int ICMPCode; + @Named("icmptype") + private final int ICMPType; + private final String protocol; + @Named("ruleid") + private final String id; + @Named("securitygroupname") + private final String securityGroupName; + @Named("startport") + private final int startPort; + + @ConstructorProperties({ + "account", "cidr", "endport", "icmpcode", "icmptype", "protocol", "ruleid", "securitygroupname", "startport" + }) + protected IngressRule(@Nullable String account, @Nullable String CIDR, int endPort, int ICMPCode, int ICMPType, + @Nullable String protocol, String id, @Nullable String securityGroupName, int startPort) { this.account = account; this.CIDR = CIDR; this.endPort = endPort; - this.ICMPCode = iCMPCode; - this.ICMPType = iCMPType; + this.ICMPCode = ICMPCode; + this.ICMPType = ICMPType; this.protocol = protocol; - this.id = id; + this.id = checkNotNull(id, "id"); this.securityGroupName = securityGroupName; this.startPort = startPort; } @@ -137,108 +189,104 @@ public class IngressRule implements Comparable { /** * @return account owning the ingress rule */ + @Nullable public String getAccount() { - return account; + return this.account; } /** * @return the CIDR notation for the base IP address of the ingress rule */ + @Nullable public String getCIDR() { - return CIDR; + return this.CIDR; } /** * @return the ending IP of the ingress rule */ public int getEndPort() { - return endPort; + return this.endPort; } /** * @return the code for the ICMP message response */ public int getICMPCode() { - return ICMPCode; + return this.ICMPCode; } /** * @return the type of the ICMP message response */ public int getICMPType() { - return ICMPType; + return this.ICMPType; } /** * @return the protocol of the ingress rule */ + @Nullable public String getProtocol() { - return protocol; + return this.protocol; } /** * @return the id of the ingress rule */ public String getId() { - return id; + return this.id; } /** * @return security group name */ + @Nullable public String getSecurityGroupName() { - return securityGroupName; + return this.securityGroupName; } /** * @return the starting IP of the ingress rule */ public int getStartPort() { - return startPort; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - IngressRule that = (IngressRule) o; - - if (!Objects.equal(CIDR, that.CIDR)) return false; - if (!Objects.equal(ICMPCode, that.ICMPCode)) return false; - if (!Objects.equal(ICMPType, that.ICMPType)) return false; - if (!Objects.equal(account, that.account)) return false; - if (!Objects.equal(endPort, that.endPort)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(protocol, that.protocol)) return false; - if (!Objects.equal(securityGroupName, that.securityGroupName)) return false; - if (!Objects.equal(startPort, that.startPort)) return false; - - return true; + return this.startPort; } @Override public int hashCode() { - return Objects.hashCode(CIDR, ICMPCode, ICMPType, account, endPort, id, protocol, securityGroupName, startPort); + return Objects.hashCode(account, CIDR, endPort, ICMPCode, ICMPType, protocol, id, securityGroupName, startPort); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + IngressRule that = IngressRule.class.cast(obj); + return Objects.equal(this.account, that.account) + && Objects.equal(this.CIDR, that.CIDR) + && Objects.equal(this.endPort, that.endPort) + && Objects.equal(this.ICMPCode, that.ICMPCode) + && Objects.equal(this.ICMPType, that.ICMPType) + && Objects.equal(this.protocol, that.protocol) + && Objects.equal(this.id, that.id) + && Objects.equal(this.securityGroupName, that.securityGroupName) + && Objects.equal(this.startPort, that.startPort); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("account", account).add("CIDR", CIDR).add("endPort", endPort).add("ICMPCode", ICMPCode) + .add("ICMPType", ICMPType).add("protocol", protocol).add("id", id).add("securityGroupName", securityGroupName).add("startPort", startPort); + } + @Override public String toString() { - return "IngressRule{" + - "account='" + account + '\'' + - ", CIDR='" + CIDR + '\'' + - ", endPort=" + endPort + - ", ICMPCode=" + ICMPCode + - ", ICMPType=" + ICMPType + - ", protocol='" + protocol + '\'' + - ", id=" + id + - ", securityGroupName='" + securityGroupName + '\'' + - ", startPort=" + startPort + - '}'; + return string().toString(); } @Override - public int compareTo(IngressRule arg0) { - return id.compareTo(arg0.getId()); + public int compareTo(IngressRule o) { + return id.compareTo(o.getId()); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/JobResult.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/JobResult.java index f6b3bc469d..732e5e60b4 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/JobResult.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/JobResult.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,73 +18,115 @@ */ package org.jclouds.cloudstack.domain; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * The result of an operation. - * + * * A handful of Cloudstack API calls return this structure when there is no domain model data to return - for example, * when deleting an object. - * + * * @author Richard Downer - */ -public class JobResult implements Comparable { +*/ +public class JobResult { - private boolean success; - @SerializedName("displaytext") - private String displayText; - - /** - * present only for the serializer - */ - JobResult() { + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromJobResult(this); } - public JobResult(boolean success, String displayText) { + public static abstract class Builder> { + protected abstract T self(); + + protected boolean success; + protected String displayText; + + /** + * @see JobResult#isSuccess() + */ + public T success(boolean success) { + this.success = success; + return self(); + } + + /** + * @see JobResult#getDisplayText() + */ + public T displayText(String displayText) { + this.displayText = displayText; + return self(); + } + + public JobResult build() { + return new JobResult(success, displayText); + } + + public T fromJobResult(JobResult in) { + return this + .success(in.isSuccess()) + .displayText(in.getDisplayText()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final boolean success; + @Named("displaytext") + private final String displayText; + + @ConstructorProperties({ + "success", "displaytext" + }) + protected JobResult(boolean success, @Nullable String displayText) { this.success = success; this.displayText = displayText; } - public boolean getSuccess() { - return success; + public boolean isSuccess() { + return this.success; } + @Nullable public String getDisplayText() { - return displayText; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - JobResult that = (JobResult) o; - - if (!Objects.equal(success, that.success)) return false; - if (!Objects.equal(displayText, that.displayText)) return false; - - return true; + return this.displayText; } @Override public int hashCode() { - return Objects.hashCode(success, displayText); + return Objects.hashCode(success, displayText); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + JobResult that = JobResult.class.cast(obj); + return Objects.equal(this.success, that.success) + && Objects.equal(this.displayText, that.displayText); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).add("success", success).add("displayText", displayText); + } + @Override public String toString() { - return "JobResult{" + - "success=" + success + - ", displayText='" + displayText + '\'' + - '}'; + return string().toString(); } - @Override - public int compareTo(JobResult other) { - int comparison = Boolean.valueOf(success).compareTo(other.success); - if (comparison == 0) - comparison = displayText.compareTo(other.displayText); - return comparison; - } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/LoadBalancerRule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/LoadBalancerRule.java index 28165de1ce..3b1654d774 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/LoadBalancerRule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/LoadBalancerRule.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,180 +20,264 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Set; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.CaseFormat; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; -import com.google.gson.annotations.SerializedName; /** + * Class LoadBalancerRule + * * @author Adrian Cole - */ -public class LoadBalancerRule implements Comparable { +*/ +public class LoadBalancerRule { + + /** + */ public static enum State { ADD, ACTIVE, UNRECOGNIZED; - + @Override public String toString() { - return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); } - + public static State fromValue(String state) { - try { - return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; } - + } + } public static enum Algorithm { SOURCE, ROUNDROBIN, LEASTCONN, UNRECOGNIZED; - + @Override public String toString() { - return name().toLowerCase(); + return name().toLowerCase(); } - + public static Algorithm fromValue(String algorithm) { - try { - return Algorithm.valueOf(checkNotNull(algorithm, "algorithm").toUpperCase()); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } + try { + return Algorithm.valueOf(checkNotNull(algorithm, "algorithm").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; } - + } + } - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromLoadBalancerRule(this); } - public static class Builder { - private String id; - private String account; - private Algorithm algorithm; - private String description; - private String domain; - private String domainId; - private String name; - private int privatePort; - private String publicIP; - private String publicIPId; - private int publicPort; - private State state; - private Set CIDRs = ImmutableSet.of(); - private String zoneId; + public static abstract class Builder> { + protected abstract T self(); - public Builder id(String id) { + protected String id; + protected String account; + protected LoadBalancerRule.Algorithm algorithm; + protected String description; + protected String domain; + protected String domainId; + protected String name; + protected int privatePort; + protected String publicIP; + protected String publicIPId; + protected int publicPort; + protected LoadBalancerRule.State state; + protected Set CIDRs = ImmutableSet.of(); + protected String zoneId; + + /** + * @see LoadBalancerRule#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder account(String account) { + /** + * @see LoadBalancerRule#getAccount() + */ + public T account(String account) { this.account = account; - return this; + return self(); } - public Builder algorithm(Algorithm algorithm) { + /** + * @see LoadBalancerRule#getAlgorithm() + */ + public T algorithm(LoadBalancerRule.Algorithm algorithm) { this.algorithm = algorithm; - return this; + return self(); } - public Builder description(String description) { + /** + * @see LoadBalancerRule#getDescription() + */ + public T description(String description) { this.description = description; - return this; + return self(); } - public Builder domain(String domain) { + /** + * @see LoadBalancerRule#getDomain() + */ + public T domain(String domain) { this.domain = domain; - return this; + return self(); } - public Builder domainId(String domainId) { + /** + * @see LoadBalancerRule#getDomainId() + */ + public T domainId(String domainId) { this.domainId = domainId; - return this; + return self(); } - public Builder name(String name) { + /** + * @see LoadBalancerRule#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder privatePort(int privatePort) { + /** + * @see LoadBalancerRule#getPrivatePort() + */ + public T privatePort(int privatePort) { this.privatePort = privatePort; - return this; + return self(); } - public Builder publicIP(String publicIP) { + /** + * @see LoadBalancerRule#getPublicIP() + */ + public T publicIP(String publicIP) { this.publicIP = publicIP; - return this; + return self(); } - public Builder publicIPId(String publicIPId) { + /** + * @see LoadBalancerRule#getPublicIPId() + */ + public T publicIPId(String publicIPId) { this.publicIPId = publicIPId; - return this; + return self(); } - public Builder publicPort(int publicPort) { + /** + * @see LoadBalancerRule#getPublicPort() + */ + public T publicPort(int publicPort) { this.publicPort = publicPort; - return this; + return self(); } - public Builder state(State state) { + /** + * @see LoadBalancerRule#getState() + */ + public T state(LoadBalancerRule.State state) { this.state = state; - return this; + return self(); } - public Builder CIDRs(Set CIDRs) { - this.CIDRs = CIDRs; - return this; + /** + * @see LoadBalancerRule#getCIDRs() + */ + public T CIDRs(Set CIDRs) { + this.CIDRs = ImmutableSet.copyOf(checkNotNull(CIDRs, "CIDRs")); + return self(); } - public Builder zoneId(String zoneId) { + public T CIDRs(String... in) { + return CIDRs(ImmutableSet.copyOf(in)); + } + + /** + * @see LoadBalancerRule#getZoneId() + */ + public T zoneId(String zoneId) { this.zoneId = zoneId; - return this; + return self(); } public LoadBalancerRule build() { - return new LoadBalancerRule(id, account, algorithm, description, domain, domainId, name, privatePort, - publicIP, publicIPId, publicPort, state, zoneId, CIDRs); + return new LoadBalancerRule(id, account, algorithm, description, domain, domainId, name, privatePort, publicIP, publicIPId, publicPort, state, CIDRs, zoneId); + } + + public T fromLoadBalancerRule(LoadBalancerRule in) { + return this + .id(in.getId()) + .account(in.getAccount()) + .algorithm(in.getAlgorithm()) + .description(in.getDescription()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .name(in.getName()) + .privatePort(in.getPrivatePort()) + .publicIP(in.getPublicIP()) + .publicIPId(in.getPublicIPId()) + .publicPort(in.getPublicPort()) + .state(in.getState()) + .CIDRs(in.getCIDRs()) + .zoneId(in.getZoneId()); } } - private String id; - private String account; - private Algorithm algorithm; - private String description; - private String domain; - @SerializedName("domainid") - private String domainId; - private String name; - @SerializedName("privateport") - private int privatePort; - @SerializedName("publicip") - private String publicIP; - @SerializedName("publicipid") - private String publicIPId; - @SerializedName("publicport") - private int publicPort; - private State state; - @SerializedName("cidrlist") - private Set CIDRs; - @SerializedName("zoneId") - private String zoneId; - - // for deserializer - LoadBalancerRule() { - + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public LoadBalancerRule(String id, String account, Algorithm algorithm, String description, String domain, - String domainId, String name, int privatePort, String publicIP, String publicIPId, int publicPort, State state, - String zoneId, Set CIDRs) { - this.id = id; + private final String id; + private final String account; + private final LoadBalancerRule.Algorithm algorithm; + private final String description; + private final String domain; + @Named("domainid") + private final String domainId; + private final String name; + @Named("privateport") + private final int privatePort; + @Named("publicip") + private final String publicIP; + @Named("publicipid") + private final String publicIPId; + @Named("publicport") + private final int publicPort; + private final LoadBalancerRule.State state; + @Named("cidrlist") + private final Set CIDRs; + private final String zoneId; + + @ConstructorProperties({ + "id", "account", "algorithm", "description", "domain", "domainid", "name", "privateport", "publicip", "publicipid", "publicport", "state", "cidrlist", "zoneId" + }) + protected LoadBalancerRule(String id, @Nullable String account, @Nullable LoadBalancerRule.Algorithm algorithm, + @Nullable String description, @Nullable String domain, @Nullable String domainId, @Nullable String name, + int privatePort, @Nullable String publicIP, @Nullable String publicIPId, int publicPort, + @Nullable LoadBalancerRule.State state, @Nullable Set CIDRs, @Nullable String zoneId) { + this.id = checkNotNull(id, "id"); this.account = account; this.algorithm = algorithm; this.description = description; @@ -205,162 +289,152 @@ public class LoadBalancerRule implements Comparable { this.publicIPId = publicIPId; this.publicPort = publicPort; this.state = state; + this.CIDRs = CIDRs == null ? ImmutableSet.of() : ImmutableSet.copyOf(CIDRs); this.zoneId = zoneId; - this.CIDRs = ImmutableSet.copyOf(CIDRs); - } /** * @return the load balancer rule ID */ public String getId() { - return id; + return this.id; } /** * @return the account of the load balancer rule */ + @Nullable public String getAccount() { - return account; + return this.account; } /** * @return the load balancer algorithm (source, roundrobin, leastconn) */ - public Algorithm getAlgorithm() { - return algorithm; + @Nullable + public LoadBalancerRule.Algorithm getAlgorithm() { + return this.algorithm; } /** * @return the description of the load balancer */ + @Nullable public String getDescription() { - return description; + return this.description; } /** * @return the domain of the load balancer rule */ + @Nullable public String getDomain() { - return domain; + return this.domain; } /** * @return the domain ID of the load balancer rule */ + @Nullable public String getDomainId() { - return domainId; + return this.domainId; } /** * @return the name of the load balancer */ + @Nullable public String getName() { - return name; + return this.name; } /** * @return the private port */ public int getPrivatePort() { - return privatePort; + return this.privatePort; } /** * @return the public ip address */ + @Nullable public String getPublicIP() { - return publicIP; + return this.publicIP; } /** * @return the public ip address id */ + @Nullable public String getPublicIPId() { - return publicIPId; + return this.publicIPId; } /** * @return the public port */ public int getPublicPort() { - return publicPort; + return this.publicPort; } /** * @return the state of the rule */ - public State getState() { - return state; + @Nullable + public LoadBalancerRule.State getState() { + return this.state; } /** * @return the cidr list to forward traffic from */ public Set getCIDRs() { - return CIDRs; + return this.CIDRs; } /** * @return the id of the zone the rule beStrings to */ + @Nullable public String getZoneId() { - return zoneId; - } - - @Override - public int compareTo(LoadBalancerRule arg0) { - return id.compareTo(arg0.getId()); - } - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - LoadBalancerRule that = (LoadBalancerRule) o; - - if (!Objects.equal(account, that.account)) return false; - if (!Objects.equal(algorithm, that.algorithm)) return false; - if (!Objects.equal(description, that.description)) return false; - if (!Objects.equal(domain, that.domain)) return false; - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(privatePort, that.privatePort)) return false; - if (!Objects.equal(publicIP, that.publicIP)) return false; - if (!Objects.equal(publicIPId, that.publicIPId)) return false; - if (!Objects.equal(publicPort, that.publicPort)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(state, that.state)) return false; - - return true; + return this.zoneId; } @Override public int hashCode() { - return Objects.hashCode(account, algorithm, description, domain, domainId, id, name, privatePort, publicIP, publicIPId, publicPort, zoneId, state); + return Objects.hashCode(id, account, algorithm, description, domain, domainId, name, privatePort, publicIP, publicIPId, publicPort, state, CIDRs, zoneId); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + LoadBalancerRule that = LoadBalancerRule.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.account, that.account) + && Objects.equal(this.algorithm, that.algorithm) + && Objects.equal(this.description, that.description) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.name, that.name) + && Objects.equal(this.privatePort, that.privatePort) + && Objects.equal(this.publicIP, that.publicIP) + && Objects.equal(this.publicIPId, that.publicIPId) + && Objects.equal(this.publicPort, that.publicPort) + && Objects.equal(this.state, that.state) + && Objects.equal(this.CIDRs, that.CIDRs) + && Objects.equal(this.zoneId, that.zoneId); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("account", account).add("algorithm", algorithm).add("description", description).add("domain", domain).add("domainId", domainId).add("name", name).add("privatePort", privatePort).add("publicIP", publicIP).add("publicIPId", publicIPId).add("publicPort", publicPort).add("state", state).add("CIDRs", CIDRs).add("zoneId", zoneId); + } + @Override public String toString() { - return "LoadBalancerRule{" + - "id=" + id + - ", account='" + account + '\'' + - ", algorithm=" + algorithm + - ", description='" + description + '\'' + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", name='" + name + '\'' + - ", privatePort=" + privatePort + - ", publicIP='" + publicIP + '\'' + - ", publicIPId=" + publicIPId + - ", publicPort=" + publicPort + - ", state=" + state + - ", CIDRs=" + CIDRs + - ", zoneId=" + zoneId + - '}'; + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/LoginResponse.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/LoginResponse.java index 8fb36e4558..aac15b6746 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/LoginResponse.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/LoginResponse.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,160 +16,219 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.cloudstack.domain; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * Representation of the login API call response * * @author Andrei Savu - */ -public class LoginResponse implements Comparable { +*/ +public class LoginResponse { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromLoginResponse(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); - private String username; - private String userId; - private String password; - private String domainId; - private long timeout; - private boolean registered; - private String accountName; - private String firstName; - private String lastName; - private Account.Type accountType; - private String timezone; - private String timezoneOffset; - private String sessionKey; - private String jSessionId; - - public Builder copyOf(LoginResponse r) { - this.username = r.username; - this.userId = r.userId; - this.password = r.password; - this.domainId = r.domainId; - this.timeout = r.timeout; - this.registered = r.registered; - this.accountName = r.accountName; - this.firstName = r.firstName; - this.lastName = r.lastName; - this.accountType = r.accountType; - this.timezone = r.timezone; - this.timezoneOffset = r.timezoneOffset; - this.sessionKey = r.sessionKey; - this.jSessionId = r.jSessionId; - return this; - } - - public Builder username(String username) { + protected String username; + protected String userId; + protected String password; + protected String domainId; + protected long timeout; + protected boolean registered; + protected String accountName; + protected String firstName; + protected String lastName; + protected Account.Type accountType; + protected String timezone; + protected String timezoneOffset; + protected String sessionKey; + protected String jSessionId; + + /** + * @see LoginResponse#getUsername() + */ + public T username(String username) { this.username = username; - return this; + return self(); } - public Builder userId(String userId) { + /** + * @see LoginResponse#getUserId() + */ + public T userId(String userId) { this.userId = userId; - return this; + return self(); } - public Builder password(String password) { + /** + * @see LoginResponse#getPassword() + */ + public T password(String password) { this.password = password; - return this; + return self(); } - public Builder domainId(String domainId) { + /** + * @see LoginResponse#getDomainId() + */ + public T domainId(String domainId) { this.domainId = domainId; - return this; + return self(); } - public Builder timeout(long timeout) { + /** + * @see LoginResponse#getTimeout() + */ + public T timeout(long timeout) { this.timeout = timeout; - return this; + return self(); } - public Builder registered(boolean registered) { + /** + * @see LoginResponse#isRegistered() + */ + public T registered(boolean registered) { this.registered = registered; - return this; + return self(); } - public Builder accountName(String accountName) { + /** + * @see LoginResponse#getAccountName() + */ + public T accountName(String accountName) { this.accountName = accountName; - return this; + return self(); } - public Builder firstName(String firstName) { + /** + * @see LoginResponse#getFirstName() + */ + public T firstName(String firstName) { this.firstName = firstName; - return this; + return self(); } - public Builder lastName(String lastName) { + /** + * @see LoginResponse#getLastName() + */ + public T lastName(String lastName) { this.lastName = lastName; - return this; + return self(); } - public Builder accountType(Account.Type accountType) { + /** + * @see LoginResponse#getAccountType() + */ + public T accountType(Account.Type accountType) { this.accountType = accountType; - return this; + return self(); } - public Builder timezone(String timezone) { + /** + * @see LoginResponse#getTimezone() + */ + public T timezone(String timezone) { this.timezone = timezone; - return this; + return self(); } - public Builder timezoneOffset(String timezoneOffset) { + /** + * @see LoginResponse#getTimezoneOffset() + */ + public T timezoneOffset(String timezoneOffset) { this.timezoneOffset = timezoneOffset; - return this; + return self(); } - public Builder sessionKey(String sessionKey) { + /** + * @see LoginResponse#getSessionKey() + */ + public T sessionKey(String sessionKey) { this.sessionKey = sessionKey; - return this; + return self(); } - public Builder jSessionId(String jSessionId) { + /** + * @see LoginResponse#getJSessionId() + */ + public T jSessionId(String jSessionId) { this.jSessionId = jSessionId; - return this; + return self(); } public LoginResponse build() { - return new LoginResponse(username, userId, password, domainId, timeout, registered, accountName, firstName, - lastName, accountType, timezone, timezoneOffset, sessionKey, jSessionId); + return new LoginResponse(username, userId, password, domainId, timeout, registered, accountName, firstName, lastName, accountType, timezone, timezoneOffset, sessionKey, jSessionId); + } + + public T fromLoginResponse(LoginResponse in) { + return this + .username(in.getUsername()) + .userId(in.getUserId()) + .password(in.getPassword()) + .domainId(in.getDomainId()) + .timeout(in.getTimeout()) + .registered(in.isRegistered()) + .accountName(in.getAccountName()) + .firstName(in.getFirstName()) + .lastName(in.getLastName()) + .accountType(in.getAccountType()) + .timezone(in.getTimezone()) + .timezoneOffset(in.getTimezoneOffset()) + .sessionKey(in.getSessionKey()) + .jSessionId(in.getJSessionId()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; } } private final String username; - @SerializedName("userid") + @Named("userid") private final String userId; private final String password; - @SerializedName("domainid") + @Named("domainid") private final String domainId; private final long timeout; private final boolean registered; - @SerializedName("account") + @Named("account") private final String accountName; - @SerializedName("firstname") + @Named("firstname") private final String firstName; - @SerializedName("lastname") + @Named("lastname") private final String lastName; - @SerializedName("type") + @Named("type") private final Account.Type accountType; private final String timezone; - @SerializedName("timezoneoffset") + @Named("timezoneoffset") private final String timezoneOffset; - @SerializedName("sessionkey") + @Named("sessionkey") private final String sessionKey; private final String jSessionId; - public LoginResponse(String username, String userId, String password, String domainId, long timeout, boolean registered, - String accountName, String firstName, String lastName, Account.Type accountType, String timezone, - String timezoneOffset, String sessionKey, String jSessionId) { + @ConstructorProperties({ + "username", "userid", "password", "domainid", "timeout", "registered", "account", "firstname", "lastname", "type", "timezone", "timezoneoffset", "sessionkey", "jSessionId" + }) + protected LoginResponse(@Nullable String username, @Nullable String userId, @Nullable String password, @Nullable String domainId, long timeout, boolean registered, @Nullable String accountName, @Nullable String firstName, @Nullable String lastName, @Nullable Account.Type accountType, @Nullable String timezone, @Nullable String timezoneOffset, @Nullable String sessionKey, @Nullable String jSessionId) { this.username = username; this.userId = userId; this.password = password; @@ -186,107 +245,108 @@ public class LoginResponse implements Comparable { this.jSessionId = jSessionId; } + @Nullable public String getUsername() { - return username; + return this.username; } + @Nullable public String getUserId() { - return userId; + return this.userId; } + @Nullable public String getPassword() { - return password; + return this.password; } + @Nullable public String getDomainId() { - return domainId; + return this.domainId; } public long getTimeout() { - return timeout; + return this.timeout; } public boolean isRegistered() { - return registered; + return this.registered; } + @Nullable public String getAccountName() { - return accountName; + return this.accountName; } + @Nullable public String getFirstName() { - return firstName; + return this.firstName; } + @Nullable public String getLastName() { - return lastName; + return this.lastName; } + @Nullable public Account.Type getAccountType() { - return accountType; + return this.accountType; } + @Nullable public String getTimezone() { - return timezone; + return this.timezone; } + @Nullable public String getTimezoneOffset() { - return timezoneOffset; + return this.timezoneOffset; } + @Nullable public String getSessionKey() { - return sessionKey; + return this.sessionKey; } + @Nullable public String getJSessionId() { - return jSessionId; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - LoginResponse that = (LoginResponse) o; - - if (!Objects.equal(accountName, that.accountName)) return false; - if (!Objects.equal(accountType, that.accountType)) return false; - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(firstName, that.firstName)) return false; - if (!Objects.equal(jSessionId, that.jSessionId)) return false; - if (!Objects.equal(lastName, that.lastName)) return false; - if (!Objects.equal(password, that.password)) return false; - if (!Objects.equal(registered, that.registered)) return false; - if (!Objects.equal(sessionKey, that.sessionKey)) return false; - if (!Objects.equal(timeout, that.timeout)) return false; - if (!Objects.equal(timezone, that.timezone)) return false; - if (!Objects.equal(timezoneOffset, that.timezoneOffset)) return false; - if (!Objects.equal(userId, that.userId)) return false; - if (!Objects.equal(username, that.username)) return false; - - return true; + return this.jSessionId; } @Override public int hashCode() { - return Objects.hashCode(accountName, accountType, domainId, firstName, jSessionId, lastName, - password, registered, sessionKey, timeout, timezone, timezoneOffset, - userId, username); + return Objects.hashCode(username, userId, password, domainId, timeout, registered, accountName, firstName, lastName, accountType, timezone, timezoneOffset, sessionKey, jSessionId); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + LoginResponse that = LoginResponse.class.cast(obj); + return Objects.equal(this.username, that.username) + && Objects.equal(this.userId, that.userId) + && Objects.equal(this.password, that.password) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.timeout, that.timeout) + && Objects.equal(this.registered, that.registered) + && Objects.equal(this.accountName, that.accountName) + && Objects.equal(this.firstName, that.firstName) + && Objects.equal(this.lastName, that.lastName) + && Objects.equal(this.accountType, that.accountType) + && Objects.equal(this.timezone, that.timezone) + && Objects.equal(this.timezoneOffset, that.timezoneOffset) + && Objects.equal(this.sessionKey, that.sessionKey) + && Objects.equal(this.jSessionId, that.jSessionId); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("username", username).add("userId", userId).add("password", password).add("domainId", domainId).add("timeout", timeout).add("registered", registered).add("accountName", accountName).add("firstName", firstName).add("lastName", lastName).add("accountType", accountType).add("timezone", timezone).add("timezoneOffset", timezoneOffset).add("sessionKey", sessionKey).add("jSessionId", jSessionId); + } + @Override public String toString() { - return "LoginResponse{" + "username='" + username + '\'' + ", userId=" + userId + ", password='" + password - + '\'' + ", domainId=" + domainId + ", timeout=" + timeout + ", registered=" + registered - + ", accountName='" + accountName + '\'' + ", firstName='" + firstName + '\'' + ", lastName='" - + lastName + '\'' + ", accountType=" + accountType + ", timezone='" + timezone + '\'' - + ", timezoneOffset='" + timezoneOffset + '\'' + ", sessionKey='" + sessionKey + '\'' + ", jSessionId='" - + jSessionId + '\'' + '}'; - } - - @Override - public int compareTo(LoginResponse arg0) { - return sessionKey.compareTo(arg0.getSessionKey()); + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NIC.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NIC.java index 6ecf585dbf..e9c9b8dbc8 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NIC.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NIC.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,128 +18,193 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.net.URI; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** - * + * Class NIC + * * @author Adrian Cole - */ +*/ public class NIC { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromNIC(this); } - public static class Builder { - private String id; - private URI broadcastURI; - private String gateway; - private String IPAddress; - private boolean isDefault; - private URI isolationURI; - private String netmask; - private String macAddress; - private String networkId; - private TrafficType trafficType; - private GuestIPType guestIPType; + public static abstract class Builder> { + protected abstract T self(); - public Builder id(String id) { + protected String id; + protected URI broadcastURI; + protected String gateway; + protected String IPAddress; + protected boolean isDefault; + protected URI isolationURI; + protected String netmask; + protected String macAddress; + protected String networkId; + protected TrafficType trafficType; + protected GuestIPType guestIPType; + + /** + * @see NIC#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder broadcastURI(URI broadcastURI) { + /** + * @see NIC#getBroadcastURI() + */ + public T broadcastURI(URI broadcastURI) { this.broadcastURI = broadcastURI; - return this; + return self(); } - public Builder gateway(String gateway) { + /** + * @see NIC#getGateway() + */ + public T gateway(String gateway) { this.gateway = gateway; - return this; + return self(); } - public Builder IPAddress(String IPAddress) { + /** + * @see NIC#getIPAddress() + */ + public T IPAddress(String IPAddress) { this.IPAddress = IPAddress; - return this; + return self(); } - public Builder isDefault(boolean isDefault) { + /** + * @see NIC#isDefault() + */ + public T isDefault(boolean isDefault) { this.isDefault = isDefault; - return this; + return self(); } - public Builder isolationURI(URI isolationURI) { + /** + * @see NIC#getIsolationURI() + */ + public T isolationURI(URI isolationURI) { this.isolationURI = isolationURI; - return this; + return self(); } - public Builder netmask(String netmask) { + /** + * @see NIC#getNetmask() + */ + public T netmask(String netmask) { this.netmask = netmask; - return this; + return self(); } - public Builder macAddress(String macAddress) { + /** + * @see NIC#getMacAddress() + */ + public T macAddress(String macAddress) { this.macAddress = macAddress; - return this; + return self(); } - public Builder networkId(String networkId) { + /** + * @see NIC#getNetworkId() + */ + public T networkId(String networkId) { this.networkId = networkId; - return this; + return self(); } - public Builder trafficType(TrafficType trafficType) { + /** + * @see NIC#getTrafficType() + */ + public T trafficType(TrafficType trafficType) { this.trafficType = trafficType; - return this; + return self(); } - public Builder guestIPType(GuestIPType guestIPType) { + /** + * @see NIC#getGuestIPType() + */ + public T guestIPType(GuestIPType guestIPType) { this.guestIPType = guestIPType; - return this; + return self(); } public NIC build() { - return new NIC(id, broadcastURI, gateway, IPAddress, isDefault, isolationURI, netmask, macAddress, networkId, - trafficType, guestIPType); - + return new NIC(id, broadcastURI, gateway, IPAddress, isDefault, isolationURI, netmask, macAddress, networkId, trafficType, guestIPType); + } + + public T fromNIC(NIC in) { + return this + .id(in.getId()) + .broadcastURI(in.getBroadcastURI()) + .gateway(in.getGateway()) + .IPAddress(in.getIPAddress()) + .isDefault(in.isDefault()) + .isolationURI(in.getIsolationURI()) + .netmask(in.getNetmask()) + .macAddress(in.getMacAddress()) + .networkId(in.getNetworkId()) + .trafficType(in.getTrafficType()) + .guestIPType(in.getGuestIPType()); } } - private String id; - @SerializedName("broadcasturi") - private URI broadcastURI; - private String gateway; - @SerializedName("ipaddress") - private String IPAddress; - @SerializedName("isdefault") - private boolean isDefault; - @SerializedName("isolationuri") - private URI isolationURI; - private String netmask; - @SerializedName("macaddress") - private String macAddress; - @SerializedName("networkid") - private String networkId; - @SerializedName("traffictype") - private TrafficType trafficType; - @SerializedName("type") - private GuestIPType guestIPType; - - /** - * present only for serializer - */ - NIC() { - + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public NIC(String id, URI broadcastURI, String gateway, String iPAddress, boolean isDefault, URI isolationURI, - String netmask, String macAddress, String networkId, TrafficType trafficType, GuestIPType guestIPType) { - this.id = id; + private final String id; + @Named("broadcasturi") + private final URI broadcastURI; + private final String gateway; + @Named("ipaddress") + private final String IPAddress; + @Named("isdefault") + private final boolean isDefault; + @Named("isolationuri") + private final URI isolationURI; + private final String netmask; + @Named("macaddress") + private final String macAddress; + @Named("networkid") + private final String networkId; + @Named("traffictype") + private final TrafficType trafficType; + @Named("type") + private final GuestIPType guestIPType; + + @ConstructorProperties({ + "id", "broadcasturi", "gateway", "ipaddress", "isdefault", "isolationuri", "netmask", "macaddress", "networkid", "traffictype", "type" + }) + protected NIC(String id, @Nullable URI broadcastURI, @Nullable String gateway, @Nullable String IPAddress, boolean isDefault, + @Nullable URI isolationURI, @Nullable String netmask, @Nullable String macAddress, @Nullable String networkId, + @Nullable TrafficType trafficType, @Nullable GuestIPType guestIPType) { + this.id = checkNotNull(id, "id"); this.broadcastURI = broadcastURI; this.gateway = gateway; - this.IPAddress = iPAddress; + this.IPAddress = IPAddress; this.isDefault = isDefault; this.isolationURI = isolationURI; this.netmask = netmask; @@ -153,121 +218,121 @@ public class NIC { * the ID of the nic */ public String getId() { - return id; + return this.id; } /** * the broadcast uri of the nic */ + @Nullable public URI getBroadcastURI() { - return broadcastURI; + return this.broadcastURI; } /** * the gateway of the nic */ + @Nullable public String getGateway() { - return gateway; + return this.gateway; } /** * the ip address of the nic */ + @Nullable public String getIPAddress() { - return IPAddress; + return this.IPAddress; } /** * true if nic is default, false otherwise */ public boolean isDefault() { - return isDefault; + return this.isDefault; } /** * the isolation uri of the nic */ + @Nullable public URI getIsolationURI() { - return isolationURI; + return this.isolationURI; } /** * the netmask of the nic */ + @Nullable public String getNetmask() { - return netmask; + return this.netmask; } /** * the MAC Address of the NIC */ + @Nullable public String getMacAddress() { - return macAddress; + return this.macAddress; } /** * the ID of the corresponding network */ + @Nullable public String getNetworkId() { - return networkId; + return this.networkId; } /** * the traffic type of the nic */ + @Nullable public TrafficType getTrafficType() { - return trafficType; + return this.trafficType; } /** * the type of the nic */ + @Nullable public GuestIPType getGuestIPType() { - return guestIPType; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - NIC that = (NIC) o; - - if (!Objects.equal(IPAddress, that.IPAddress)) return false; - if (!Objects.equal(broadcastURI, that.broadcastURI)) return false; - if (!Objects.equal(gateway, that.gateway)) return false; - if (!Objects.equal(guestIPType, that.guestIPType)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(isDefault, that.isDefault)) return false; - if (!Objects.equal(isolationURI, that.isolationURI)) return false; - if (!Objects.equal(netmask, that.netmask)) return false; - if (!Objects.equal(macAddress, that.macAddress)) return false; - if (!Objects.equal(networkId, that.networkId)) return false; - if (!Objects.equal(trafficType, that.trafficType)) return false; - - return true; + return this.guestIPType; } @Override public int hashCode() { - return Objects.hashCode(IPAddress, broadcastURI, gateway, guestIPType, id, isDefault, isolationURI, netmask, macAddress, networkId, trafficType); + return Objects.hashCode(id, broadcastURI, gateway, IPAddress, isDefault, isolationURI, netmask, macAddress, networkId, trafficType, guestIPType); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + NIC that = NIC.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.broadcastURI, that.broadcastURI) + && Objects.equal(this.gateway, that.gateway) + && Objects.equal(this.IPAddress, that.IPAddress) + && Objects.equal(this.isDefault, that.isDefault) + && Objects.equal(this.isolationURI, that.isolationURI) + && Objects.equal(this.netmask, that.netmask) + && Objects.equal(this.macAddress, that.macAddress) + && Objects.equal(this.networkId, that.networkId) + && Objects.equal(this.trafficType, that.trafficType) + && Objects.equal(this.guestIPType, that.guestIPType); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("broadcastURI", broadcastURI).add("gateway", gateway).add("IPAddress", IPAddress) + .add("isDefault", isDefault).add("isolationURI", isolationURI).add("netmask", netmask).add("macAddress", macAddress) + .add("networkId", networkId).add("trafficType", trafficType).add("guestIPType", guestIPType); + } + @Override public String toString() { - return "NIC{" + - "id=" + id + - ", broadcastURI=" + broadcastURI + - ", gateway='" + gateway + '\'' + - ", IPAddress='" + IPAddress + '\'' + - ", isDefault=" + isDefault + - ", isolationURI=" + isolationURI + - ", netmask='" + netmask + '\'' + - ", macAddress='" + macAddress + '\'' + - ", networkId=" + networkId + - ", trafficType=" + trafficType + - ", guestIPType=" + guestIPType + - '}'; + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java index f2b36311b2..5cc209fa3e 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,296 +20,428 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.net.URI; import java.util.List; import java.util.Set; -import java.util.SortedSet; -import javax.annotation.Nullable; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; -import com.google.common.base.Joiner; import com.google.common.base.Objects; -import com.google.common.base.Splitter; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; -import com.google.gson.annotations.SerializedName; /** + * Class Network + * * @author Adrian Cole - */ -public class Network implements Comparable { - public static Builder builder() { - return new Builder(); +*/ +public class Network { + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromNetwork(this); } - public static class Builder { - private String id; - private String broadcastDomainType; - private URI broadcastURI; - private String displayText; - private List DNS = ImmutableList.of(); - private String domain; - 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 String networkOfferingId; - private String networkOfferingName; - private String related; - private String startIP; - private String name; - private String state; - private GuestIPType guestIPType; - private String VLAN; - private TrafficType trafficType; - private String zoneId; - private Set services = ImmutableSet.of(); - private String account; - private String domainId; - private boolean securityGroupEnabled; - private Set tags = ImmutableSet.of(); + public static abstract class Builder> { + protected abstract T self(); - - public Builder id(String id) { + protected String id; + protected String account; + protected String broadcastDomainType; + protected URI broadcastURI; + protected String displayText; + protected String DNS1; + protected String DNS2; + protected String domain; + protected String domainId; + protected String endIP; + protected String gateway; + protected boolean isDefault; + protected boolean isShared; + protected boolean isSystem; + protected String netmask; + protected String networkDomain; + protected String networkOfferingAvailability; + protected String networkOfferingDisplayText; + protected String networkOfferingId; + protected String networkOfferingName; + protected String related; + protected String startIP; + protected String name; + protected String state; + protected GuestIPType guestIPType; + protected String VLAN; + protected TrafficType trafficType; + protected String zoneId; + protected String tags; + protected boolean securityGroupEnabled; + protected Set services = ImmutableSortedSet.of(); + + /** + * @see Network#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder account(String account) { + /** + * @see Network#getAccount() + */ + public T account(String account) { this.account = account; - return this; + return self(); } - public Builder domainId(String domainId) { - this.domainId = domainId; - return this; - } - - public Builder broadcastDomainType(String broadcastDomainType) { + /** + * @see Network#getBroadcastDomainType() + */ + public T broadcastDomainType(String broadcastDomainType) { this.broadcastDomainType = broadcastDomainType; - return this; + return self(); } - public Builder broadcastURI(URI broadcastURI) { + /** + * @see Network#getBroadcastURI() + */ + public T broadcastURI(URI broadcastURI) { this.broadcastURI = broadcastURI; - return this; + return self(); } - public Builder displayText(String displayText) { + /** + * @see Network#getDisplayText() + */ + public T displayText(String displayText) { this.displayText = displayText; - return this; + return self(); } - public Builder DNS(List DNS) { - this.DNS = ImmutableList.copyOf(checkNotNull(DNS, "DNS")); - return this; + /** + * @return the DNS for the Network + */ + public T DNS(List DNS) { + if (!DNS.isEmpty()) this.DNS1 = DNS.get(0); + if (DNS.size() > 1) this.DNS2 = DNS.get(1); + return self(); } - - public Builder domain(String domain) { + /** + * @see Network#getDomain() + */ + public T domain(String domain) { this.domain = domain; - return this; + return self(); } - public Builder endIP(String endIP) { + /** + * @see Network#getDomainId() + */ + public T domainId(String domainId) { + this.domainId = domainId; + return self(); + } + + /** + * @see Network#getEndIP() + */ + public T endIP(String endIP) { this.endIP = endIP; - return this; + return self(); } - public Builder gateway(String gateway) { + /** + * @see Network#getGateway() + */ + public T gateway(String gateway) { this.gateway = gateway; - return this; + return self(); } - public Builder isDefault(boolean isDefault) { + /** + * @see Network#isDefault() + */ + public T isDefault(boolean isDefault) { this.isDefault = isDefault; - return this; + return self(); } - public Builder isShared(boolean isShared) { + /** + * @see Network#isShared() + */ + public T isShared(boolean isShared) { this.isShared = isShared; - return this; + return self(); } - public Builder isSystem(boolean isSystem) { + /** + * @see Network#isSystem() + */ + public T isSystem(boolean isSystem) { this.isSystem = isSystem; - return this; + return self(); } - public Builder netmask(String netmask) { + /** + * @see Network#getNetmask() + */ + public T netmask(String netmask) { this.netmask = netmask; - return this; + return self(); } - public Builder networkDomain(String networkDomain) { + /** + * @see Network#getNetworkDomain() + */ + public T networkDomain(String networkDomain) { this.networkDomain = networkDomain; - return this; + return self(); } - public Builder networkOfferingAvailability(String networkOfferingAvailability) { + /** + * @see Network#getNetworkOfferingAvailability() + */ + public T networkOfferingAvailability(String networkOfferingAvailability) { this.networkOfferingAvailability = networkOfferingAvailability; - return this; + return self(); } - public Builder networkOfferingDisplayText(String networkOfferingDisplayText) { + /** + * @see Network#getNetworkOfferingDisplayText() + */ + public T networkOfferingDisplayText(String networkOfferingDisplayText) { this.networkOfferingDisplayText = networkOfferingDisplayText; - return this; + return self(); } - public Builder networkOfferingId(String networkOfferingId) { + /** + * @see Network#getNetworkOfferingId() + */ + public T networkOfferingId(String networkOfferingId) { this.networkOfferingId = networkOfferingId; - return this; + return self(); } - public Builder networkOfferingName(String networkOfferingName) { + /** + * @see Network#getNetworkOfferingName() + */ + public T networkOfferingName(String networkOfferingName) { this.networkOfferingName = networkOfferingName; - return this; + return self(); } - public Builder related(String related) { + /** + * @see Network#getRelated() + */ + public T related(String related) { this.related = related; - return this; + return self(); } - public Builder startIP(String startIP) { + /** + * @see Network#getStartIP() + */ + public T startIP(String startIP) { this.startIP = startIP; - return this; + return self(); } - public Builder name(String name) { + /** + * @see Network#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder state(String state) { + /** + * @see Network#getState() + */ + public T state(String state) { this.state = state; - return this; + return self(); } - public Builder guestIPType(GuestIPType guestIPType) { + /** + * @see Network#getGuestIPType() + */ + public T guestIPType(GuestIPType guestIPType) { this.guestIPType = guestIPType; - return this; + return self(); } - public Builder VLAN(String VLAN) { + /** + * @see Network#getVLAN() + */ + public T VLAN(String VLAN) { this.VLAN = VLAN; - return this; + return self(); } - public Builder trafficType(TrafficType trafficType) { + /** + * @see Network#getTrafficType() + */ + public T trafficType(TrafficType trafficType) { this.trafficType = trafficType; - return this; + return self(); } - public Builder zoneId(String zoneId) { + /** + * @see Network#getZoneId() + */ + public T zoneId(String zoneId) { this.zoneId = zoneId; - return this; + return self(); } - public Builder services(Set services) { - this.services = ImmutableSet.copyOf(checkNotNull(services, "services")); - return this; + /** + * @see Network#getTags() + */ + public T tags(String tags) { + this.tags = tags; + return self(); } - public Builder tags(Set tags) { - this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); - return this; - } - - public Builder securityGroupEnabled(boolean securityGroupEnabled) { + /** + * @see Network#isSecurityGroupEnabled() + */ + public T securityGroupEnabled(boolean securityGroupEnabled) { this.securityGroupEnabled = securityGroupEnabled; - return this; + return self(); + } + + /** + * @see Network#getServices() + */ + public T services(Set services) { + this.services = services; + return self(); } public Network build() { - return new Network(id, 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, tags, securityGroupEnabled, account); + return new Network(id, account, broadcastDomainType, broadcastURI, displayText, DNS1, DNS2, domain, domainId, endIP, gateway, isDefault, isShared, isSystem, netmask, networkDomain, networkOfferingAvailability, networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state, guestIPType, VLAN, trafficType, zoneId, tags, securityGroupEnabled, services); + } + + public T fromNetwork(Network in) { + return this + .id(in.getId()) + .account(in.getAccount()) + .broadcastDomainType(in.getBroadcastDomainType()) + .broadcastURI(in.getBroadcastURI()) + .displayText(in.getDisplayText()) + .DNS(in.getDNS()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .endIP(in.getEndIP()) + .gateway(in.getGateway()) + .isDefault(in.isDefault()) + .isShared(in.isShared()) + .isSystem(in.isSystem()) + .netmask(in.getNetmask()) + .networkDomain(in.getNetworkDomain()) + .networkOfferingAvailability(in.getNetworkOfferingAvailability()) + .networkOfferingDisplayText(in.getNetworkOfferingDisplayText()) + .networkOfferingId(in.getNetworkOfferingId()) + .networkOfferingName(in.getNetworkOfferingName()) + .related(in.getRelated()) + .startIP(in.getStartIP()) + .name(in.getName()) + .state(in.getState()) + .guestIPType(in.getGuestIPType()) + .VLAN(in.getVLAN()) + .trafficType(in.getTrafficType()) + .zoneId(in.getZoneId()) + .tags(in.getTags()) + .securityGroupEnabled(in.isSecurityGroupEnabled()) + .services(in.getServices()); } } - private String id; - private String account; - @SerializedName("broadcastdomaintype") - private String broadcastDomainType; - @SerializedName("broadcasturi") - private URI broadcastURI; - @SerializedName("displaytext") - private String displayText; - @SerializedName("dns1") - private String DNS1; - @SerializedName("dns2") - private String DNS2; - private String domain; - @SerializedName("domainid") - private String domainId; - @SerializedName("endip") - private String endIP; - private String gateway; - @SerializedName("isdefault") - private boolean isDefault; - @SerializedName("isshared") - private boolean isShared; - @SerializedName("issystem") - private boolean isSystem; - private String netmask; - @Nullable - @SerializedName("networkdomain") - private String networkDomain; - @SerializedName("networkofferingavailability") - private String networkOfferingAvailability; - @SerializedName("networkofferingdisplaytext") - private String networkOfferingDisplayText; - @SerializedName("networkofferingid") - private String networkOfferingId; - @SerializedName("networkofferingname") - private String networkOfferingName; - private String related; - @SerializedName("startip") - private String startIP; - private String name; - private String state; - @SerializedName("type") - private GuestIPType guestIPType; - @SerializedName("vlan") - private String VLAN; - @SerializedName("traffictype") - private TrafficType trafficType; - @SerializedName("zoneid") - private String zoneId; - private String tags; - @SerializedName("securitygroupenabled") - private boolean securityGroupEnabled; - // so tests and serialization comes out expected - @SerializedName("service") - private SortedSet services = ImmutableSortedSet.of(); - - /** - * present only for serializer - */ - Network() { - + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public Network(String id, String broadcastDomainType, URI broadcastURI, String displayText, - List DNS, String domain, String domainId, String endIP, String gateway, boolean isDefault, - boolean isShared, boolean isSystem, String netmask, String networkDomain, String networkOfferingAvailability, - String networkOfferingDisplayText, String networkOfferingId, String networkOfferingName, String related, - String startIP, String name, String state, GuestIPType type, String vLAN, TrafficType trafficType, - String zoneId, Set services, Set tags, boolean securityGroupEnabled, - String account) { - this.id = id; + private final String id; + private final String account; + @Named("broadcastdomaintype") + private final String broadcastDomainType; + @Named("broadcasturi") + private final URI broadcastURI; + @Named("displaytext") + private final String displayText; + @Named("dns1") + private final String DNS1; + @Named("dns2") + private final String DNS2; + private final String domain; + @Named("domainid") + private final String domainId; + @Named("endip") + private final String endIP; + private final String gateway; + @Named("isdefault") + private final boolean isDefault; + @Named("isshared") + private final boolean isShared; + @Named("issystem") + private final boolean isSystem; + private final String netmask; + @Named("networkdomain") + private final String networkDomain; + @Named("networkofferingavailability") + private final String networkOfferingAvailability; + @Named("networkofferingdisplaytext") + private final String networkOfferingDisplayText; + @Named("networkofferingid") + private final String networkOfferingId; + @Named("networkofferingname") + private final String networkOfferingName; + private final String related; + @Named("startip") + private final String startIP; + private final String name; + private final String state; + @Named("type") + private final GuestIPType guestIPType; + @Named("vlan") + private final String VLAN; + @Named("traffictype") + private final TrafficType trafficType; + @Named("zoneid") + private final String zoneId; + private final String tags; + @Named("securitygroupenabled") + private final boolean securityGroupEnabled; + @Named("service") + private final Set services; + + @ConstructorProperties({ + "id", "account", "broadcastdomaintype", "broadcasturi", "displaytext", "dns1", "dns2", "domain", "domainid", "endip", "gateway", "isdefault", "isshared", "issystem", "netmask", "networkdomain", "networkofferingavailability", "networkofferingdisplaytext", "networkofferingid", "networkofferingname", "related", "startip", "name", "state", "type", "vlan", "traffictype", "zoneid", "tags", "securitygroupenabled", "service" + }) + protected Network(String id, @Nullable String account, @Nullable String broadcastDomainType, @Nullable URI broadcastURI, + @Nullable String displayText, @Nullable String DNS1, @Nullable String DNS2, @Nullable String domain, @Nullable String domainId, + @Nullable String endIP, @Nullable String gateway, boolean isDefault, boolean isShared, boolean isSystem, + @Nullable String netmask, @Nullable String networkDomain, @Nullable String networkOfferingAvailability, + @Nullable String networkOfferingDisplayText, @Nullable String networkOfferingId, @Nullable String networkOfferingName, + @Nullable String related, @Nullable String startIP, @Nullable String name, @Nullable String state, + @Nullable GuestIPType guestIPType, @Nullable String VLAN, @Nullable TrafficType trafficType, + @Nullable String zoneId, @Nullable String tags, boolean securityGroupEnabled, Set services) { + this.id = checkNotNull(id, "id"); + this.account = account; this.broadcastDomainType = broadcastDomainType; this.broadcastURI = broadcastURI; this.displayText = displayText; - this.DNS1 = checkNotNull(DNS, "DNS").size() > 0 ? DNS.get(0) : null; - this.DNS2 = DNS.size() > 1 ? DNS.get(1) : null; + this.DNS1 = DNS1; + this.DNS2 = DNS2; this.domain = domain; this.domainId = domainId; this.endIP = endIP; @@ -327,47 +459,54 @@ public class Network implements Comparable { this.startIP = startIP; this.name = name; this.state = state; - this.guestIPType = type; - this.VLAN = vLAN; + this.guestIPType = guestIPType; + this.VLAN = VLAN; this.trafficType = trafficType; this.zoneId = zoneId; - this.services = ImmutableSortedSet.copyOf(checkNotNull(services, "services")); - this.tags = tags.size() == 0 ? null : Joiner.on(',').join(tags); + this.tags = tags; this.securityGroupEnabled = securityGroupEnabled; - this.account = account; + this.services = ImmutableSortedSet.copyOf(services); } /** * @return network id */ public String getId() { - return id; + return this.id; + } + + /** + * @return the account associated with the network + */ + @Nullable + public String getAccount() { + return this.account; } /** * @return Broadcast domain type of the network */ + @Nullable public String getBroadcastDomainType() { - return broadcastDomainType; + return this.broadcastDomainType; } /** * @return broadcast uri of the network */ + @Nullable public URI getBroadcastURI() { - return broadcastURI; + return this.broadcastURI; } /** * @return the display text of the zone */ + @Nullable public String getDisplayText() { - return displayText; + return this.displayText; } - /** - * @return the external DNS for the network - */ public List getDNS() { ImmutableList.Builder builder = ImmutableList.builder(); if (DNS1 != null && !"".equals(DNS1)) @@ -380,266 +519,247 @@ public class Network implements Comparable { /** * @return Domain name for the Network */ + @Nullable public String getDomain() { - return domain; + return this.domain; } /** * @return the domain id of the Network */ + @Nullable public String getDomainId() { - return domainId; - } - - /** - * @return the account associated with the network - */ - public String getAccount() { - return account; + return this.domainId; } /** * @return the end ip of the network */ + @Nullable public String getEndIP() { - return endIP; + return this.endIP; } /** * @return the network's gateway */ + @Nullable public String getGateway() { - return gateway; + return this.gateway; } /** * @return true if network offering is default, false otherwise */ public boolean isDefault() { - return isDefault; + return this.isDefault; } /** * @return true if network offering is shared, false otherwise */ public boolean isShared() { - return isShared; + return this.isShared; } /** * @return true if network offering is system, false otherwise */ public boolean isSystem() { - return isSystem; + return this.isSystem; + } + + /** + * @return the network's netmask + */ + @Nullable + public String getNetmask() { + return this.netmask; + } + + /** + * @return the network domain + */ + @Nullable + public String getNetworkDomain() { + return this.networkDomain; + } + + /** + * @return availability of the network offering the network is created from + */ + @Nullable + public String getNetworkOfferingAvailability() { + return this.networkOfferingAvailability; + } + + /** + * @return display text of the network offering the network is created from + */ + @Nullable + public String getNetworkOfferingDisplayText() { + return this.networkOfferingDisplayText; + } + + /** + * @return network offering id the network is created from + */ + @Nullable + public String getNetworkOfferingId() { + return this.networkOfferingId; + } + + /** + * @return name of the network offering the network is created from + */ + @Nullable + public String getNetworkOfferingName() { + return this.networkOfferingName; + } + + /** + * @return related to what other network configuration + */ + @Nullable + public String getRelated() { + return this.related; + } + + /** + * @return the start ip of the network + */ + @Nullable + public String getStartIP() { + return this.startIP; } /** * @return network name */ + @Nullable public String getName() { - return name; + return this.name; + } + + /** + * @return state of the network + */ + @Nullable + public String getState() { + return this.state; } /** * @return the GuestIPType of the network */ public GuestIPType getGuestIPType() { - return guestIPType; - } - - /** - * @return state of the network - */ - public String getState() { - return state; + return this.guestIPType; } /** * @return the vlan range of the zone */ + @Nullable public String getVLAN() { - return VLAN; + return this.VLAN; } /** * @return the traffic type for this network offering */ + @Nullable public TrafficType getTrafficType() { - return trafficType; - } - - /** - * @return the network's netmask - */ - public String getNetmask() { - return netmask; - } - - /** - * @return the network domain - */ - public String getNetworkDomain() { - return networkDomain; - } - - /** - * @return availability of the network offering the network is created from - */ - public String getNetworkOfferingAvailability() { - return networkOfferingAvailability; - } - - /** - * @return display text of the network offering the network is created from - */ - public String getNetworkOfferingDisplayText() { - return networkOfferingDisplayText; - } - - /** - * @return network offering id the network is created from - */ - public String getNetworkOfferingId() { - return networkOfferingId; - } - - /** - * @return name of the network offering the network is created from - */ - public String getNetworkOfferingName() { - return networkOfferingName; - } - - /** - * @return related to what other network configuration - */ - public String getRelated() { - return related; - } - - /** - * @return the start ip of the network - */ - public String getStartIP() { - return startIP; + return this.trafficType; } /** * @return zone id of the network */ + @Nullable public String getZoneId() { - return zoneId; + return this.zoneId; } /** - * @return the list of services + * @return the tags for the Network */ - public Set getServices() { - return services; + @Nullable + public String getTags() { + return this.tags; } /** * @return true if security group is enabled, false otherwise */ public boolean isSecurityGroupEnabled() { - return securityGroupEnabled; + return this.securityGroupEnabled; } /** - * @return the tags for the Network + * @return the list of services */ - public Set getTags() { - return tags != null ? ImmutableSet.copyOf(Splitter.on(',').split(tags)) : ImmutableSet.of(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Network that = (Network) o; - - if (!Objects.equal(DNS1, that.DNS1)) return false; - if (!Objects.equal(DNS2, that.DNS2)) return false; - if (!Objects.equal(VLAN, that.VLAN)) return false; - if (!Objects.equal(broadcastDomainType, that.broadcastDomainType)) return false; - if (!Objects.equal(broadcastURI, that.broadcastURI)) return false; - if (!Objects.equal(displayText, that.displayText)) return false; - if (!Objects.equal(domain, that.domain)) return false; - if (!Objects.equal(endIP, that.endIP)) return false; - if (!Objects.equal(gateway, that.gateway)) return false; - if (!Objects.equal(guestIPType, that.guestIPType)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(isDefault, that.isDefault)) return false; - if (!Objects.equal(isShared, that.isShared)) return false; - if (!Objects.equal(isSystem, that.isSystem)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(netmask, that.netmask)) return false; - if (!Objects.equal(networkDomain, that.networkDomain)) return false; - if (!Objects.equal(networkOfferingAvailability, that.networkOfferingAvailability)) return false; - if (!Objects.equal(networkOfferingDisplayText, that.networkOfferingDisplayText)) return false; - if (!Objects.equal(networkOfferingId, that.networkOfferingId)) return false; - if (!Objects.equal(networkOfferingName, that.networkOfferingName)) return false; - if (!Objects.equal(related, that.related)) return false; - if (!Objects.equal(services, that.services)) return false; - if (!Objects.equal(startIP, that.startIP)) return false; - if (!Objects.equal(state, that.state)) return false; - if (!Objects.equal(trafficType, that.trafficType)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(tags, that.tags)) return false; - if (!Objects.equal(domainId, that.domainId)) return false; - - return true; + public Set getServices() { + return this.services; } @Override public int hashCode() { - return Objects.hashCode(DNS1, DNS2, VLAN, broadcastDomainType, broadcastURI, displayText, domain, - endIP, gateway, guestIPType, id, isDefault, isShared, isSystem, name, - netmask, networkDomain, networkOfferingAvailability, networkOfferingDisplayText, - networkOfferingId, networkOfferingName, related, services, startIP, state, - trafficType, zoneId, tags, domainId); + return Objects.hashCode(id, account, broadcastDomainType, broadcastURI, displayText, DNS1, DNS2, domain, domainId, endIP, gateway, isDefault, isShared, isSystem, netmask, networkDomain, networkOfferingAvailability, networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state, guestIPType, VLAN, trafficType, zoneId, tags, securityGroupEnabled, services); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Network that = Network.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.account, that.account) + && Objects.equal(this.broadcastDomainType, that.broadcastDomainType) + && Objects.equal(this.broadcastURI, that.broadcastURI) + && Objects.equal(this.displayText, that.displayText) + && Objects.equal(this.DNS1, that.DNS1) + && Objects.equal(this.DNS2, that.DNS2) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.endIP, that.endIP) + && Objects.equal(this.gateway, that.gateway) + && Objects.equal(this.isDefault, that.isDefault) + && Objects.equal(this.isShared, that.isShared) + && Objects.equal(this.isSystem, that.isSystem) + && Objects.equal(this.netmask, that.netmask) + && Objects.equal(this.networkDomain, that.networkDomain) + && Objects.equal(this.networkOfferingAvailability, that.networkOfferingAvailability) + && Objects.equal(this.networkOfferingDisplayText, that.networkOfferingDisplayText) + && Objects.equal(this.networkOfferingId, that.networkOfferingId) + && Objects.equal(this.networkOfferingName, that.networkOfferingName) + && Objects.equal(this.related, that.related) + && Objects.equal(this.startIP, that.startIP) + && Objects.equal(this.name, that.name) + && Objects.equal(this.state, that.state) + && Objects.equal(this.guestIPType, that.guestIPType) + && Objects.equal(this.VLAN, that.VLAN) + && Objects.equal(this.trafficType, that.trafficType) + && Objects.equal(this.zoneId, that.zoneId) + && Objects.equal(this.tags, that.tags) + && Objects.equal(this.securityGroupEnabled, that.securityGroupEnabled) + && Objects.equal(this.services, that.services); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("account", account).add("broadcastDomainType", broadcastDomainType).add("broadcastURI", broadcastURI) + .add("displayText", displayText).add("DNS1", DNS1).add("DNS2", DNS2).add("domain", domain).add("domainId", domainId) + .add("endIP", endIP).add("gateway", gateway).add("isDefault", isDefault).add("isShared", isShared).add("isSystem", isSystem) + .add("netmask", netmask).add("networkDomain", networkDomain).add("networkOfferingAvailability", networkOfferingAvailability) + .add("networkOfferingDisplayText", networkOfferingDisplayText).add("networkOfferingId", networkOfferingId) + .add("networkOfferingName", networkOfferingName).add("related", related).add("startIP", startIP).add("name", name) + .add("state", state).add("guestIPType", guestIPType).add("VLAN", VLAN).add("trafficType", trafficType) + .add("zoneId", zoneId).add("tags", tags).add("securityGroupEnabled", securityGroupEnabled).add("services", services); + } + @Override public String toString() { - return "Network{" + - "id=" + id + - ", account='" + account + '\'' + - ", broadcastDomainType='" + broadcastDomainType + '\'' + - ", broadcastURI=" + broadcastURI + - ", displayText='" + displayText + '\'' + - ", DNS1='" + DNS1 + '\'' + - ", DNS2='" + DNS2 + '\'' + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", endIP='" + endIP + '\'' + - ", gateway='" + gateway + '\'' + - ", isDefault=" + isDefault + - ", isShared=" + isShared + - ", isSystem=" + isSystem + - ", netmask='" + netmask + '\'' + - ", networkDomain='" + networkDomain + '\'' + - ", networkOfferingAvailability='" + networkOfferingAvailability + '\'' + - ", networkOfferingDisplayText='" + networkOfferingDisplayText + '\'' + - ", networkOfferingId=" + networkOfferingId + - ", networkOfferingName='" + networkOfferingName + '\'' + - ", related=" + related + - ", startIP='" + startIP + '\'' + - ", name='" + name + '\'' + - ", state='" + state + '\'' + - ", guestIPType=" + guestIPType + - ", VLAN='" + VLAN + '\'' + - ", trafficType=" + trafficType + - ", zoneId=" + zoneId + - ", tags='" + tags + '\'' + - ", securityGroupEnabled=" + securityGroupEnabled + - ", services=" + services + - '}'; + return string().toString(); } - @Override - public int compareTo(Network arg0) { - return id.compareTo(arg0.getId()); - } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java index c8d475bff8..f71a4a5a18 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,299 +20,339 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; -import java.util.Set; -import javax.annotation.Nullable; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; -import com.google.common.base.Joiner; import com.google.common.base.Objects; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** + * Class NetworkOffering * * @author Adrian Cole - */ +*/ public class NetworkOffering implements Comparable { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromNetworkOffering(this); } - public static class Builder { - private String id; - private String name; - private String displayText; - private Date created; - private NetworkOfferingAvailabilityType availability; - private Integer maxConnections; - private int networkRate; - private boolean isDefault; - private boolean supportsVLAN; - private TrafficType trafficType; - private GuestIPType guestIPType; - private Set tags = ImmutableSet.of(); + public static abstract class Builder> { + protected abstract T self(); - public Builder id(String id) { + protected String id; + protected String name; + protected String displayText; + protected Date created; + protected NetworkOfferingAvailabilityType availability; + protected Integer maxConnections; + protected boolean isDefault; + protected boolean supportsVLAN; + protected TrafficType trafficType; + protected GuestIPType guestIPType; + protected int networkRate; + protected String tags; + + /** + * @see NetworkOffering#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder name(String name) { + /** + * @see NetworkOffering#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder displayText(String displayText) { + /** + * @see NetworkOffering#getDisplayText() + */ + public T displayText(String displayText) { this.displayText = displayText; - return this; + return self(); } - public Builder created(Date created) { + /** + * @see NetworkOffering#getCreated() + */ + public T created(Date created) { this.created = created; - return this; + return self(); } - public Builder availability(NetworkOfferingAvailabilityType availability) { + /** + * @see NetworkOffering#getAvailability() + */ + public T availability(NetworkOfferingAvailabilityType availability) { this.availability = availability; - return this; + return self(); } - public Builder maxConnections(Integer maxConnections) { + /** + * @see NetworkOffering#getMaxConnections() + */ + public T maxConnections(Integer maxConnections) { this.maxConnections = maxConnections; - return this; + return self(); } - public Builder isDefault(boolean isDefault) { + /** + * @see NetworkOffering#isDefault() + */ + public T isDefault(boolean isDefault) { this.isDefault = isDefault; - return this; + return self(); } - public Builder networkRate(int networkRate) { - this.networkRate = networkRate; - return this; - } - - public Builder supportsVLAN(boolean supportsVLAN) { + /** + * @see NetworkOffering#supportsVLAN() + */ + public T supportsVLAN(boolean supportsVLAN) { this.supportsVLAN = supportsVLAN; - return this; + return self(); } - public Builder trafficType(TrafficType trafficType) { + /** + * @see NetworkOffering#getTrafficType() + */ + public T trafficType(TrafficType trafficType) { this.trafficType = trafficType; - return this; + return self(); } - public Builder guestIPType(GuestIPType guestIPType) { + /** + * @see NetworkOffering#getGuestIPType() + */ + public T guestIPType(GuestIPType guestIPType) { this.guestIPType = guestIPType; - return this; + return self(); } - public Builder tags(Set tags) { - this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); - return this; + /** + * @see NetworkOffering#getNetworkRate() + */ + public T networkRate(int networkRate) { + this.networkRate = networkRate; + return self(); + } + + /** + * @see NetworkOffering#getTags() + */ + public T tags(String tags) { + this.tags = tags; + return self(); } public NetworkOffering build() { - return new NetworkOffering(id, name, displayText, created, availability, supportsVLAN, maxConnections, - isDefault, trafficType, guestIPType, networkRate, tags); + return new NetworkOffering(id, name, displayText, created, availability, maxConnections, isDefault, supportsVLAN, trafficType, guestIPType, networkRate, tags); + } + + public T fromNetworkOffering(NetworkOffering in) { + return this + .id(in.getId()) + .name(in.getName()) + .displayText(in.getDisplayText()) + .created(in.getCreated()) + .availability(in.getAvailability()) + .maxConnections(in.getMaxConnections()) + .isDefault(in.isDefault()) + .supportsVLAN(in.supportsVLAN()) + .trafficType(in.getTrafficType()) + .guestIPType(in.getGuestIPType()) + .networkRate(in.getNetworkRate()) + .tags(in.getTags()); } } - private String id; - private String name; - @SerializedName("displaytext") - private String displayText; - private Date created; - @SerializedName("availability") - private NetworkOfferingAvailabilityType availability; - @SerializedName("maxconnections") - private Integer maxConnections; - @SerializedName("isdefault") - private boolean isDefault; - @SerializedName("specifyvlan") - private boolean supportsVLAN; - @SerializedName("traffictype") - private TrafficType trafficType; - @SerializedName("guestiptype") - private GuestIPType guestIPType; - @SerializedName("networkrate") - private int networkRate = -1; - private String tags; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - public NetworkOffering(String id, String name, String displayText, @Nullable Date created, - NetworkOfferingAvailabilityType availability, boolean supportsVLAN, @Nullable Integer maxConnections, - boolean isDefault, TrafficType trafficType, GuestIPType guestIPType, int networkRate, Set tags) { - this.id = id; + private final String id; + private final String name; + @Named("displaytext") + private final String displayText; + private final Date created; + private final NetworkOfferingAvailabilityType availability; + @Named("maxconnections") + private final Integer maxConnections; + @Named("isdefault") + private final boolean isDefault; + @Named("specifyvlan") + private final boolean supportsVLAN; + @Named("traffictype") + private final TrafficType trafficType; + @Named("guestiptype") + private final GuestIPType guestIPType; + @Named("networkrate") + private final int networkRate; + private final String tags; + + @ConstructorProperties({ + "id", "name", "displaytext", "created", "availability", "maxconnections", "isdefault", "specifyvlan", "traffictype", "guestiptype", "networkrate", "tags" + }) + protected NetworkOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, @Nullable NetworkOfferingAvailabilityType availability, @Nullable Integer maxConnections, boolean isDefault, boolean supportsVLAN, @Nullable TrafficType trafficType, @Nullable GuestIPType guestIPType, int networkRate, @Nullable String tags) { + this.id = checkNotNull(id, "id"); this.name = name; this.displayText = displayText; this.created = created; this.availability = availability; - this.supportsVLAN = supportsVLAN; this.maxConnections = maxConnections; this.isDefault = isDefault; + this.supportsVLAN = supportsVLAN; this.trafficType = trafficType; this.guestIPType = guestIPType; this.networkRate = networkRate; - this.tags = tags.size() == 0 ? null : Joiner.on(',').join(tags); + this.tags = tags; } /** - * present only for serializer - * - */ - NetworkOffering() { - - } - - /** - * * @return the id of the network offering */ public String getId() { - return id; + return this.id; } /** - * * @return the name of the network offering */ - + @Nullable public String getName() { - return name; + return this.name; } /** - * * @return an alternate display text of the network offering. */ + @Nullable public String getDisplayText() { - return displayText; + return this.displayText; } /** - * * @return the date this network offering was created */ @Nullable public Date getCreated() { - return created; + return this.created; } /** - * * @return Availability name for the offering */ + @Nullable public NetworkOfferingAvailabilityType getAvailability() { - return availability; + return this.availability; } /** - * - * @return true if network offering supports vlans, false otherwise - */ - public boolean supportsVLAN() { - return supportsVLAN; - } - - /** - * * @return the max number of concurrent connection the network offering - * supports + supports */ @Nullable public Integer getMaxConnections() { - return maxConnections; + return this.maxConnections; } /** - * * @return true if network offering is default, false otherwise */ public boolean isDefault() { - return isDefault; + return this.isDefault; + } + + /** + * @return true if network offering supports vlans, false otherwise + */ + public boolean supportsVLAN() { + return this.supportsVLAN; } /** - * * @return the traffic type for this network offering */ + @Nullable public TrafficType getTrafficType() { - return trafficType; + return this.trafficType; } /** - * * @return the guest ip type for this network offering */ + @Nullable public GuestIPType getGuestIPType() { - return guestIPType; + return this.guestIPType; } /** - * * @return data transfer rate in megabits per second allowed. */ public int getNetworkRate() { - return networkRate; + return this.networkRate; } /** - * * @return the tags for the network offering */ - public Set getTags() { - return tags != null ? ImmutableSet.copyOf(Splitter.on(',').split(tags)) : ImmutableSet. of(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - NetworkOffering that = (NetworkOffering) o; - - if (!Objects.equal(availability, that.availability)) return false; - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(displayText, that.displayText)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(isDefault, that.isDefault)) return false; - if (!Objects.equal(maxConnections, that.maxConnections)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(supportsVLAN, that.supportsVLAN)) return false; - if (!Objects.equal(tags, that.tags)) return false; - if (!Objects.equal(trafficType, that.trafficType)) return false; - - return true; + @Nullable + public String getTags() { + return this.tags; } @Override public int hashCode() { - return Objects.hashCode(availability, created, displayText, id, isDefault, maxConnections, name, supportsVLAN, tags, trafficType); + return Objects.hashCode(id, name, displayText, created, availability, maxConnections, isDefault, supportsVLAN, trafficType, guestIPType, networkRate, tags); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + NetworkOffering that = NetworkOffering.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.name, that.name) + && Objects.equal(this.displayText, that.displayText) + && Objects.equal(this.created, that.created) + && Objects.equal(this.availability, that.availability) + && Objects.equal(this.maxConnections, that.maxConnections) + && Objects.equal(this.isDefault, that.isDefault) + && Objects.equal(this.supportsVLAN, that.supportsVLAN) + && Objects.equal(this.trafficType, that.trafficType) + && Objects.equal(this.guestIPType, that.guestIPType) + && Objects.equal(this.networkRate, that.networkRate) + && Objects.equal(this.tags, that.tags); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("displayText", displayText).add("created", created).add("availability", availability).add("maxConnections", maxConnections).add("isDefault", isDefault).add("supportsVLAN", supportsVLAN).add("trafficType", trafficType).add("guestIPType", guestIPType).add("networkRate", networkRate).add("tags", tags); + } + @Override public String toString() { - return "NetworkOffering{" + - "id=" + id + - ", name='" + name + '\'' + - ", displayText='" + displayText + '\'' + - ", created=" + created + - ", availability=" + availability + - ", maxConnections=" + maxConnections + - ", isDefault=" + isDefault + - ", supportsVLAN=" + supportsVLAN + - ", trafficType=" + trafficType + - ", guestIPType=" + guestIPType + - ", networkRate=" + networkRate + - ", tags='" + tags + '\'' + - '}'; + return string().toString(); } @Override - public int compareTo(NetworkOffering arg0) { - return id.compareTo(arg0.getId()); + public int compareTo(NetworkOffering o) { + return id.compareTo(o.getId()); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkService.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkService.java index 71a1db51d0..158e0ef336 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkService.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkService.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,129 +20,229 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Map; -import java.util.SortedSet; -import java.util.Map.Entry; +import java.util.Set; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.collect.ImmutableMap; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.gson.annotations.SerializedName; +import com.google.common.collect.Sets; /** - * + * Class NetworkService + * * @author Adrian Cole */ public class NetworkService implements Comparable { - // internal only to match json type - private static class Capability implements Comparable { - private String name; - private String value; - - private Capability() { + public static class Capability implements Comparable { + public static Builder builder() { + return new ConcreteBuilder(); } - private Capability(String name, String value) { - this.name = name; + public Builder toBuilder() { + return new ConcreteBuilder().fromCapability(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String name; + protected String value; + + /** + * @see Capability#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + /** + * @see Capability#getValue() + */ + public T value(String value) { + this.value = value; + return self(); + } + + public Capability build() { + return new Capability(name, value); + } + + public T fromCapability(Capability in) { + return this + .name(in.getName()) + .value(in.getValue()); + } + + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String name; + private final String value; + + @ConstructorProperties({ + "name", "value" + }) + protected Capability(String name, @Nullable String value) { + this.name = checkNotNull(name, "name"); this.value = value; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - NetworkService.Capability that = (NetworkService.Capability) o; - - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(value, that.value)) return false; - - return true; + public String getName() { + return this.name; } - + + @Nullable + public String getValue() { + return this.value; + } + @Override public int hashCode() { - return Objects.hashCode(name, value); + return Objects.hashCode(name, value); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Capability that = Capability.class.cast(obj); + return Objects.equal(this.name, that.name) + && Objects.equal(this.value, that.value); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("name", name).add("value", value); } @Override public String toString() { - return "[name=" + name + ", value=" + value + "]"; + return string().toString(); } @Override public int compareTo(Capability o) { - return name.compareTo(o.name); + return name.compareTo(o.getName()); + } + } + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromNetworkService(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String name; + protected Set capabilities = Sets.newHashSet(); + + /** + * @see NetworkService#getName() + */ + public T name(String name) { + this.name = name; + return self(); } + /** + * @see NetworkService#getCapabilities() + */ + public T capabilities(Map capabilities) { + for (Map.Entry entry : capabilities.entrySet()) { + this.capabilities.add(Capability.builder().name(entry.getKey()).value(entry.getValue()).build()); + } + return self(); + } + + public NetworkService build() { + return new NetworkService(name, capabilities); + } + + public T fromNetworkService(NetworkService in) { + return this + .name(in.getName()) + .capabilities(in.getCapabilities()); + } } - private String name; - @SerializedName("capability") - // so tests and serialization comes out expected - private SortedSet capabilities = ImmutableSortedSet.of(); - - NetworkService() { - + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public NetworkService(String name) { - this(name, ImmutableMap. of()); - } + private final String name; + @Named("capability") + private final Set capabilities; - public NetworkService(String name, Map capabilities) { + @ConstructorProperties({ + "name", "capability" + }) + protected NetworkService(String name, @Nullable Set capabilities) { this.name = checkNotNull(name, "name"); - ImmutableSortedSet.Builder internal = ImmutableSortedSet.naturalOrder(); - for (Entry capabililty : checkNotNull(capabilities, "capabilities").entrySet()) - internal.add(new Capability(capabililty.getKey(), capabililty.getValue())); - this.capabilities = internal.build(); + this.capabilities = capabilities == null ? ImmutableSet.of() : ImmutableSortedSet.copyOf(capabilities); } public String getName() { - return name; + return this.name; } public Map getCapabilities() { // so tests and serialization comes out expected - Builder returnVal = ImmutableSortedMap.naturalOrder(); + ImmutableSortedMap.Builder returnVal = ImmutableSortedMap.naturalOrder(); for (Capability capability : capabilities) { returnVal.put(capability.name, capability.value); } return returnVal.build(); } - + @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - NetworkService that = (NetworkService) o; - - if (!Objects.equal(capabilities, that.capabilities)) return false; - if (!Objects.equal(name, that.name)) return false; - - return true; + public int hashCode() { + return Objects.hashCode(name, capabilities); } @Override - public int hashCode() { - return Objects.hashCode(capabilities, name); + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + NetworkService that = NetworkService.class.cast(obj); + return Objects.equal(this.name, that.name) + && Objects.equal(this.capabilities, that.capabilities); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).add("name", name).add("capabilities", capabilities); } @Override public String toString() { - return "NetworkService{" + - "name='" + name + '\'' + - ", capabilities=" + capabilities + - '}'; + return string().toString(); } @Override public int compareTo(NetworkService o) { return name.compareTo(o.getName()); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/OSType.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/OSType.java index 1a1305ed9e..4ca638ab3a 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/OSType.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/OSType.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,56 +18,92 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** - * + * Class OSType + * * @author Adrian Cole */ public class OSType implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { - private String id; - private String OSCategoryId; - private String description; + public Builder toBuilder() { + return new ConcreteBuilder().fromOSType(this); + } - public Builder id(String id) { + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected String OSCategoryId; + protected String description; + + /** + * @see OSType#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder OSCategoryId(String OSCategoryId) { + /** + * @see OSType#getOSCategoryId() + */ + public T OSCategoryId(String OSCategoryId) { this.OSCategoryId = OSCategoryId; - return this; + return self(); } - public Builder description(String description) { + /** + * @see OSType#getDescription() + */ + public T description(String description) { this.description = description; - return this; + return self(); } public OSType build() { return new OSType(id, OSCategoryId, description); } + + public T fromOSType(OSType in) { + return this + .id(in.getId()) + .OSCategoryId(in.getOSCategoryId()) + .description(in.getDescription()); + } } - // for deserialization - OSType() { - + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - private String id; - @SerializedName("oscategoryid") - private String OSCategoryId; - private String description; + private final String id; + @Named("oscategoryid") + private final String OSCategoryId; + private final String description; - public OSType(String id, String OSCategoryId, String description) { - this.id = id; + @ConstructorProperties({ + "id", "oscategoryid", "description" + }) + protected OSType(String id, @Nullable String OSCategoryId, @Nullable String description) { + this.id = checkNotNull(id, "id"); this.OSCategoryId = OSCategoryId; this.description = description; } @@ -76,54 +112,51 @@ public class OSType implements Comparable { * @return the ID of the OS type */ public String getId() { - return id; + return this.id; } /** * @return the ID of the OS category */ + @Nullable public String getOSCategoryId() { - return OSCategoryId; + return this.OSCategoryId; } /** * @return the name/description of the OS type */ + @Nullable public String getDescription() { - return description; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - OSType that = (OSType) o; - - if (!Objects.equal(OSCategoryId, that.OSCategoryId)) return false; - if (!Objects.equal(description, that.description)) return false; - if (!Objects.equal(id, that.id)) return false; - - return true; + return this.description; } @Override public int hashCode() { - return Objects.hashCode(OSCategoryId, description, id); + return Objects.hashCode(id, OSCategoryId, description); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + OSType that = OSType.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.OSCategoryId, that.OSCategoryId) + && Objects.equal(this.description, that.description); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).add("id", id).add("OSCategoryId", OSCategoryId).add("description", description); } @Override public String toString() { - return "OSType{" + - "id=" + id + - ", OSCategoryId=" + OSCategoryId + - ", description='" + description + '\'' + - '}'; + return string().toString(); } @Override - public int compareTo(OSType arg0) { - return id.compareTo(arg0.getId()); + public int compareTo(OSType o) { + return id.compareTo(o.getId()); } - } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Pod.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Pod.java index db49ce654c..6dc5366a13 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Pod.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Pod.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,130 +18,162 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * Represents a Pod in CloudStack. - * + * * @author Richard Downer - */ +*/ public class Pod implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromPod(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); - private String id; - private String name; - private String zoneId; - private String zoneName; - private String gateway; - private String netmask; - private String startIp; - private String endIp; - private AllocationState allocationState; - - private Builder() {} - - /** - * @param id the ID of the Pod + protected String id; + protected String name; + protected String zoneId; + protected String zoneName; + protected String gateway; + protected String netmask; + protected String startIp; + protected String endIp; + protected AllocationState allocationState; + + /** + * @see Pod#getId() */ - public Builder id(String id) { - this.id = id; - return this; + public T id(String id) { + this.id = id; + return self(); } - /** - * @param name the name of the Pod + /** + * @see Pod#getName() */ - public Builder name(String name) { + public T name(String name) { this.name = name; - return this; + return self(); } - /** - * @param zoneId the Zone ID of the Pod + /** + * @see Pod#getZoneId() */ - public Builder zoneId(String zoneId) { + public T zoneId(String zoneId) { this.zoneId = zoneId; - return this; + return self(); } - /** - * @param zoneName the Zone name of the Pod + /** + * @see Pod#getZoneName() */ - public Builder zoneName(String zoneName) { + public T zoneName(String zoneName) { this.zoneName = zoneName; - return this; + return self(); } - /** - * @param gateway the gateway of the Pod + /** + * @see Pod#getGateway() */ - public Builder gateway(String gateway) { + public T gateway(String gateway) { this.gateway = gateway; - return this; + return self(); } - /** - * @param netmask the netmask of the Pod + /** + * @see Pod#getNetmask() */ - public Builder netmask(String netmask) { + public T netmask(String netmask) { this.netmask = netmask; - return this; + return self(); } - /** - * @param startIp the starting IP for the Pod + /** + * @see Pod#getStartIp() */ - public Builder startIp(String startIp) { + public T startIp(String startIp) { this.startIp = startIp; - return this; + return self(); } - /** - * @param endIp the ending IP for the Pod + /** + * @see Pod#getEndIp() */ - public Builder endIp(String endIp) { + public T endIp(String endIp) { this.endIp = endIp; - return this; + return self(); } - /** - * @param allocationState the allocation state of the cluster + /** + * @see Pod#getAllocationState() */ - public Builder allocationState(AllocationState allocationState) { + public T allocationState(AllocationState allocationState) { this.allocationState = allocationState; - return this; + return self(); } - /** - * Build the Pod object - * @return the Pod object - */ public Pod build() { return new Pod(id, name, zoneId, zoneName, gateway, netmask, startIp, endIp, allocationState); } + + public T fromPod(Pod in) { + return this + .id(in.getId()) + .name(in.getName()) + .zoneId(in.getZoneId()) + .zoneName(in.getZoneName()) + .gateway(in.getGateway()) + .netmask(in.getNetmask()) + .startIp(in.getStartIp()) + .endIp(in.getEndIp()) + .allocationState(in.getAllocationState()); + } } - private String id; - private String name; - @SerializedName("zoneid") private String zoneId; - @SerializedName("zonename") private String zoneName; - private String gateway; - private String netmask; - @SerializedName("startip") private String startIp; - @SerializedName("endip") private String endIp; - @SerializedName("allocationstate") private AllocationState allocationState; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - /* Just for the serializer */ - Pod() {} + private final String id; + private final String name; + @Named("zoneid") + private final String zoneId; + @Named("zonename") + private final String zoneName; + private final String gateway; + private final String netmask; + @Named("startip") + private final String startIp; + @Named("endip") + private final String endIp; + @Named("allocationstate") + private final AllocationState allocationState; - public Pod(String id, String name, String zoneId, String zoneName, String gateway, String netmask, String startIp, String endIp, AllocationState allocationState) { - this.id = id; + @ConstructorProperties({ + "id", "name", "zoneid", "zonename", "gateway", "netmask", "startip", "endip", "allocationstate" + }) + protected Pod(String id, @Nullable String name, @Nullable String zoneId, @Nullable String zoneName, @Nullable String gateway, @Nullable String netmask, @Nullable String startIp, @Nullable String endIp, @Nullable AllocationState allocationState) { + this.id = checkNotNull(id, "id"); this.name = name; this.zoneId = zoneId; this.zoneName = zoneName; @@ -156,103 +188,102 @@ public class Pod implements Comparable { * @return id the ID of the Pod */ public String getId() { - return id; + return this.id; } /** * @return name the name of the Pod */ + @Nullable public String getName() { - return name; + return this.name; } /** * @return zoneId the Zone ID of the Pod */ + @Nullable public String getZoneId() { - return zoneId; + return this.zoneId; } /** * @return zoneName the Zone name of the Pod */ + @Nullable public String getZoneName() { - return zoneName; + return this.zoneName; } /** * @return gateway the gateway of the Pod */ + @Nullable public String getGateway() { - return gateway; + return this.gateway; } /** * @return netmask the netmask of the Pod */ + @Nullable public String getNetmask() { - return netmask; + return this.netmask; } /** * @return startIp the starting IP for the Pod */ + @Nullable public String getStartIp() { - return startIp; + return this.startIp; } /** * @return endIp the ending IP for the Pod */ + @Nullable public String getEndIp() { - return endIp; + return this.endIp; } /** - * @param allocationState the allocation state of the cluster + * @return the allocation state of the cluster */ + @Nullable public AllocationState getAllocationState() { - return allocationState; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Pod that = (Pod) o; - - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(allocationState, that.allocationState)) return false; - if (!Objects.equal(endIp, that.endIp)) return false; - if (!Objects.equal(gateway, that.gateway)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(netmask, that.netmask)) return false; - if (!Objects.equal(startIp, that.startIp)) return false; - if (!Objects.equal(zoneName, that.zoneName)) return false; - - return true; + return this.allocationState; } @Override public int hashCode() { - return Objects.hashCode(id, zoneId, allocationState, endIp, gateway, name, netmask, startIp, zoneName); + return Objects.hashCode(id, name, zoneId, zoneName, gateway, netmask, startIp, endIp, allocationState); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Pod that = Pod.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.name, that.name) + && Objects.equal(this.zoneId, that.zoneId) + && Objects.equal(this.zoneName, that.zoneName) + && Objects.equal(this.gateway, that.gateway) + && Objects.equal(this.netmask, that.netmask) + && Objects.equal(this.startIp, that.startIp) + && Objects.equal(this.endIp, that.endIp) + && Objects.equal(this.allocationState, that.allocationState); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("zoneId", zoneId).add("zoneName", zoneName).add("gateway", gateway).add("netmask", netmask).add("startIp", startIp).add("endIp", endIp).add("allocationState", allocationState); + } + @Override public String toString() { - return "Pod{" + - "id=" + id + - ", name='" + name + '\'' + - ", zoneId=" + zoneId + - ", zoneName='" + zoneName + '\'' + - ", gateway='" + gateway + '\'' + - ", netmask='" + netmask + '\'' + - ", startIp='" + startIp + '\'' + - ", endIp='" + endIp + '\'' + - ", allocationState=" + allocationState + - '}'; + return string().toString(); } @Override diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PortForwardingRule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PortForwardingRule.java index ee7f10c12d..73f317a964 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PortForwardingRule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PortForwardingRule.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,16 +18,25 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.util.Set; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.CaseFormat; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; -import com.google.gson.annotations.SerializedName; /** + * Class PortForwardingRule + * * @author Adrian Cole, Andrei Savu - */ +*/ public class PortForwardingRule implements Comparable { public static enum Protocol { @@ -73,126 +82,204 @@ public class PortForwardingRule implements Comparable { } } - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromPortForwardingRule(this); } - public static class Builder { - private String id; - private String IPAddress; - private String IPAddressId; - private int privatePort; - private Protocol protocol; - public int publicPort; - private State state; - private String virtualMachineDisplayName; - public String virtualMachineId; - private String virtualMachineName; - private Set CIDRs = ImmutableSet.of(); - private int privateEndPort; - private int publicEndPort; + public static abstract class Builder> { + protected abstract T self(); - public Builder id(String id) { + protected String id; + protected String IPAddress; + protected String IPAddressId; + protected int privatePort; + protected Protocol protocol; + protected int publicPort; + protected State state; + protected String virtualMachineDisplayName; + protected String virtualMachineId; + protected String virtualMachineName; + protected Set CIDRs = ImmutableSet.of(); + protected int privateEndPort; + protected int publicEndPort; + + /** + * @see PortForwardingRule#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder IPAddress(String IPAddress) { + /** + * @see PortForwardingRule#getIPAddress() + */ + public T IPAddress(String IPAddress) { this.IPAddress = IPAddress; - return this; + return self(); } - public Builder IPAddressId(String IPAddressId) { + /** + * @see PortForwardingRule#getIPAddressId() + */ + public T IPAddressId(String IPAddressId) { this.IPAddressId = IPAddressId; - return this; + return self(); } - public Builder privatePort(int privatePort) { + /** + * @see PortForwardingRule#getPrivatePort() + */ + public T privatePort(int privatePort) { this.privatePort = privatePort; - return this; + return self(); } - public Builder protocol(Protocol protocol) { + /** + * @see PortForwardingRule#getProtocol() + */ + public T protocol(Protocol protocol) { this.protocol = protocol; - return this; + return self(); } - public Builder publicPort(int publicPort) { + /** + * @see PortForwardingRule#getPublicPort() + */ + public T publicPort(int publicPort) { this.publicPort = publicPort; - return this; + return self(); } - public Builder state(State state) { + /** + * @see PortForwardingRule#getState() + */ + public T state(State state) { this.state = state; - return this; + return self(); } - public Builder virtualMachineDisplayName(String virtualMachineDisplayName) { + /** + * @see PortForwardingRule#getVirtualMachineDisplayName() + */ + public T virtualMachineDisplayName(String virtualMachineDisplayName) { this.virtualMachineDisplayName = virtualMachineDisplayName; - return this; + return self(); } - public Builder virtualMachineId(String virtualMachineId) { + /** + * @see PortForwardingRule#getVirtualMachineId() + */ + public T virtualMachineId(String virtualMachineId) { this.virtualMachineId = virtualMachineId; - return this; + return self(); } - public Builder virtualMachineName(String virtualMachineName) { + /** + * @see PortForwardingRule#getVirtualMachineName() + */ + public T virtualMachineName(String virtualMachineName) { this.virtualMachineName = virtualMachineName; - return this; + return self(); } - public Builder CIDRs(Set CIDRs) { - this.CIDRs = CIDRs; - return this; + /** + * @see PortForwardingRule#getCIDRs() + */ + public T CIDRs(Set CIDRs) { + this.CIDRs = ImmutableSet.copyOf(checkNotNull(CIDRs, "CIDRs")); + return self(); } - public Builder privateEndPort(int privateEndPort) { + public T CIDRs(String... in) { + return CIDRs(ImmutableSet.copyOf(in)); + } + + /** + * @see PortForwardingRule#getPrivateEndPort() + */ + public T privateEndPort(int privateEndPort) { this.privateEndPort = privateEndPort; - return this; + return self(); } - public Builder publicEndPort(int publicEndPort) { + /** + * @see PortForwardingRule#getPublicEndPort() + */ + public T publicEndPort(int publicEndPort) { this.publicEndPort = publicEndPort; - return this; + return self(); } public PortForwardingRule build() { - return new PortForwardingRule(id, IPAddress, IPAddressId, privatePort, protocol, publicPort, state, - virtualMachineDisplayName, virtualMachineId, virtualMachineName, CIDRs, privateEndPort, publicEndPort); + return new PortForwardingRule(id, IPAddress, IPAddressId, privatePort, protocol, publicPort, state, virtualMachineDisplayName, + virtualMachineId, virtualMachineName, CIDRs, privateEndPort, publicEndPort); + } + + public T fromPortForwardingRule(PortForwardingRule in) { + return this + .id(in.getId()) + .IPAddress(in.getIPAddress()) + .IPAddressId(in.getIPAddressId()) + .privatePort(in.getPrivatePort()) + .protocol(in.getProtocol()) + .publicPort(in.getPublicPort()) + .state(in.getState()) + .virtualMachineDisplayName(in.getVirtualMachineDisplayName()) + .virtualMachineId(in.getVirtualMachineId()) + .virtualMachineName(in.getVirtualMachineName()) + .CIDRs(in.getCIDRs()) + .privateEndPort(in.getPrivateEndPort()) + .publicEndPort(in.getPublicEndPort()); } } - private String id; - @SerializedName("ipaddress") - private String IPAddress; - @SerializedName("ipaddressid") - private String IPAddressId; - @SerializedName("privateport") - private int privatePort; - private Protocol protocol; - @SerializedName("publicport") - public int publicPort; - private State state; - @SerializedName("virtualmachinedisplayname") - private String virtualMachineDisplayName; - @SerializedName("virtualmachineid") - public String virtualMachineId; - @SerializedName("virtualmachinename") - private String virtualMachineName; - @SerializedName("cidrlist") - private Set CIDRs; - @SerializedName("privateendport") - private int privateEndPort; - @SerializedName("publicendport") - private int publicEndPort; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - public PortForwardingRule(String id, String iPAddress, String iPAddressId, int privatePort, Protocol protocol, - int publicPort, State state, String virtualMachineDisplayName, String virtualMachineId, - String virtualMachineName, Set CIDRs, int privateEndPort, int publicEndPort) { - this.id = id; - this.IPAddress = iPAddress; - this.IPAddressId = iPAddressId; + private final String id; + @Named("ipaddress") + private final String IPAddress; + @Named("ipaddressid") + private final String IPAddressId; + @Named("privateport") + private final int privatePort; + private final PortForwardingRule.Protocol protocol; + @Named("publicport") + private final int publicPort; + private final PortForwardingRule.State state; + @Named("virtualmachinedisplayname") + private final String virtualMachineDisplayName; + @Named("virtualmachineid") + private final String virtualMachineId; + @Named("virtualmachinename") + private final String virtualMachineName; + @Named("cidrlist") + private final Set CIDRs; + @Named("privateendport") + private final int privateEndPort; + @Named("publicendport") + private final int publicEndPort; + + @ConstructorProperties({ + "id", "ipaddress", "ipaddressid", "privateport", "protocol", "publicport", "state", "virtualmachinedisplayname", + "virtualmachineid", "virtualmachinename", "cidrlist", "privateendport", "publicendport" + }) + protected PortForwardingRule(String id, @Nullable String IPAddress, @Nullable String IPAddressId, int privatePort, + @Nullable Protocol protocol, int publicPort, @Nullable State state, + @Nullable String virtualMachineDisplayName, @Nullable String virtualMachineId, + @Nullable String virtualMachineName, @Nullable Set CIDRs, int privateEndPort, int publicEndPort) { + this.id = checkNotNull(id, "id"); + this.IPAddress = IPAddress; + this.IPAddressId = IPAddressId; this.privatePort = privatePort; this.protocol = protocol; this.publicPort = publicPort; @@ -200,150 +287,149 @@ public class PortForwardingRule implements Comparable { this.virtualMachineDisplayName = virtualMachineDisplayName; this.virtualMachineId = virtualMachineId; this.virtualMachineName = virtualMachineName; - this.CIDRs = CIDRs; + this.CIDRs = CIDRs == null ? ImmutableSet.of() : ImmutableSet.copyOf(CIDRs); this.privateEndPort = privateEndPort; this.publicEndPort = publicEndPort; } - @Override - public int compareTo(PortForwardingRule arg0) { - return id.compareTo(arg0.getId()); - } - /** * @return the ID of the port forwarding rule */ public String getId() { - return id; + return this.id; } /** * @return the public ip address for the port forwarding rule */ + @Nullable public String getIPAddress() { - return IPAddress; + return this.IPAddress; } /** * @return the public ip address id for the port forwarding rule */ + @Nullable public String getIPAddressId() { - return IPAddressId; + return this.IPAddressId; } /** * @return the private port for the port forwarding rule */ public int getPrivatePort() { - return privatePort; + return this.privatePort; } /** * @return the protocol of the port forwarding rule */ + @Nullable public Protocol getProtocol() { - return protocol; + return this.protocol; } /** * @return the public port for the port forwarding rule */ public int getPublicPort() { - return publicPort; + return this.publicPort; } /** * @return the state of the rule */ + @Nullable public State getState() { - return state; + return this.state; } /** * @return the VM display name for the port forwarding rule */ + @Nullable public String getVirtualMachineDisplayName() { - return virtualMachineDisplayName; + return this.virtualMachineDisplayName; } /** * @return the VM ID for the port forwarding rule */ + @Nullable public String getVirtualMachineId() { - return virtualMachineId; + return this.virtualMachineId; } /** * @return the VM name for the port forwarding rule */ + @Nullable public String getVirtualMachineName() { - return virtualMachineName; + return this.virtualMachineName; } /** * @return the cidr list to forward traffic from */ public Set getCIDRs() { - return CIDRs; + return this.CIDRs; } /** * @return the starting port of port forwarding rule's private port range */ public int getPrivateEndPort() { - return privateEndPort; + return this.privateEndPort; } /** * @return the starting port of port forwarding rule's public port range */ public int getPublicEndPort() { - return publicEndPort; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - PortForwardingRule that = (PortForwardingRule) o; - - if (!Objects.equal(IPAddress, that.IPAddress)) return false; - if (!Objects.equal(IPAddressId, that.IPAddressId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(privatePort, that.privatePort)) return false; - if (!Objects.equal(protocol, that.protocol)) return false; - if (!Objects.equal(publicPort, that.publicPort)) return false; - if (!Objects.equal(state, that.state)) return false; - if (!Objects.equal(virtualMachineDisplayName, that.virtualMachineDisplayName)) return false; - if (!Objects.equal(virtualMachineId, that.virtualMachineId)) return false; - if (!Objects.equal(virtualMachineName, that.virtualMachineName)) return false; - - return true; + return this.publicEndPort; } @Override public int hashCode() { - return Objects.hashCode(IPAddress, IPAddressId, id, privatePort, protocol, publicPort, state, virtualMachineDisplayName, virtualMachineId, virtualMachineName); + return Objects.hashCode(id, IPAddress, IPAddressId, privatePort, protocol, publicPort, state, virtualMachineDisplayName, virtualMachineId, virtualMachineName, CIDRs, privateEndPort, publicEndPort); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + PortForwardingRule that = PortForwardingRule.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.IPAddress, that.IPAddress) + && Objects.equal(this.IPAddressId, that.IPAddressId) + && Objects.equal(this.privatePort, that.privatePort) + && Objects.equal(this.protocol, that.protocol) + && Objects.equal(this.publicPort, that.publicPort) + && Objects.equal(this.state, that.state) + && Objects.equal(this.virtualMachineDisplayName, that.virtualMachineDisplayName) + && Objects.equal(this.virtualMachineId, that.virtualMachineId) + && Objects.equal(this.virtualMachineName, that.virtualMachineName) + && Objects.equal(this.CIDRs, that.CIDRs) + && Objects.equal(this.privateEndPort, that.privateEndPort) + && Objects.equal(this.publicEndPort, that.publicEndPort); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("IPAddress", IPAddress).add("IPAddressId", IPAddressId).add("privatePort", privatePort) + .add("protocol", protocol).add("publicPort", publicPort).add("state", state).add("virtualMachineDisplayName", virtualMachineDisplayName) + .add("virtualMachineId", virtualMachineId).add("virtualMachineName", virtualMachineName).add("CIDRs", CIDRs) + .add("privateEndPort", privateEndPort).add("publicEndPort", publicEndPort); + } + @Override public String toString() { - return "PortForwardingRule{" + - "id=" + id + - ", IPAddress='" + IPAddress + '\'' + - ", IPAddressId=" + IPAddressId + - ", privatePort=" + privatePort + - ", protocol='" + protocol + '\'' + - ", publicPort=" + publicPort + - ", state='" + state + '\'' + - ", virtualMachineDisplayName='" + virtualMachineDisplayName + '\'' + - ", virtualMachineId=" + virtualMachineId + - ", virtualMachineName='" + virtualMachineName + '\'' + - ", CIDRs=" + getCIDRs() + - ", privateEndPort=" + privateEndPort + - ", publicEndPort=" + publicEndPort + - '}'; + return string().toString(); } + @Override + public int compareTo(PortForwardingRule o) { + return id.compareTo(o.getId()); + } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PublicIPAddress.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PublicIPAddress.java index 596cfc0e83..12c759a60c 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PublicIPAddress.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/PublicIPAddress.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,234 +20,339 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; -import javax.annotation.Nullable; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; import com.google.common.base.CaseFormat; import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** + * Class PublicIPAddress + * * @author Adrian Cole - */ -public class PublicIPAddress implements Comparable { +*/ +public class PublicIPAddress { - public static Builder builder() { - return new Builder(); + /** + */ + public static enum State { + ALLOCATING, ALLOCATED, RELEASING, UNRECOGNIZED; + + @Override + public String toString() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + public static State fromValue(String state) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } - public static class Builder { - private String id; - private String account; - private Date allocated; - private String associatedNetworkId; - private String domain; - private String domainId; - private boolean usesVirtualNetwork; - private String IPAddress; - private boolean isSourceNAT; - private boolean isStaticNAT; - private String networkId; - private State state; - private String virtualMachineDisplayName; - private String virtualMachineId; - private String virtualMachineName; - private String VLANId; - private String VLANName; - private String zoneId; - private String zoneName; - private String jobId; - private Integer jobStatus; + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromPublicIPAddress(this); + } - public Builder id(String id) { + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected String account; + protected Date allocated; + protected String associatedNetworkId; + protected String domain; + protected String domainId; + protected boolean usesVirtualNetwork; + protected String IPAddress; + protected boolean isSourceNAT; + protected boolean isStaticNAT; + protected String networkId; + protected PublicIPAddress.State state; + protected String virtualMachineDisplayName; + protected String virtualMachineId; + protected String virtualMachineName; + protected String VLANId; + protected String VLANName; + protected String zoneId; + protected String zoneName; + protected String jobId; + protected Integer jobStatus; + + /** + * @see PublicIPAddress#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder account(String account) { + /** + * @see PublicIPAddress#getAccount() + */ + public T account(String account) { this.account = account; - return this; + return self(); } - public Builder allocated(Date allocated) { + /** + * @see PublicIPAddress#getAllocated() + */ + public T allocated(Date allocated) { this.allocated = allocated; - return this; + return self(); } - public Builder associatedNetworkId(String associatedNetworkId) { + /** + * @see PublicIPAddress#getAssociatedNetworkId() + */ + public T associatedNetworkId(String associatedNetworkId) { this.associatedNetworkId = associatedNetworkId; - return this; + return self(); } - public Builder domain(String domain) { + /** + * @see PublicIPAddress#getDomain() + */ + public T domain(String domain) { this.domain = domain; - return this; + return self(); } - public Builder domainId(String domainId) { + /** + * @see PublicIPAddress#getDomainId() + */ + public T domainId(String domainId) { this.domainId = domainId; - return this; + return self(); } - public Builder usesVirtualNetwork(boolean usesVirtualNetwork) { + /** + * @see PublicIPAddress#isUsesVirtualNetwork() + */ + public T usesVirtualNetwork(boolean usesVirtualNetwork) { this.usesVirtualNetwork = usesVirtualNetwork; - return this; + return self(); } - public Builder IPAddress(String IPAddress) { + /** + * @see PublicIPAddress#getIPAddress() + */ + public T IPAddress(String IPAddress) { this.IPAddress = IPAddress; - return this; + return self(); } - public Builder isSourceNAT(boolean isSourceNAT) { + /** + * @see PublicIPAddress#isSourceNAT() + */ + public T isSourceNAT(boolean isSourceNAT) { this.isSourceNAT = isSourceNAT; - return this; + return self(); } - public Builder isStaticNAT(boolean isStaticNAT) { + /** + * @see PublicIPAddress#isStaticNAT() + */ + public T isStaticNAT(boolean isStaticNAT) { this.isStaticNAT = isStaticNAT; - return this; + return self(); } - public Builder networkId(String networkId) { + /** + * @see PublicIPAddress#getNetworkId() + */ + public T networkId(String networkId) { this.networkId = networkId; - return this; + return self(); } - public Builder state(State state) { + /** + * @see PublicIPAddress#getState() + */ + public T state(PublicIPAddress.State state) { this.state = state; - return this; + return self(); } - public Builder virtualMachineDisplayName(String virtualMachineDisplayName) { + /** + * @see PublicIPAddress#getVirtualMachineDisplayName() + */ + public T virtualMachineDisplayName(String virtualMachineDisplayName) { this.virtualMachineDisplayName = virtualMachineDisplayName; - return this; + return self(); } - public Builder virtualMachineId(String virtualMachineId) { + /** + * @see PublicIPAddress#getVirtualMachineId() + */ + public T virtualMachineId(String virtualMachineId) { this.virtualMachineId = virtualMachineId; - return this; + return self(); } - public Builder virtualMachineName(String virtualMachineName) { + /** + * @see PublicIPAddress#getVirtualMachineName() + */ + public T virtualMachineName(String virtualMachineName) { this.virtualMachineName = virtualMachineName; - return this; + return self(); } - public Builder VLANId(String VLANId) { + /** + * @see PublicIPAddress#getVLANId() + */ + public T VLANId(String VLANId) { this.VLANId = VLANId; - return this; + return self(); } - public Builder VLANName(String VLANName) { + /** + * @see PublicIPAddress#getVLANName() + */ + public T VLANName(String VLANName) { this.VLANName = VLANName; - return this; + return self(); } - public Builder zoneId(String zoneId) { + /** + * @see PublicIPAddress#getZoneId() + */ + public T zoneId(String zoneId) { this.zoneId = zoneId; - return this; + return self(); } - public Builder zoneName(String zoneName) { + /** + * @see PublicIPAddress#getZoneName() + */ + public T zoneName(String zoneName) { this.zoneName = zoneName; - return this; + return self(); } - public Builder jobId(String jobId) { + /** + * @see PublicIPAddress#getJobId() + */ + public T jobId(String jobId) { this.jobId = jobId; - return this; + return self(); } - public Builder jobStatus(int jobStatus) { + /** + * @see PublicIPAddress#getJobStatus() + */ + public T jobStatus(Integer jobStatus) { this.jobStatus = jobStatus; - return this; + return self(); } public PublicIPAddress build() { - return new PublicIPAddress(id, account, allocated, associatedNetworkId, domain, domainId, usesVirtualNetwork, - IPAddress, isSourceNAT, isStaticNAT, networkId, state, virtualMachineDisplayName, virtualMachineId, - virtualMachineName, VLANId, VLANName, zoneId, zoneName, jobId, jobStatus); + return new PublicIPAddress(id, account, allocated, associatedNetworkId, domain, domainId, usesVirtualNetwork, IPAddress, isSourceNAT, isStaticNAT, networkId, state, virtualMachineDisplayName, virtualMachineId, virtualMachineName, VLANId, VLANName, zoneId, zoneName, jobId, jobStatus); + } + + public T fromPublicIPAddress(PublicIPAddress in) { + return this + .id(in.getId()) + .account(in.getAccount()) + .allocated(in.getAllocated()) + .associatedNetworkId(in.getAssociatedNetworkId()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .usesVirtualNetwork(in.isUsesVirtualNetwork()) + .IPAddress(in.getIPAddress()) + .isSourceNAT(in.isSourceNAT()) + .isStaticNAT(in.isStaticNAT()) + .networkId(in.getNetworkId()) + .state(in.getState()) + .virtualMachineDisplayName(in.getVirtualMachineDisplayName()) + .virtualMachineId(in.getVirtualMachineId()) + .virtualMachineName(in.getVirtualMachineName()) + .VLANId(in.getVLANId()) + .VLANName(in.getVLANName()) + .zoneId(in.getZoneId()) + .zoneName(in.getZoneName()) + .jobId(in.getJobId()) + .jobStatus(in.getJobStatus()); } } - private String id; - private String account; - private Date allocated; - @SerializedName("associatednetworkid") - private String associatedNetworkId; - private String domain; - @SerializedName("domainid") - private String domainId; - @SerializedName("forvirtualnetwork") - private boolean usesVirtualNetwork; - @SerializedName("ipaddress") - private String IPAddress; - @SerializedName("issourcenat") - private boolean isSourceNAT; - @SerializedName("isstaticnat") - private boolean isStaticNAT; - @SerializedName("networkid") - private String networkId; - private State state; - @SerializedName("virtualmachinedisplayname") - private String virtualMachineDisplayName; - @SerializedName("virtualmachineid") - private String virtualMachineId; - @SerializedName("virtualmachinename") - private String virtualMachineName; - @SerializedName("VLANid") - private String VLANId; - @SerializedName("VLANname") - private String VLANName; - @SerializedName("zoneid") - private String zoneId; - @SerializedName("zonename") - private String zoneName; - @SerializedName("jobid") - @Nullable - private String jobId; - @SerializedName("jobstatus") - @Nullable - private Integer jobStatus; - - public static enum State { - ALLOCATING, ALLOCATED, RELEASING, UNRECOGNIZED; - + private static class ConcreteBuilder extends Builder { @Override - public String toString() { - return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + protected ConcreteBuilder self() { + return this; } - - public static State fromValue(String state) { - try { - return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } - } - // for serialization - PublicIPAddress() { + private final String id; + private final String account; + private final Date allocated; + @Named("associatednetworkid") + private final String associatedNetworkId; + private final String domain; + @Named("domainid") + private final String domainId; + @Named("forvirtualnetwork") + private final boolean usesVirtualNetwork; + @Named("ipaddress") + private final String IPAddress; + @Named("issourcenat") + private final boolean isSourceNAT; + @Named("isstaticnat") + private final boolean isStaticNAT; + @Named("networkid") + private final String networkId; + private final PublicIPAddress.State state; + @Named("virtualmachinedisplayname") + private final String virtualMachineDisplayName; + @Named("virtualmachineid") + private final String virtualMachineId; + @Named("virtualmachinename") + private final String virtualMachineName; + @Named("VLANid") + private final String VLANId; + @Named("VLANname") + private final String VLANName; + @Named("zoneid") + private final String zoneId; + @Named("zonename") + private final String zoneName; + @Named("jobid") + private final String jobId; + @Named("jobstatus") + private final Integer jobStatus; - } - - public PublicIPAddress(String id, String account, Date allocated, String associatedNetworkId, String domain, - String domainId, boolean usesVirtualNetwork, String iPAddress, boolean isSourceNAT, boolean isStaticNAT, - String networkId, State state, String virtualMachineDisplayName, String virtualMachineId, - String virtualMachineName, String VLANId, String VLANName, String zoneId, String zoneName, String jobId, - Integer jobStatus) { - this.id = id; + @ConstructorProperties({ + "id", "account", "allocated", "associatednetworkid", "domain", "domainid", "forvirtualnetwork", "ipaddress", "issourcenat", + "isstaticnat", "networkid", "state", "virtualmachinedisplayname", "virtualmachineid", "virtualmachinename", "VLANid", + "VLANname", "zoneid", "zonename", "jobid", "jobstatus" + }) + protected PublicIPAddress(String id, @Nullable String account, @Nullable Date allocated, @Nullable String associatedNetworkId, + @Nullable String domain, @Nullable String domainId, boolean usesVirtualNetwork, @Nullable String IPAddress, + boolean isSourceNAT, boolean isStaticNAT, @Nullable String networkId, @Nullable PublicIPAddress.State state, + @Nullable String virtualMachineDisplayName, @Nullable String virtualMachineId, @Nullable String virtualMachineName, + @Nullable String VLANId, @Nullable String VLANName, @Nullable String zoneId, @Nullable String zoneName, + @Nullable String jobId, @Nullable Integer jobStatus) { + this.id = checkNotNull(id, "id"); this.account = account; this.allocated = allocated; this.associatedNetworkId = associatedNetworkId; this.domain = domain; this.domainId = domainId; this.usesVirtualNetwork = usesVirtualNetwork; - this.IPAddress = iPAddress; + this.IPAddress = IPAddress; this.isSourceNAT = isSourceNAT; this.isStaticNAT = isStaticNAT; this.networkId = networkId; @@ -261,43 +366,168 @@ public class PublicIPAddress implements Comparable { this.zoneName = zoneName; this.jobId = jobId; this.jobStatus = jobStatus; - - } - - @Override - public int compareTo(PublicIPAddress arg0) { - return id.compareTo(arg0.getId()); } /** * @return public IP address id */ public String getId() { - return id; + return this.id; } /** * @return the account the public IP address is associated with */ + @Nullable public String getAccount() { - return account; + return this.account; } /** * @return date the public IP address was acquired */ + @Nullable public Date getAllocated() { - return allocated; + return this.allocated; + } + + /** + * @return the ID of the Network associated with the IP address + */ + @Nullable + public String getAssociatedNetworkId() { + return this.associatedNetworkId; + } + + /** + * @return the domain the public IP address is associated with + */ + @Nullable + public String getDomain() { + return this.domain; + } + + /** + * @return the domain ID the public IP address is associated with + */ + @Nullable + public String getDomainId() { + return this.domainId; + } + + /** + * @return uses virtual network + */ + public boolean isUsesVirtualNetwork() { + return this.usesVirtualNetwork; + } + + /** + * @return public IP address + */ + @Nullable + public String getIPAddress() { + return this.IPAddress; + } + + /** + * @return true if the IP address is a source nat address, false otherwise + */ + public boolean isSourceNAT() { + return this.isSourceNAT; + } + + /** + * @return true if this ip is for static nat, false otherwise + */ + public boolean isStaticNAT() { + return this.isStaticNAT; + } + + /** + * @return the ID of the Network where ip belongs to + */ + @Nullable + public String getNetworkId() { + return this.networkId; + } + + /** + * @return State of the ip address. Can be: Allocating, Allocated and + Releasing + */ + @Nullable + public PublicIPAddress.State getState() { + return this.state; + } + + /** + * @return virtual machine display name the ip address is assigned to (not + null only for static nat Ip) + */ + @Nullable + public String getVirtualMachineDisplayName() { + return this.virtualMachineDisplayName; + } + + /** + * @return virtual machine id the ip address is assigned to (not null only + for static nat Ip) + */ + @Nullable + public String getVirtualMachineId() { + return this.virtualMachineId; + } + + /** + * @return virtual machine name the ip address is assigned to (not null only + for static nat Ip) + */ + @Nullable + public String getVirtualMachineName() { + return this.virtualMachineName; + } + + /** + * @return the ID of the VLAN associated with the IP address + */ + @Nullable + public String getVLANId() { + return this.VLANId; + } + + /** + * @return the VLAN associated with the IP address + */ + @Nullable + public String getVLANName() { + return this.VLANName; + } + + /** + * @return the ID of the zone the public IP address belongs to + */ + @Nullable + public String getZoneId() { + return this.zoneId; + } + + /** + * @return the name of the zone the public IP address belongs to + */ + @Nullable + public String getZoneName() { + return this.zoneName; } /** * @return shows the current pending asynchronous job ID. This tag is not - * returned if no current pending jobs are acting on the virtual - * machine + returned if no current pending jobs are acting on the virtual + machine */ @Nullable public String getJobId() { - return jobId; + return this.jobId; } /** @@ -305,190 +535,55 @@ public class PublicIPAddress implements Comparable { */ @Nullable public Integer getJobStatus() { - return jobStatus; - } - - - /** - * @return the ID of the Network associated with the IP address - */ - public String getAssociatedNetworkId() { - return associatedNetworkId; - } - - /** - * @return the domain the public IP address is associated with - */ - public String getDomain() { - return domain; - } - - /** - * @return the domain ID the public IP address is associated with - */ - public String getDomainId() { - return domainId; - } - - /** - * @return uses virtual network - */ - public boolean usesVirtualNetwork() { - return usesVirtualNetwork; - } - - /** - * @return public IP address - */ - public String getIPAddress() { - return IPAddress; - } - - /** - * @return true if the IP address is a source nat address, false otherwise - */ - public boolean isSourceNAT() { - return isSourceNAT; - } - - /** - * @return true if this ip is for static nat, false otherwise - */ - public boolean isStaticNAT() { - return isStaticNAT; - } - - /** - * @return the ID of the Network where ip belongs to - */ - public String getNetworkId() { - return networkId; - } - - /** - * @return State of the ip address. Can be: Allocating, Allocated and - * Releasing - */ - public State getState() { - return state; - } - - /** - * @return virtual machine display name the ip address is assigned to (not - * null only for static nat Ip) - */ - public String getVirtualMachineDisplayName() { - return virtualMachineDisplayName; - } - - /** - * @return virtual machine id the ip address is assigned to (not null only - * for static nat Ip) - */ - public String getVirtualMachineId() { - return virtualMachineId; - } - - /** - * @return virtual machine name the ip address is assigned to (not null only - * for static nat Ip) - */ - public String getVirtualMachineName() { - return virtualMachineName; - } - - /** - * @return the ID of the VLAN associated with the IP address - */ - public String getVLANId() { - return VLANId; - } - - /** - * @return the VLAN associated with the IP address - */ - public String getVLANName() { - return VLANName; - } - - /** - * @return the ID of the zone the public IP address belongs to - */ - public String getZoneId() { - return zoneId; - } - - /** - * @return the name of the zone the public IP address belongs to - */ - public String getZoneName() { - return zoneName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - PublicIPAddress that = (PublicIPAddress) o; - - if (!Objects.equal(IPAddress, that.IPAddress)) return false; - if (!Objects.equal(VLANId, that.VLANId)) return false; - if (!Objects.equal(VLANName, that.VLANName)) return false; - if (!Objects.equal(account, that.account)) return false; - if (!Objects.equal(allocated, that.allocated)) return false; - if (!Objects.equal(associatedNetworkId, that.associatedNetworkId)) return false; - if (!Objects.equal(domain, that.domain)) return false; - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(isSourceNAT, that.isSourceNAT)) return false; - if (!Objects.equal(isStaticNAT, that.isStaticNAT)) return false; - if (!Objects.equal(networkId, that.networkId)) return false; - if (!Objects.equal(state, that.state)) return false; - if (!Objects.equal(usesVirtualNetwork, that.usesVirtualNetwork)) return false; - if (!Objects.equal(virtualMachineDisplayName, that.virtualMachineDisplayName)) return false; - if (!Objects.equal(virtualMachineId, that.virtualMachineId)) return false; - if (!Objects.equal(virtualMachineName, that.virtualMachineName)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(zoneName, that.zoneName)) return false; - if (!Objects.equal(jobStatus, that.jobStatus)) return false; - - return true; + return this.jobStatus; } @Override public int hashCode() { - return Objects.hashCode(IPAddress, VLANId, VLANName, account, allocated, associatedNetworkId, - domain, domainId, id, isSourceNAT, isStaticNAT, networkId, state, - usesVirtualNetwork, virtualMachineDisplayName, virtualMachineId, - virtualMachineName, zoneId, zoneName, jobStatus); + return Objects.hashCode(id, account, allocated, associatedNetworkId, domain, domainId, usesVirtualNetwork, IPAddress, isSourceNAT, isStaticNAT, networkId, state, virtualMachineDisplayName, virtualMachineId, virtualMachineName, VLANId, VLANName, zoneId, zoneName, jobId, jobStatus); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + PublicIPAddress that = PublicIPAddress.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.account, that.account) + && Objects.equal(this.allocated, that.allocated) + && Objects.equal(this.associatedNetworkId, that.associatedNetworkId) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.usesVirtualNetwork, that.usesVirtualNetwork) + && Objects.equal(this.IPAddress, that.IPAddress) + && Objects.equal(this.isSourceNAT, that.isSourceNAT) + && Objects.equal(this.isStaticNAT, that.isStaticNAT) + && Objects.equal(this.networkId, that.networkId) + && Objects.equal(this.state, that.state) + && Objects.equal(this.virtualMachineDisplayName, that.virtualMachineDisplayName) + && Objects.equal(this.virtualMachineId, that.virtualMachineId) + && Objects.equal(this.virtualMachineName, that.virtualMachineName) + && Objects.equal(this.VLANId, that.VLANId) + && Objects.equal(this.VLANName, that.VLANName) + && Objects.equal(this.zoneId, that.zoneId) + && Objects.equal(this.zoneName, that.zoneName) + && Objects.equal(this.jobId, that.jobId) + && Objects.equal(this.jobStatus, that.jobStatus); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("account", account).add("allocated", allocated).add("associatedNetworkId", associatedNetworkId) + .add("domain", domain).add("domainId", domainId).add("usesVirtualNetwork", usesVirtualNetwork).add("IPAddress", IPAddress) + .add("isSourceNAT", isSourceNAT).add("isStaticNAT", isStaticNAT).add("networkId", networkId).add("state", state) + .add("virtualMachineDisplayName", virtualMachineDisplayName).add("virtualMachineId", virtualMachineId) + .add("virtualMachineName", virtualMachineName).add("VLANId", VLANId).add("VLANName", VLANName).add("zoneId", zoneId) + .add("zoneName", zoneName).add("jobId", jobId).add("jobStatus", jobStatus); + } + @Override public String toString() { - return "PublicIPAddress{" + - "id=" + id + - ", account='" + account + '\'' + - ", allocated=" + allocated + - ", associatedNetworkId=" + associatedNetworkId + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", usesVirtualNetwork=" + usesVirtualNetwork + - ", IPAddress='" + IPAddress + '\'' + - ", isSourceNAT=" + isSourceNAT + - ", isStaticNAT=" + isStaticNAT + - ", networkId=" + networkId + - ", state=" + state + - ", virtualMachineDisplayName='" + virtualMachineDisplayName + '\'' + - ", virtualMachineId=" + virtualMachineId + - ", virtualMachineName='" + virtualMachineName + '\'' + - ", VLANId=" + VLANId + - ", VLANName='" + VLANName + '\'' + - ", zoneId=" + zoneId + - ", zoneName='" + zoneName + '\'' + - ", jobId=" + jobId + - ", jobStatus=" + jobStatus + - '}'; + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ResourceLimit.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ResourceLimit.java index f2e6aa88f6..300dcc4231 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ResourceLimit.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ResourceLimit.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,143 +16,29 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Map; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Function; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; -import com.google.gson.annotations.SerializedName; /** + * Class ResourceLimit + * * @author Vijay Kiran - */ -public class ResourceLimit implements Comparable { - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String account; - private String domain; - private String domainId; - private int max; - private ResourceType resourceType; - - public Builder account(String account) { - this.account = account; - return this; - } - - public Builder domain(String domain) { - this.domain = domain; - return this; - } - - public Builder domainId(String domainId) { - this.domainId = domainId; - return this; - } - - public Builder max(int max) { - this.max = max; - return this; - } - - public Builder resourceType(ResourceType resourceType) { - this.resourceType = resourceType; - return this; - } - - public ResourceLimit build() { - return new ResourceLimit(account, domain, domainId, max, resourceType); - } - } - - // for deserialization - ResourceLimit() { - - } - - private String account; - private String domain; - @SerializedName("domainid") - private String domainId; - private int max; - @SerializedName("resourcetype") - private ResourceType resourceType; - - public ResourceLimit(String account, String domain, String domainId, int max, ResourceType resourceType) { - this.account = account; - this.domain = domain; - this.domainId = domainId; - this.max = max; - this.resourceType = resourceType; - } - - public String getAccount() { - return account; - } - - public String getDomain() { - return domain; - } - - public String getDomainId() { - return domainId; - } - - public int getMax() { - return max; - } - - public ResourceType getResourceType() { - return resourceType; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ResourceLimit that = (ResourceLimit) o; - - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(max, that.max)) return false; - if (!Objects.equal(resourceType, that.resourceType)) return false; - if (!Objects.equal(account, that.account)) return false; - if (!Objects.equal(domain, that.domain)) return false; - - return true; - } - - @Override - public int hashCode() { - return Objects.hashCode(domainId, max, resourceType, account, domain); - } - - @Override - public int compareTo(ResourceLimit that) { - return this.account.compareTo(that.account); - } - - @Override - public String toString() { - return "ResourceLimit{" + - "account='" + account + '\'' + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", max=" + max + - ", resourceType=" + resourceType + - '}'; - } +*/ +public class ResourceLimit { /** * Type of resource to update. @@ -200,7 +86,7 @@ public class ResourceLimit implements Comparable { public int getCode(){ return code; } - + @Override public String toString() { return name(); @@ -210,6 +96,155 @@ public class ResourceLimit implements Comparable { Integer code = new Integer(checkNotNull(resourceType, "resourcetype")); return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED; } - } + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromResourceLimit(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String account; + protected String domain; + protected String domainId; + protected int max; + protected ResourceType resourceType; + + /** + * @see ResourceLimit#getAccount() + */ + public T account(String account) { + this.account = account; + return self(); + } + + /** + * @see ResourceLimit#getDomain() + */ + public T domain(String domain) { + this.domain = domain; + return self(); + } + + /** + * @see ResourceLimit#getDomainId() + */ + public T domainId(String domainId) { + this.domainId = domainId; + return self(); + } + + /** + * @see ResourceLimit#getMax() + */ + public T max(int max) { + this.max = max; + return self(); + } + + /** + * @see ResourceLimit#getResourceType() + */ + public T resourceType(ResourceType resourceType) { + this.resourceType = resourceType; + return self(); + } + + public ResourceLimit build() { + return new ResourceLimit(account, domain, domainId, max, resourceType); + } + + public T fromResourceLimit(ResourceLimit in) { + return this + .account(in.getAccount()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .max(in.getMax()) + .resourceType(in.getResourceType()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String account; + private final String domain; + @Named("domainid") + private final String domainId; + private final int max; + @Named("resourcetype") + private final ResourceLimit.ResourceType resourceType; + + @ConstructorProperties({ + "account", "domain", "domainid", "max", "resourcetype" + }) + protected ResourceLimit(@Nullable String account, @Nullable String domain, @Nullable String domainId, int max, + @Nullable ResourceType resourceType) { + this.account = account; + this.domain = domain; + this.domainId = domainId; + this.max = max; + this.resourceType = resourceType; + } + + @Nullable + public String getAccount() { + return this.account; + } + + @Nullable + public String getDomain() { + return this.domain; + } + + @Nullable + public String getDomainId() { + return this.domainId; + } + + public int getMax() { + return this.max; + } + + @Nullable + public ResourceType getResourceType() { + return this.resourceType; + } + + @Override + public int hashCode() { + return Objects.hashCode(account, domain, domainId, max, resourceType); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ResourceLimit that = ResourceLimit.class.cast(obj); + return Objects.equal(this.account, that.account) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.max, that.max) + && Objects.equal(this.resourceType, that.resourceType); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("account", account).add("domain", domain).add("domainId", domainId).add("max", max).add("resourceType", resourceType); + } + + @Override + public String toString() { + return string().toString(); + } + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java index 88232c2048..2076a016e0 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,106 +20,164 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Set; -import java.util.SortedSet; -import javax.annotation.Nullable; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; -import com.google.gson.annotations.SerializedName; /** + * Class SecurityGroup + * * @author Adrian Cole - */ +*/ public class SecurityGroup implements Comparable { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromSecurityGroup(this); } - public static class Builder { - private String id; - private String account; - private String name; - private String description; - private String domain; - private String domainId; - private String jobId; - private Integer jobStatus; + public static abstract class Builder> { + protected abstract T self(); - private Set ingressRules = ImmutableSet.of(); - - public Builder id(String id) { + protected String id; + protected String account; + protected String name; + protected String description; + protected String domain; + protected String domainId; + protected String jobId; + protected Integer jobStatus; + protected Set ingressRules; + + /** + * @see SecurityGroup#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder account(String account) { + /** + * @see SecurityGroup#getAccount() + */ + public T account(String account) { this.account = account; - return this; + return self(); } - public Builder name(String name) { + /** + * @see SecurityGroup#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder description(String description) { + /** + * @see SecurityGroup#getDescription() + */ + public T description(String description) { this.description = description; - return this; + return self(); } - public Builder domain(String domain) { + /** + * @see SecurityGroup#getDomain() + */ + public T domain(String domain) { this.domain = domain; - return this; + return self(); } - public Builder domainId(String domainId) { + /** + * @see SecurityGroup#getDomainId() + */ + public T domainId(String domainId) { this.domainId = domainId; - return this; + return self(); } - public Builder jobId(String jobId) { + /** + * @see SecurityGroup#getJobId() + */ + public T jobId(String jobId) { this.jobId = jobId; - return this; + return self(); } - public Builder jobStatus(int jobStatus) { + /** + * @see SecurityGroup#getJobStatus() + */ + public T jobStatus(Integer jobStatus) { this.jobStatus = jobStatus; - return this; + return self(); } - public Builder ingressRules(Set ingressRules) { - this.ingressRules = ImmutableSet.copyOf(checkNotNull(ingressRules, "ingressRules")); - return this; + /** + * @see SecurityGroup#getIngressRules() + */ + public T ingressRules(Set ingressRules) { + this.ingressRules = ingressRules; + return self(); } public SecurityGroup build() { return new SecurityGroup(id, account, name, description, domain, domainId, jobId, jobStatus, ingressRules); } + + public T fromSecurityGroup(SecurityGroup in) { + return this + .id(in.getId()) + .account(in.getAccount()) + .name(in.getName()) + .description(in.getDescription()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .jobId(in.getJobId()) + .jobStatus(in.getJobStatus()) + .ingressRules(in.getIngressRules()); + } } - private String id; - private String account; - private String name; - private String description; - private String domain; - @SerializedName("domainid") - private String domainId; - @SerializedName("jobid") - @Nullable - private String jobId; - @SerializedName("jobstatus") - @Nullable - private Integer jobStatus; - @SerializedName("ingressrule") - // so that tests and serialization come out expected - private SortedSet ingressRules = ImmutableSortedSet.of(); + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - public SecurityGroup(String id, String account, String name, String description, String domain, String domainId, - String jobId, Integer jobStatus, Set ingressRules) { - this.id = id; + private final String id; + private final String account; + private final String name; + private final String description; + private final String domain; + @Named("domainid") + private final String domainId; + @Named("jobid") + private final String jobId; + @Named("jobstatus") + private final Integer jobStatus; + @Named("ingressrule") + private final Set ingressRules; + + @ConstructorProperties({ + "id", "account", "name", "description", "domain", "domainid", "jobid", "jobstatus", "ingressrule" + }) + protected SecurityGroup(String id, @Nullable String account, @Nullable String name, @Nullable String description, + @Nullable String domain, @Nullable String domainId, @Nullable String jobId, @Nullable Integer jobStatus, + @Nullable Set ingressRules) { + this.id = checkNotNull(id, "id"); this.account = account; this.name = name; this.description = description; @@ -127,60 +185,64 @@ public class SecurityGroup implements Comparable { this.domainId = domainId; this.jobId = jobId; this.jobStatus = jobStatus; - this.ingressRules = ImmutableSortedSet.copyOf(checkNotNull(ingressRules, "ingressRules")); - } - - /** - * present only for serializer - */ - SecurityGroup() { - + this.ingressRules = ingressRules == null ? ImmutableSet.of() : ImmutableSortedSet.copyOf(ingressRules); } /** * @return the id of the security group */ public String getId() { - return id; + return this.id; + } + + /** + * @return the account owning the security group + */ + @Nullable + public String getAccount() { + return this.account; } /** * @return the name of the security group */ - + @Nullable public String getName() { - return name; + return this.name; } /** * @return an alternate display text of the security group. */ + @Nullable public String getDescription() { - return description; + return this.description; } /** * @return Domain name for the security group */ + @Nullable public String getDomain() { - return domain; + return this.domain; } /** * @return the domain id of the security group */ + @Nullable public String getDomainId() { - return domainId; + return this.domainId; } /** * @return shows the current pending asynchronous job ID. This tag is not - * returned if no current pending jobs are acting on the virtual - * machine + returned if no current pending jobs are acting on the virtual + machine */ @Nullable public String getJobId() { - return jobId; + return this.jobId; } /** @@ -188,59 +250,49 @@ public class SecurityGroup implements Comparable { */ @Nullable public Integer getJobStatus() { - return jobStatus; - } - - /** - * @return the account owning the security group - */ - public String getAccount() { - return account; + return this.jobStatus; } /** * @return the list of ingress rules associated with the security group */ public Set getIngressRules() { - return ingressRules; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SecurityGroup that = (SecurityGroup) o; - - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(jobStatus, that.jobStatus)) return false; - - return true; + return this.ingressRules; } @Override public int hashCode() { - return Objects.hashCode(domainId, id, jobStatus); + return Objects.hashCode(id, account, name, description, domain, domainId, jobId, jobStatus, ingressRules); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + SecurityGroup that = SecurityGroup.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.account, that.account) + && Objects.equal(this.name, that.name) + && Objects.equal(this.description, that.description) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.jobId, that.jobId) + && Objects.equal(this.jobStatus, that.jobStatus) + && Objects.equal(this.ingressRules, that.ingressRules); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).add("id", id).add("account", account).add("name", name).add("description", description) + .add("domain", domain).add("domainId", domainId).add("jobId", jobId).add("jobStatus", jobStatus).add("ingressRules", ingressRules); + } + @Override public String toString() { - return "SecurityGroup{" + - "id=" + id + - ", account='" + account + '\'' + - ", name='" + name + '\'' + - ", description='" + description + '\'' + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", jobId=" + jobId + - ", jobStatus=" + jobStatus + - ", ingressRules=" + ingressRules + - '}'; + return string().toString(); } @Override - public int compareTo(SecurityGroup arg0) { - return id.compareTo(arg0.getId()); + public int compareTo(SecurityGroup o) { + return id.compareTo(o.getId()); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java index 8fc731fd54..b192cf9172 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,180 +20,275 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; import java.util.Set; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Joiner; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; -import com.google.gson.annotations.SerializedName; /** + * Class ServiceOffering + * * @author Adrian Cole */ public class ServiceOffering implements Comparable { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); } - public static class Builder { + public Builder toBuilder() { + return new ConcreteBuilder().fromServiceOffering(this); + } - private String id; - private String name; - private String displayText; - private Date created; - private String domain; - private String domainId; - private int cpuNumber; - private int cpuSpeed; - private int memory; - private boolean haSupport; - private StorageType storageType; - private boolean defaultUse; - private String hostTags; - private boolean systemOffering; - private boolean cpuUseLimited; - private long networkRate; - private boolean systemVmType; + public static abstract class Builder> { + protected abstract T self(); + protected String id; + protected String name; + protected String displayText; + protected Date created; + protected String domain; + protected String domainId; + protected int cpuNumber; + protected int cpuSpeed; + protected int memory; + protected boolean haSupport; + protected StorageType storageType; + protected boolean defaultUse; + protected String hostTags; + protected boolean systemOffering; + protected boolean cpuUseLimited; + protected long networkRate; + protected boolean systemVmType; private Set tags = ImmutableSet.of(); - public Builder id(String id) { + /** + * @see ServiceOffering#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder name(String name) { + /** + * @see ServiceOffering#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder displayText(String displayText) { + /** + * @see ServiceOffering#getDisplayText() + */ + public T displayText(String displayText) { this.displayText = displayText; - return this; + return self(); } - public Builder created(Date created) { + /** + * @see ServiceOffering#getCreated() + */ + public T created(Date created) { this.created = created; - return this; + return self(); } - public Builder domain(String domain) { + /** + * @see ServiceOffering#getDomain() + */ + public T domain(String domain) { this.domain = domain; - return this; + return self(); } - public Builder domainId(String domainId) { + /** + * @see ServiceOffering#getDomainId() + */ + public T domainId(String domainId) { this.domainId = domainId; - return this; + return self(); } - public Builder cpuNumber(int cpuNumber) { + /** + * @see ServiceOffering#getCpuNumber() + */ + public T cpuNumber(int cpuNumber) { this.cpuNumber = cpuNumber; - return this; + return self(); } - public Builder cpuSpeed(int cpuSpeed) { + /** + * @see ServiceOffering#getCpuSpeed() + */ + public T cpuSpeed(int cpuSpeed) { this.cpuSpeed = cpuSpeed; - return this; + return self(); } - public Builder memory(int memory) { + /** + * @see ServiceOffering#getMemory() + */ + public T memory(int memory) { this.memory = memory; - return this; + return self(); } - public Builder haSupport(boolean haSupport) { + /** + * @see ServiceOffering#supportsHA() + */ + public T supportsHA(boolean haSupport) { this.haSupport = haSupport; - return this; + return self(); } - public Builder storageType(StorageType storageType) { + /** + * @see ServiceOffering#getStorageType() + */ + public T storageType(StorageType storageType) { this.storageType = storageType; - return this; + return self(); } - public Builder tags(Set tags) { + /** + * @see ServiceOffering#getTags() + */ + public T tags(Set tags) { this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); - return this; + return self(); } - public Builder defaultUse(boolean defaultUse) { + /** + * @see ServiceOffering#isDefaultUse() + */ + public T defaultUse(boolean defaultUse) { this.defaultUse = defaultUse; - return this; + return self(); } - public Builder hostTags(String hostTags) { + /** + * @see ServiceOffering#getHostTags() + */ + public T hostTags(String hostTags) { this.hostTags = hostTags; - return this; + return self(); } - public Builder systemOffering(boolean systemOffering) { + /** + * @see ServiceOffering#isSystemOffering() + */ + public T systemOffering(boolean systemOffering) { this.systemOffering = systemOffering; - return this; + return self(); } - public Builder cpuUseLimited(boolean cpuUseLimited) { + /** + * @see ServiceOffering#isCpuUseLimited() + */ + public T cpuUseLimited(boolean cpuUseLimited) { this.cpuUseLimited = cpuUseLimited; - return this; + return self(); } - public Builder networkRate(long networkRate) { + /** + * @see ServiceOffering#getNetworkRate() + */ + public T networkRate(long networkRate) { this.networkRate = networkRate; - return this; + return self(); } - public Builder systemVmType(boolean systemVmType) { + /** + * @see ServiceOffering#isSystemVmType() + */ + public T systemVmType(boolean systemVmType) { this.systemVmType = systemVmType; - return this; + return self(); } - public ServiceOffering build() { - return new ServiceOffering(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory, - haSupport, storageType, tags, defaultUse, hostTags, systemOffering, cpuUseLimited, networkRate, - systemVmType); + return new ServiceOffering(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory, haSupport, storageType, + Joiner.on(",").join(tags), defaultUse, hostTags, systemOffering, cpuUseLimited, networkRate, systemVmType); + } + + public T fromServiceOffering(ServiceOffering in) { + return this + .id(in.getId()) + .name(in.getName()) + .displayText(in.getDisplayText()) + .created(in.getCreated()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .cpuNumber(in.getCpuNumber()) + .cpuSpeed(in.getCpuSpeed()) + .memory(in.getMemory()) + .supportsHA(in.supportsHA()) + .storageType(in.getStorageType()) + .tags(in.getTags()) + .defaultUse(in.isDefaultUse()) + .hostTags(in.getHostTags()) + .systemOffering(in.isSystemOffering()) + .cpuUseLimited(in.isCpuUseLimited()) + .networkRate(in.getNetworkRate()) + .systemVmType(in.isSystemVmType()); } } - private String id; - private String name; - @SerializedName("displaytext") - private String displayText; - private Date created; - private String domain; - @SerializedName("domainid") - private String domainId; - @SerializedName("cpunumber") - private int cpuNumber; - @SerializedName("cpuspeed") - private int cpuSpeed; - private int memory; - @SerializedName("offerha") - private boolean haSupport; - @SerializedName("storagetype") - private StorageType storageType; - private String tags; - @SerializedName("defaultuse") - private boolean defaultUse; - @SerializedName("hosttags") - private String hostTags; - @SerializedName("issystem") - private boolean systemOffering; - @SerializedName("limitcpuuse") - private boolean cpuUseLimited; - @SerializedName("networkrate") - private long networkRate; - @SerializedName("systemvmtype") - private boolean systemVmType; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + private final String id; + private final String name; + @Named("displaytext") + private final String displayText; + private final Date created; + private final String domain; + @Named("domainid") + private final String domainId; + @Named("cpunumber") + private final int cpuNumber; + @Named("cpuspeed") + private final int cpuSpeed; + private final int memory; + @Named("offerha") + private final boolean haSupport; + @Named("storagetype") + private final StorageType storageType; + private final String tags; + @Named("defaultuse") + private final boolean defaultUse; + @Named("hosttags") + private final String hostTags; + @Named("issystem") + private final boolean systemOffering; + @Named("limitcpuuse") + private final boolean cpuUseLimited; + @Named("networkrate") + private final long networkRate; + @Named("systemvmtype") + private final boolean systemVmType; - public ServiceOffering(String id, String name, String displayText, Date created, String domain, String domainId, - int cpuNumber, int cpuSpeed, int memory, boolean haSupport, StorageType storageType, Set tags, - boolean defaultUse, String hostTags, boolean systemOffering, boolean cpuUseLimited, long networkRate, - boolean systemVmType) { - this.id = id; + @ConstructorProperties({ + "id", "name", "displaytext", "created", "domain", "domainid", "cpunumber", "cpuspeed", "memory", "offerha", "storagetype", "tags", "defaultuse", "hosttags", "issystem", "limitcpuuse", "networkrate", "systemvmtype" + }) + protected ServiceOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, + @Nullable String domain, @Nullable String domainId, int cpuNumber, int cpuSpeed, int memory, + boolean haSupport, @Nullable StorageType storageType, @Nullable String tags, boolean defaultUse, + @Nullable String hostTags, boolean systemOffering, boolean cpuUseLimited, long networkRate, boolean systemVmType) { + this.id = checkNotNull(id, "id"); this.name = name; this.displayText = displayText; this.created = created; @@ -204,198 +299,191 @@ public class ServiceOffering implements Comparable { this.memory = memory; this.haSupport = haSupport; this.storageType = storageType; - this.tags = tags.size() == 0 ? null : Joiner.on(',').join(tags); - } - - /** - * present only for serializer - */ - ServiceOffering() { - + this.tags = tags; + this.defaultUse = defaultUse; + this.hostTags = hostTags; + this.systemOffering = systemOffering; + this.cpuUseLimited = cpuUseLimited; + this.networkRate = networkRate; + this.systemVmType = systemVmType; } /** * @return the id of the service offering */ public String getId() { - return id; + return this.id; } /** * @return the name of the service offering */ - public String getName() { - return name; + return this.name; } /** * @return an alternate display text of the service offering. */ + @Nullable public String getDisplayText() { - return displayText; + return this.displayText; } /** * @return the date this service offering was created */ + @Nullable public Date getCreated() { - return created; + return this.created; } /** * @return Domain name for the offering */ + @Nullable public String getDomain() { - return domain; + return this.domain; } /** * @return the domain id of the service offering */ + @Nullable public String getDomainId() { - return domainId; + return this.domainId; } /** * @return the number of CPU */ public int getCpuNumber() { - return cpuNumber; + return this.cpuNumber; } /** * @return the clock rate CPU speed in Mhz */ public int getCpuSpeed() { - return cpuSpeed; + return this.cpuSpeed; } /** * @return the memory in MB */ public int getMemory() { - return memory; + return this.memory; } - /** - * @return the ha support in the service offering - */ public boolean supportsHA() { - return haSupport; + return this.haSupport; } /** * @return the storage type for this service offering */ + @Nullable public StorageType getStorageType() { - return storageType; - } - - /** - * @return whether this is a default system vm offering - */ - public boolean isDefaultUse() { - return defaultUse; - } - - /** - * @return the host tag for the service offering - */ - public String getHostTags() { - return hostTags; - } - - /** - * @return whether this is a system vm offering - */ - public boolean isSystemOffering() { - return systemOffering; - } - - /** - * @return whether restrict the CPU usage to committed service offering - */ - public boolean isCpuUseLimited() { - return cpuUseLimited; - } - - /** - * @return data transfer rate in megabits per second allowed. - */ - public long getNetworkRate() { - return networkRate; - } - - /** - * @return whether this is a the systemvm type for system vm offering - */ - public boolean isSystemVmType() { - return systemVmType; + return this.storageType; } /** * @return the tags for the service offering */ public Set getTags() { - return tags != null ? ImmutableSet.copyOf(Splitter.on(',').split(tags)) : ImmutableSet.of(); + return tags == null ? ImmutableSet.of() : ImmutableSet.copyOf(Splitter.on(',').split(tags)); } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + /** + * @return whether this is a default system vm offering + */ + public boolean isDefaultUse() { + return this.defaultUse; + } - ServiceOffering that = (ServiceOffering) o; + /** + * @return the host tag for the service offering + */ + @Nullable + public String getHostTags() { + return this.hostTags; + } - if (!Objects.equal(cpuNumber, that.cpuNumber)) return false; - if (!Objects.equal(cpuSpeed, that.cpuSpeed)) return false; - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(displayText, that.displayText)) return false; - if (!Objects.equal(domain, that.domain)) return false; - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(haSupport, that.haSupport)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(memory, that.memory)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(storageType, that.storageType)) return false; - if (!Objects.equal(tags, that.tags)) return false; + /** + * @return whether this is a system vm offering + */ + public boolean isSystemOffering() { + return this.systemOffering; + } - return true; + /** + * @return whether restrict the CPU usage to committed service offering + */ + public boolean isCpuUseLimited() { + return this.cpuUseLimited; + } + + /** + * @return data transfer rate in megabits per second allowed. + */ + public long getNetworkRate() { + return this.networkRate; + } + + /** + * @return whether this is a the systemvm type for system vm offering + */ + public boolean isSystemVmType() { + return this.systemVmType; } @Override public int hashCode() { - return Objects.hashCode(cpuNumber, cpuSpeed, created, displayText, domain, domainId, haSupport, id, memory, name, storageType, tags); + return Objects.hashCode(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory, haSupport, storageType, tags, defaultUse, hostTags, systemOffering, cpuUseLimited, networkRate, systemVmType); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ServiceOffering that = ServiceOffering.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.name, that.name) + && Objects.equal(this.displayText, that.displayText) + && Objects.equal(this.created, that.created) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.cpuNumber, that.cpuNumber) + && Objects.equal(this.cpuSpeed, that.cpuSpeed) + && Objects.equal(this.memory, that.memory) + && Objects.equal(this.haSupport, that.haSupport) + && Objects.equal(this.storageType, that.storageType) + && Objects.equal(this.getTags(), that.getTags()) + && Objects.equal(this.defaultUse, that.defaultUse) + && Objects.equal(this.hostTags, that.hostTags) + && Objects.equal(this.systemOffering, that.systemOffering) + && Objects.equal(this.cpuUseLimited, that.cpuUseLimited) + && Objects.equal(this.networkRate, that.networkRate) + && Objects.equal(this.systemVmType, that.systemVmType); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("displayText", displayText).add("created", created).add("domain", domain) + .add("domainId", domainId).add("cpuNumber", cpuNumber).add("cpuSpeed", cpuSpeed).add("memory", memory) + .add("haSupport", haSupport).add("storageType", storageType).add("tags", getTags()).add("defaultUse", defaultUse) + .add("hostTags", hostTags).add("systemOffering", systemOffering).add("cpuUseLimited", cpuUseLimited) + .add("networkRate", networkRate).add("systemVmType", systemVmType); } @Override public String toString() { - return "ServiceOffering{" + - "id=" + id + - ", name='" + name + '\'' + - ", displayText='" + displayText + '\'' + - ", created=" + created + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", cpuNumber=" + cpuNumber + - ", cpuSpeed=" + cpuSpeed + - ", memory=" + memory + - ", haSupport=" + haSupport + - ", storageType=" + storageType + - ", tags='" + tags + '\'' + - ", defaultUse=" + defaultUse + - ", hostTags='" + hostTags + '\'' + - ", systemOffering=" + systemOffering + - ", cpuUseLimited=" + cpuUseLimited + - ", networkRate=" + networkRate + - ", systemVmType=" + systemVmType + - '}'; + return string().toString(); } @Override - public int compareTo(ServiceOffering arg0) { - return id.compareTo(arg0.getId()); + public int compareTo(ServiceOffering o) { + return id.compareTo(o.getId()); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Snapshot.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Snapshot.java index a4a97044be..7e84da0993 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Snapshot.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Snapshot.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,158 +20,27 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.CaseFormat; import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** + * Class Snapshot + * * @author Richard Downer */ -public class Snapshot implements Comparable { +public class Snapshot { - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String id; - private String account; - private Date created; - private String domain; - private String domainId; - private Interval interval; - private String jobId; - private String jobStatus; - private String name; - private Type snapshotType; - private State state; - private String volumeId; - private String volumeName; - private Volume.Type volumeType; - - /** - * @param id ID of the snapshot - */ - public Builder id(String id) { - this.id = id; - return this; - } - - /** - * @param account the account associated with the snapshot - */ - public Builder account(String account) { - this.account = account; - return this; - } - - /** - * @param created the date the snapshot was created - */ - public Builder created(Date created) { - this.created = created; - return this; - } - - /** - * @param domain the domain name of the snapshot's account - */ - public Builder domain(String domain) { - this.domain = domain; - return this; - } - - /** - * @param domainId the domain ID of the snapshot's account - */ - public Builder domainId(String domainId) { - this.domainId = domainId; - return this; - } - - /** - * @param interval valid types are hourly, daily, weekly, monthy, template, and none. - */ - public Builder interval(Interval interval) { - this.interval = interval; - return this; - } - - /** - * @param jobId the job ID associated with the snapshot. This is only displayed if the snapshot listed is part of a currently running asynchronous job. - */ - public Builder jobId(String jobId) { - this.jobId = jobId; - return this; - } - - /** - * @param jobStatus the job status associated with the snapshot. This is only displayed if the snapshot listed is part of a currently running asynchronous job. - */ - public Builder jobStatus(String jobStatus) { - this.jobStatus = jobStatus; - return this; - } - - /** - * @param name name of the snapshot - */ - public Builder name(String name) { - this.name = name; - return this; - } - - /** - * @param snapshotType the type of the snapshot - */ - public Builder snapshotType(Type snapshotType) { - this.snapshotType = snapshotType; - return this; - } - - /** - * @param state the state of the snapshot. BackedUp means that snapshot is ready to be used; Creating - the snapshot is being allocated on the primary storage; BackingUp - the snapshot is being backed up on secondary storage - */ - public Builder state(State state) { - this.state = state; - return this; - } - - /** - * @param volumeId ID of the disk volume - */ - public Builder volumeId(String volumeId) { - this.volumeId = volumeId; - return this; - } - - /** - * @param volumeName name of the disk volume - */ - public Builder volumeName(String volumeName) { - this.volumeName = volumeName; - return this; - } - - /** - * @param volumeType type of the disk volume - */ - public Builder volumeType(Volume.Type volumeType) { - this.volumeType = volumeType; - return this; - } - - public Snapshot build() { - return new Snapshot(id, account, created, domain, domainId, interval, jobId, - jobStatus, name, snapshotType, state, volumeId, volumeName, volumeType); - } - - } - - public enum State { + /** + */ + public static enum State { BACKED_UP, CREATING, BACKING_UP, UNRECOGNIZED; @@ -189,7 +58,9 @@ public class Snapshot implements Comparable { } } - public enum Type { + /** + */ + public static enum Type { MANUAL, RECURRING, UNRECOGNIZED; @@ -202,7 +73,9 @@ public class Snapshot implements Comparable { } } - public enum Interval { + /** + */ + public static enum Interval { HOURLY, DAILY, WEEKLY, MONTHLY, template, none, UNRECOGNIZED; @@ -215,32 +88,206 @@ public class Snapshot implements Comparable { } } - private String id; - private String account; - private Date created; - private String domain; - @SerializedName("domainid") - private String domainId; - @SerializedName("intervaltype") - private Interval interval; - @SerializedName("jobid") - private String jobId; - @SerializedName("jobstatus") - private String jobStatus; - private String name; - @SerializedName("snapshottype") - private Type snapshotType; - private State state; - @SerializedName("volumeid") - private String volumeId; - @SerializedName("volumename") - private String volumeName; - @SerializedName("volumetype") - private Volume.Type volumeType; + public static Builder builder() { + return new ConcreteBuilder(); + } - public Snapshot(String id, String account, Date created, String domain, String domainId, Interval interval, String jobId, - String jobStatus, String name, Type snapshotType, State state, String volumeId, String volumeName, Volume.Type volumeType) { - this.id = id; + public Builder toBuilder() { + return new ConcreteBuilder().fromSnapshot(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected String account; + protected Date created; + protected String domain; + protected String domainId; + protected Snapshot.Interval interval; + protected String jobId; + protected String jobStatus; + protected String name; + protected Snapshot.Type snapshotType; + protected Snapshot.State state; + protected String volumeId; + protected String volumeName; + protected Volume.Type volumeType; + + /** + * @see Snapshot#getId() + */ + public T id(String id) { + this.id = id; + return self(); + } + + /** + * @see Snapshot#getAccount() + */ + public T account(String account) { + this.account = account; + return self(); + } + + /** + * @see Snapshot#getCreated() + */ + public T created(Date created) { + this.created = created; + return self(); + } + + /** + * @see Snapshot#getDomain() + */ + public T domain(String domain) { + this.domain = domain; + return self(); + } + + /** + * @see Snapshot#getDomainId() + */ + public T domainId(String domainId) { + this.domainId = domainId; + return self(); + } + + /** + * @see Snapshot#getInterval() + */ + public T interval(Snapshot.Interval interval) { + this.interval = interval; + return self(); + } + + /** + * @see Snapshot#getJobId() + */ + public T jobId(String jobId) { + this.jobId = jobId; + return self(); + } + + /** + * @see Snapshot#getJobStatus() + */ + public T jobStatus(String jobStatus) { + this.jobStatus = jobStatus; + return self(); + } + + /** + * @see Snapshot#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + /** + * @see Snapshot#getSnapshotType() + */ + public T snapshotType(Snapshot.Type snapshotType) { + this.snapshotType = snapshotType; + return self(); + } + + /** + * @see Snapshot#getState() + */ + public T state(Snapshot.State state) { + this.state = state; + return self(); + } + + /** + * @see Snapshot#getVolumeId() + */ + public T volumeId(String volumeId) { + this.volumeId = volumeId; + return self(); + } + + /** + * @see Snapshot#getVolumeName() + */ + public T volumeName(String volumeName) { + this.volumeName = volumeName; + return self(); + } + + /** + * @see Snapshot#getVolumeType() + */ + public T volumeType(Volume.Type volumeType) { + this.volumeType = volumeType; + return self(); + } + + public Snapshot build() { + return new Snapshot(id, account, created, domain, domainId, interval, jobId, jobStatus, name, snapshotType, state, + volumeId, volumeName, volumeType); + } + + public T fromSnapshot(Snapshot in) { + return this + .id(in.getId()) + .account(in.getAccount()) + .created(in.getCreated()) + .domain(in.getDomain()) + .domainId(in.getDomainId()) + .interval(in.getInterval()) + .jobId(in.getJobId()) + .jobStatus(in.getJobStatus()) + .name(in.getName()) + .snapshotType(in.getSnapshotType()) + .state(in.getState()) + .volumeId(in.getVolumeId()) + .volumeName(in.getVolumeName()) + .volumeType(in.getVolumeType()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + private final String account; + private final Date created; + private final String domain; + @Named("domainid") + private final String domainId; + @Named("intervaltype") + private final Snapshot.Interval interval; + @Named("jobid") + private final String jobId; + @Named("jobstatus") + private final String jobStatus; + private final String name; + @Named("snapshottype") + private final Snapshot.Type snapshotType; + private final Snapshot.State state; + @Named("volumeid") + private final String volumeId; + @Named("volumename") + private final String volumeName; + @Named("volumetype") + private final Volume.Type volumeType; + + @ConstructorProperties({ + "id", "account", "created", "domain", "domainid", "intervaltype", "jobid", "jobstatus", "name", "snapshottype", "state", "volumeid", "volumename", "volumetype" + }) + protected Snapshot(String id, @Nullable String account, @Nullable Date created, @Nullable String domain, @Nullable String domainId, + @Nullable Snapshot.Interval interval, @Nullable String jobId, @Nullable String jobStatus, @Nullable String name, + @Nullable Snapshot.Type snapshotType, @Nullable Snapshot.State state, @Nullable String volumeId, @Nullable String volumeName, + @Nullable Volume.Type volumeType) { + this.id = checkNotNull(id, "id"); this.account = account; this.created = created; this.domain = domain; @@ -256,164 +303,153 @@ public class Snapshot implements Comparable { this.volumeType = volumeType; } - /** - * present only for serializer - */ - Snapshot() { - } - /** * @return ID of the snapshot */ public String getId() { - return id; + return this.id; } /** * @return the account associated with the snapshot */ + @Nullable public String getAccount() { - return account; + return this.account; } /** * @return the date the snapshot was created */ + @Nullable public Date getCreated() { - return created; + return this.created; } /** * @return the domain name of the snapshot's account */ + @Nullable public String getDomain() { - return domain; + return this.domain; } /** * @return the domain ID of the snapshot's account */ + @Nullable public String getDomainId() { - return domainId; + return this.domainId; } /** * @return valid types are hourly, daily, weekly, monthy, template, and none. */ - public Interval getInterval() { - return interval; + @Nullable + public Snapshot.Interval getInterval() { + return this.interval; } /** * @return the job ID associated with the snapshot. This is only displayed if the snapshot listed is part of a currently running asynchronous job. */ + @Nullable public String getJobId() { - return jobId; + return this.jobId; } /** * @return the job status associated with the snapshot. This is only displayed if the snapshot listed is part of a currently running asynchronous job. */ + @Nullable public String getJobStatus() { - return jobStatus; + return this.jobStatus; } /** * @return name of the snapshot */ + @Nullable public String getName() { - return name; + return this.name; } /** * @return the type of the snapshot */ - public Type getSnapshotType() { - return snapshotType; + @Nullable + public Snapshot.Type getSnapshotType() { + return this.snapshotType; } /** * @return the state of the snapshot. BackedUp means that snapshot is ready to be used; Creating - the snapshot is being allocated on the primary storage; BackingUp - the snapshot is being backed up on secondary storage */ - public State getState() { - return state; + @Nullable + public Snapshot.State getState() { + return this.state; } /** * @return ID of the disk volume */ + @Nullable public String getVolumeId() { - return volumeId; + return this.volumeId; } /** * @return name of the disk volume */ + @Nullable public String getVolumeName() { - return volumeName; + return this.volumeName; } /** * @return type of the disk volume */ + @Nullable public Volume.Type getVolumeType() { - return volumeType; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Snapshot that = (Snapshot) o; - - if (!Objects.equal(domainId, that.domainId)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(jobId, that.jobId)) return false; - if (!Objects.equal(volumeId, that.volumeId)) return false; - if (!Objects.equal(account, that.account)) return false; - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(domain, that.domain)) return false; - if (!Objects.equal(interval, that.interval)) return false; - if (!Objects.equal(jobStatus, that.jobStatus)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(snapshotType, that.snapshotType)) return false; - if (!Objects.equal(state, that.state)) return false; - if (!Objects.equal(volumeName, that.volumeName)) return false; - if (!Objects.equal(volumeType, that.volumeType)) return false; - - return true; + return this.volumeType; } @Override public int hashCode() { - return Objects.hashCode(domainId, id, jobId, volumeId, account, created, domain, - interval, jobStatus, name, snapshotType, state, volumeName, - volumeType); + return Objects.hashCode(id, account, created, domain, domainId, interval, jobId, jobStatus, name, snapshotType, state, volumeId, volumeName, volumeType); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Snapshot that = Snapshot.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.account, that.account) + && Objects.equal(this.created, that.created) + && Objects.equal(this.domain, that.domain) + && Objects.equal(this.domainId, that.domainId) + && Objects.equal(this.interval, that.interval) + && Objects.equal(this.jobId, that.jobId) + && Objects.equal(this.jobStatus, that.jobStatus) + && Objects.equal(this.name, that.name) + && Objects.equal(this.snapshotType, that.snapshotType) + && Objects.equal(this.state, that.state) + && Objects.equal(this.volumeId, that.volumeId) + && Objects.equal(this.volumeName, that.volumeName) + && Objects.equal(this.volumeType, that.volumeType); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("account", account).add("created", created).add("domain", domain).add("domainId", domainId) + .add("interval", interval).add("jobId", jobId).add("jobStatus", jobStatus).add("name", name).add("snapshotType", snapshotType) + .add("state", state).add("volumeId", volumeId).add("volumeName", volumeName).add("volumeType", volumeType); } @Override public String toString() { - return "Snapshot{" + - "id=" + id + - ", account='" + account + '\'' + - ", created=" + created + - ", domain='" + domain + '\'' + - ", domainId=" + domainId + - ", interval=" + interval + - ", jobId=" + jobId + - ", jobStatus='" + jobStatus + '\'' + - ", name='" + name + '\'' + - ", snapshotType=" + snapshotType + - ", state=" + state + - ", volumeId=" + volumeId + - ", volumeName='" + volumeName + '\'' + - ", volumeType=" + volumeType + - '}'; + return string().toString(); } - @Override - public int compareTo(Snapshot other) { - return id.compareTo(other.getId()); - } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SnapshotPolicy.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SnapshotPolicy.java index b736eb73e9..3651a5641d 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SnapshotPolicy.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SnapshotPolicy.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,184 +18,208 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** + * Class SnapshotPolicy + * * @author Richard Downer - */ -public class SnapshotPolicy implements Comparable { +*/ +public class SnapshotPolicy { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromSnapshotPolicy(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); - private String id; - private Snapshot.Interval interval; - private long numberToRetain; - private String schedule; - private String timezone; - private String volumeId; - - /** - * @param id the ID of the snapshot policy + protected String id; + protected Snapshot.Interval interval; + protected long numberToRetain; + protected String schedule; + protected String timezone; + protected String volumeId; + + /** + * @see SnapshotPolicy#getId() */ - public Builder id(String id) { + public T id(String id) { this.id = id; - return this; + return self(); } - /** - * @param interval valid types are hourly, daily, weekly, monthy, template, and none. + /** + * @see SnapshotPolicy#getInterval() */ - public Builder interval(Snapshot.Interval interval) { + public T interval(Snapshot.Interval interval) { this.interval = interval; - return this; + return self(); } - /** - * @param numberToRetain maximum number of snapshots retained + /** + * @see SnapshotPolicy#getNumberToRetain() */ - public Builder numberToRetain(long numberToRetain) { + public T numberToRetain(long numberToRetain) { this.numberToRetain = numberToRetain; - return this; + return self(); } - /** - * @param schedule time the snapshot is scheduled to be taken. + /** + * @see SnapshotPolicy#getSchedule() */ - public Builder schedule(String schedule) { + public T schedule(String schedule) { this.schedule = schedule; - return this; + return self(); } - /** - * @param timezone the time zone of the snapshot policy + /** + * @see SnapshotPolicy#getTimezone() */ - public Builder timezone(String timezone) { + public T timezone(String timezone) { this.timezone = timezone; - return this; + return self(); } - /** - * @param volumeId ID of the disk volume + /** + * @see SnapshotPolicy#getVolumeId() */ - public Builder volumeId(String volumeId) { + public T volumeId(String volumeId) { this.volumeId = volumeId; - return this; + return self(); } public SnapshotPolicy build() { return new SnapshotPolicy(id, interval, numberToRetain, schedule, timezone, volumeId); } + + public T fromSnapshotPolicy(SnapshotPolicy in) { + return this + .id(in.getId()) + .interval(in.getInterval()) + .numberToRetain(in.getNumberToRetain()) + .schedule(in.getSchedule()) + .timezone(in.getTimezone()) + .volumeId(in.getVolumeId()); + } } - private String id; - @SerializedName("intervaltype") - private Snapshot.Interval interval; - @SerializedName("maxsnaps") - private long numberToRetain; - private String schedule; - private String timezone; - @SerializedName("volumeid") - private String volumeId; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - public SnapshotPolicy(String id, Snapshot.Interval interval, long numberToRetain, String schedule, String timezone, String volumeId) { - this.id = id; + private final String id; + @Named("intervaltype") + private final Snapshot.Interval interval; + @Named("maxsnaps") + private final long numberToRetain; + private final String schedule; + private final String timezone; + @Named("volumeid") + private final String volumeId; + + @ConstructorProperties({ + "id", "intervaltype", "maxsnaps", "schedule", "timezone", "volumeid" + }) + protected SnapshotPolicy(String id, @Nullable Snapshot.Interval interval, long numberToRetain, @Nullable String schedule, + @Nullable String timezone, @Nullable String volumeId) { + this.id = checkNotNull(id, "id"); this.interval = interval; this.numberToRetain = numberToRetain; this.schedule = schedule; this.timezone = timezone; this.volumeId = volumeId; } - - /** - * present only for serializer - */ - SnapshotPolicy() { - } /** * @return the ID of the snapshot policy */ public String getId() { - return id; + return this.id; } /** * @return valid types are hourly, daily, weekly, monthy, template, and none. */ + @Nullable public Snapshot.Interval getInterval() { - return interval; + return this.interval; } /** * @return maximum number of snapshots retained */ public long getNumberToRetain() { - return numberToRetain; + return this.numberToRetain; } /** * @return time the snapshot is scheduled to be taken. */ + @Nullable public String getSchedule() { - return schedule; + return this.schedule; } /** * @return the time zone of the snapshot policy */ + @Nullable public String getTimezone() { - return timezone; + return this.timezone; } /** * @return ID of the disk volume */ + @Nullable public String getVolumeId() { - return volumeId; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SnapshotPolicy that = (SnapshotPolicy) o; - - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(numberToRetain, that.numberToRetain)) return false; - if (!Objects.equal(volumeId, that.volumeId)) return false; - if (!Objects.equal(interval, that.interval)) return false; - if (!Objects.equal(schedule, that.schedule)) return false; - if (!Objects.equal(timezone, that.timezone)) return false; - - return true; + return this.volumeId; } @Override public int hashCode() { - return Objects.hashCode(id, numberToRetain, volumeId, interval, schedule, timezone); + return Objects.hashCode(id, interval, numberToRetain, schedule, timezone, volumeId); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + SnapshotPolicy that = SnapshotPolicy.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.interval, that.interval) + && Objects.equal(this.numberToRetain, that.numberToRetain) + && Objects.equal(this.schedule, that.schedule) + && Objects.equal(this.timezone, that.timezone) + && Objects.equal(this.volumeId, that.volumeId); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("interval", interval).add("numberToRetain", numberToRetain).add("schedule", schedule).add("timezone", timezone) + .add("volumeId", volumeId); + } + @Override public String toString() { - return "SnapshotPolicy{" + - "id=" + id + - ", interval=" + interval + - ", numberToRetain=" + numberToRetain + - ", schedule='" + schedule + '\'' + - ", timezone='" + timezone + '\'' + - ", volumeId=" + volumeId + - '}'; - } - - @Override - public int compareTo(SnapshotPolicy other) { - return id.compareTo(other.getId()); + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SnapshotPolicySchedule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SnapshotPolicySchedule.java index 82525c2c21..d006ce79da 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SnapshotPolicySchedule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SnapshotPolicySchedule.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,35 +18,112 @@ */ package org.jclouds.cloudstack.domain; +import java.beans.ConstructorProperties; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + /** * Describes the schedule of a snapshot policy. * * @see org.jclouds.cloudstack.util.SnapshotPolicySchedules * @author Richard Downer - */ +*/ public class SnapshotPolicySchedule { - private Snapshot.Interval interval; - private String time; + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromSnapshotPolicySchedule(this); + } - public SnapshotPolicySchedule(Snapshot.Interval interval, String time) { + public static abstract class Builder> { + protected abstract T self(); + + protected Snapshot.Interval interval; + protected String time; + + /** + * @see SnapshotPolicySchedule#getInterval() + */ + public T interval(Snapshot.Interval interval) { + this.interval = interval; + return self(); + } + + /** + * @see SnapshotPolicySchedule#getTime() + */ + public T time(String time) { + this.time = time; + return self(); + } + + public SnapshotPolicySchedule build() { + return new SnapshotPolicySchedule(interval, time); + } + + public T fromSnapshotPolicySchedule(SnapshotPolicySchedule in) { + return this + .interval(in.getInterval()) + .time(in.getTime()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final Snapshot.Interval interval; + private final String time; + + @ConstructorProperties({ + "interval", "time" + }) + protected SnapshotPolicySchedule(@Nullable Snapshot.Interval interval, @Nullable String time) { this.interval = interval; this.time = time; } + @Nullable public Snapshot.Interval getInterval() { - return interval; + return this.interval; } + @Nullable public String getTime() { - return time; + return this.time; } @Override - public String toString() { - return "SnapshotPolicySchedule{" + - "interval=" + interval + - ", time='" + time + '\'' + - '}'; + public int hashCode() { + return Objects.hashCode(interval, time); } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + SnapshotPolicySchedule that = SnapshotPolicySchedule.class.cast(obj); + return Objects.equal(this.interval, that.interval) + && Objects.equal(this.time, that.time); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("interval", interval).add("time", time); + } + + @Override + public String toString() { + return string().toString(); + } + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SshKeyPair.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SshKeyPair.java index ef36ea3b77..c1dcfcad7d 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SshKeyPair.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SshKeyPair.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,106 +16,135 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** + * Class SshKeyPair + * * @author Vijay Kiran - */ -public class SshKeyPair implements Comparable { +*/ +public class SshKeyPair { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromSshKeyPair(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); - private String fingerprint; - private String name; - private String privateKey; - - public Builder fingerprint(String fingerprint) { + protected String fingerprint; + protected String name; + protected String privateKey; + + /** + * @see SshKeyPair#getFingerprint() + */ + public T fingerprint(String fingerprint) { this.fingerprint = fingerprint; - return this; + return self(); } - public Builder name(String name) { + /** + * @see SshKeyPair#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder privateKey(String privateKey) { + /** + * @see SshKeyPair#getPrivateKey() + */ + public T privateKey(String privateKey) { this.privateKey = privateKey; - return this; + return self(); } public SshKeyPair build() { return new SshKeyPair(fingerprint, name, privateKey); } + + public T fromSshKeyPair(SshKeyPair in) { + return this + .fingerprint(in.getFingerprint()) + .name(in.getName()) + .privateKey(in.getPrivateKey()); + } } - // for deserialization - SshKeyPair() { - + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - private String fingerprint; - private String name; - @SerializedName("privatekey") - private String privateKey; + private final String fingerprint; + private final String name; + @Named("privatekey") + private final String privateKey; - public SshKeyPair(String fingerprint, String name, String privateKey) { + @ConstructorProperties({ + "fingerprint", "name", "privatekey" + }) + protected SshKeyPair(@Nullable String fingerprint, String name, @Nullable String privateKey) { this.fingerprint = fingerprint; - this.name = name; + this.name = checkNotNull(name, "name"); this.privateKey = privateKey; } + @Nullable public String getFingerprint() { - return fingerprint; + return this.fingerprint; } public String getName() { - return name; + return this.name; } + @Nullable public String getPrivateKey() { - return privateKey; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SshKeyPair that = (SshKeyPair) o; - - if (!Objects.equal(fingerprint, that.fingerprint)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(privateKey, that.privateKey)) return false; - - return true; + return this.privateKey; } @Override public int hashCode() { - return Objects.hashCode(fingerprint, name, privateKey); + return Objects.hashCode(fingerprint, name, privateKey); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + SshKeyPair that = SshKeyPair.class.cast(obj); + return Objects.equal(this.fingerprint, that.fingerprint) + && Objects.equal(this.name, that.name) + && Objects.equal(this.privateKey, that.privateKey); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("fingerprint", fingerprint).add("name", name).add("privateKey", privateKey); + } + @Override public String toString() { - return "SshKeyPair{" + - "fingerprint='" + fingerprint + '\'' + - ", name='" + name + '\'' + - ", privateKey='" + privateKey + '\'' + - '}'; - } - - @Override - public int compareTo(SshKeyPair arg0) { - return fingerprint.compareTo(arg0.getFingerprint()); + return string().toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java index 03471a05c5..aa1d8fc533 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,17 +20,22 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.CaseFormat; import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * Represents a storage pool in CloudStack - * + * * @author Richard Downer - */ +*/ public class StoragePool implements Comparable { public enum State { @@ -56,7 +61,7 @@ public class StoragePool implements Comparable { } } - public static enum Type { + public enum Type { FILESYSTEM, NETWORK_FILESYSTEM, ISCSI_LUN, @@ -70,169 +75,264 @@ public class StoragePool implements Comparable { EXT, OCFS2, UNRECOGNIZED; - + @Override public String toString() { - return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); } - + public static Type fromValue(String type) { - try { - return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } } } - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromStoragePool(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); - private Builder() { - } - - private String id; - private String name; - private String path; - private String tags; - private State state; - private Type type; - private String zoneId; - private String zoneName; - private String podId; - private String podName; - private String clusterId; - private String clusterName; - private Date created; - private long diskSizeAllocated; - private long diskSizeTotal; - private String ipAddress; - private String jobId; - private String jobStatus; - - public Builder id(String id) { + protected String id; + protected String name; + protected String path; + protected String tags; + protected StoragePool.State state; + protected StoragePool.Type type; + protected String zoneId; + protected String zoneName; + protected String podId; + protected String podName; + protected String clusterId; + protected String clusterName; + protected Date created; + protected long diskSizeAllocated; + protected long diskSizeTotal; + protected String ipAddress; + protected String jobId; + protected String jobStatus; + + /** + * @see StoragePool#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder name(String name) { + /** + * @see StoragePool#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder path(String path) { + /** + * @see StoragePool#getPath() + */ + public T path(String path) { this.path = path; - return this; + return self(); } - public Builder tags(String tags) { + /** + * @see StoragePool#getTags() + */ + public T tags(String tags) { this.tags = tags; - return this; + return self(); } - public Builder state(State state) { + /** + * @see StoragePool#getState() + */ + public T state(StoragePool.State state) { this.state = state; - return this; + return self(); } - public Builder type(Type type) { + /** + * @see StoragePool#getType() + */ + public T type(StoragePool.Type type) { this.type = type; - return this; + return self(); } - public Builder zoneId(String zoneId) { + /** + * @see StoragePool#getZoneId() + */ + public T zoneId(String zoneId) { this.zoneId = zoneId; - return this; + return self(); } - public Builder zoneName(String zoneName) { + /** + * @see StoragePool#getZoneName() + */ + public T zoneName(String zoneName) { this.zoneName = zoneName; - return this; + return self(); } - public Builder podId(String podId) { + /** + * @see StoragePool#getPodId() + */ + public T podId(String podId) { this.podId = podId; - return this; + return self(); } - public Builder podName(String podName) { + /** + * @see StoragePool#getPodName() + */ + public T podName(String podName) { this.podName = podName; - return this; + return self(); } - public Builder clusterId(String clusterId) { + /** + * @see StoragePool#getClusterId() + */ + public T clusterId(String clusterId) { this.clusterId = clusterId; - return this; + return self(); } - public Builder clusterName(String clusterName) { + /** + * @see StoragePool#getClusterName() + */ + public T clusterName(String clusterName) { this.clusterName = clusterName; - return this; + return self(); } - public Builder created(Date created) { + /** + * @see StoragePool#getCreated() + */ + public T created(Date created) { this.created = created; - return this; + return self(); } - public Builder diskSizeAllocated(long diskSizeAllocated) { + /** + * @see StoragePool#getDiskSizeAllocated() + */ + public T diskSizeAllocated(long diskSizeAllocated) { this.diskSizeAllocated = diskSizeAllocated; - return this; + return self(); } - public Builder diskSizeTotal(long diskSizeTotal) { + /** + * @see StoragePool#getDiskSizeTotal() + */ + public T diskSizeTotal(long diskSizeTotal) { this.diskSizeTotal = diskSizeTotal; - return this; + return self(); } - public Builder ipAddress(String ipAddress) { + /** + * @see StoragePool#getIpAddress() + */ + public T ipAddress(String ipAddress) { this.ipAddress = ipAddress; - return this; + return self(); } - public Builder jobId(String jobId) { + /** + * @see StoragePool#getJobId() + */ + public T jobId(String jobId) { this.jobId = jobId; - return this; + return self(); } - public Builder jobStatus(String jobStatus) { + /** + * @see StoragePool#getJobStatus() + */ + public T jobStatus(String jobStatus) { this.jobStatus = jobStatus; - return this; + return self(); } public StoragePool build() { return new StoragePool(id, name, path, tags, state, type, zoneId, zoneName, podId, podName, clusterId, clusterName, created, diskSizeAllocated, diskSizeTotal, ipAddress, jobId, jobStatus); } + + public T fromStoragePool(StoragePool in) { + return this + .id(in.getId()) + .name(in.getName()) + .path(in.getPath()) + .tags(in.getTags()) + .state(in.getState()) + .type(in.getType()) + .zoneId(in.getZoneId()) + .zoneName(in.getZoneName()) + .podId(in.getPodId()) + .podName(in.getPodName()) + .clusterId(in.getClusterId()) + .clusterName(in.getClusterName()) + .created(in.getCreated()) + .diskSizeAllocated(in.getDiskSizeAllocated()) + .diskSizeTotal(in.getDiskSizeTotal()) + .ipAddress(in.getIpAddress()) + .jobId(in.getJobId()) + .jobStatus(in.getJobStatus()); + } } - private String id; - private String name; - private String path; - private String tags; - private State state; - private Type type; - @SerializedName("zoneid") private String zoneId; - @SerializedName("zonename") private String zoneName; - @SerializedName("podid") private String podId; - @SerializedName("podname") private String podName; - @SerializedName("clusterid") private String clusterId; - @SerializedName("clustername") private String clusterName; - private Date created; - @SerializedName("disksizeallocated") private long diskSizeAllocated; - @SerializedName("disksizetotal") private long diskSizeTotal; - @SerializedName("ipaddress") private String ipAddress; - @SerializedName("jobid") private String jobId; - @SerializedName("jobstatus") private String jobStatus; - - /* Exists only for the serializer */ - StoragePool() { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public StoragePool(String id, String name, String path, String tags, State state, Type type, String zoneId, String zoneName, String podId, String podName, String clusterId, String clusterName, Date created, long diskSizeAllocated, long diskSizeTotal, String ipAddress, String jobId, String jobStatus) { - this.id = id; + private final String id; + private final String name; + private final String path; + private final String tags; + private final StoragePool.State state; + private final StoragePool.Type type; + @Named("zoneid") + private final String zoneId; + @Named("zonename") + private final String zoneName; + @Named("podid") + private final String podId; + @Named("podname") + private final String podName; + @Named("clusterid") + private final String clusterId; + @Named("clustername") + private final String clusterName; + private final Date created; + @Named("disksizeallocated") + private final long diskSizeAllocated; + @Named("disksizetotal") + private final long diskSizeTotal; + @Named("ipaddress") + private final String ipAddress; + @Named("jobid") + private final String jobId; + @Named("jobstatus") + private final String jobStatus; + + @ConstructorProperties({ + "id", "name", "path", "tags", "state", "type", "zoneid", "zonename", "podid", "podname", "clusterid", "clustername", "created", "disksizeallocated", "disksizetotal", "ipaddress", "jobid", "jobstatus" + }) + protected StoragePool(String id, @Nullable String name, @Nullable String path, @Nullable String tags, @Nullable StoragePool.State state, @Nullable StoragePool.Type type, @Nullable String zoneId, @Nullable String zoneName, @Nullable String podId, @Nullable String podName, @Nullable String clusterId, @Nullable String clusterName, @Nullable Date created, long diskSizeAllocated, long diskSizeTotal, @Nullable String ipAddress, @Nullable String jobId, @Nullable String jobStatus) { + this.id = checkNotNull(id, "id"); this.name = name; this.path = path; this.tags = tags; @@ -253,137 +353,132 @@ public class StoragePool implements Comparable { } public String getId() { - return id; + return this.id; } + @Nullable public String getName() { - return name; + return this.name; } + @Nullable public String getPath() { - return path; + return this.path; } + @Nullable public String getTags() { - return tags; + return this.tags; } - public State getState() { - return state; + @Nullable + public StoragePool.State getState() { + return this.state; } - public Type getType() { - return type; + @Nullable + public StoragePool.Type getType() { + return this.type; } + @Nullable public String getZoneId() { - return zoneId; + return this.zoneId; } + @Nullable public String getZoneName() { - return zoneName; + return this.zoneName; } + @Nullable public String getPodId() { - return podId; + return this.podId; } + @Nullable public String getPodName() { - return podName; + return this.podName; } + @Nullable public String getClusterId() { - return clusterId; + return this.clusterId; } + @Nullable public String getClusterName() { - return clusterName; + return this.clusterName; } + @Nullable public Date getCreated() { - return created; + return this.created; } public long getDiskSizeAllocated() { - return diskSizeAllocated; + return this.diskSizeAllocated; } public long getDiskSizeTotal() { - return diskSizeTotal; + return this.diskSizeTotal; } + @Nullable public String getIpAddress() { - return ipAddress; + return this.ipAddress; } + @Nullable public String getJobId() { - return jobId; + return this.jobId; } + @Nullable public String getJobStatus() { - return jobStatus; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - StoragePool that = (StoragePool) o; - - if (!Objects.equal(clusterId, that.clusterId)) return false; - if (!Objects.equal(diskSizeAllocated, that.diskSizeAllocated)) return false; - if (!Objects.equal(diskSizeTotal, that.diskSizeTotal)) return false; - if (!Objects.equal(id, that.id)) return false; - if (!Objects.equal(podId, that.podId)) return false; - if (!Objects.equal(zoneId, that.zoneId)) return false; - if (!Objects.equal(clusterName, that.clusterName)) return false; - if (!Objects.equal(created, that.created)) return false; - if (!Objects.equal(ipAddress, that.ipAddress)) return false; - if (!Objects.equal(jobId, that.jobId)) return false; - if (!Objects.equal(jobStatus, that.jobStatus)) return false; - if (!Objects.equal(name, that.name)) return false; - if (!Objects.equal(path, that.path)) return false; - if (!Objects.equal(podName, that.podName)) return false; - if (!Objects.equal(state, that.state)) return false; - if (!Objects.equal(tags, that.tags)) return false; - if (!Objects.equal(type, that.type)) return false; - if (!Objects.equal(zoneName, that.zoneName)) return false; - - return true; + return this.jobStatus; } @Override public int hashCode() { - return Objects.hashCode(clusterId, diskSizeAllocated, diskSizeTotal, id, podId, zoneId, - clusterName, created, ipAddress, jobId, jobStatus, name, path, - podName, state, tags, type, zoneName); + return Objects.hashCode(id, name, path, tags, state, type, zoneId, zoneName, podId, podName, clusterId, clusterName, created, diskSizeAllocated, diskSizeTotal, ipAddress, jobId, jobStatus); } @Override - public String toString() { - return "StoragePool{" + - "id=" + id + - ", name='" + name + '\'' + - ", path='" + path + '\'' + - ", tags='" + tags + '\'' + - ", state=" + state + - ", type=" + type + - ", zoneId=" + zoneId + - ", zoneName='" + zoneName + '\'' + - ", podId=" + podId + - ", podName='" + podName + '\'' + - ", clusterId=" + clusterId + - ", clusterName='" + clusterName + '\'' + - ", created=" + created + - ", diskSizeAllocated=" + diskSizeAllocated + - ", diskSizeTotal=" + diskSizeTotal + - ", ipAddress='" + ipAddress + '\'' + - ", jobId=" + jobId + - ", jobStatus='" + jobStatus + '\'' + - '}'; + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + StoragePool that = StoragePool.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.name, that.name) + && Objects.equal(this.path, that.path) + && Objects.equal(this.tags, that.tags) + && Objects.equal(this.state, that.state) + && Objects.equal(this.type, that.type) + && Objects.equal(this.zoneId, that.zoneId) + && Objects.equal(this.zoneName, that.zoneName) + && Objects.equal(this.podId, that.podId) + && Objects.equal(this.podName, that.podName) + && Objects.equal(this.clusterId, that.clusterId) + && Objects.equal(this.clusterName, that.clusterName) + && Objects.equal(this.created, that.created) + && Objects.equal(this.diskSizeAllocated, that.diskSizeAllocated) + && Objects.equal(this.diskSizeTotal, that.diskSizeTotal) + && Objects.equal(this.ipAddress, that.ipAddress) + && Objects.equal(this.jobId, that.jobId) + && Objects.equal(this.jobStatus, that.jobStatus); } - + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("path", path).add("tags", tags).add("state", state).add("type", type).add("zoneId", zoneId).add("zoneName", zoneName).add("podId", podId).add("podName", podName).add("clusterId", clusterId).add("clusterName", clusterName).add("created", created).add("diskSizeAllocated", diskSizeAllocated).add("diskSizeTotal", diskSizeTotal).add("ipAddress", ipAddress).add("jobId", jobId).add("jobStatus", jobStatus); + } + + @Override + public String toString() { + return string().toString(); + } + @Override public int compareTo(StoragePool other) { return this.id.compareTo(other.id); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java index 52fc1efcf5..92f382e9f8 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,66 +20,69 @@ package org.jclouds.cloudstack.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; -import javax.annotation.Nullable; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * @author Adrian Cole - */ +*/ public class Template implements Comparable