nova: issue 971 adding/adjusting builders and applying ConstructorProperties to domain objects

This commit is contained in:
Adam Lowe 2012-07-12 17:03:03 +01:00
parent 3e1d9b22e7
commit 2f01337b64
19 changed files with 1643 additions and 975 deletions

View File

@ -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 {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAbsoluteLimit(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected int value;
public String getName() {
return name;
/**
* @see AbsoluteLimit#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
public void setName(String value) {
this.name = value;
/**
* @see AbsoluteLimit#getValue()
*/
public T value(int value) {
this.value = value;
return self();
}
public int getValue() {
return value;
public AbsoluteLimit build() {
return new AbsoluteLimit(name, value);
}
public void setValue(int value) {
public T fromAbsoluteLimit(AbsoluteLimit in) {
return this
.name(in.getName())
.value(in.getValue());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@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();
}
}

View File

@ -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,60 +18,27 @@
*/
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.gson.annotations.SerializedName;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* @author Dmitri Babaev
*/
*/
public class Address {
@SerializedName("addr")
private String address;
private int version;
//for de-serialization
@SuppressWarnings("unused")
private Address() {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
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 Builder<?> toBuilder() {
return new ConcreteBuilder().fromAddress(this);
}
public static Function<Address, String> newAddress2StringFunction() {
@ -95,4 +62,88 @@ public class Address {
}
};
}
public static abstract class Builder<T extends Builder<T>> {
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<ConcreteBuilder> {
@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();
}
}

View File

@ -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<Address> publicAddresses = Sets.newLinkedHashSet();
@SerializedName("private")
private Set<Address> privateAddresses = Sets.newLinkedHashSet();
public Addresses() {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Addresses(Set<Address> publicAddresses, Set<Address> privateAddresses) {
this.publicAddresses = publicAddresses;
this.privateAddresses = privateAddresses;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAddresses(this);
}
public void setPublicAddresses(Set<Address> publicAddresses) {
this.publicAddresses = publicAddresses;
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected Set<Address> publicAddresses = ImmutableSet.of();
protected Set<Address> privateAddresses = ImmutableSet.of();
/**
* @see Addresses#getPublicAddresses()
*/
public T publicAddresses(Collection<Address> 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<Address> 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());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final Set<Address> publicAddresses;
private final Set<Address> privateAddresses;
@ConstructorProperties({
"public", "private"
})
protected Addresses(Set<Address> publicAddresses, Set<Address> privateAddresses) {
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
}
public Set<Address> getPublicAddresses() {
return publicAddresses;
}
public void setPrivateAddresses(Set<Address> privateAddresses) {
this.privateAddresses = privateAddresses;
return this.publicAddresses;
}
public Set<Address> 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();
}
}

View File

@ -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,17 @@
*/
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.
*
@ -27,97 +36,128 @@ package org.jclouds.openstack.nova.domain;
*/
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<T extends Builder<T>> extends Resource.Builder<T> {
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<ConcreteBuilder> {
@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<Map<String, String>> links, @Nullable Map<LinkType, URI> 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);
}
}

View File

@ -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 <a href="http://wiki.openstack.org/os_api_floating_ip">Floating IP Wiki
* page</a>. 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 FloatingIP(int id, String ip, String fixedIP, int instanceID) {
this.id = id;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromFloatingIP(this);
}
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String ip;
protected String fixedIP;
protected int instanceID;
/**
* @see FloatingIP#getIp()
*/
public T ip(String ip) {
this.ip = ip;
return self();
}
/**
* @see FloatingIP#getFixedIP()
*/
public T fixedIP(String fixedIP) {
this.fixedIP = fixedIP;
return self();
}
/**
* @see FloatingIP#getInstanceID()
*/
public T instanceID(int instanceID) {
this.instanceID = instanceID;
return self();
}
/**
* @return the id
*/
public int getId() {
return id;
public FloatingIP build() {
return new FloatingIP(id, links, orderedSelfReferences, ip, fixedIP, instanceID);
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
public T fromFloatingIP(FloatingIP in) {
return super.fromResource(in)
.ip(in.getIp())
.fixedIP(in.getFixedIP())
.instanceID(in.getInstanceID());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String ip;
private final String fixedIP;
private final int instanceID;
@ConstructorProperties({
"id", "links", "orderedSelfReferences", "ip", "fixed_ip", "instance_id"
})
protected FloatingIP(int id, List<Map<String, String>> links, Map<LinkType, URI> 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 ip
*/
public String getIp() {
return ip;
}
/**
* @param ip the ip to set
*/
public void setIp(String ip) {
this.ip = ip;
return this.ip;
}
/**
* @return the fixedIP
*/
public String getFixedIP() {
return fixedIP;
}
/**
* @param fixedIP the fixedIP to set
*/
public void setFixedIP(String fixedIP) {
this.fixedIP = fixedIP;
return this.fixedIP;
}
/**
* @return the instanceID
*/
public int getInstanceID() {
return instanceID;
return this.instanceID;
}
/**
* @param instanceID the instanceID to set
*/
public void setInstanceID(int instanceID) {
this.instanceID = instanceID;
}
/* (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();
}
/* (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;
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;
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);
}
}

View File

@ -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<String, String> 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<T extends Builder<T>> extends Resource.Builder<T> {
protected String name;
protected Integer progress;
protected String serverRef;
protected ImageStatus status;
protected Map<String, String> metadata = ImmutableMap.of();
protected Date created;
protected Date updated;
public Image() {
}
public Image(int id, String name) {
this.id = id;
/**
* @see Image#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
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) {
/**
* @see Image#getProgress()
*/
public T progress(Integer progress) {
this.progress = progress;
return self();
}
public Integer getProgress() {
return progress;
}
public void setServerRef(String serverRef) {
/**
* @see Image#getServerRef()
*/
public T serverRef(String serverRef) {
this.serverRef = serverRef;
return self();
}
public String getServerRef() {
return serverRef;
}
public void setStatus(ImageStatus status) {
/**
* @see Image#getStatus()
*/
public T status(ImageStatus status) {
this.status = status;
return self();
}
/**
* @see Image#getMetadata()
*/
public T metadata(Map<String, String> 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());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@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<String, String> 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<Map<String, String>> links, @Nullable Map<LinkType, URI> orderedSelfReferences, @Nullable String name,
@Nullable Integer progress, @Nullable String serverRef, @Nullable ImageStatus status, @Nullable Map<String, String> metadata,
@Nullable Date created, @Nullable Date updated) {
super(id, links, orderedSelfReferences);
this.name = name;
this.progress = progress;
this.serverRef = serverRef;
this.status = status == null ? ImageStatus.UNKNOWN : status;
this.metadata = metadata == null ? ImmutableMap.<String, String>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 this.serverRef;
}
@Nullable
public ImageStatus getStatus() {
return status;
return this.status;
}
public Map<String, String> getMetadata() {
return Collections.unmodifiableMap(metadata);
return this.metadata;
}
public void setMetadata(Map<String, String> 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);
}
}

View File

@ -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<RateLimit> rate = Lists.newArrayList();
private List<AbsoluteLimit> absolute = Lists.newArrayList();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public void setRate(List<RateLimit> rate) {
this.rate = rate;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromLimits(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected List<RateLimit> rate = ImmutableList.of();
protected List<AbsoluteLimit> absolute = ImmutableList.of();
/**
* @see Limits#getRate()
*/
public T rate(List<RateLimit> 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<AbsoluteLimit> 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<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final List<RateLimit> rate;
private final List<AbsoluteLimit> absolute;
@ConstructorProperties({
"rate", "absolute"
})
protected Limits(List<RateLimit> rate, List<AbsoluteLimit> absolute) {
this.rate = ImmutableList.copyOf(checkNotNull(rate, "rate"));
this.absolute = ImmutableList.copyOf(checkNotNull(absolute, "absolute"));
}
public List<RateLimit> getRate() {
return rate;
}
public void setAbsolute(List<AbsoluteLimit> absolute) {
this.absolute = absolute;
return this.rate;
}
public List<AbsoluteLimit> 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();
}
}

View File

@ -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.
* <p/>
* 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<T extends Builder<T>> {
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<ConcreteBuilder> {
@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();
}
}

View File

@ -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,28 +18,31 @@
*/
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<Map<String, String>> links = Lists.newArrayList();
//This is the preference order for returning a URI in getURI
private enum LinkType {
public static enum LinkType {
BOOKMARK_JSON(new Predicate<Map<String, String>>() {
@Override
public boolean apply(@Nullable Map<String, String> linkMap) {
@ -60,23 +63,82 @@ public class Resource {
}
});
Predicate<Map<String,String>> linkPredicate;
Predicate<Map<String, String>> linkPredicate;
LinkType(Predicate<Map<String,String>> linkPredicate) {
LinkType(Predicate<Map<String, String>> linkPredicate) {
this.linkPredicate = linkPredicate;
};
}
}
private final ConcurrentSkipListMap<LinkType,URI> orderedSelfReferences;
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
public Resource(){
orderedSelfReferences = new ConcurrentSkipListMap<LinkType,URI>();
protected int id;
protected List<Map<String, String>> links = ImmutableList.of();
protected Map<Resource.LinkType, URI> orderedSelfReferences;
/**
* @see Resource#getId()
*/
public T id(int id) {
this.id = id;
return self();
}
/**
* @see Resource#getLinks()
*/
public T links(List<Map<String, String>> links) {
this.links = ImmutableList.copyOf(checkNotNull(links, "links"));
return self();
}
public T links(Map<String, String>... in) {
return links(ImmutableList.copyOf(in));
}
/**
* @see Resource#getOrderedSelfReferences()
*/
public T orderedSelfReferences(Map<Resource.LinkType, URI> 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<Map<String, String>> links;
private final ConcurrentSkipListMap<Resource.LinkType, URI> orderedSelfReferences;
protected Resource(int id, List<Map<String, String>> links, @Nullable Map<Resource.LinkType, URI> orderedSelfReferences) {
this.id = id;
this.links = links == null ? ImmutableList.<Map<String, String>>of() : ImmutableList.copyOf(checkNotNull(links, "links"));
this.orderedSelfReferences = orderedSelfReferences == null ? new ConcurrentSkipListMap<LinkType, URI>() : new ConcurrentSkipListMap<LinkType, URI>(orderedSelfReferences);
}
public int getId() {
return id;
}
public List<Map<String, String>> getLinks() {
return this.links;
}
public Map<Resource.LinkType, URI> getOrderedSelfReferences() {
return this.orderedSelfReferences;
}
private void populateOrderedSelfReferences() {
for (Map<String, String> 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();
}
}

View File

@ -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;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
private String name;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromSecurityGroup(this);
}
private String description;
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
@SerializedName(value="tenant_id")
private String tenantId;
protected int id;
protected String name;
protected String description;
protected String tenantId;
public SecurityGroup() {
/**
* @see SecurityGroup#getId()
*/
public T id(int id) {
this.id = id;
return self();
}
/**
* @see SecurityGroup#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see SecurityGroup#getDescription()
*/
public T description(String description) {
this.description = description;
return self();
}
/**
* @see SecurityGroup#getTenantId()
*/
public T tenantId(String tenantId) {
this.tenantId = tenantId;
return self();
}
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());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final int id;
private final String name;
private final String description;
private final String tenantId;
@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;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
return this.id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
return this.name;
}
/**
* @return the description
*/
@Nullable
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
return this.description;
}
/**
* @return the tenantId
*/
@Nullable
public String getTenantId() {
return tenantId;
return this.tenantId;
}
/**
* @param tenantId the tenantId to set
*/
public void setTenantId(String tenantId) {
this.tenantId = 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();
}
/* (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 Objects.hashCode(id, name, description, tenantId);
}
/* (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;
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();
}
}

View File

@ -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<String, String> metadata = Maps.newHashMap();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
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;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromServer(this);
}
@SerializedName(value="key_name")
private String keyName;
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String name;
protected Map<String, String> 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<SecurityGroup> securityGroups = ImmutableSet.of();
protected Date created;
protected Date updated;
protected Integer progress;
protected ServerStatus status;
/**
* Actually, security groups are not returned by nova on server query but is
* needed when creating a server to specify a set of groups
* @see Server#getName()
*/
@SerializedName(value="security_groups")
private Set<SecurityGroup> securityGroups = Sets.newHashSet();
private Date created;
private Date updated;
public Date getCreated() {
return created;
}
public Date getUpdated() {
return updated;
}
private Integer progress;
private ServerStatus status;
public Server() {
}
public Server(int id, String name) {
this.id = id;
public T name(String name) {
this.name = name;
return self();
}
public String getAffinityId() {
return affinityId;
/**
* @see Server#getMetadata()
*/
public T metadata(Map<String, String> metadata) {
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self();
}
public void setAffinityId(String affinityId) {
/**
* @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();
}
public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
/**
* @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<SecurityGroup> 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());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final Map<String, String> 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<SecurityGroup> securityGroups;
private final Date created;
private final Date updated;
private final Integer progress;
private final ServerStatus status;
@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<Map<String, String>> links, Map<LinkType, URI> orderedSelfReferences, String name,
@Nullable Map<String, String> 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<SecurityGroup> 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.<String, String>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.<SecurityGroup>of() : ImmutableSet.copyOf(securityGroups);
this.created = created;
this.updated = updated;
this.progress = progress;
this.status = status == null ? ServerStatus.UNKNOWN : status;
}
public String getName() {
return this.name;
}
public Map<String, String> 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 {
* <p/>
* 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<SecurityGroup> 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<SecurityGroup> getSecurityGroups() {
return securityGroups;
}
public void setSecurityGroups(Set<SecurityGroup> 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;
}
@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 + "]";
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);
}
}

View File

@ -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<String, String> metadata;
List<File> personality;
String key_name;
@SerializedName(value="security_groups")
Set<SecurityGroup> securityGroups;
final String adminPass;
final Map<String, String> metadata;
final List<File> personality;
@Named("key_name")
final String keyName;
@Named("security_groups")
final Set<SecurityGroup> 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<String, String> metadata,
List<File> personality, String keyName, Set<SecurityGroup> 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<String, String> metadata = Maps.newHashMap();
@ -101,26 +106,19 @@ public class CreateServerOptions implements MapBinder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> 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();
Set<SecurityGroup> groups = Sets.newLinkedHashSet();
for (String groupName : securityGroups) {
SecurityGroup group = new SecurityGroup();
group.setName(groupName);
server.securityGroups.add(group);
}
}
if (adminPass != null) {
server.adminPass = adminPass;
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));
}

View File

@ -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());
}
}

View File

@ -50,8 +50,8 @@ public class ParseFlavorListFromJsonResponseTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
List<Flavor> expects = ImmutableList.of(new Flavor(1, "256 MB Server", null, null, null), new Flavor(2,
"512 MB Server", null, null, null));
List<Flavor> expects = ImmutableList.of(Flavor.builder().id(1).name("256 MB Server").build(),
Flavor.builder().id(2).name("512 MB Server").build());
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {

View File

@ -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);
}
}

View File

@ -62,7 +62,8 @@ public class ParseImageListFromJsonResponseTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
List<Image> expects = ImmutableList.of(new Image(1, "CentOS 5.2"), new Image(743, "My Server Backup"));
List<Image> expects = ImmutableList.of(Image.builder().id(1).name("CentOS 5.2").build(),
Image.builder().id(743).name("My Server Backup").build());
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {

View File

@ -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;
@ -75,8 +74,8 @@ public class ParseServerFromJsonResponseDiabloTest {
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
new HashSet<Address>(privateAddresses));
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);

View File

@ -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;
@ -76,8 +75,7 @@ public class ParseServerFromJsonResponseTest {
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
new HashSet<Address>(privateAddresses));
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);

View File

@ -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;
@ -62,7 +61,8 @@ public class ParseServerListFromJsonResponseTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
List<Server> expects = ImmutableList.of(new Server(1234, "sample-server"), new Server(5678, "sample-server2"));
List<Server> expects = ImmutableList.of(Server.builder().id(1234).name("sample-server").build(),
Server.builder().id(5678).name("sample-server2").build());
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
@ -95,8 +95,7 @@ public class ParseServerListFromJsonResponseTest {
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
new HashSet<Address>(privateAddresses));
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"));
@ -114,8 +113,8 @@ public class ParseServerListFromJsonResponseTest {
ImmutableList.of("67.23.10.133", "::babe:67.23.10.133"), Address.newString2AddressFunction()));
List<Address> privateAddresses2 = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.17", "::babe:10.176.42.17"), Address.newString2AddressFunction()));
Addresses addresses2 = new Addresses(new HashSet<Address>(publicAddresses2), new HashSet<Address>(
privateAddresses2));
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"));