mirror of https://github.com/apache/jclouds.git
nova: issue 971 adding/adjusting builders and applying ConstructorProperties to domain objects
This commit is contained in:
parent
3e1d9b22e7
commit
2f01337b64
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,30 +18,108 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
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
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class AbsoluteLimit {
|
public class AbsoluteLimit {
|
||||||
|
|
||||||
protected String name;
|
public static Builder<?> builder() {
|
||||||
protected int value;
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public Builder<?> toBuilder() {
|
||||||
return name;
|
return new ConcreteBuilder().fromAbsoluteLimit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String value) {
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
this.name = value;
|
protected abstract T self();
|
||||||
}
|
|
||||||
|
|
||||||
public int getValue() {
|
protected String name;
|
||||||
return value;
|
protected int value;
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(int value) {
|
/**
|
||||||
this.value = value;
|
* @see AbsoluteLimit#getName()
|
||||||
}
|
*/
|
||||||
|
public T name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see AbsoluteLimit#getValue()
|
||||||
|
*/
|
||||||
|
public T value(int value) {
|
||||||
|
this.value = value;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
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<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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,60 +18,27 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
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 org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
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
|
* @author Dmitri Babaev
|
||||||
*/
|
*/
|
||||||
public class Address {
|
public class Address {
|
||||||
@SerializedName("addr")
|
|
||||||
private String address;
|
|
||||||
private int version;
|
|
||||||
|
|
||||||
//for de-serialization
|
public static Builder<?> builder() {
|
||||||
@SuppressWarnings("unused")
|
return new ConcreteBuilder();
|
||||||
private Address() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Address(String address, int version) {
|
public Builder<?> toBuilder() {
|
||||||
this.address = address;
|
return new ConcreteBuilder().fromAddress(this);
|
||||||
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<Address, String> newAddress2StringFunction() {
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,81 +18,119 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
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 java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.base.Objects;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Addresses {
|
public class Addresses {
|
||||||
|
|
||||||
@SerializedName("public")
|
public static Builder<?> builder() {
|
||||||
private Set<Address> publicAddresses = Sets.newLinkedHashSet();
|
return new ConcreteBuilder();
|
||||||
@SerializedName("private")
|
|
||||||
private Set<Address> privateAddresses = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
public Addresses() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Addresses(Set<Address> publicAddresses, Set<Address> privateAddresses) {
|
public Builder<?> toBuilder() {
|
||||||
this.publicAddresses = publicAddresses;
|
return new ConcreteBuilder().fromAddresses(this);
|
||||||
this.privateAddresses = privateAddresses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPublicAddresses(Set<Address> publicAddresses) {
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
this.publicAddresses = publicAddresses;
|
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() {
|
public Set<Address> getPublicAddresses() {
|
||||||
return publicAddresses;
|
return this.publicAddresses;
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrivateAddresses(Set<Address> privateAddresses) {
|
|
||||||
this.privateAddresses = privateAddresses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Address> getPrivateAddresses() {
|
public Set<Address> getPrivateAddresses() {
|
||||||
return privateAddresses;
|
return this.privateAddresses;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Addresses [privateAddresses=" + privateAddresses + ", publicAddresses="
|
|
||||||
+ publicAddresses + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(publicAddresses, privateAddresses);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
|
|
||||||
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Addresses that = Addresses.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.publicAddresses, that.publicAddresses)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.privateAddresses, that.privateAddresses);
|
||||||
return false;
|
}
|
||||||
Addresses other = (Addresses) obj;
|
|
||||||
if (privateAddresses == null) {
|
protected ToStringHelper string() {
|
||||||
if (other.privateAddresses != null)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("publicAddresses", publicAddresses).add("privateAddresses", privateAddresses);
|
||||||
} else if (!privateAddresses.equals(other.privateAddresses))
|
}
|
||||||
return false;
|
|
||||||
if (publicAddresses == null) {
|
@Override
|
||||||
if (other.publicAddresses != null)
|
public String toString() {
|
||||||
return false;
|
return string().toString();
|
||||||
} else if (!publicAddresses.equals(other.publicAddresses))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,8 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
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
|
* A flavor is an available hardware configuration for a server. Each flavor has a unique
|
||||||
* combination of disk space and memory capacity.
|
* combination of disk space and memory capacity.
|
||||||
*
|
*
|
||||||
|
@ -27,97 +36,128 @@ package org.jclouds.openstack.nova.domain;
|
||||||
*/
|
*/
|
||||||
public class Flavor extends Resource {
|
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 String name;
|
||||||
private final Integer disk;
|
private final Integer disk;
|
||||||
private final Integer ram;
|
private final Integer ram;
|
||||||
private final Integer vcpus;
|
private final Integer vcpus;
|
||||||
|
|
||||||
//Required because of how Gson is being used to do wire marshalling with the Server class
|
@ConstructorProperties({
|
||||||
private Flavor(){
|
"id", "links", "orderedSelfReferences", "name", "disk", "ram", "vcpus"
|
||||||
id=0;
|
})
|
||||||
name=null;
|
protected Flavor(int id, List<Map<String, String>> links, @Nullable Map<LinkType, URI> orderedSelfReferences,
|
||||||
disk=null;
|
@Nullable String name, @Nullable Integer disk, @Nullable Integer ram, @Nullable Integer vcpus) {
|
||||||
ram=null;
|
super(id, links, orderedSelfReferences);
|
||||||
vcpus=null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Flavor(int id, String name, Integer disk, Integer ram, Integer vcpus) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.disk = disk;
|
this.disk = disk;
|
||||||
this.ram = ram;
|
this.ram = ram;
|
||||||
this.vcpus = vcpus;
|
this.vcpus = vcpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDisk() {
|
@Nullable
|
||||||
return disk;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Integer getDisk() {
|
||||||
|
return this.disk;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Integer getRam() {
|
public Integer getRam() {
|
||||||
return ram;
|
return this.ram;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Integer getVcpus() {
|
public Integer getVcpus() {
|
||||||
return vcpus;
|
return this.vcpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(super.hashCode(), name, disk, ram, vcpus);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Flavor that = Flavor.class.cast(obj);
|
||||||
return false;
|
return super.equals(that)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.name, that.name)
|
||||||
return false;
|
&& Objects.equal(this.disk, that.disk)
|
||||||
Flavor other = (Flavor) obj;
|
&& Objects.equal(this.ram, that.ram)
|
||||||
if (disk == null) {
|
&& Objects.equal(this.vcpus, that.vcpus);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected ToStringHelper string() {
|
||||||
public String toString() {
|
return super.string().add("name", name).add("disk", disk).add("ram", ram).add("vcpus", vcpus);
|
||||||
return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + ", vcpus=" + vcpus +"]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,153 +18,134 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
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
|
* 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.
|
* page</a>. Available since OpenStack Diablo release and API 1.1.
|
||||||
*
|
*
|
||||||
* @author chamerling
|
* @author chamerling
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
public class FloatingIP extends Resource {
|
public class FloatingIP extends Resource {
|
||||||
|
|
||||||
private int id;
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
private String ip;
|
public Builder<?> toBuilder() {
|
||||||
|
return new ConcreteBuilder().fromFloatingIP(this);
|
||||||
|
}
|
||||||
|
|
||||||
@SerializedName(value="fixed_ip")
|
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
|
||||||
private String fixedIP;
|
protected String ip;
|
||||||
|
protected String fixedIP;
|
||||||
|
protected int instanceID;
|
||||||
|
|
||||||
@SerializedName(value = "instance_id")
|
/**
|
||||||
private int instanceID;
|
* @see FloatingIP#getIp()
|
||||||
|
*/
|
||||||
|
public T ip(String ip) {
|
||||||
|
this.ip = ip;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
/**
|
||||||
private FloatingIP() {
|
* @see FloatingIP#getFixedIP()
|
||||||
}
|
*/
|
||||||
|
public T fixedIP(String fixedIP) {
|
||||||
|
this.fixedIP = fixedIP;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
public FloatingIP(int id, String ip, String fixedIP, int instanceID) {
|
/**
|
||||||
this.id = id;
|
* @see FloatingIP#getInstanceID()
|
||||||
this.ip = ip;
|
*/
|
||||||
this.fixedIP = fixedIP;
|
public T instanceID(int instanceID) {
|
||||||
this.instanceID = instanceID;
|
this.instanceID = instanceID;
|
||||||
}
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public FloatingIP build() {
|
||||||
* @return the id
|
return new FloatingIP(id, links, orderedSelfReferences, ip, fixedIP, instanceID);
|
||||||
*/
|
}
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public T fromFloatingIP(FloatingIP in) {
|
||||||
* @param id the id to set
|
return super.fromResource(in)
|
||||||
*/
|
.ip(in.getIp())
|
||||||
public void setId(int id) {
|
.fixedIP(in.getFixedIP())
|
||||||
this.id = id;
|
.instanceID(in.getInstanceID());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
* @return the ip
|
@Override
|
||||||
*/
|
protected ConcreteBuilder self() {
|
||||||
public String getIp() {
|
return this;
|
||||||
return ip;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private final String ip;
|
||||||
* @param ip the ip to set
|
private final String fixedIP;
|
||||||
*/
|
private final int instanceID;
|
||||||
public void setIp(String ip) {
|
|
||||||
this.ip = ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@ConstructorProperties({
|
||||||
* @return the fixedIP
|
"id", "links", "orderedSelfReferences", "ip", "fixed_ip", "instance_id"
|
||||||
*/
|
})
|
||||||
public String getFixedIP() {
|
protected FloatingIP(int id, List<Map<String, String>> links, Map<LinkType, URI> orderedSelfReferences, String ip,
|
||||||
return fixedIP;
|
String fixedIP, int instanceID) {
|
||||||
}
|
super(id, links, orderedSelfReferences);
|
||||||
|
this.ip = checkNotNull(ip, "ip");
|
||||||
|
this.fixedIP = checkNotNull(fixedIP, "fixedIP");
|
||||||
|
this.instanceID = instanceID;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param fixedIP the fixedIP to set
|
* @return the ip
|
||||||
*/
|
*/
|
||||||
public void setFixedIP(String fixedIP) {
|
public String getIp() {
|
||||||
this.fixedIP = fixedIP;
|
return this.ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the instanceID
|
* @return the fixedIP
|
||||||
*/
|
*/
|
||||||
public int getInstanceID() {
|
public String getFixedIP() {
|
||||||
return instanceID;
|
return this.fixedIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param instanceID the instanceID to set
|
* @return the instanceID
|
||||||
*/
|
*/
|
||||||
public void setInstanceID(int instanceID) {
|
public int getInstanceID() {
|
||||||
this.instanceID = instanceID;
|
return this.instanceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
@Override
|
||||||
* @see java.lang.Object#toString()
|
public int hashCode() {
|
||||||
*/
|
return Objects.hashCode(super.hashCode(), ip, fixedIP, instanceID);
|
||||||
@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)
|
@Override
|
||||||
* @see java.lang.Object#hashCode()
|
public boolean equals(Object obj) {
|
||||||
*/
|
if (this == obj) return true;
|
||||||
@Override
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
public int hashCode() {
|
FloatingIP that = FloatingIP.class.cast(obj);
|
||||||
final int prime = 31;
|
return super.equals(that)
|
||||||
int result = 1;
|
&& Objects.equal(this.ip, that.ip)
|
||||||
result = prime * result + ((fixedIP == null) ? 0 : fixedIP.hashCode());
|
&& Objects.equal(this.fixedIP, that.fixedIP)
|
||||||
result = prime * result + id;
|
&& Objects.equal(this.instanceID, that.instanceID);
|
||||||
result = prime * result + instanceID;
|
}
|
||||||
result = prime * result + ((ip == null) ? 0 : ip.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
protected ToStringHelper string() {
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
return super.string().add("ip", ip).add("fixedIP", fixedIP).add("instanceID", instanceID);
|
||||||
*/
|
}
|
||||||
@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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,11 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
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.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
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
|
* 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 {
|
public class Image extends Resource {
|
||||||
|
|
||||||
private int id;
|
public static Builder<?> builder() {
|
||||||
private String name;
|
return new ConcreteBuilder();
|
||||||
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 Date getUpdated() {
|
public Builder<?> toBuilder() {
|
||||||
return updated;
|
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() {
|
/**
|
||||||
|
* @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<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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image(int id, String name) {
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
this.id = id;
|
@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.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;
|
this.progress = progress;
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getProgress() {
|
|
||||||
return progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServerRef(String serverRef) {
|
|
||||||
this.serverRef = serverRef;
|
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() {
|
public String getServerRef() {
|
||||||
return serverRef;
|
return this.serverRef;
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(ImageStatus status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public ImageStatus getStatus() {
|
public ImageStatus getStatus() {
|
||||||
return status;
|
return this.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, String> getMetadata() {
|
public Map<String, String> getMetadata() {
|
||||||
return Collections.unmodifiableMap(metadata);
|
return this.metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMetadata(Map<String, String> metadata) {
|
@Nullable
|
||||||
this.metadata = Maps.newHashMap(metadata);
|
public Date getCreated() {
|
||||||
|
return this.created;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Date getUpdated() {
|
||||||
|
return this.updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* note that this ignores some fields
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(super.hashCode(), name, serverRef);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* note that this ignores some fields
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Image that = Image.class.cast(obj);
|
||||||
return false;
|
return super.equals(that)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.name, that.name)
|
||||||
return false;
|
&& Objects.equal(this.serverRef, that.serverRef);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected ToStringHelper string() {
|
||||||
public String toString() {
|
return super.string().add("name", name).add("progress", progress).add("serverRef", serverRef).add("status", status)
|
||||||
return "Image [created=" + getCreated() + ", id=" + id + ", name=" + name + ", serverRef="
|
.add("metadata", metadata).add("created", created).add("updated", updated);
|
||||||
+ serverRef + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,29 +18,114 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.List;
|
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 {
|
public class Limits {
|
||||||
|
|
||||||
private List<RateLimit> rate = Lists.newArrayList();
|
public static Builder<?> builder() {
|
||||||
private List<AbsoluteLimit> absolute = Lists.newArrayList();
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
public void setRate(List<RateLimit> rate) {
|
public Builder<?> toBuilder() {
|
||||||
this.rate = rate;
|
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() {
|
public List<RateLimit> getRate() {
|
||||||
return rate;
|
return this.rate;
|
||||||
}
|
|
||||||
|
|
||||||
public void setAbsolute(List<AbsoluteLimit> absolute) {
|
|
||||||
this.absolute = absolute;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AbsoluteLimit> getAbsolute() {
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,10 +18,16 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* RateLimit.
|
* RateLimit.
|
||||||
* <p/>
|
* <p/>
|
||||||
* we specify rate limits in terms of both a human readable wild-card URI and a machine processable
|
* 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.
|
* will be returned with a Reply-After header to notify the client when theyagain.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class RateLimit {
|
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 uri;
|
||||||
private final String regex;
|
private final String regex;
|
||||||
private final int remaining;
|
private final int remaining;
|
||||||
|
@ -47,43 +151,74 @@ public class RateLimit {
|
||||||
private final int value;
|
private final int value;
|
||||||
private final HttpMethod verb;
|
private final HttpMethod verb;
|
||||||
|
|
||||||
public RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit,
|
@ConstructorProperties({
|
||||||
int value, HttpMethod verb) {
|
"uri", "regex", "remaining", "resetTime", "unit", "value", "verb"
|
||||||
this.uri = uri;
|
})
|
||||||
this.regex = regex;
|
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.remaining = remaining;
|
||||||
this.resetTime = resetTime;
|
this.resetTime = resetTime;
|
||||||
this.unit = unit;
|
this.unit = checkNotNull(unit, "unit");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.verb = verb;
|
this.verb = checkNotNull(verb, "verb");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return this.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRegex() {
|
public String getRegex() {
|
||||||
return regex;
|
return this.regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRemaining() {
|
public int getRemaining() {
|
||||||
return remaining;
|
return this.remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getResetTime() {
|
public long getResetTime() {
|
||||||
return resetTime;
|
return this.resetTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RateLimitUnit getUnit() {
|
public RateLimitUnit getUnit() {
|
||||||
return unit;
|
return this.unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpMethod getVerb() {
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,65 +18,127 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
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.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
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.Functions;
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
import com.google.common.base.Predicate;
|
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 Dmitri Babaev
|
||||||
* @author Matt Stephenson
|
* @author Matt Stephenson
|
||||||
*/
|
*/
|
||||||
public class Resource {
|
public abstract class Resource {
|
||||||
|
|
||||||
private List<Map<String, String>> links = Lists.newArrayList();
|
public static enum LinkType {
|
||||||
|
BOOKMARK_JSON(new Predicate<Map<String, String>>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(@Nullable Map<String, String> linkMap) {
|
||||||
|
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark") &&
|
||||||
|
Functions.forMap(linkMap, "").apply("type").contains("json");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
BOOKMARK_ANY(new Predicate<Map<String, String>>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(@Nullable Map<String, String> linkMap) {
|
||||||
|
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
SELF(new Predicate<Map<String, String>>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(@Nullable Map<String, String> linkMap) {
|
||||||
|
return Functions.forMap(linkMap, "").apply("rel").equals("self");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//This is the preference order for returning a URI in getURI
|
Predicate<Map<String, String>> linkPredicate;
|
||||||
private enum LinkType {
|
|
||||||
BOOKMARK_JSON(new Predicate<Map<String, String>>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(@Nullable Map<String, String> linkMap) {
|
|
||||||
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark") &&
|
|
||||||
Functions.forMap(linkMap, "").apply("type").contains("json");
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
BOOKMARK_ANY(new Predicate<Map<String, String>>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(@Nullable Map<String, String> linkMap) {
|
|
||||||
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark");
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
SELF(new Predicate<Map<String, String>>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(@Nullable Map<String, String> linkMap) {
|
|
||||||
return Functions.forMap(linkMap, "").apply("rel").equals("self");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Predicate<Map<String,String>> linkPredicate;
|
LinkType(Predicate<Map<String, String>> linkPredicate) {
|
||||||
|
this.linkPredicate = 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(){
|
protected int id;
|
||||||
orderedSelfReferences = new ConcurrentSkipListMap<LinkType,URI>();
|
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() {
|
private void populateOrderedSelfReferences() {
|
||||||
for (Map<String, String> linkProperties : links) {
|
for (Map<String, String> linkProperties : links) {
|
||||||
for (LinkType type : LinkType.values()) {
|
for (LinkType type : LinkType.values()) {
|
||||||
if(type.linkPredicate.apply(linkProperties)) {
|
if (type.linkPredicate.apply(linkProperties)) {
|
||||||
try {
|
try {
|
||||||
orderedSelfReferences.put(type, new URI(linkProperties.get("href")));
|
orderedSelfReferences.put(type, new URI(linkProperties.get("href")));
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
|
@ -85,21 +147,45 @@ public class Resource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(orderedSelfReferences.isEmpty())
|
if (orderedSelfReferences.isEmpty())
|
||||||
throw new IllegalStateException("URI is not available");
|
throw new IllegalStateException("URI is not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI getURI() {
|
public URI getURI() {
|
||||||
if(orderedSelfReferences.isEmpty())
|
if (orderedSelfReferences.isEmpty())
|
||||||
populateOrderedSelfReferences();
|
populateOrderedSelfReferences();
|
||||||
|
|
||||||
return orderedSelfReferences.firstEntry().getValue();
|
return orderedSelfReferences.firstEntry().getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI getSelfURI() {
|
public URI getSelfURI() {
|
||||||
if(orderedSelfReferences.isEmpty())
|
if (orderedSelfReferences.isEmpty())
|
||||||
populateOrderedSelfReferences();
|
populateOrderedSelfReferences();
|
||||||
|
|
||||||
return orderedSelfReferences.get(LinkType.SELF);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,148 +18,159 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
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
|
* Defines a security group
|
||||||
*
|
*
|
||||||
* @author chamerling
|
* @author chamerling
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
public class SecurityGroup {
|
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")
|
protected int id;
|
||||||
private String tenantId;
|
protected String name;
|
||||||
|
protected String description;
|
||||||
|
protected String tenantId;
|
||||||
|
|
||||||
public SecurityGroup() {
|
/**
|
||||||
}
|
* @see SecurityGroup#getId()
|
||||||
|
*/
|
||||||
|
public T id(int id) {
|
||||||
|
this.id = id;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the id
|
* @see SecurityGroup#getName()
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public T name(String name) {
|
||||||
return id;
|
this.name = name;
|
||||||
}
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id the id to set
|
* @see SecurityGroup#getDescription()
|
||||||
*/
|
*/
|
||||||
public void setId(int id) {
|
public T description(String description) {
|
||||||
this.id = id;
|
this.description = description;
|
||||||
}
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the name
|
* @see SecurityGroup#getTenantId()
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public T tenantId(String tenantId) {
|
||||||
return name;
|
this.tenantId = tenantId;
|
||||||
}
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public SecurityGroup build() {
|
||||||
* @param name the name to set
|
return new SecurityGroup(id, name, description, tenantId);
|
||||||
*/
|
}
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public T fromSecurityGroup(SecurityGroup in) {
|
||||||
* @return the description
|
return this
|
||||||
*/
|
.id(in.getId())
|
||||||
public String getDescription() {
|
.name(in.getName())
|
||||||
return description;
|
.description(in.getDescription())
|
||||||
}
|
.tenantId(in.getTenantId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
* @param description the description to set
|
@Override
|
||||||
*/
|
protected ConcreteBuilder self() {
|
||||||
public void setDescription(String description) {
|
return this;
|
||||||
this.description = description;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private final int id;
|
||||||
* @return the tenantId
|
private final String name;
|
||||||
*/
|
private final String description;
|
||||||
public String getTenantId() {
|
private final String tenantId;
|
||||||
return tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@ConstructorProperties({
|
||||||
* @param tenantId the tenantId to set
|
"id", "name", "description", "tenant_id"
|
||||||
*/
|
})
|
||||||
public void setTenantId(String tenantId) {
|
protected SecurityGroup(int id, String name, @Nullable String description, @Nullable String tenantId) {
|
||||||
this.tenantId = tenantId;
|
this.id = id;
|
||||||
}
|
this.name = checkNotNull(name, "name");
|
||||||
|
this.description = description;
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see java.lang.Object#toString()
|
* @return the id
|
||||||
*/
|
*/
|
||||||
@Override
|
public int getId() {
|
||||||
public String toString() {
|
return this.id;
|
||||||
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()
|
* @return the name
|
||||||
*/
|
*/
|
||||||
@Override
|
public String getName() {
|
||||||
public int hashCode() {
|
return this.name;
|
||||||
final int prime = 31;
|
}
|
||||||
int result = 1;
|
|
||||||
result = prime * result
|
/**
|
||||||
+ ((description == null) ? 0 : description.hashCode());
|
* @return the description
|
||||||
result = prime * result + id;
|
*/
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
@Nullable
|
||||||
result = prime * result
|
public String getDescription() {
|
||||||
+ ((tenantId == null) ? 0 : tenantId.hashCode());
|
return this.description;
|
||||||
return result;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,13 +18,21 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
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.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
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.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A server is a virtual machine instance in the OpenStack Nova system. Flavor and image are
|
* 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
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Server extends Resource {
|
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;
|
|
||||||
|
|
||||||
@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<SecurityGroup> securityGroups = Sets.newHashSet();
|
|
||||||
|
|
||||||
private Date created;
|
|
||||||
private Date updated;
|
|
||||||
|
|
||||||
public Date getCreated() {
|
|
||||||
return created;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getUpdated() {
|
public Builder<?> toBuilder() {
|
||||||
return updated;
|
return new ConcreteBuilder().fromServer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
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<String, String> 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<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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Server(int id, String name) {
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
this.id = id;
|
@Override
|
||||||
this.name = name;
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAffinityId() {
|
private final String name;
|
||||||
return affinityId;
|
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;
|
||||||
|
|
||||||
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<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.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 void setMetadata(Map<String, String> metadata) {
|
public String getName() {
|
||||||
this.metadata = metadata;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getMetadata() {
|
public Map<String, String> getMetadata() {
|
||||||
return metadata;
|
return this.metadata;
|
||||||
}
|
|
||||||
|
|
||||||
public void setAddresses(Addresses addresses) {
|
|
||||||
this.addresses = addresses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Addresses getAddresses() {
|
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() {
|
public String getAdminPass() {
|
||||||
return adminPass;
|
return this.adminPass;
|
||||||
}
|
|
||||||
|
|
||||||
public void setFlavorRef(String flavorRef) {
|
|
||||||
this.flavorRef = flavorRef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getFlavor()}
|
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getFlavor()}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Nullable
|
||||||
public String getFlavorRef() {
|
public String getFlavorRef() {
|
||||||
return flavorRef;
|
return this.flavorRef;
|
||||||
}
|
|
||||||
|
|
||||||
public void setHostId(String hostId) {
|
|
||||||
this.hostId = hostId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,40 +368,64 @@ public class Server extends Resource {
|
||||||
* <p/>
|
* <p/>
|
||||||
* Note: hostId is unique PER ACCOUNT and is not globally unique.
|
* Note: hostId is unique PER ACCOUNT and is not globally unique.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getHostId() {
|
public String getHostId() {
|
||||||
return hostId;
|
return this.hostId;
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImageRef(String imageRef) {
|
|
||||||
this.imageRef = imageRef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getImage()}.
|
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getImage()}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Nullable
|
||||||
public String getImageRef() {
|
public String getImageRef() {
|
||||||
return imageRef;
|
return this.imageRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
@Nullable
|
||||||
return name;
|
public String getAffinityId() {
|
||||||
|
return this.affinityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgress(Integer progress) {
|
@Nullable
|
||||||
this.progress = progress;
|
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() {
|
public Integer getProgress() {
|
||||||
return progress;
|
return this.progress;
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(ServerStatus status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,196 +433,48 @@ public class Server extends Resource {
|
||||||
* state. Servers with an ACTIVE status are available for use.
|
* state. Servers with an ACTIVE status are available for use.
|
||||||
*/
|
*/
|
||||||
public ServerStatus getStatus() {
|
public ServerStatus getStatus() {
|
||||||
return status;
|
return this.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(super.hashCode(), name, metadata, addresses, accessIPv4, accessIPv6, adminPass, flavorRef,
|
||||||
int result = 1;
|
hostId, imageRef, affinityId, uuid, flavor, image, keyName, securityGroups, created, updated);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Server that = Server.class.cast(obj);
|
||||||
return false;
|
return super.equals(that)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.name, that.name)
|
||||||
return false;
|
&& Objects.equal(this.metadata, that.metadata)
|
||||||
Server other = (Server) obj;
|
&& Objects.equal(this.addresses, that.addresses)
|
||||||
if (addresses == null) {
|
&& Objects.equal(this.accessIPv4, that.accessIPv4)
|
||||||
if (other.addresses != null)
|
&& Objects.equal(this.accessIPv6, that.accessIPv6)
|
||||||
return false;
|
&& Objects.equal(this.adminPass, that.adminPass)
|
||||||
} else if (!addresses.equals(other.addresses))
|
&& Objects.equal(this.flavorRef, that.flavorRef)
|
||||||
return false;
|
&& Objects.equal(this.hostId, that.hostId)
|
||||||
if (adminPass == null) {
|
&& Objects.equal(this.imageRef, that.imageRef)
|
||||||
if (other.adminPass != null)
|
&& Objects.equal(this.affinityId, that.affinityId)
|
||||||
return false;
|
&& Objects.equal(this.uuid, that.uuid)
|
||||||
} else if (!adminPass.equals(other.adminPass))
|
&& Objects.equal(this.flavor, that.flavor)
|
||||||
return false;
|
&& Objects.equal(this.image, that.image)
|
||||||
if (flavorRef == null) {
|
&& Objects.equal(this.keyName, that.keyName)
|
||||||
if (other.flavorRef != null)
|
&& Objects.equal(this.securityGroups, that.securityGroups)
|
||||||
return false;
|
&& Objects.equal(this.created, that.created)
|
||||||
} else if (!flavorRef.equals(other.flavorRef))
|
&& Objects.equal(this.updated, that.updated);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
protected ToStringHelper string() {
|
||||||
this.name = name;
|
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 + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.encryption.internal.Base64;
|
import org.jclouds.encryption.internal.Base64;
|
||||||
import org.jclouds.http.HttpRequest;
|
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.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CreateServerOptions implements MapBinder {
|
public class CreateServerOptions implements MapBinder {
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -73,24 +72,30 @@ public class CreateServerOptions implements MapBinder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private class ServerRequest {
|
private class ServerRequest {
|
||||||
final String name;
|
final String name;
|
||||||
final String imageRef;
|
final String imageRef;
|
||||||
final String flavorRef;
|
final String flavorRef;
|
||||||
String adminPass;
|
final String adminPass;
|
||||||
Map<String, String> metadata;
|
final Map<String, String> metadata;
|
||||||
List<File> personality;
|
final List<File> personality;
|
||||||
String key_name;
|
@Named("key_name")
|
||||||
@SerializedName(value="security_groups")
|
final String keyName;
|
||||||
Set<SecurityGroup> securityGroups;
|
@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.name = name;
|
||||||
this.imageRef = imageRef;
|
this.imageRef = imageRef;
|
||||||
this.flavorRef = flavorRef;
|
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();
|
private Map<String, String> metadata = Maps.newHashMap();
|
||||||
|
@ -101,26 +106,19 @@ public class CreateServerOptions implements MapBinder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
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(),
|
Set<SecurityGroup> groups = Sets.newLinkedHashSet();
|
||||||
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
|
for (String groupName : securityGroups) {
|
||||||
checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString());
|
groups.add(SecurityGroup.builder().name(groupName).build());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
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));
|
return bindToRequest(request, ImmutableMap.of("server", server));
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,19 +30,17 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ServerTest {
|
public class ServerTest {
|
||||||
public void testStatusDoesntAffectEquals() {
|
public void testStatusDoesntAffectEquals() {
|
||||||
Server server1 = new Server(1, "hello");
|
Server server1 = Server.builder().id(1).name("hello").status(ServerStatus.ACTIVE).build();
|
||||||
server1.setStatus(ServerStatus.ACTIVE);
|
Server server2 = Server.builder().id(1).name("hello").status(ServerStatus.BUILD).build();
|
||||||
Server server2 = new Server(1, "hello");
|
|
||||||
server2.setStatus(ServerStatus.BUILD);
|
|
||||||
assertEquals(server1, server2);
|
assertEquals(server1, server2);
|
||||||
|
assertEquals(server1.hashCode(), server2.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testProgressDoesntAffectEquals() {
|
public void testProgressDoesntAffectEquals() {
|
||||||
Server server1 = new Server(1, "hello");
|
Server server1 = Server.builder().id(1).name("hello").progress(1).build();
|
||||||
server1.setProgress(1);
|
Server server2 = Server.builder().id(1).name("hello").progress(2).build();
|
||||||
Server server2 = new Server(1, "hello");
|
|
||||||
server2.setProgress(2);
|
|
||||||
assertEquals(server1, server2);
|
assertEquals(server1, server2);
|
||||||
|
assertEquals(server1.hashCode(), server2.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,8 @@ public class ParseFlavorListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
|
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,
|
List<Flavor> expects = ImmutableList.of(Flavor.builder().id(1).name("256 MB Server").build(),
|
||||||
"512 MB Server", null, null, null));
|
Flavor.builder().id(2).name("512 MB Server").build());
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
|
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class ParseFloatingIPListFromJsonResponse {
|
||||||
.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
||||||
|
|
||||||
assertEquals(response.size(), 1);
|
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);
|
assertEquals(response.get(0), floatingIP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,8 @@ public class ParseImageListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
|
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
|
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.SimpleTimeZone;
|
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"),
|
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||||
Address.newString2AddressFunction()));
|
Address.newString2AddressFunction()));
|
||||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
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.getAddresses(), addresses1);
|
||||||
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.io.InputStream;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.SimpleTimeZone;
|
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"),
|
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||||
Address.newString2AddressFunction()));
|
Address.newString2AddressFunction()));
|
||||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
||||||
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
|
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
|
||||||
new HashSet<Address>(privateAddresses));
|
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
@ -62,11 +61,12 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
|
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
|
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
||||||
}));
|
}));
|
||||||
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
||||||
|
|
||||||
assertEquals(response, expects);
|
assertEquals(response, expects);
|
||||||
|
@ -77,8 +77,8 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json");
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
||||||
}));
|
}));
|
||||||
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
||||||
|
|
||||||
assertEquals(response.get(0).getId(), 1234);
|
assertEquals(response.get(0).getId(), 1234);
|
||||||
|
@ -91,12 +91,11 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
|
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
|
||||||
|
|
||||||
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
|
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||||
Address.newString2AddressFunction()));
|
Address.newString2AddressFunction()));
|
||||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
||||||
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
|
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
|
||||||
new HashSet<Address>(privateAddresses));
|
|
||||||
|
|
||||||
assertEquals(response.get(0).getAddresses(), addresses1);
|
assertEquals(response.get(0).getAddresses(), addresses1);
|
||||||
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
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);
|
assertEquals(response.get(1).getProgress(), null);
|
||||||
|
|
||||||
List<Address> publicAddresses2 = ImmutableList.copyOf(Iterables.transform(
|
List<Address> 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<Address> privateAddresses2 = ImmutableList.copyOf(Iterables.transform(
|
List<Address> privateAddresses2 = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("10.176.42.17", "::babe:10.176.42.17"), Address.newString2AddressFunction()));
|
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).getAddresses(), addresses2);
|
||||||
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
||||||
|
|
Loading…
Reference in New Issue