diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/AbsoluteLimit.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/AbsoluteLimit.java index a0322057b4..cd110a54c6 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/AbsoluteLimit.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/AbsoluteLimit.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,30 +18,108 @@ */ package org.jclouds.openstack.nova.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** * * @author Adrian Cole - */ +*/ public class AbsoluteLimit { - protected String name; - protected int value; + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromAbsoluteLimit(this); + } - public String getName() { - return name; - } + public static abstract class Builder> { + protected abstract T self(); - public void setName(String value) { - this.name = value; - } + protected String name; + protected int value; + + /** + * @see AbsoluteLimit#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } - public int getValue() { - return value; - } + /** + * @see AbsoluteLimit#getValue() + */ + public T value(int value) { + this.value = value; + return self(); + } - public void setValue(int value) { - this.value = value; - } + public AbsoluteLimit build() { + return new AbsoluteLimit(name, value); + } + + public T fromAbsoluteLimit(AbsoluteLimit 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 int value; + + @ConstructorProperties({ + "name", "value" + }) + protected AbsoluteLimit(String name, int value) { + this.name = checkNotNull(name, "name"); + this.value = value; + } + + public String getName() { + return this.name; + } + + public int getValue() { + return this.value; + } + + @Override + public int hashCode() { + return Objects.hashCode(name, value); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + AbsoluteLimit that = AbsoluteLimit.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 string().toString(); + } } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Address.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Address.java index 2e3eef910c..b4f60bc26e 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Address.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Address.java @@ -1,98 +1,149 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.openstack.nova.domain; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.base.Function; -import com.google.gson.annotations.SerializedName; - -/** - * @author Dmitri Babaev - */ -public class Address { - @SerializedName("addr") - private String address; - private int version; - - //for de-serialization - @SuppressWarnings("unused") - private Address() { - } - - public Address(String address, int version) { - this.address = address; - this.version = version; - } - - public String getAddress() { - return address; - } - - public int getVersion() { - return version; - } - - @Override - public String toString() { - return address; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Address address1 = (Address) o; - - if (version != address1.version) return false; - if (address != null ? !address.equals(address1.address) : address1.address != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = address != null ? address.hashCode() : 0; - result = 31 * result + version; - return result; - } - - public static Function newAddress2StringFunction() { - return new Function() { - @Override - public String apply(@Nullable Address input) { - return input.getAddress(); - } - }; - } - - public static Address valueOf(String address) { - return new Address(address, address.startsWith("::") ? 6 : 4); - } - - public static Function newString2AddressFunction() { - return new Function() { - @Override - public Address apply(@Nullable String input) { - return valueOf(input); - } - }; - } -} +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +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; + +/** + * @author Dmitri Babaev +*/ +public class Address { + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromAddress(this); + } + + public static Function newAddress2StringFunction() { + return new Function() { + @Override + public String apply(@Nullable Address input) { + return input.getAddress(); + } + }; + } + + public static Address valueOf(String address) { + return new Address(address, address.startsWith("::") ? 6 : 4); + } + + public static Function newString2AddressFunction() { + return new Function() { + @Override + public Address apply(@Nullable String input) { + return valueOf(input); + } + }; + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String address; + protected int version; + + /** + * @see Address#getAddress() + */ + public T address(String address) { + this.address = address; + return self(); + } + + /** + * @see Address#getVersion() + */ + public T version(int version) { + this.version = version; + return self(); + } + + public Address build() { + return new Address(address, version); + } + + public T fromAddress(Address in) { + return this + .address(in.getAddress()) + .version(in.getVersion()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String address; + private final int version; + + @ConstructorProperties({ + "addr", "version" + }) + protected Address(String address, int version) { + this.address = checkNotNull(address, "address"); + this.version = version; + } + + public String getAddress() { + return this.address; + } + + public int getVersion() { + return this.version; + } + + @Override + public int hashCode() { + return Objects.hashCode(address, version); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Address that = Address.class.cast(obj); + return Objects.equal(this.address, that.address) + && Objects.equal(this.version, that.version); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("address", address).add("version", version); + } + + @Override + public String toString() { + return string().toString(); + } + +} diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Addresses.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Addresses.java index 40887dfd98..f4ea5573c9 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Addresses.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Addresses.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,81 +18,119 @@ */ package org.jclouds.openstack.nova.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Collection; import java.util.Set; -import com.google.common.collect.Sets; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * * @author Adrian Cole - */ +*/ public class Addresses { - @SerializedName("public") - private Set
publicAddresses = Sets.newLinkedHashSet(); - @SerializedName("private") - private Set
privateAddresses = Sets.newLinkedHashSet(); - - public Addresses() { + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromAddresses(this); } - public Addresses(Set
publicAddresses, Set
privateAddresses) { - this.publicAddresses = publicAddresses; - this.privateAddresses = privateAddresses; + public static abstract class Builder> { + protected abstract T self(); + + protected Set
publicAddresses = ImmutableSet.of(); + protected Set
privateAddresses = ImmutableSet.of(); + + /** + * @see Addresses#getPublicAddresses() + */ + public T publicAddresses(Collection
publicAddresses) { + this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses")); + return self(); + } + + public T publicAddresses(Address... in) { + return publicAddresses(ImmutableSet.copyOf(in)); + } + + /** + * @see Addresses#getPrivateAddresses() + */ + public T privateAddresses(Collection
privateAddresses) { + this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses")); + return self(); + } + + public T privateAddresses(Address... in) { + return privateAddresses(ImmutableSet.copyOf(in)); + } + + public Addresses build() { + return new Addresses(publicAddresses, privateAddresses); + } + + public T fromAddresses(Addresses in) { + return this + .publicAddresses(in.getPublicAddresses()) + .privateAddresses(in.getPrivateAddresses()); + } } - public void setPublicAddresses(Set
publicAddresses) { - this.publicAddresses = publicAddresses; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final Set
publicAddresses; + private final Set
privateAddresses; + + @ConstructorProperties({ + "public", "private" + }) + protected Addresses(Set
publicAddresses, Set
privateAddresses) { + this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses")); + this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses")); } public Set
getPublicAddresses() { - return publicAddresses; - } - - public void setPrivateAddresses(Set
privateAddresses) { - this.privateAddresses = privateAddresses; + return this.publicAddresses; } public Set
getPrivateAddresses() { - return privateAddresses; - } - - @Override - public String toString() { - return "Addresses [privateAddresses=" + privateAddresses + ", publicAddresses=" - + publicAddresses + "]"; + return this.privateAddresses; } @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode()); - result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode()); - return result; + return Objects.hashCode(publicAddresses, privateAddresses); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Addresses other = (Addresses) obj; - if (privateAddresses == null) { - if (other.privateAddresses != null) - return false; - } else if (!privateAddresses.equals(other.privateAddresses)) - return false; - if (publicAddresses == null) { - if (other.publicAddresses != null) - return false; - } else if (!publicAddresses.equals(other.publicAddresses)) - return false; - return true; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Addresses that = Addresses.class.cast(obj); + return Objects.equal(this.publicAddresses, that.publicAddresses) + && Objects.equal(this.privateAddresses, that.privateAddresses); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("publicAddresses", publicAddresses).add("privateAddresses", privateAddresses); + } + + @Override + public String toString() { + return string().toString(); } } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java index f0491e19c8..b169c5657b 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.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,106 +18,146 @@ */ package org.jclouds.openstack.nova.domain; +import java.beans.ConstructorProperties; +import java.net.URI; +import java.util.List; +import java.util.Map; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + /** - * * A flavor is an available hardware configuration for a server. Each flavor has a unique * combination of disk space and memory capacity. - * + * * @author Adrian Cole */ public class Flavor extends Resource { - private final int id; + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromFlavor(this); + } + + public static abstract class Builder> extends Resource.Builder { + protected String name; + protected Integer disk; + protected Integer ram; + protected Integer vcpus; + + /** + * @see Flavor#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + /** + * @see Flavor#getDisk() + */ + public T disk(Integer disk) { + this.disk = disk; + return self(); + } + + /** + * @see Flavor#getRam() + */ + public T ram(Integer ram) { + this.ram = ram; + return self(); + } + + /** + * @see Flavor#getVcpus() + */ + public T vcpus(Integer vcpus) { + this.vcpus = vcpus; + return self(); + } + + public Flavor build() { + return new Flavor(id, links, orderedSelfReferences, name, disk, ram, vcpus); + } + + public T fromFlavor(Flavor in) { + return super.fromResource(in) + .name(in.getName()) + .disk(in.getDisk()) + .ram(in.getRam()) + .vcpus(in.getVcpus()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + private final String name; private final Integer disk; private final Integer ram; private final Integer vcpus; - //Required because of how Gson is being used to do wire marshalling with the Server class - private Flavor(){ - id=0; - name=null; - disk=null; - ram=null; - vcpus=null; - } - - public Flavor(int id, String name, Integer disk, Integer ram, Integer vcpus) { - this.id = id; + @ConstructorProperties({ + "id", "links", "orderedSelfReferences", "name", "disk", "ram", "vcpus" + }) + protected Flavor(int id, List> links, @Nullable Map orderedSelfReferences, + @Nullable String name, @Nullable Integer disk, @Nullable Integer ram, @Nullable Integer vcpus) { + super(id, links, orderedSelfReferences); this.name = name; this.disk = disk; this.ram = ram; this.vcpus = vcpus; } - public Integer getDisk() { - return disk; - } - - public int getId() { - return id; - } - + @Nullable public String getName() { - return name; + return this.name; } + @Nullable + public Integer getDisk() { + return this.disk; + } + + @Nullable public Integer getRam() { - return ram; + return this.ram; } + @Nullable public Integer getVcpus() { - return vcpus; + return this.vcpus; } @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((disk == null) ? 0 : disk.hashCode()); - result = prime * result + id; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((ram == null) ? 0 : ram.hashCode()); - result = prime * result + ((vcpus == null) ? 0 : vcpus.hashCode()); - return result; + return Objects.hashCode(super.hashCode(), name, disk, ram, vcpus); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Flavor other = (Flavor) obj; - if (disk == null) { - if (other.disk != null) - return false; - } else if (!disk.equals(other.disk)) - return false; - if (id != other.id) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (ram == null) { - if (other.ram != null) - return false; - } else if (!ram.equals(other.ram)) - return false; - if (vcpus == null) { - if (other.vcpus != null) - return false; - } else if (!vcpus.equals(other.vcpus)) - return false; - return true; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Flavor that = Flavor.class.cast(obj); + return super.equals(that) + && Objects.equal(this.name, that.name) + && Objects.equal(this.disk, that.disk) + && Objects.equal(this.ram, that.ram) + && Objects.equal(this.vcpus, that.vcpus); } - @Override - public String toString() { - return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + ", vcpus=" + vcpus +"]"; + protected ToStringHelper string() { + return super.string().add("name", name).add("disk", disk).add("ram", ram).add("vcpus", vcpus); } + } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/FloatingIP.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/FloatingIP.java index cefc53b84d..cb3f206940 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/FloatingIP.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/FloatingIP.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,153 +18,134 @@ */ package org.jclouds.openstack.nova.domain; -import com.google.gson.annotations.SerializedName; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.net.URI; +import java.util.List; +import java.util.Map; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** * Check Floating IP Wiki * page. Available since OpenStack Diablo release and API 1.1. * * @author chamerling - * - */ +*/ public class FloatingIP extends Resource { - - private int id; - - private String ip; - - @SerializedName(value="fixed_ip") - private String fixedIP; - - @SerializedName(value = "instance_id") - private int instanceID; - @SuppressWarnings("unused") - private FloatingIP() { - } + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromFloatingIP(this); + } - public FloatingIP(int id, String ip, String fixedIP, int instanceID) { - this.id = id; - this.ip = ip; - this.fixedIP = fixedIP; - this.instanceID = instanceID; - } + public static abstract class Builder> extends Resource.Builder { + protected String ip; + protected String fixedIP; + protected int instanceID; + + /** + * @see FloatingIP#getIp() + */ + public T ip(String ip) { + this.ip = ip; + return self(); + } - /** - * @return the id - */ - public int getId() { - return id; - } + /** + * @see FloatingIP#getFixedIP() + */ + public T fixedIP(String fixedIP) { + this.fixedIP = fixedIP; + return self(); + } - /** - * @param id the id to set - */ - public void setId(int id) { - this.id = id; - } + /** + * @see FloatingIP#getInstanceID() + */ + public T instanceID(int instanceID) { + this.instanceID = instanceID; + return self(); + } - /** - * @return the ip - */ - public String getIp() { - return ip; - } + public FloatingIP build() { + return new FloatingIP(id, links, orderedSelfReferences, ip, fixedIP, instanceID); + } + + public T fromFloatingIP(FloatingIP in) { + return super.fromResource(in) + .ip(in.getIp()) + .fixedIP(in.getFixedIP()) + .instanceID(in.getInstanceID()); + } + } - /** - * @param ip the ip to set - */ - public void setIp(String ip) { - this.ip = ip; - } + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - /** - * @return the fixedIP - */ - public String getFixedIP() { - return fixedIP; - } + private final String ip; + private final String fixedIP; + private final int instanceID; - /** - * @param fixedIP the fixedIP to set - */ - public void setFixedIP(String fixedIP) { - this.fixedIP = fixedIP; - } + @ConstructorProperties({ + "id", "links", "orderedSelfReferences", "ip", "fixed_ip", "instance_id" + }) + protected FloatingIP(int id, List> links, Map orderedSelfReferences, String ip, + String fixedIP, int instanceID) { + super(id, links, orderedSelfReferences); + this.ip = checkNotNull(ip, "ip"); + this.fixedIP = checkNotNull(fixedIP, "fixedIP"); + this.instanceID = instanceID; + } - /** - * @return the instanceID - */ - public int getInstanceID() { - return instanceID; - } + /** + * @return the ip + */ + public String getIp() { + return this.ip; + } - /** - * @param instanceID the instanceID to set - */ - public void setInstanceID(int instanceID) { - this.instanceID = instanceID; - } + /** + * @return the fixedIP + */ + public String getFixedIP() { + return this.fixedIP; + } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("FloatingIP [id="); - builder.append(id); - builder.append(", ip="); - builder.append(ip); - builder.append(", fixedIP="); - builder.append(fixedIP); - builder.append(", instanceID="); - builder.append(instanceID); - builder.append("]"); - return builder.toString(); - } + /** + * @return the instanceID + */ + public int getInstanceID() { + return this.instanceID; + } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((fixedIP == null) ? 0 : fixedIP.hashCode()); - result = prime * result + id; - result = prime * result + instanceID; - result = prime * result + ((ip == null) ? 0 : ip.hashCode()); - return result; - } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), ip, fixedIP, instanceID); + } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - FloatingIP other = (FloatingIP) obj; - if (fixedIP == null) { - if (other.fixedIP != null) - return false; - } else if (!fixedIP.equals(other.fixedIP)) - return false; - if (id != other.id) - return false; - if (instanceID != other.instanceID) - return false; - if (ip == null) { - if (other.ip != null) - return false; - } else if (!ip.equals(other.ip)) - return false; - return true; - } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + FloatingIP that = FloatingIP.class.cast(obj); + return super.equals(that) + && Objects.equal(this.ip, that.ip) + && Objects.equal(this.fixedIP, that.fixedIP) + && Objects.equal(this.instanceID, that.instanceID); + } + + protected ToStringHelper string() { + return super.string().add("ip", ip).add("fixedIP", fixedIP).add("instanceID", instanceID); + } } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Image.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Image.java index 9e3e4d8420..b1dc9fc1a1 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Image.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Image.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,11 +18,19 @@ */ package org.jclouds.openstack.nova.domain; -import java.util.Collections; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.net.URI; import java.util.Date; +import java.util.List; import java.util.Map; -import com.google.common.collect.Maps; +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableMap; /** * An image is a collection of files used to create or rebuild a server. Rackspace provides a number @@ -34,122 +42,179 @@ import com.google.common.collect.Maps; */ public class Image extends Resource { - private int id; - private String name; - private Integer progress; - private String serverRef; - private ImageStatus status; - private Map metadata = Maps.newHashMap(); - - private Date created; - private Date updated; - - public Date getCreated() { - return created; + public static Builder builder() { + return new ConcreteBuilder(); } - public Date getUpdated() { - return updated; + public Builder toBuilder() { + return new ConcreteBuilder().fromImage(this); } + public static abstract class Builder> extends Resource.Builder { + protected String name; + protected Integer progress; + protected String serverRef; + protected ImageStatus status; + protected Map metadata = ImmutableMap.of(); + protected Date created; + protected Date updated; - public Image() { + /** + * @see Image#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + /** + * @see Image#getProgress() + */ + public T progress(Integer progress) { + this.progress = progress; + return self(); + } + + /** + * @see Image#getServerRef() + */ + public T serverRef(String serverRef) { + this.serverRef = serverRef; + return self(); + } + + /** + * @see Image#getStatus() + */ + public T status(ImageStatus status) { + this.status = status; + return self(); + } + + /** + * @see Image#getMetadata() + */ + public T metadata(Map metadata) { + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); + return self(); + } + + /** + * @see Image#getCreated() + */ + public T created(Date created) { + this.created = created; + return self(); + } + + /** + * @see Image#getUpdated() + */ + public T updated(Date updated) { + this.updated = updated; + return self(); + } + + public Image build() { + return new Image(id, links, orderedSelfReferences, name, progress, serverRef, status, metadata, created, updated); + } + + public T fromImage(Image in) { + return super.fromResource(in) + .id(in.getId()) + .name(in.getName()) + .progress(in.getProgress()) + .serverRef(in.getServerRef()) + .status(in.getStatus()) + .metadata(in.getMetadata()) + .created(in.getCreated()) + .updated(in.getUpdated()); + } } - public Image(int id, String name) { - this.id = id; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String name; + private final Integer progress; + private final String serverRef; + private final ImageStatus status; + private final Map metadata; + private final Date created; + private final Date updated; + + @ConstructorProperties({ + "id", "links", "orderedSelfReferences", "name", "progress", "serverRef", "status", "metadata", "created", "updated" + }) + protected Image(int id, List> links, @Nullable Map orderedSelfReferences, @Nullable String name, + @Nullable Integer progress, @Nullable String serverRef, @Nullable ImageStatus status, @Nullable Map metadata, + @Nullable Date created, @Nullable Date updated) { + super(id, links, orderedSelfReferences); this.name = name; - } - - - public void setId(int id) { - this.id = id; - } - - public int getId() { - return id; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setProgress(Integer progress) { this.progress = progress; - } - - public Integer getProgress() { - return progress; - } - - public void setServerRef(String serverRef) { this.serverRef = serverRef; + this.status = status == null ? ImageStatus.UNKNOWN : status; + this.metadata = metadata == null ? ImmutableMap.of() : ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); + this.created = created; + this.updated = updated; } + @Nullable + public String getName() { + return this.name; + } + + @Nullable + public Integer getProgress() { + return this.progress; + } + + @Nullable public String getServerRef() { - return serverRef; - } - - public void setStatus(ImageStatus status) { - this.status = status; + return this.serverRef; } + @Nullable public ImageStatus getStatus() { - return status; + return this.status; } - public Map getMetadata() { - return Collections.unmodifiableMap(metadata); + return this.metadata; } - public void setMetadata(Map metadata) { - this.metadata = Maps.newHashMap(metadata); + @Nullable + public Date getCreated() { + return this.created; + } + + @Nullable + public Date getUpdated() { + return this.updated; } - /** - * note that this ignores some fields - */ @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((serverRef == null) ? 0 : serverRef.hashCode()); - return result; + return Objects.hashCode(super.hashCode(), name, serverRef); } - /** - * note that this ignores some fields - */ @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Image other = (Image) obj; - if (id != other.id) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Image that = Image.class.cast(obj); + return super.equals(that) + && Objects.equal(this.name, that.name) + && Objects.equal(this.serverRef, that.serverRef); } - @Override - public String toString() { - return "Image [created=" + getCreated() + ", id=" + id + ", name=" + name + ", serverRef=" - + serverRef + "]"; + protected ToStringHelper string() { + return super.string().add("name", name).add("progress", progress).add("serverRef", serverRef).add("status", status) + .add("metadata", metadata).add("created", created).add("updated", updated); } } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Limits.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Limits.java index 8f4b908a40..28cab7b885 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Limits.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Limits.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,114 @@ */ package org.jclouds.openstack.nova.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.util.List; -import com.google.common.collect.Lists; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableList; public class Limits { - private List rate = Lists.newArrayList(); - private List absolute = Lists.newArrayList(); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromLimits(this); + } - public void setRate(List rate) { - this.rate = rate; + public static abstract class Builder> { + protected abstract T self(); + + protected List rate = ImmutableList.of(); + protected List absolute = ImmutableList.of(); + + /** + * @see Limits#getRate() + */ + public T rate(List rate) { + this.rate = ImmutableList.copyOf(checkNotNull(rate, "rate")); + return self(); + } + + public T rate(RateLimit... in) { + return rate(ImmutableList.copyOf(in)); + } + + /** + * @see Limits#getAbsolute() + */ + public T absolute(List absolute) { + this.absolute = ImmutableList.copyOf(checkNotNull(absolute, "absolute")); + return self(); + } + + public T absolute(AbsoluteLimit... in) { + return absolute(ImmutableList.copyOf(in)); + } + + public Limits build() { + return new Limits(rate, absolute); + } + + public T fromLimits(Limits in) { + return this + .rate(in.getRate()) + .absolute(in.getAbsolute()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final List rate; + private final List absolute; + + @ConstructorProperties({ + "rate", "absolute" + }) + protected Limits(List rate, List absolute) { + this.rate = ImmutableList.copyOf(checkNotNull(rate, "rate")); + this.absolute = ImmutableList.copyOf(checkNotNull(absolute, "absolute")); } public List getRate() { - return rate; - } - - public void setAbsolute(List absolute) { - this.absolute = absolute; + return this.rate; } public List getAbsolute() { - return absolute; + return this.absolute; + } + + @Override + public int hashCode() { + return Objects.hashCode(rate, absolute); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Limits that = Limits.class.cast(obj); + return Objects.equal(this.rate, that.rate) + && Objects.equal(this.absolute, that.absolute); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("rate", rate).add("absolute", absolute); + } + + @Override + public String toString() { + return string().toString(); } } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/RateLimit.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/RateLimit.java index 87dabfd759..d3c779f55a 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/RateLimit.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/RateLimit.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,10 +18,16 @@ */ package org.jclouds.openstack.nova.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + import javax.ws.rs.HttpMethod; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + /** - * * RateLimit. *

* we specify rate limits in terms of both a human readable wild-card URI and a machine processable @@ -36,9 +42,107 @@ import javax.ws.rs.HttpMethod; * will be returned with a Reply-After header to notify the client when theyagain. * * @author Adrian Cole - */ +*/ public class RateLimit { + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromRateLimit(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String uri; + protected String regex; + protected int remaining; + protected long resetTime; + protected RateLimitUnit unit; + protected int value; + protected HttpMethod verb; + + /** + * @see RateLimit#getUri() + */ + public T uri(String uri) { + this.uri = uri; + return self(); + } + + /** + * @see RateLimit#getRegex() + */ + public T regex(String regex) { + this.regex = regex; + return self(); + } + + /** + * @see RateLimit#getRemaining() + */ + public T remaining(int remaining) { + this.remaining = remaining; + return self(); + } + + /** + * @see RateLimit#getResetTime() + */ + public T resetTime(long resetTime) { + this.resetTime = resetTime; + return self(); + } + + /** + * @see RateLimit#getUnit() + */ + public T unit(RateLimitUnit unit) { + this.unit = unit; + return self(); + } + + /** + * @see RateLimit#getValue() + */ + public T value(int value) { + this.value = value; + return self(); + } + + /** + * @see RateLimit#getVerb() + */ + public T verb(HttpMethod verb) { + this.verb = verb; + return self(); + } + + public RateLimit build() { + return new RateLimit(uri, regex, remaining, resetTime, unit, value, verb); + } + + public T fromRateLimit(RateLimit in) { + return this + .uri(in.getUri()) + .regex(in.getRegex()) + .remaining(in.getRemaining()) + .resetTime(in.getResetTime()) + .unit(in.getUnit()) + .value(in.getValue()) + .verb(in.getVerb()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + private final String uri; private final String regex; private final int remaining; @@ -47,43 +151,74 @@ public class RateLimit { private final int value; private final HttpMethod verb; - public RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit, - int value, HttpMethod verb) { - this.uri = uri; - this.regex = regex; + @ConstructorProperties({ + "uri", "regex", "remaining", "resetTime", "unit", "value", "verb" + }) + protected RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit, int value, HttpMethod verb) { + this.uri = checkNotNull(uri, "uri"); + this.regex = checkNotNull(regex, "regex"); this.remaining = remaining; this.resetTime = resetTime; - this.unit = unit; + this.unit = checkNotNull(unit, "unit"); this.value = value; - this.verb = verb; + this.verb = checkNotNull(verb, "verb"); } public String getUri() { - return uri; + return this.uri; } public String getRegex() { - return regex; + return this.regex; } public int getRemaining() { - return remaining; + return this.remaining; } public long getResetTime() { - return resetTime; + return this.resetTime; } public RateLimitUnit getUnit() { - return unit; + return this.unit; } public int getValue() { - return value; + return this.value; } public HttpMethod getVerb() { - return verb; + return this.verb; + } + + @Override + public int hashCode() { + return Objects.hashCode(uri, regex, remaining, resetTime, unit, value, verb); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + RateLimit that = RateLimit.class.cast(obj); + return Objects.equal(this.uri, that.uri) + && Objects.equal(this.regex, that.regex) + && Objects.equal(this.remaining, that.remaining) + && Objects.equal(this.resetTime, that.resetTime) + && Objects.equal(this.unit, that.unit) + && Objects.equal(this.value, that.value) + && Objects.equal(this.verb, that.verb); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("uri", uri).add("regex", regex).add("remaining", remaining).add("resetTime", resetTime).add("unit", unit).add("value", value).add("verb", verb); + } + + @Override + public String toString() { + return string().toString(); } } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java index 8dea23f058..53ff322bfb 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.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,65 +18,127 @@ */ package org.jclouds.openstack.nova.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.net.URI; import java.net.URISyntaxException; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentSkipListMap; -import javax.annotation.Nullable; +import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Functions; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Predicate; -import com.google.common.collect.Lists; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; /** * @author Dmitri Babaev * @author Matt Stephenson */ -public class Resource { +public abstract class Resource { - private List> links = Lists.newArrayList(); + public static enum LinkType { + BOOKMARK_JSON(new Predicate>() { + @Override + public boolean apply(@Nullable Map linkMap) { + return Functions.forMap(linkMap, "").apply("rel").equals("bookmark") && + Functions.forMap(linkMap, "").apply("type").contains("json"); + } + }), + BOOKMARK_ANY(new Predicate>() { + @Override + public boolean apply(@Nullable Map linkMap) { + return Functions.forMap(linkMap, "").apply("rel").equals("bookmark"); + } + }), + SELF(new Predicate>() { + @Override + public boolean apply(@Nullable Map linkMap) { + return Functions.forMap(linkMap, "").apply("rel").equals("self"); + } + }); - //This is the preference order for returning a URI in getURI - private enum LinkType { - BOOKMARK_JSON(new Predicate>() { - @Override - public boolean apply(@Nullable Map linkMap) { - return Functions.forMap(linkMap, "").apply("rel").equals("bookmark") && - Functions.forMap(linkMap, "").apply("type").contains("json"); - } - }), - BOOKMARK_ANY(new Predicate>() { - @Override - public boolean apply(@Nullable Map linkMap) { - return Functions.forMap(linkMap, "").apply("rel").equals("bookmark"); - } - }), - SELF(new Predicate>() { - @Override - public boolean apply(@Nullable Map linkMap) { - return Functions.forMap(linkMap, "").apply("rel").equals("self"); - } - }); + Predicate> linkPredicate; - Predicate> linkPredicate; - - LinkType(Predicate> linkPredicate) { - this.linkPredicate = linkPredicate; - }; + LinkType(Predicate> linkPredicate) { + this.linkPredicate = linkPredicate; + } } - private final ConcurrentSkipListMap orderedSelfReferences; + public static abstract class Builder> { + protected abstract T self(); - public Resource(){ - orderedSelfReferences = new ConcurrentSkipListMap(); + protected int id; + protected List> links = ImmutableList.of(); + protected Map orderedSelfReferences; + + /** + * @see Resource#getId() + */ + public T id(int id) { + this.id = id; + return self(); + } + + /** + * @see Resource#getLinks() + */ + public T links(List> links) { + this.links = ImmutableList.copyOf(checkNotNull(links, "links")); + return self(); + } + + public T links(Map... in) { + return links(ImmutableList.copyOf(in)); + } + + + /** + * @see Resource#getOrderedSelfReferences() + */ + public T orderedSelfReferences(Map orderedSelfReferences) { + this.orderedSelfReferences = ImmutableMap.copyOf(orderedSelfReferences); + return self(); + } + + public T fromResource(Resource in) { + return this + .links(in.getLinks()) + .orderedSelfReferences(in.getOrderedSelfReferences()); + } + } + + private final int id; + private final List> links; + private final ConcurrentSkipListMap orderedSelfReferences; + + protected Resource(int id, List> links, @Nullable Map orderedSelfReferences) { + this.id = id; + this.links = links == null ? ImmutableList.>of() : ImmutableList.copyOf(checkNotNull(links, "links")); + this.orderedSelfReferences = orderedSelfReferences == null ? new ConcurrentSkipListMap() : new ConcurrentSkipListMap(orderedSelfReferences); + } + + public int getId() { + return id; + } + + public List> getLinks() { + return this.links; + } + + public Map getOrderedSelfReferences() { + return this.orderedSelfReferences; } private void populateOrderedSelfReferences() { for (Map linkProperties : links) { for (LinkType type : LinkType.values()) { - if(type.linkPredicate.apply(linkProperties)) { + if (type.linkPredicate.apply(linkProperties)) { try { orderedSelfReferences.put(type, new URI(linkProperties.get("href"))); } catch (URISyntaxException e) { @@ -85,21 +147,45 @@ public class Resource { } } } - if(orderedSelfReferences.isEmpty()) + if (orderedSelfReferences.isEmpty()) throw new IllegalStateException("URI is not available"); } public URI getURI() { - if(orderedSelfReferences.isEmpty()) + if (orderedSelfReferences.isEmpty()) populateOrderedSelfReferences(); return orderedSelfReferences.firstEntry().getValue(); } public URI getSelfURI() { - if(orderedSelfReferences.isEmpty()) + if (orderedSelfReferences.isEmpty()) populateOrderedSelfReferences(); return orderedSelfReferences.get(LinkType.SELF); } + + @Override + public int hashCode() { + return Objects.hashCode(id, orderedSelfReferences); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Resource that = Resource.class.cast(obj); + return Objects.equal(id, that.id) && Objects.equal(this.orderedSelfReferences, that.orderedSelfReferences); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("links", links).add("orderedSelfReferences", orderedSelfReferences); + } + + @Override + public String toString() { + return string().toString(); + } + } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/SecurityGroup.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/SecurityGroup.java index ae832407b6..d28acdcecf 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/SecurityGroup.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/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 @@ -18,148 +18,159 @@ */ package org.jclouds.openstack.nova.domain; -import com.google.gson.annotations.SerializedName; +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; /** * Defines a security group * * @author chamerling - * - */ +*/ public class SecurityGroup { - - private int id; - - private String name; - - private String description; - @SerializedName(value="tenant_id") - private String tenantId; - - public SecurityGroup() { - } + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromSecurityGroup(this); + } - /** - * @return the id - */ - public int getId() { - return id; - } + public static abstract class Builder> { + protected abstract T self(); - /** - * @param id the id to set - */ - public void setId(int id) { - this.id = id; - } + protected int id; + protected String name; + protected String description; + protected String tenantId; + + /** + * @see SecurityGroup#getId() + */ + public T id(int id) { + this.id = id; + return self(); + } - /** - * @return the name - */ - public String getName() { - return name; - } + /** + * @see SecurityGroup#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } + /** + * @see SecurityGroup#getDescription() + */ + public T description(String description) { + this.description = description; + return self(); + } - /** - * @return the description - */ - public String getDescription() { - return description; - } + /** + * @see SecurityGroup#getTenantId() + */ + public T tenantId(String tenantId) { + this.tenantId = tenantId; + return self(); + } - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } + public SecurityGroup build() { + return new SecurityGroup(id, name, description, tenantId); + } + + public T fromSecurityGroup(SecurityGroup in) { + return this + .id(in.getId()) + .name(in.getName()) + .description(in.getDescription()) + .tenantId(in.getTenantId()); + } + } - /** - * @return the tenantId - */ - public String getTenantId() { - return tenantId; - } + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - /** - * @param tenantId the tenantId to set - */ - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } + private final int id; + private final String name; + private final String description; + private final String tenantId; - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("SecurityGroup [id="); - builder.append(id); - builder.append(", name="); - builder.append(name); - builder.append(", description="); - builder.append(description); - builder.append(", tenantId="); - builder.append(tenantId); - builder.append("]"); - return builder.toString(); - } + @ConstructorProperties({ + "id", "name", "description", "tenant_id" + }) + protected SecurityGroup(int id, String name, @Nullable String description, @Nullable String tenantId) { + this.id = id; + this.name = checkNotNull(name, "name"); + this.description = description; + this.tenantId = tenantId; + } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result + id; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result - + ((tenantId == null) ? 0 : tenantId.hashCode()); - return result; - } + /** + * @return the id + */ + public int getId() { + return this.id; + } + + /** + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * @return the description + */ + @Nullable + public String getDescription() { + return this.description; + } + + /** + * @return the tenantId + */ + @Nullable + public String getTenantId() { + return this.tenantId; + } + + @Override + public int hashCode() { + return Objects.hashCode(id, name, description, tenantId); + } + + @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.name, that.name) + && Objects.equal(this.description, that.description) + && Objects.equal(this.tenantId, that.tenantId); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("description", description).add("tenantId", tenantId); + } + + @Override + public String toString() { + return string().toString(); + } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SecurityGroup other = (SecurityGroup) obj; - if (description == null) { - if (other.description != null) - return false; - } else if (!description.equals(other.description)) - return false; - if (id != other.id) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (tenantId == null) { - if (other.tenantId != null) - return false; - } else if (!tenantId.equals(other.tenantId)) - return false; - return true; - } } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Server.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Server.java index d0568ea7eb..958faaa567 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Server.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Server.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,13 +18,21 @@ */ package org.jclouds.openstack.nova.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.net.URI; import java.util.Date; +import java.util.List; import java.util.Map; import java.util.Set; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.google.gson.annotations.SerializedName; +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; /** * A server is a virtual machine instance in the OpenStack Nova system. Flavor and image are @@ -33,102 +41,323 @@ import com.google.gson.annotations.SerializedName; * @author Adrian Cole */ public class Server extends Resource { - private int id; - private String name; - private Map metadata = Maps.newHashMap(); - - private Addresses addresses; - private String accessIPv4; - private String accessIPv6; - private String adminPass; - private String flavorRef; - private String hostId; - private String imageRef; - private String affinityId; - private String uuid; - private Flavor flavor; - private Image image; - - @SerializedName(value="key_name") - private String keyName; - - /** - * Actually, security groups are not returned by nova on server query but is - * needed when creating a server to specify a set of groups - */ - @SerializedName(value="security_groups") - private Set securityGroups = Sets.newHashSet(); - - private Date created; - private Date updated; - - public Date getCreated() { - return created; + public static Builder builder() { + return new ConcreteBuilder(); } - public Date getUpdated() { - return updated; + public Builder toBuilder() { + return new ConcreteBuilder().fromServer(this); } + public static abstract class Builder> extends Resource.Builder { + protected String name; + protected Map metadata = ImmutableMap.of(); + protected Addresses addresses; + protected String accessIPv4; + protected String accessIPv6; + protected String adminPass; + protected String flavorRef; + protected String hostId; + protected String imageRef; + protected String affinityId; + protected String uuid; + protected Flavor flavor; + protected Image image; + protected String keyName; + protected Set securityGroups = ImmutableSet.of(); + protected Date created; + protected Date updated; + protected Integer progress; + protected ServerStatus status; - private Integer progress; - private ServerStatus status; + /** + * @see Server#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } - public Server() { + /** + * @see Server#getMetadata() + */ + public T metadata(Map metadata) { + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); + return self(); + } + + /** + * @see Server#getAddresses() + */ + public T addresses(Addresses addresses) { + this.addresses = addresses; + return self(); + } + + /** + * @see Server#getAccessIPv4() + */ + public T accessIPv4(String accessIPv4) { + this.accessIPv4 = accessIPv4; + return self(); + } + + /** + * @see Server#getAccessIPv6() + */ + public T accessIPv6(String accessIPv6) { + this.accessIPv6 = accessIPv6; + return self(); + } + + /** + * @see Server#getAdminPass() + */ + public T adminPass(String adminPass) { + this.adminPass = adminPass; + return self(); + } + + /** + * @see Server#getFlavorRef() + */ + public T flavorRef(String flavorRef) { + this.flavorRef = flavorRef; + return self(); + } + + /** + * @see Server#getHostId() + */ + public T hostId(String hostId) { + this.hostId = hostId; + return self(); + } + + /** + * @see Server#getImageRef() + */ + public T imageRef(String imageRef) { + this.imageRef = imageRef; + return self(); + } + + /** + * @see Server#getAffinityId() + */ + public T affinityId(String affinityId) { + this.affinityId = affinityId; + return self(); + } + + /** + * @see Server#getUuid() + */ + public T uuid(String uuid) { + this.uuid = uuid; + return self(); + } + + /** + * @see Server#getFlavor() + */ + public T flavor(Flavor flavor) { + this.flavor = flavor; + return self(); + } + + /** + * @see Server#getImage() + */ + public T image(Image image) { + this.image = image; + return self(); + } + + /** + * @see Server#getKeyName() + */ + public T keyName(String keyName) { + this.keyName = keyName; + return self(); + } + + /** + * @see Server#getSecurityGroups() + */ + public T securityGroups(Set securityGroups) { + this.securityGroups = ImmutableSet.copyOf(checkNotNull(securityGroups, "securityGroups")); + return self(); + } + + public T securityGroups(SecurityGroup... in) { + return securityGroups(ImmutableSet.copyOf(in)); + } + + /** + * @see Server#getCreated() + */ + public T created(Date created) { + this.created = created; + return self(); + } + + /** + * @see Server#getUpdated() + */ + public T updated(Date updated) { + this.updated = updated; + return self(); + } + + /** + * @see Server#getProgress() + */ + public T progress(Integer progress) { + this.progress = progress; + return self(); + } + + /** + * @see Server#getStatus() + */ + public T status(ServerStatus status) { + this.status = status; + return self(); + } + + public Server build() { + return new Server(id, links, orderedSelfReferences, name, metadata, addresses, accessIPv4, accessIPv6, adminPass, + flavorRef, hostId, imageRef, affinityId, uuid, flavor, image, keyName, securityGroups, created, updated, + progress, status); + } + + public T fromServer(Server in) { + return super.fromResource(in) + .id(in.getId()) + .name(in.getName()) + .metadata(in.getMetadata()) + .addresses(in.getAddresses()) + .accessIPv4(in.getAccessIPv4()) + .accessIPv6(in.getAccessIPv6()) + .adminPass(in.getAdminPass()) + .flavorRef(in.getFlavorRef()) + .hostId(in.getHostId()) + .imageRef(in.getImageRef()) + .affinityId(in.getAffinityId()) + .uuid(in.getUuid()) + .flavor(in.getFlavor()) + .image(in.getImage()) + .keyName(in.getKeyName()) + .securityGroups(in.getSecurityGroups()) + .created(in.getCreated()) + .updated(in.getUpdated()) + .progress(in.getProgress()) + .status(in.getStatus()); + } } - public Server(int id, String name) { - this.id = id; - this.name = name; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - public String getAffinityId() { - return affinityId; - } + private final String name; + private final Map metadata; + private final Addresses addresses; + private final String accessIPv4; + private final String accessIPv6; + private final String adminPass; + private final String flavorRef; + private final String hostId; + private final String imageRef; + private final String affinityId; + private final String uuid; + private final Flavor flavor; + private final Image image; + private final String keyName; + private final Set securityGroups; + private final Date created; + private final Date updated; + private final Integer progress; + private final ServerStatus status; - public void setAffinityId(String affinityId) { + @ConstructorProperties({ + "id", "links", "orderedSelfReferences", "name", "metadata", "addresses", "accessIPv4", "accessIPv6", "adminPass", + "flavorRef", "hostId", "imageRef", "affinityId", "uuid", "flavor", "image", "key_name", "security_groups", + "created", "updated", "progress", "status" + }) + protected Server(int id, List> links, Map orderedSelfReferences, String name, + @Nullable Map metadata, @Nullable Addresses addresses, @Nullable String accessIPv4, + @Nullable String accessIPv6, @Nullable String adminPass, @Nullable String flavorRef, @Nullable String hostId, + @Nullable String imageRef, @Nullable String affinityId, @Nullable String uuid, @Nullable Flavor flavor, + @Nullable Image image, @Nullable String keyName, @Nullable Set securityGroups, + @Nullable Date created, @Nullable Date updated, @Nullable Integer progress, @Nullable ServerStatus status) { + super(id, links, orderedSelfReferences); + this.name = checkNotNull(name, "name"); + this.metadata = metadata == null ? ImmutableMap.of() : ImmutableMap.copyOf(metadata); + this.addresses = addresses; + this.accessIPv4 = accessIPv4; + this.accessIPv6 = accessIPv6; + this.adminPass = adminPass; + this.flavorRef = flavorRef; + this.hostId = hostId; + this.imageRef = imageRef; this.affinityId = affinityId; + this.uuid = uuid; + this.flavor = flavor; + this.image = image; + this.keyName = keyName; + this.securityGroups = securityGroups == null ? ImmutableSet.of() : ImmutableSet.copyOf(securityGroups); + this.created = created; + this.updated = updated; + this.progress = progress; + this.status = status == null ? ServerStatus.UNKNOWN : status; } - public void setMetadata(Map metadata) { - this.metadata = metadata; + public String getName() { + return this.name; } public Map getMetadata() { - return metadata; - } - - public void setAddresses(Addresses addresses) { - this.addresses = addresses; + return this.metadata; } + @Nullable public Addresses getAddresses() { - return addresses; + return this.addresses; } - public void setAdminPass(String adminPass) { - this.adminPass = adminPass; + /** + * @return the accessIPv4 + */ + @Nullable + public String getAccessIPv4() { + return this.accessIPv4; } + /** + * @return the accessIPv6 + */ + @Nullable + public String getAccessIPv6() { + return this.accessIPv6; + } + + @Nullable public String getAdminPass() { - return adminPass; - } - - public void setFlavorRef(String flavorRef) { - this.flavorRef = flavorRef; + return this.adminPass; } /** * @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getFlavor()} */ - @Deprecated + @Nullable public String getFlavorRef() { - return flavorRef; - } - - public void setHostId(String hostId) { - this.hostId = hostId; + return this.flavorRef; } /** @@ -139,40 +368,64 @@ public class Server extends Resource { *

* Note: hostId is unique PER ACCOUNT and is not globally unique. */ + @Nullable public String getHostId() { - return hostId; - } - - public int getId() { - return id; - } - - public void setImageRef(String imageRef) { - this.imageRef = imageRef; + return this.hostId; } /** * @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getImage()}. */ - @Deprecated + @Nullable public String getImageRef() { - return imageRef; + return this.imageRef; } - public String getName() { - return name; + @Nullable + public String getAffinityId() { + return this.affinityId; } - public void setProgress(Integer progress) { - this.progress = progress; + @Nullable + public String getUuid() { + return this.uuid; } + @Nullable + public Flavor getFlavor() { + return this.flavor; + } + + public Image getImage() { + return this.image; + } + + @Nullable + public String getKeyName() { + return this.keyName; + } + + /** + * Actually, security groups are not returned by nova on server query but is + * needed when creating a server to specify a set of groups + */ + public Set getSecurityGroups() { + return this.securityGroups; + } + + @Nullable + public Date getCreated() { + return this.created; + } + + @Nullable + public Date getUpdated() { + return this.updated; + } + + @Nullable public Integer getProgress() { - return progress; - } - - public void setStatus(ServerStatus status) { - this.status = status; + return this.progress; } /** @@ -180,196 +433,48 @@ public class Server extends Resource { * state. Servers with an ACTIVE status are available for use. */ public ServerStatus getStatus() { - return status; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public Flavor getFlavor() { - return flavor; - } - - public void setFlavor(Flavor flavor) { - this.flavor = flavor; - } - - public Image getImage() { - return image; - } - - public void setImage(Image image) { - this.image = image; - } - - public String getKeyName() { - return keyName; - } - - public void setKeyName(String keyName) { - this.keyName = keyName; - } - - public Set getSecurityGroups() { - return securityGroups; - } - - public void setSecurityGroups(Set securityGroups) { - this.securityGroups = securityGroups; - } - - /** - * @return the accessIPv4 - */ - public String getAccessIPv4() { - return accessIPv4; - } - - /** - * @param accessIPv4 - * the accessIPv4 to set - */ - public void setAccessIPv4(String accessIPv4) { - this.accessIPv4 = accessIPv4; - } - - /** - * @return the accessIPv6 - */ - public String getAccessIPv6() { - return accessIPv6; - } - - /** - * @param accessIPv6 - * the accessIPv6 to set - */ - public void setAccessIPv6(String accessIPv6) { - this.accessIPv6 = accessIPv6; + return this.status; } @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((addresses == null) ? 0 : addresses.hashCode()); - result = prime * result + ((adminPass == null) ? 0 : adminPass.hashCode()); - result = prime * result + ((flavorRef == null) ? 0 : flavorRef.hashCode()); - result = prime * result + ((hostId == null) ? 0 : hostId.hashCode()); - result = prime * result + id; - result = prime * result + ((imageRef == null) ? 0 : imageRef.hashCode()); - result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); - result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); - result = prime * result + ((keyName == null) ? 0 : keyName.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((flavor == null) ? 0 : flavor.hashCode()); - result = prime * result + ((image == null) ? 0 : image.hashCode()); - result = prime * result + ((accessIPv4 == null) ? 0 : accessIPv4.hashCode()); - result = prime * result + ((accessIPv6 == null) ? 0 : accessIPv6.hashCode()); - return result; + return Objects.hashCode(super.hashCode(), name, metadata, addresses, accessIPv4, accessIPv6, adminPass, flavorRef, + hostId, imageRef, affinityId, uuid, flavor, image, keyName, securityGroups, created, updated); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Server other = (Server) obj; - if (addresses == null) { - if (other.addresses != null) - return false; - } else if (!addresses.equals(other.addresses)) - return false; - if (adminPass == null) { - if (other.adminPass != null) - return false; - } else if (!adminPass.equals(other.adminPass)) - return false; - if (flavorRef == null) { - if (other.flavorRef != null) - return false; - } else if (!flavorRef.equals(other.flavorRef)) - return false; - if (hostId == null) { - if (other.hostId != null) - return false; - } else if (!hostId.equals(other.hostId)) - return false; - if (id != other.id) - return false; - if (imageRef == null) { - if (other.imageRef != null) - return false; - } else if (!imageRef.equals(other.imageRef)) - return false; - if (metadata == null) { - if (other.metadata != null) - return false; - } else if (!metadata.equals(other.metadata)) - return false; - if (securityGroups == null) { - if (other.securityGroups != null) - return false; - } else if (!securityGroups.equals(other.securityGroups)) - return false; - if (uuid == null) { - if (other.uuid != null) - return false; - } else if (!uuid.equals(other.uuid)) - return false; - if (keyName == null) { - if (other.keyName != null) - return false; - } else if (!keyName.equals(other.keyName)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (flavor == null) { - if (other.flavor != null) - return false; - } else if (!flavor.equals(other.flavor)) - return false; - if (image == null) { - if (other.image != null) - return false; - } else if (!image.equals(other.image)) - return false; - if (accessIPv4 == null) { - if (other.accessIPv4 != null) - return false; - } else if (!accessIPv4.equals(other.accessIPv4)) - return false; - if (accessIPv6 == null) { - if (other.accessIPv6 != null) - return false; - } else if (!accessIPv6.equals(other.accessIPv6)) - return false; - return true; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Server that = Server.class.cast(obj); + return super.equals(that) + && Objects.equal(this.name, that.name) + && Objects.equal(this.metadata, that.metadata) + && Objects.equal(this.addresses, that.addresses) + && Objects.equal(this.accessIPv4, that.accessIPv4) + && Objects.equal(this.accessIPv6, that.accessIPv6) + && Objects.equal(this.adminPass, that.adminPass) + && Objects.equal(this.flavorRef, that.flavorRef) + && Objects.equal(this.hostId, that.hostId) + && Objects.equal(this.imageRef, that.imageRef) + && Objects.equal(this.affinityId, that.affinityId) + && Objects.equal(this.uuid, that.uuid) + && Objects.equal(this.flavor, that.flavor) + && Objects.equal(this.image, that.image) + && Objects.equal(this.keyName, that.keyName) + && Objects.equal(this.securityGroups, that.securityGroups) + && Objects.equal(this.created, that.created) + && Objects.equal(this.updated, that.updated); } - public void setName(String name) { - this.name = name; + protected ToStringHelper string() { + return super.string() + .add("name", name).add("metadata", metadata).add("addresses", addresses) + .add("accessIPv4", accessIPv4).add("accessIPv6", accessIPv6).add("adminPass", adminPass) + .add("flavorRef", flavorRef).add("hostId", hostId).add("imageRef", imageRef).add("affinityId", affinityId) + .add("uuid", uuid).add("flavor", flavor).add("image", image).add("keyName", keyName) + .add("securityGroups", securityGroups).add("created", created).add("updated", updated) + .add("progress", progress).add("status", status); } - @Override - public String toString() { - return "Server [addresses=" + addresses + ", accessIPv4=" + accessIPv4 - + ", accessIPv6=" + accessIPv6 + ", adminPass=" + adminPass - + ", flavorRef=" + flavorRef + ", hostId=" + hostId + ", id=" - + id + ", imageRef=" + imageRef + ", metadata=" + metadata - + ", uuid=" + uuid + ", name=" + name + ", keyName=" + keyName - + " , securityGroups=" + securityGroups + "]"; - } - } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java index d75b22778f..9ad40caf6e 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java @@ -22,12 +22,14 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import java.beans.ConstructorProperties; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Map.Entry; import javax.inject.Inject; +import javax.inject.Named; import org.jclouds.encryption.internal.Base64; import org.jclouds.http.HttpRequest; @@ -39,12 +41,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.gson.annotations.SerializedName; /** - * * @author Adrian Cole - * */ public class CreateServerOptions implements MapBinder { @Inject @@ -73,24 +72,30 @@ public class CreateServerOptions implements MapBinder { } - @SuppressWarnings("unused") private class ServerRequest { final String name; final String imageRef; final String flavorRef; - String adminPass; - Map metadata; - List personality; - String key_name; - @SerializedName(value="security_groups") - Set securityGroups; + final String adminPass; + final Map metadata; + final List personality; + @Named("key_name") + final String keyName; + @Named("security_groups") + final Set securityGroups; - private ServerRequest(String name, String imageRef, String flavorRef) { + @ConstructorProperties({"name", "imageRef", "flavorRef", "adminPass", "metadata", "personality", "key_name", "security_groups"}) + private ServerRequest(String name, String imageRef, String flavorRef, String adminPass, Map metadata, + List personality, String keyName, Set securityGroups) { this.name = name; this.imageRef = imageRef; this.flavorRef = flavorRef; + this.adminPass = adminPass; + this.metadata = metadata.isEmpty() ? null : metadata; + this.personality = personality.isEmpty() ? null : personality; + this.keyName = keyName; + this.securityGroups = securityGroups.isEmpty() ? null : securityGroups; } - } private Map metadata = Maps.newHashMap(); @@ -101,26 +106,19 @@ public class CreateServerOptions implements MapBinder { @Override public R bindToRequest(R request, Map postParams) { - ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present").toString(), - checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(), - checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString()); - if (metadata.size() > 0) - server.metadata = metadata; - if (files.size() > 0) - server.personality = files; - if (keyName != null) - server.key_name = keyName; - if (securityGroups.size() > 0) { - server.securityGroups = Sets.newHashSet(); - for (String groupName : securityGroups) { - SecurityGroup group = new SecurityGroup(); - group.setName(groupName); - server.securityGroups.add(group); - } - } - if (adminPass != null) { - server.adminPass = adminPass; + Set groups = Sets.newLinkedHashSet(); + for (String groupName : securityGroups) { + groups.add(SecurityGroup.builder().name(groupName).build()); } + ServerRequest server = new ServerRequest( + checkNotNull(postParams.get("name"), "name parameter not present").toString(), + checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(), + checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString(), + adminPass, + metadata, + files, + keyName, + groups); return bindToRequest(request, ImmutableMap.of("server", server)); } diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/domain/ServerTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/domain/ServerTest.java index 1595308b55..bea926c78f 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/domain/ServerTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/domain/ServerTest.java @@ -30,19 +30,17 @@ import org.testng.annotations.Test; @Test(groups = "unit") public class ServerTest { public void testStatusDoesntAffectEquals() { - Server server1 = new Server(1, "hello"); - server1.setStatus(ServerStatus.ACTIVE); - Server server2 = new Server(1, "hello"); - server2.setStatus(ServerStatus.BUILD); + Server server1 = Server.builder().id(1).name("hello").status(ServerStatus.ACTIVE).build(); + Server server2 = Server.builder().id(1).name("hello").status(ServerStatus.BUILD).build(); assertEquals(server1, server2); + assertEquals(server1.hashCode(), server2.hashCode()); } public void testProgressDoesntAffectEquals() { - Server server1 = new Server(1, "hello"); - server1.setProgress(1); - Server server2 = new Server(1, "hello"); - server2.setProgress(2); + Server server1 = Server.builder().id(1).name("hello").progress(1).build(); + Server server2 = Server.builder().id(1).name("hello").progress(2).build(); assertEquals(server1, server2); + assertEquals(server1.hashCode(), server2.hashCode()); } } diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorListFromJsonResponseTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorListFromJsonResponseTest.java index 6a1a00bf0b..eaaec0c593 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorListFromJsonResponseTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorListFromJsonResponseTest.java @@ -50,8 +50,8 @@ public class ParseFlavorListFromJsonResponseTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/test_list_flavors.json"); - List expects = ImmutableList.of(new Flavor(1, "256 MB Server", null, null, null), new Flavor(2, - "512 MB Server", null, null, null)); + List expects = ImmutableList.of(Flavor.builder().id(1).name("256 MB Server").build(), + Flavor.builder().id(2).name("512 MB Server").build()); UnwrapOnlyJsonValue> parser = i.getInstance(Key .get(new TypeLiteral>>() { diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFloatingIPListFromJsonResponse.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFloatingIPListFromJsonResponse.java index 63166d2f20..8ec149ab79 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFloatingIPListFromJsonResponse.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFloatingIPListFromJsonResponse.java @@ -54,7 +54,7 @@ public class ParseFloatingIPListFromJsonResponse { .apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()); assertEquals(response.size(), 1); - FloatingIP floatingIP = new FloatingIP(1, "10.0.0.3", "11.0.0.1", 12); + FloatingIP floatingIP = FloatingIP.builder().id(1).ip("10.0.0.3").fixedIP("11.0.0.1").instanceID(12).build(); assertEquals(response.get(0), floatingIP); } } diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseImageListFromJsonResponseTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseImageListFromJsonResponseTest.java index 95233c2d2c..5a5b587d0c 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseImageListFromJsonResponseTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseImageListFromJsonResponseTest.java @@ -62,7 +62,8 @@ public class ParseImageListFromJsonResponseTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/test_list_images.json"); - List expects = ImmutableList.of(new Image(1, "CentOS 5.2"), new Image(743, "My Server Backup")); + List expects = ImmutableList.of(Image.builder().id(1).name("CentOS 5.2").build(), + Image.builder().id(743).name("My Server Backup").build()); UnwrapOnlyJsonValue> parser = i.getInstance(Key .get(new TypeLiteral>>() { diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerFromJsonResponseDiabloTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerFromJsonResponseDiabloTest.java index baf95ccb25..2062d94ace 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerFromJsonResponseDiabloTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerFromJsonResponseDiabloTest.java @@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; import java.text.SimpleDateFormat; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.SimpleTimeZone; @@ -74,9 +73,9 @@ public class ParseServerFromJsonResponseDiabloTest { ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"), Address.newString2AddressFunction())); List

privateAddresses = ImmutableList.copyOf(Iterables.transform( - ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction())); - Addresses addresses1 = new Addresses(new HashSet
(publicAddresses), - new HashSet
(privateAddresses)); + ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction())); + + Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build(); assertEquals(response.getAddresses(), addresses1); assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")); assertEquals(response.getAddresses(), addresses1); diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerFromJsonResponseTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerFromJsonResponseTest.java index 3821b23899..59f50117c1 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerFromJsonResponseTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerFromJsonResponseTest.java @@ -24,7 +24,6 @@ import java.io.InputStream; import java.net.UnknownHostException; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.SimpleTimeZone; @@ -75,9 +74,8 @@ public class ParseServerFromJsonResponseTest { ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"), Address.newString2AddressFunction())); List
privateAddresses = ImmutableList.copyOf(Iterables.transform( - ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction())); - Addresses addresses1 = new Addresses(new HashSet
(publicAddresses), - new HashSet
(privateAddresses)); + ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction())); + Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build(); assertEquals(response.getAddresses(), addresses1); assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")); assertEquals(response.getAddresses(), addresses1); diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerListFromJsonResponseTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerListFromJsonResponseTest.java index e9f255b7b6..d7394a6e84 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerListFromJsonResponseTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseServerListFromJsonResponseTest.java @@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.UnknownHostException; -import java.util.HashSet; import java.util.List; import org.jclouds.http.HttpResponse; @@ -44,7 +43,7 @@ import com.google.inject.TypeLiteral; /** * Tests behavior of {@code ParseServerListFromJsonResponse} - * + * * @author Adrian Cole */ @Test(groups = "unit") @@ -62,11 +61,12 @@ public class ParseServerListFromJsonResponseTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/test_list_servers.json"); - List expects = ImmutableList.of(new Server(1234, "sample-server"), new Server(5678, "sample-server2")); + List expects = ImmutableList.of(Server.builder().id(1234).name("sample-server").build(), + Server.builder().id(5678).name("sample-server2").build()); UnwrapOnlyJsonValue> parser = i.getInstance(Key - .get(new TypeLiteral>>() { - })); + .get(new TypeLiteral>>() { + })); List response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()); assertEquals(response, expects); @@ -77,8 +77,8 @@ public class ParseServerListFromJsonResponseTest { InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json"); UnwrapOnlyJsonValue> parser = i.getInstance(Key - .get(new TypeLiteral>>() { - })); + .get(new TypeLiteral>>() { + })); List response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()); assertEquals(response.get(0).getId(), 1234); @@ -91,12 +91,11 @@ public class ParseServerListFromJsonResponseTest { assertEquals(response.get(0).getProgress(), Integer.valueOf(60)); List
publicAddresses = ImmutableList.copyOf(Iterables.transform( - ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"), - Address.newString2AddressFunction())); + ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"), + Address.newString2AddressFunction())); List
privateAddresses = ImmutableList.copyOf(Iterables.transform( - ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction())); - Addresses addresses1 = new Addresses(new HashSet
(publicAddresses), - new HashSet
(privateAddresses)); + ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction())); + Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build(); assertEquals(response.get(0).getAddresses(), addresses1); assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")); @@ -111,11 +110,11 @@ public class ParseServerListFromJsonResponseTest { assertEquals(response.get(1).getProgress(), null); List
publicAddresses2 = ImmutableList.copyOf(Iterables.transform( - ImmutableList.of("67.23.10.133", "::babe:67.23.10.133"), Address.newString2AddressFunction())); + ImmutableList.of("67.23.10.133", "::babe:67.23.10.133"), Address.newString2AddressFunction())); List
privateAddresses2 = ImmutableList.copyOf(Iterables.transform( - ImmutableList.of("10.176.42.17", "::babe:10.176.42.17"), Address.newString2AddressFunction())); - Addresses addresses2 = new Addresses(new HashSet
(publicAddresses2), new HashSet
( - privateAddresses2)); + ImmutableList.of("10.176.42.17", "::babe:10.176.42.17"), Address.newString2AddressFunction())); + + Addresses addresses2 = Addresses.builder().publicAddresses(publicAddresses2).privateAddresses(privateAddresses2).build(); assertEquals(response.get(1).getAddresses(), addresses2); assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));