mirror of https://github.com/apache/jclouds.git
cloudservers: Issue 971 changing to immutable domain objects with builders, annotated with ConstructorProperties and Named
This commit is contained in:
parent
2f01337b64
commit
74f8b2d0c0
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,30 +18,109 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.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;
|
||||
|
||||
/**
|
||||
* Class AbsoluteLimit
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class AbsoluteLimit {
|
||||
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromAbsoluteLimit(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected String name;
|
||||
protected int value;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
/**
|
||||
* @see AbsoluteLimit#getName()
|
||||
*/
|
||||
public T name(String name) {
|
||||
this.name = name;
|
||||
return self();
|
||||
}
|
||||
|
||||
public void setName(String value) {
|
||||
this.name = value;
|
||||
/**
|
||||
* @see AbsoluteLimit#getValue()
|
||||
*/
|
||||
public T value(int value) {
|
||||
this.value = value;
|
||||
return self();
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
public AbsoluteLimit build() {
|
||||
return new AbsoluteLimit(name, value);
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
public T fromAbsoluteLimit(AbsoluteLimit in) {
|
||||
return this
|
||||
.name(in.getName())
|
||||
.value(in.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final int value;
|
||||
|
||||
@ConstructorProperties({
|
||||
"name", "value"
|
||||
})
|
||||
protected AbsoluteLimit(String name, int value) {
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
AbsoluteLimit that = AbsoluteLimit.class.cast(obj);
|
||||
return Objects.equal(this.name, that.name)
|
||||
&& Objects.equal(this.value, that.value);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("name", name).add("value", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,81 +18,128 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Class Addresses
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Addresses {
|
||||
|
||||
@SerializedName("public")
|
||||
private Set<String> publicAddresses = Sets.newLinkedHashSet();
|
||||
@SerializedName("private")
|
||||
private Set<String> privateAddresses = Sets.newLinkedHashSet();
|
||||
|
||||
public Addresses() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Addresses(Set<String> publicAddresses, Set<String> privateAddresses) {
|
||||
this.publicAddresses = publicAddresses;
|
||||
this.privateAddresses = privateAddresses;
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromAddresses(this);
|
||||
}
|
||||
|
||||
public void setPublicAddresses(Set<String> publicAddresses) {
|
||||
this.publicAddresses = publicAddresses;
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected Set<String> publicAddresses;
|
||||
protected Set<String> privateAddresses;
|
||||
|
||||
/**
|
||||
* @see Addresses#getPublicAddresses()
|
||||
*/
|
||||
public T publicAddresses(Collection<String> publicAddresses) {
|
||||
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
|
||||
return self();
|
||||
}
|
||||
|
||||
public Set<String> getPublicAddresses() {
|
||||
return publicAddresses;
|
||||
public T publicAddresses(String... in) {
|
||||
return publicAddresses(ImmutableSet.copyOf(in));
|
||||
}
|
||||
|
||||
public void setPrivateAddresses(Set<String> privateAddresses) {
|
||||
this.privateAddresses = privateAddresses;
|
||||
/**
|
||||
* @see Addresses#getPrivateAddresses()
|
||||
*/
|
||||
public T privateAddresses(Collection<String> privateAddresses) {
|
||||
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
|
||||
return self();
|
||||
}
|
||||
|
||||
public Set<String> getPrivateAddresses() {
|
||||
return privateAddresses;
|
||||
public T privateAddresses(String... 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
|
||||
public String toString() {
|
||||
return "Addresses [privateAddresses=" + privateAddresses + ", publicAddresses="
|
||||
+ publicAddresses + "]";
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Named("public")
|
||||
private final Set<String> publicAddresses;
|
||||
@Named("private")
|
||||
private final Set<String> privateAddresses;
|
||||
|
||||
@ConstructorProperties({
|
||||
"public", "private"
|
||||
})
|
||||
protected Addresses(@Nullable Set<String> publicAddresses, @Nullable Set<String> privateAddresses) {
|
||||
this.publicAddresses = publicAddresses == null ? null : ImmutableSet.copyOf(publicAddresses);
|
||||
this.privateAddresses = privateAddresses == null ? null : ImmutableSet.copyOf(privateAddresses);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Set<String> getPublicAddresses() {
|
||||
return this.publicAddresses;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Set<String> getPrivateAddresses() {
|
||||
return this.privateAddresses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
|
||||
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
|
||||
return result;
|
||||
return Objects.hashCode(publicAddresses, privateAddresses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Addresses other = (Addresses) obj;
|
||||
if (privateAddresses == null) {
|
||||
if (other.privateAddresses != null)
|
||||
return false;
|
||||
} else if (!privateAddresses.equals(other.privateAddresses))
|
||||
return false;
|
||||
if (publicAddresses == null) {
|
||||
if (other.publicAddresses != null)
|
||||
return false;
|
||||
} else if (!publicAddresses.equals(other.publicAddresses))
|
||||
return false;
|
||||
return true;
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
Addresses that = Addresses.class.cast(obj);
|
||||
return Objects.equal(this.publicAddresses, that.publicAddresses)
|
||||
&& Objects.equal(this.privateAddresses, that.privateAddresses);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("publicAddresses", publicAddresses).add("privateAddresses", privateAddresses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,6 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* A backup schedule can be defined to create server images at regular intervals (daily and weekly).
|
||||
* Backup schedules are configurable per server.
|
||||
|
@ -25,80 +34,115 @@ package org.jclouds.cloudservers.domain;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class BackupSchedule {
|
||||
protected DailyBackup daily = DailyBackup.DISABLED;
|
||||
protected boolean enabled;
|
||||
protected WeeklyBackup weekly = WeeklyBackup.DISABLED;
|
||||
|
||||
public BackupSchedule() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public BackupSchedule(WeeklyBackup weekly, DailyBackup daily, boolean enabled) {
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromBackupSchedule(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected DailyBackup daily;
|
||||
protected boolean enabled;
|
||||
protected WeeklyBackup weekly;
|
||||
|
||||
/**
|
||||
* @see BackupSchedule#getDaily()
|
||||
*/
|
||||
public T daily(DailyBackup daily) {
|
||||
this.daily = daily;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BackupSchedule#isEnabled()
|
||||
*/
|
||||
public T enabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BackupSchedule#getWeekly()
|
||||
*/
|
||||
public T weekly(WeeklyBackup weekly) {
|
||||
this.weekly = weekly;
|
||||
return self();
|
||||
}
|
||||
|
||||
public BackupSchedule build() {
|
||||
return new BackupSchedule(daily, enabled, weekly);
|
||||
}
|
||||
|
||||
public T fromBackupSchedule(BackupSchedule in) {
|
||||
return this
|
||||
.daily(in.getDaily())
|
||||
.enabled(in.isEnabled())
|
||||
.weekly(in.getWeekly());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final DailyBackup daily;
|
||||
private final boolean enabled;
|
||||
private final WeeklyBackup weekly;
|
||||
|
||||
@ConstructorProperties({
|
||||
"daily", "enabled", "weekly"
|
||||
})
|
||||
protected BackupSchedule(@Nullable DailyBackup daily, boolean enabled, @Nullable WeeklyBackup weekly) {
|
||||
this.daily = daily;
|
||||
this.enabled = enabled;
|
||||
this.weekly = weekly;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DailyBackup getDaily() {
|
||||
return daily;
|
||||
}
|
||||
|
||||
public void setDaily(DailyBackup value) {
|
||||
this.daily = value;
|
||||
return this.daily;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean value) {
|
||||
this.enabled = value;
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public WeeklyBackup getWeekly() {
|
||||
return weekly;
|
||||
}
|
||||
|
||||
public void setWeekly(WeeklyBackup value) {
|
||||
this.weekly = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[daily=" + daily + ", enabled=" + enabled + ", weekly=" + weekly + "]";
|
||||
return this.weekly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((daily == null) ? 0 : daily.hashCode());
|
||||
result = prime * result + (enabled ? 1231 : 1237);
|
||||
result = prime * result + ((weekly == null) ? 0 : weekly.hashCode());
|
||||
return result;
|
||||
return Objects.hashCode(daily, enabled, weekly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
BackupSchedule other = (BackupSchedule) obj;
|
||||
if (daily == null) {
|
||||
if (other.daily != null)
|
||||
return false;
|
||||
} else if (!daily.equals(other.daily))
|
||||
return false;
|
||||
if (enabled != other.enabled)
|
||||
return false;
|
||||
if (weekly == null) {
|
||||
if (other.weekly != null)
|
||||
return false;
|
||||
} else if (!weekly.equals(other.weekly))
|
||||
return false;
|
||||
return true;
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
BackupSchedule that = BackupSchedule.class.cast(obj);
|
||||
return Objects.equal(this.daily, that.daily)
|
||||
&& Objects.equal(this.enabled, that.enabled)
|
||||
&& Objects.equal(this.weekly, that.weekly);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("daily", daily).add("enabled", enabled).add("weekly", weekly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,8 +18,16 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* A flavor is an available hardware configuration for a server. Each flavor has a unique
|
||||
* combination of disk space and memory capacity.
|
||||
*
|
||||
|
@ -27,94 +35,131 @@ package org.jclouds.cloudservers.domain;
|
|||
*/
|
||||
public class Flavor {
|
||||
|
||||
public Flavor() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + "]";
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromFlavor(this);
|
||||
}
|
||||
|
||||
public Flavor(int id, String name) {
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected int id;
|
||||
protected String name;
|
||||
protected Integer disk;
|
||||
protected Integer ram;
|
||||
|
||||
/**
|
||||
* @see Flavor#getId()
|
||||
*/
|
||||
public T id(int id) {
|
||||
this.id = id;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Flavor#getName()
|
||||
*/
|
||||
public T name(String name) {
|
||||
this.name = name;
|
||||
return self();
|
||||
}
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private Integer disk;
|
||||
private Integer ram;
|
||||
|
||||
public Integer getDisk() {
|
||||
return disk;
|
||||
/**
|
||||
* @see Flavor#getDisk()
|
||||
*/
|
||||
public T disk(Integer disk) {
|
||||
this.disk = disk;
|
||||
return self();
|
||||
}
|
||||
|
||||
public void setDisk(Integer value) {
|
||||
this.disk = value;
|
||||
/**
|
||||
* @see Flavor#getRam()
|
||||
*/
|
||||
public T ram(Integer ram) {
|
||||
this.ram = ram;
|
||||
return self();
|
||||
}
|
||||
|
||||
public Flavor build() {
|
||||
return new Flavor(id, name, disk, ram);
|
||||
}
|
||||
|
||||
public T fromFlavor(Flavor in) {
|
||||
return this
|
||||
.id(in.getId())
|
||||
.name(in.getName())
|
||||
.disk(in.getDisk())
|
||||
.ram(in.getRam());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final Integer disk;
|
||||
private final Integer ram;
|
||||
|
||||
@ConstructorProperties({
|
||||
"id", "name", "disk", "ram"
|
||||
})
|
||||
protected Flavor(int id, String name, @Nullable Integer disk, @Nullable Integer ram) {
|
||||
this.id = id;
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.disk = disk;
|
||||
this.ram = ram;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int value) {
|
||||
this.id = value;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String value) {
|
||||
this.name = value;
|
||||
@Nullable
|
||||
public Integer getDisk() {
|
||||
return this.disk;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getRam() {
|
||||
return ram;
|
||||
}
|
||||
|
||||
public void setRam(Integer value) {
|
||||
this.ram = value;
|
||||
return this.ram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((disk == null) ? 0 : disk.hashCode());
|
||||
result = prime * result + id;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((ram == null) ? 0 : ram.hashCode());
|
||||
return result;
|
||||
return Objects.hashCode(id, name, disk, ram);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Flavor other = (Flavor) obj;
|
||||
if (disk == null) {
|
||||
if (other.disk != null)
|
||||
return false;
|
||||
} else if (!disk.equals(other.disk))
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (ram == null) {
|
||||
if (other.ram != null)
|
||||
return false;
|
||||
} else if (!ram.equals(other.ram))
|
||||
return false;
|
||||
return true;
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
Flavor that = Flavor.class.cast(obj);
|
||||
return Objects.equal(this.id, that.id)
|
||||
&& Objects.equal(this.name, that.name)
|
||||
&& Objects.equal(this.disk, that.disk)
|
||||
&& Objects.equal(this.ram, that.ram);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("id", id).add("name", name).add("disk", disk).add("ram", ram);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,8 +18,16 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* An image is a collection of files used to create or rebuild a server. Rackspace provides a number
|
||||
* of pre-built OS images by default. You may also create custom images from cloud servers you have
|
||||
|
@ -30,116 +38,185 @@ import java.util.Date;
|
|||
*/
|
||||
public class Image {
|
||||
|
||||
private Date created;
|
||||
private int id;
|
||||
private String name;
|
||||
private Integer progress;
|
||||
private Integer serverId;
|
||||
private ImageStatus status;
|
||||
private Date updated;
|
||||
|
||||
public Image() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Image(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromImage(this);
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected Date created;
|
||||
protected int id;
|
||||
protected String name;
|
||||
protected Integer progress;
|
||||
protected Integer serverId;
|
||||
protected ImageStatus status;
|
||||
protected Date updated;
|
||||
|
||||
/**
|
||||
* @see Image#getCreated()
|
||||
*/
|
||||
public T created(Date created) {
|
||||
this.created = created;
|
||||
return self();
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
/**
|
||||
* @see Image#getId()
|
||||
*/
|
||||
public T id(int id) {
|
||||
this.id = id;
|
||||
return self();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
/**
|
||||
* @see Image#getName()
|
||||
*/
|
||||
public T name(String name) {
|
||||
this.name = name;
|
||||
return self();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setProgress(Integer progress) {
|
||||
/**
|
||||
* @see Image#getProgress()
|
||||
*/
|
||||
public T progress(Integer progress) {
|
||||
this.progress = progress;
|
||||
return self();
|
||||
}
|
||||
|
||||
public Integer getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setServerId(Integer serverId) {
|
||||
/**
|
||||
* @see Image#getServerId()
|
||||
*/
|
||||
public T serverId(Integer serverId) {
|
||||
this.serverId = serverId;
|
||||
return self();
|
||||
}
|
||||
|
||||
public Integer getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
public void setStatus(ImageStatus status) {
|
||||
/**
|
||||
* @see Image#getStatus()
|
||||
*/
|
||||
public T status(ImageStatus status) {
|
||||
this.status = status;
|
||||
return self();
|
||||
}
|
||||
|
||||
public ImageStatus getStatus() {
|
||||
return status;
|
||||
/**
|
||||
* @see Image#getUpdated()
|
||||
*/
|
||||
public T updated(Date updated) {
|
||||
this.updated = updated;
|
||||
return self();
|
||||
}
|
||||
|
||||
public void setUpdated(Date updated) {
|
||||
public Image build() {
|
||||
return new Image(created, id, name, progress, serverId, status, updated);
|
||||
}
|
||||
|
||||
public T fromImage(Image in) {
|
||||
return this
|
||||
.created(in.getCreated())
|
||||
.id(in.getId())
|
||||
.name(in.getName())
|
||||
.progress(in.getProgress())
|
||||
.serverId(in.getServerId())
|
||||
.status(in.getStatus())
|
||||
.updated(in.getUpdated());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final Date created;
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final Integer progress;
|
||||
private final Integer serverId;
|
||||
private final ImageStatus status;
|
||||
private final Date updated;
|
||||
|
||||
@ConstructorProperties({
|
||||
"created", "id", "name", "progress", "serverId", "status", "updated"
|
||||
})
|
||||
protected Image(@Nullable Date created, int id, String name, @Nullable Integer progress, @Nullable Integer serverId, @Nullable ImageStatus status, @Nullable Date updated) {
|
||||
this.created = created;
|
||||
this.id = id;
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.progress = progress;
|
||||
this.serverId = serverId;
|
||||
this.status = status;
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public Date getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
/**
|
||||
* note that this ignores the create time
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + id;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((serverId == null) ? 0 : serverId.hashCode());
|
||||
return result;
|
||||
@Nullable
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getProgress() {
|
||||
return this.progress;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getServerId() {
|
||||
return this.serverId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ImageStatus getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Date getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(created, id, name, progress, serverId, status, updated);
|
||||
}
|
||||
|
||||
/**
|
||||
* note that this ignores the serverid and create time.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Image other = (Image) obj;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
Image that = Image.class.cast(obj);
|
||||
return Objects.equal(this.created, that.created)
|
||||
&& Objects.equal(this.id, that.id)
|
||||
&& Objects.equal(this.name, that.name)
|
||||
&& Objects.equal(this.progress, that.progress)
|
||||
&& Objects.equal(this.serverId, that.serverId)
|
||||
&& Objects.equal(this.status, that.status)
|
||||
&& Objects.equal(this.updated, that.updated);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("created", created).add("id", id).add("name", name).add("progress", progress).add("serverId", serverId).add("status", status).add("updated", updated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Image [created=" + created + ", id=" + id + ", name=" + name + ", serverId=" + serverId + ", status="
|
||||
+ status + "]";
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,59 +18,115 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Class Limits
|
||||
*/
|
||||
public class Limits {
|
||||
|
||||
private Set<RateLimit> rate = Sets.newLinkedHashSet();
|
||||
private Map<String, Integer> absolute = Maps.newLinkedHashMap();
|
||||
|
||||
public Set<RateLimit> getRate() {
|
||||
return rate;
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromLimits(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected Set<RateLimit> rate = ImmutableSet.of();
|
||||
protected Map<String, Integer> absolute = ImmutableMap.of();
|
||||
|
||||
/**
|
||||
* @see Limits#getRate()
|
||||
*/
|
||||
public T rate(Set<RateLimit> rate) {
|
||||
this.rate = ImmutableSet.copyOf(checkNotNull(rate, "rate"));
|
||||
return self();
|
||||
}
|
||||
|
||||
public T rate(RateLimit... in) {
|
||||
return rate(ImmutableSet.copyOf(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Limits#getAbsolute()
|
||||
*/
|
||||
public T absolute(Map<String, Integer> absolute) {
|
||||
this.absolute = ImmutableMap.copyOf(checkNotNull(absolute, "absolute"));
|
||||
return self();
|
||||
}
|
||||
|
||||
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
|
||||
public String toString() {
|
||||
return "Limits [rate=" + rate + ", absolute=" + absolute + "]";
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final Set<RateLimit> rate;
|
||||
private final Map<String, Integer> absolute;
|
||||
|
||||
@ConstructorProperties({
|
||||
"rate", "absolute"
|
||||
})
|
||||
protected Limits(Set<RateLimit> rate, Map<String, Integer> absolute) {
|
||||
this.rate = ImmutableSet.copyOf(checkNotNull(rate, "rate"));
|
||||
this.absolute = ImmutableMap.copyOf(checkNotNull(absolute, "absolute"));
|
||||
}
|
||||
|
||||
public Set<RateLimit> getRate() {
|
||||
return this.rate;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getAbsolute() {
|
||||
return this.absolute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((absolute == null) ? 0 : absolute.hashCode());
|
||||
result = prime * result + ((rate == null) ? 0 : rate.hashCode());
|
||||
return result;
|
||||
return Objects.hashCode(rate, absolute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Limits other = (Limits) obj;
|
||||
if (absolute == null) {
|
||||
if (other.absolute != null)
|
||||
return false;
|
||||
} else if (!absolute.equals(other.absolute))
|
||||
return false;
|
||||
if (rate == null) {
|
||||
if (other.rate != null)
|
||||
return false;
|
||||
} else if (!rate.equals(other.rate))
|
||||
return false;
|
||||
return true;
|
||||
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);
|
||||
}
|
||||
|
||||
public Map<String, Integer> getAbsolute() {
|
||||
return 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
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,8 +18,16 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* RateLimit.
|
||||
* <p/>
|
||||
* we specify rate limits in terms of both a human readable wild-card URI and a machine processable
|
||||
|
@ -37,70 +45,118 @@ package org.jclouds.cloudservers.domain;
|
|||
*/
|
||||
public class RateLimit {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((regex == null) ? 0 : regex.hashCode());
|
||||
result = prime * result + remaining;
|
||||
result = prime * result + (int) (resetTime ^ (resetTime >>> 32));
|
||||
result = prime * result + ((unit == null) ? 0 : unit.hashCode());
|
||||
result = prime * result + ((uri == null) ? 0 : uri.hashCode());
|
||||
result = prime * result + value;
|
||||
result = prime * result + ((verb == null) ? 0 : verb.hashCode());
|
||||
return result;
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
RateLimit other = (RateLimit) obj;
|
||||
if (regex == null) {
|
||||
if (other.regex != null)
|
||||
return false;
|
||||
} else if (!regex.equals(other.regex))
|
||||
return false;
|
||||
if (remaining != other.remaining)
|
||||
return false;
|
||||
if (resetTime != other.resetTime)
|
||||
return false;
|
||||
if (unit != other.unit)
|
||||
return false;
|
||||
if (uri == null) {
|
||||
if (other.uri != null)
|
||||
return false;
|
||||
} else if (!uri.equals(other.uri))
|
||||
return false;
|
||||
if (value != other.value)
|
||||
return false;
|
||||
if (verb == null) {
|
||||
if (other.verb != null)
|
||||
return false;
|
||||
} else if (!verb.equals(other.verb))
|
||||
return false;
|
||||
return true;
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromRateLimit(this);
|
||||
}
|
||||
|
||||
private String uri;
|
||||
private String regex;
|
||||
private int remaining;
|
||||
private long resetTime;
|
||||
private RateLimitUnit unit;
|
||||
private int value;
|
||||
private String verb;
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
// for deserializer
|
||||
public RateLimit() {
|
||||
protected String uri;
|
||||
protected String regex;
|
||||
protected int remaining;
|
||||
protected long resetTime;
|
||||
protected RateLimitUnit unit;
|
||||
protected int value;
|
||||
protected String verb;
|
||||
|
||||
}
|
||||
|
||||
public RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit, int value, String 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(String verb) {
|
||||
this.verb = verb;
|
||||
return self();
|
||||
}
|
||||
|
||||
public RateLimit build() {
|
||||
return new RateLimit(uri, regex, remaining, resetTime, unit, value, verb);
|
||||
}
|
||||
|
||||
public T fromRateLimit(RateLimit in) {
|
||||
return this
|
||||
.uri(in.getUri())
|
||||
.regex(in.getRegex())
|
||||
.remaining(in.getRemaining())
|
||||
.resetTime(in.getResetTime())
|
||||
.unit(in.getUnit())
|
||||
.value(in.getValue())
|
||||
.verb(in.getVerb());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final String uri;
|
||||
private final String regex;
|
||||
private final int remaining;
|
||||
private final long resetTime;
|
||||
private final RateLimitUnit unit;
|
||||
private final int value;
|
||||
private final String verb;
|
||||
|
||||
@ConstructorProperties({
|
||||
"uri", "regex", "remaining", "resetTime", "unit", "value", "verb"
|
||||
})
|
||||
protected RateLimit(String uri, @Nullable String regex, int remaining, long resetTime, @Nullable RateLimitUnit unit,
|
||||
int value, @Nullable String verb) {
|
||||
this.uri = checkNotNull(uri, "uri");
|
||||
this.regex = regex;
|
||||
this.remaining = remaining;
|
||||
this.resetTime = resetTime;
|
||||
|
@ -110,37 +166,63 @@ public class RateLimit {
|
|||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
return this.uri;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getRegex() {
|
||||
return regex;
|
||||
return this.regex;
|
||||
}
|
||||
|
||||
public int getRemaining() {
|
||||
return remaining;
|
||||
return this.remaining;
|
||||
}
|
||||
|
||||
public long getResetTime() {
|
||||
return resetTime;
|
||||
return this.resetTime;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public RateLimitUnit getUnit() {
|
||||
return unit;
|
||||
return this.unit;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String 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 "[uri=" + uri + ", regex=" + regex + ", remaining=" + remaining + ", resetTime=" + resetTime + ", unit="
|
||||
+ unit + ", value=" + value + ", verb=" + verb + "]";
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,10 +18,16 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* A server is a virtual machine instance in the Cloud Servers system. Flavor and image are
|
||||
|
@ -30,60 +36,202 @@ import com.google.common.collect.Maps;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class Server {
|
||||
private int id;
|
||||
private String name;
|
||||
private Map<String, String> metadata = Maps.newHashMap();
|
||||
private Addresses addresses;
|
||||
private String adminPass;
|
||||
private Integer flavorId;
|
||||
private String hostId;
|
||||
private Integer imageId;
|
||||
private Integer sharedIpGroupId;
|
||||
private Integer progress;
|
||||
private ServerStatus status;
|
||||
|
||||
public Server() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Server(int id, String name) {
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromServer(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected int id;
|
||||
protected String name;
|
||||
protected Map<String, String> metadata;
|
||||
protected Addresses addresses;
|
||||
protected String adminPass;
|
||||
protected Integer flavorId;
|
||||
protected String hostId;
|
||||
protected Integer imageId;
|
||||
protected Integer sharedIpGroupId;
|
||||
protected Integer progress;
|
||||
protected ServerStatus status;
|
||||
|
||||
/**
|
||||
* @see Server#getId()
|
||||
*/
|
||||
public T id(int id) {
|
||||
this.id = id;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Server#getName()
|
||||
*/
|
||||
public T name(String name) {
|
||||
this.name = name;
|
||||
return self();
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
/**
|
||||
* @see Server#getMetadata()
|
||||
*/
|
||||
public T metadata(Map<String, String> metadata) {
|
||||
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
|
||||
return self();
|
||||
}
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setAddresses(Addresses addresses) {
|
||||
/**
|
||||
* @see Server#getAddresses()
|
||||
*/
|
||||
public T addresses(Addresses addresses) {
|
||||
this.addresses = addresses;
|
||||
return self();
|
||||
}
|
||||
|
||||
public Addresses getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public void setAdminPass(String adminPass) {
|
||||
/**
|
||||
* @see Server#getAdminPass()
|
||||
*/
|
||||
public T adminPass(String adminPass) {
|
||||
this.adminPass = adminPass;
|
||||
return self();
|
||||
}
|
||||
|
||||
public String getAdminPass() {
|
||||
return adminPass;
|
||||
}
|
||||
|
||||
public void setFlavorId(Integer flavorId) {
|
||||
/**
|
||||
* @see Server#getFlavorId()
|
||||
*/
|
||||
public T flavorId(Integer flavorId) {
|
||||
this.flavorId = flavorId;
|
||||
return self();
|
||||
}
|
||||
|
||||
public Integer getFlavorId() {
|
||||
return flavorId;
|
||||
}
|
||||
|
||||
public void setHostId(String hostId) {
|
||||
/**
|
||||
* @see Server#getHostId()
|
||||
*/
|
||||
public T hostId(String hostId) {
|
||||
this.hostId = hostId;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Server#getImageId()
|
||||
*/
|
||||
public T imageId(Integer imageId) {
|
||||
this.imageId = imageId;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Server#getSharedIpGroupId()
|
||||
*/
|
||||
public T sharedIpGroupId(Integer sharedIpGroupId) {
|
||||
this.sharedIpGroupId = sharedIpGroupId;
|
||||
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, name, metadata, addresses, adminPass, flavorId, hostId, imageId, sharedIpGroupId, progress, status);
|
||||
}
|
||||
|
||||
public T fromServer(Server in) {
|
||||
return this
|
||||
.id(in.getId())
|
||||
.name(in.getName())
|
||||
.metadata(in.getMetadata())
|
||||
.addresses(in.getAddresses())
|
||||
.adminPass(in.getAdminPass())
|
||||
.flavorId(in.getFlavorId())
|
||||
.hostId(in.getHostId())
|
||||
.imageId(in.getImageId())
|
||||
.sharedIpGroupId(in.getSharedIpGroupId())
|
||||
.progress(in.getProgress())
|
||||
.status(in.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final Map<String, String> metadata;
|
||||
private final Addresses addresses;
|
||||
private final String adminPass;
|
||||
private final Integer flavorId;
|
||||
private final String hostId;
|
||||
private final Integer imageId;
|
||||
private final Integer sharedIpGroupId;
|
||||
private final Integer progress;
|
||||
private final ServerStatus status;
|
||||
|
||||
@ConstructorProperties({
|
||||
"id", "name", "metadata", "addresses", "adminPass", "flavorId", "hostId", "imageId", "sharedIpGroupId", "progress", "status"
|
||||
})
|
||||
protected Server(int id, String name, @Nullable Map<String, String> metadata, @Nullable Addresses addresses,
|
||||
@Nullable String adminPass, @Nullable Integer flavorId, @Nullable String hostId, @Nullable Integer imageId,
|
||||
@Nullable Integer sharedIpGroupId, @Nullable Integer progress, @Nullable ServerStatus status) {
|
||||
this.id = id;
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.metadata = metadata == null ? null : ImmutableMap.copyOf(metadata);
|
||||
this.addresses = addresses;
|
||||
this.adminPass = adminPass;
|
||||
this.flavorId = flavorId;
|
||||
this.hostId = hostId;
|
||||
this.imageId = imageId;
|
||||
this.sharedIpGroupId = sharedIpGroupId;
|
||||
this.progress = progress;
|
||||
this.status = status == null ? ServerStatus.UNKNOWN : status;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, String> getMetadata() {
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Addresses getAddresses() {
|
||||
return this.addresses;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAdminPass() {
|
||||
return this.adminPass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getFlavorId() {
|
||||
return this.flavorId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,48 +242,24 @@ public class Server {
|
|||
* <p/>
|
||||
* Note: hostId is unique PER ACCOUNT and is not globally unique.
|
||||
*/
|
||||
@Nullable
|
||||
public String getHostId() {
|
||||
return hostId;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setImageId(Integer imageId) {
|
||||
this.imageId = imageId;
|
||||
return this.hostId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getImageId() {
|
||||
return imageId;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setProgress(Integer progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public Integer getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setSharedIpGroupId(Integer sharedIpGroupId) {
|
||||
this.sharedIpGroupId = sharedIpGroupId;
|
||||
return this.imageId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getSharedIpGroupId() {
|
||||
return sharedIpGroupId;
|
||||
return this.sharedIpGroupId;
|
||||
}
|
||||
|
||||
public void setStatus(ServerStatus status) {
|
||||
this.status = status;
|
||||
@Nullable
|
||||
public Integer getProgress() {
|
||||
return this.progress;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,13 +267,12 @@ public class Server {
|
|||
* state. Servers with an ACTIVE status are available for use.
|
||||
*/
|
||||
public ServerStatus getStatus() {
|
||||
return status;
|
||||
return this.status;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(id, name);
|
||||
return Objects.hashCode(id, name, metadata, addresses, adminPass, flavorId, hostId, imageId, sharedIpGroupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,21 +280,25 @@ public class Server {
|
|||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
Server that = Server.class.cast(obj);
|
||||
return Objects.equal(this.getId(), that.getId())
|
||||
&& Objects.equal(this.name, that.name);
|
||||
return Objects.equal(this.id, that.id)
|
||||
&& Objects.equal(this.name, that.name)
|
||||
&& Objects.equal(this.metadata, that.metadata)
|
||||
&& Objects.equal(this.addresses, that.addresses)
|
||||
&& Objects.equal(this.adminPass, that.adminPass)
|
||||
&& Objects.equal(this.flavorId, that.flavorId)
|
||||
&& Objects.equal(this.hostId, that.hostId)
|
||||
&& Objects.equal(this.imageId, that.imageId)
|
||||
&& Objects.equal(this.sharedIpGroupId, that.sharedIpGroupId);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("id", id).add("name", name).add("metadata", metadata).add("addresses", addresses).add("adminPass", adminPass).add("flavorId", flavorId).add("hostId", hostId).add("imageId", imageId).add("sharedIpGroupId", sharedIpGroupId).add("progress", progress).add("status", status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("")
|
||||
.add("id", getId())
|
||||
.add("name", name)
|
||||
.add("addresses", addresses)
|
||||
.add("flavorId", flavorId)
|
||||
.add("imageId", imageId)
|
||||
.add("hostId", hostId)
|
||||
.add("metadata", metadata)
|
||||
.add("sharedIpGroupId", sharedIpGroupId).toString();
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,25 +18,105 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* Class ShareIp
|
||||
*/
|
||||
public class ShareIp {
|
||||
|
||||
private boolean configureServer;
|
||||
private int sharedIpGroupId;
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public void setConfigureServer(boolean configureServer) {
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromShareIp(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected boolean configureServer;
|
||||
protected int sharedIpGroupId;
|
||||
|
||||
/**
|
||||
* @see ShareIp#isConfigureServer()
|
||||
*/
|
||||
public T configureServer(boolean configureServer) {
|
||||
this.configureServer = configureServer;
|
||||
return self();
|
||||
}
|
||||
|
||||
public boolean isConfigureServer() {
|
||||
return configureServer;
|
||||
/**
|
||||
* @see ShareIp#getSharedIpGroupId()
|
||||
*/
|
||||
public T sharedIpGroupId(int sharedIpGroupId) {
|
||||
this.sharedIpGroupId = sharedIpGroupId;
|
||||
return self();
|
||||
}
|
||||
|
||||
public void setSharedIpGroupId(int sharedIpGroupId) {
|
||||
public ShareIp build() {
|
||||
return new ShareIp(configureServer, sharedIpGroupId);
|
||||
}
|
||||
|
||||
public T fromShareIp(ShareIp in) {
|
||||
return this
|
||||
.configureServer(in.isConfigureServer())
|
||||
.sharedIpGroupId(in.getSharedIpGroupId());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final boolean configureServer;
|
||||
private final int sharedIpGroupId;
|
||||
|
||||
@ConstructorProperties({
|
||||
"configureServer", "sharedIpGroupId"
|
||||
})
|
||||
protected ShareIp(boolean configureServer, int sharedIpGroupId) {
|
||||
this.configureServer = configureServer;
|
||||
this.sharedIpGroupId = sharedIpGroupId;
|
||||
}
|
||||
|
||||
public boolean isConfigureServer() {
|
||||
return this.configureServer;
|
||||
}
|
||||
|
||||
public int getSharedIpGroupId() {
|
||||
return sharedIpGroupId;
|
||||
return this.sharedIpGroupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(configureServer, sharedIpGroupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
ShareIp that = ShareIp.class.cast(obj);
|
||||
return Objects.equal(this.configureServer, that.configureServer)
|
||||
&& Objects.equal(this.sharedIpGroupId, that.sharedIpGroupId);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("configureServer", configureServer).add("sharedIpGroupId", sharedIpGroupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,9 +18,16 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* A shared IP group is a collection of servers that can share IPs with other members of the group.
|
||||
|
@ -32,80 +39,117 @@ import com.google.common.collect.Lists;
|
|||
*/
|
||||
public class SharedIpGroup {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
private List<Integer> servers = Lists.newArrayList();
|
||||
|
||||
public SharedIpGroup() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public SharedIpGroup(int id, String name) {
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromSharedIpGroup(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected int id;
|
||||
protected String name;
|
||||
protected List<Integer> servers = null;
|
||||
|
||||
/**
|
||||
* @see SharedIpGroup#getId()
|
||||
*/
|
||||
public T id(int id) {
|
||||
this.id = id;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see SharedIpGroup#getName()
|
||||
*/
|
||||
public T name(String name) {
|
||||
this.name = name;
|
||||
return self();
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
/**
|
||||
* @see SharedIpGroup#getServers()
|
||||
*/
|
||||
public T servers(List<Integer> servers) {
|
||||
this.servers = ImmutableList.copyOf(checkNotNull(servers, "servers"));
|
||||
return self();
|
||||
}
|
||||
|
||||
public T servers(Integer... in) {
|
||||
return servers(ImmutableList.copyOf(in));
|
||||
}
|
||||
|
||||
public SharedIpGroup build() {
|
||||
return new SharedIpGroup(id, name, servers);
|
||||
}
|
||||
|
||||
public T fromSharedIpGroup(SharedIpGroup in) {
|
||||
return this
|
||||
.id(in.getId())
|
||||
.name(in.getName())
|
||||
.servers(in.getServers());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final List<Integer> servers;
|
||||
|
||||
@ConstructorProperties({
|
||||
"id", "name", "servers"
|
||||
})
|
||||
protected SharedIpGroup(int id, String name, @Nullable List<Integer> servers) {
|
||||
this.id = id;
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.servers = servers == null ? null : ImmutableList.copyOf(servers);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setServers(List<Integer> servers) {
|
||||
this.servers = servers;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<Integer> getServers() {
|
||||
return servers;
|
||||
return this.servers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + id;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((servers == null) ? 0 : servers.hashCode());
|
||||
return result;
|
||||
return Objects.hashCode(id, name, servers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
SharedIpGroup other = (SharedIpGroup) obj;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (servers == null) {
|
||||
if (other.servers != null)
|
||||
return false;
|
||||
} else if (!servers.equals(other.servers))
|
||||
return false;
|
||||
return true;
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
SharedIpGroup that = SharedIpGroup.class.cast(obj);
|
||||
return Objects.equal(this.id, that.id)
|
||||
&& Objects.equal(this.name, that.name)
|
||||
&& Objects.equal(this.servers, that.servers);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("id", id).add("name", name).add("servers", servers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SharedIpGroup [id=" + id + ", name=" + name + ", servers=" + servers + "]";
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,42 +18,144 @@
|
|||
*/
|
||||
package org.jclouds.cloudservers.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* Class Version
|
||||
*/
|
||||
public class Version {
|
||||
|
||||
private String docURL;
|
||||
private String id = "v1.0";
|
||||
private VersionStatus status;
|
||||
private String wadl;
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public void setDocURL(String docURL) {
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromVersion(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected String docURL;
|
||||
protected String id;
|
||||
protected VersionStatus status;
|
||||
protected String wadl;
|
||||
|
||||
/**
|
||||
* @see Version#getDocURL()
|
||||
*/
|
||||
public T docURL(String docURL) {
|
||||
this.docURL = docURL;
|
||||
return self();
|
||||
}
|
||||
|
||||
public String getDocURL() {
|
||||
return docURL;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
/**
|
||||
* @see Version#getId()
|
||||
*/
|
||||
public T id(String id) {
|
||||
this.id = id;
|
||||
return self();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setStatus(VersionStatus status) {
|
||||
/**
|
||||
* @see Version#getStatus()
|
||||
*/
|
||||
public T status(VersionStatus status) {
|
||||
this.status = status;
|
||||
return self();
|
||||
}
|
||||
|
||||
public VersionStatus getStatus() {
|
||||
return status;
|
||||
/**
|
||||
* @see Version#getWadl()
|
||||
*/
|
||||
public T wadl(String wadl) {
|
||||
this.wadl = wadl;
|
||||
return self();
|
||||
}
|
||||
|
||||
public void setWadl(String wadl) {
|
||||
public Version build() {
|
||||
return new Version(docURL, id, status, wadl);
|
||||
}
|
||||
|
||||
public T fromVersion(Version in) {
|
||||
return this
|
||||
.docURL(in.getDocURL())
|
||||
.id(in.getId())
|
||||
.status(in.getStatus())
|
||||
.wadl(in.getWadl());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final String docURL;
|
||||
private final String id;
|
||||
private final VersionStatus status;
|
||||
private final String wadl;
|
||||
|
||||
@ConstructorProperties({
|
||||
"docURL", "id", "status", "wadl"
|
||||
})
|
||||
protected Version(String docURL, String id, @Nullable VersionStatus status, @Nullable String wadl) {
|
||||
this.docURL = checkNotNull(docURL, "docURL");
|
||||
this.id = checkNotNull(id, "id");
|
||||
this.status = status == null ? VersionStatus.UNRECOGNIZED : status;
|
||||
this.wadl = wadl;
|
||||
}
|
||||
|
||||
public String getDocURL() {
|
||||
return this.docURL;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public VersionStatus getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getWadl() {
|
||||
return wadl;
|
||||
return this.wadl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(docURL, id, status, wadl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
Version that = Version.class.cast(obj);
|
||||
return Objects.equal(this.docURL, that.docURL)
|
||||
&& Objects.equal(this.id, that.id)
|
||||
&& Objects.equal(this.status, that.status)
|
||||
&& Objects.equal(this.wadl, that.wadl);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("docURL", docURL).add("id", id).add("status", status).add("wadl", wadl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.jclouds.rest.MapBinder;
|
|||
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
@ -105,9 +106,7 @@ public class CreateServerOptions implements MapBinder {
|
|||
if (sharedIpGroupId != null)
|
||||
server.sharedIpGroupId = this.sharedIpGroupId;
|
||||
if (publicIp != null) {
|
||||
server.addresses = new Addresses();
|
||||
server.addresses.getPublicAddresses().add(publicIp);
|
||||
server.addresses.setPrivateAddresses(null);
|
||||
server.addresses = Addresses.builder().publicAddresses(ImmutableSet.of(publicIp)).build();
|
||||
}
|
||||
return bindToRequest(request, ImmutableMap.of("server", server));
|
||||
}
|
||||
|
|
|
@ -502,8 +502,8 @@ public class CloudServersAsyncClientTest extends BaseAsyncClientTest<CloudServer
|
|||
|
||||
public void testReplaceBackupSchedule() throws IOException, SecurityException, NoSuchMethodException {
|
||||
Method method = CloudServersAsyncClient.class.getMethod("replaceBackupSchedule", int.class, BackupSchedule.class);
|
||||
HttpRequest request = processor.createRequest(method, 2, new BackupSchedule(WeeklyBackup.MONDAY,
|
||||
DailyBackup.H_0800_1000, true));
|
||||
HttpRequest request = processor.createRequest(method, 2, BackupSchedule.builder().weekly(WeeklyBackup.MONDAY)
|
||||
.daily(DailyBackup.H_0800_1000).enabled(true).build());
|
||||
|
||||
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/backup_schedule HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
|
|
@ -503,11 +503,8 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
|||
|
||||
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareNoConfig")
|
||||
public void testBackup() throws Exception {
|
||||
assertEquals(new BackupSchedule(), client.getBackupSchedule(serverId));
|
||||
BackupSchedule dailyWeekly = new BackupSchedule();
|
||||
dailyWeekly.setEnabled(true);
|
||||
dailyWeekly.setWeekly(WeeklyBackup.FRIDAY);
|
||||
dailyWeekly.setDaily(DailyBackup.H_0400_0600);
|
||||
assertEquals(BackupSchedule.builder().build(), client.getBackupSchedule(serverId));
|
||||
BackupSchedule dailyWeekly = BackupSchedule.builder().enabled(true).weekly(WeeklyBackup.FRIDAY).daily(DailyBackup.H_0400_0600).build();
|
||||
client.replaceBackupSchedule(serverId, dailyWeekly);
|
||||
client.deleteBackupSchedule(serverId);
|
||||
// disables, doesn't delete: Web Hosting #119571
|
||||
|
|
|
@ -30,18 +30,14 @@ import org.testng.annotations.Test;
|
|||
@Test(groups = "unit")
|
||||
public class ServerTest {
|
||||
public void testStatusDoesntAffectEquals() {
|
||||
Server server1 = new Server(1, "hello");
|
||||
server1.setStatus(ServerStatus.ACTIVE);
|
||||
Server server2 = new Server(1, "hello");
|
||||
server2.setStatus(ServerStatus.BUILD);
|
||||
Server server1 = Server.builder().id(1).name("hello").status(ServerStatus.ACTIVE).build();
|
||||
Server server2 = Server.builder().id(1).name("hello").status(ServerStatus.BUILD).build();
|
||||
assertEquals(server1, server2);
|
||||
}
|
||||
|
||||
public void testProgressDoesntAffectEquals() {
|
||||
Server server1 = new Server(1, "hello");
|
||||
server1.setProgress(1);
|
||||
Server server2 = new Server(1, "hello");
|
||||
server2.setProgress(2);
|
||||
Server server1 = Server.builder().id(1).name("hello").progress(1).build();
|
||||
Server server2 = Server.builder().id(1).name("hello").progress(2).build();
|
||||
assertEquals(server1, server2);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public class ParseBackupScheduleFromJsonResponseTest {
|
|||
.get(new TypeLiteral<UnwrapOnlyJsonValue<BackupSchedule>>() {
|
||||
}));
|
||||
BackupSchedule response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
||||
assertEquals(new BackupSchedule(WeeklyBackup.THURSDAY, DailyBackup.H_0400_0600, true), response);
|
||||
assertEquals(BackupSchedule.builder().weekly(WeeklyBackup.THURSDAY).daily(DailyBackup.H_0400_0600).enabled(true).build(), response);
|
||||
}
|
||||
|
||||
public void testNoSchedule() throws UnknownHostException {
|
||||
|
@ -63,6 +63,6 @@ public class ParseBackupScheduleFromJsonResponseTest {
|
|||
BackupSchedule response = parser.apply(HttpResponse.builder()
|
||||
.statusCode(200).message("ok")
|
||||
.payload("{\"backupSchedule\":{\"enabled\" : false}}").build());
|
||||
assertEquals(new BackupSchedule(), response);
|
||||
assertEquals(BackupSchedule.builder().build(), response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,8 @@ public class ParseFlavorListFromJsonResponseTest {
|
|||
public void testApplyInputStream() {
|
||||
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
|
||||
|
||||
List<Flavor> expects = ImmutableList.of(new Flavor(1, "256 MB Server"), new Flavor(2, "512 MB Server"));
|
||||
List<Flavor> expects = ImmutableList.of(Flavor.builder().id(1).name("256 MB Server").build(),
|
||||
Flavor.builder().id(2).name("512 MB Server").build());
|
||||
|
||||
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
|
||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
|
||||
|
|
|
@ -61,7 +61,8 @@ public class ParseImageListFromJsonResponseTest {
|
|||
public void testApplyInputStream() {
|
||||
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
|
||||
|
||||
List<Image> expects = ImmutableList.of(new Image(2, "CentOS 5.2"), new Image(743, "My Server Backup"));
|
||||
List<Image> expects = ImmutableList.of(Image.builder().id(2).name("CentOS 5.2").build(),
|
||||
Image.builder().id(743).name("My Server Backup").build());
|
||||
|
||||
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
|
||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
|
||||
|
|
|
@ -59,9 +59,7 @@ public class ParseServerFromJsonResponseTest {
|
|||
assertEquals(response.getProgress(), Integer.valueOf(60));
|
||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||
Addresses addresses1 = new Addresses();
|
||||
addresses1.getPrivateAddresses().addAll(privateAddresses);
|
||||
addresses1.getPublicAddresses().addAll(publicAddresses);
|
||||
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
|
||||
assertEquals(response.getAddresses(), addresses1);
|
||||
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||
|
||||
|
|
|
@ -53,7 +53,8 @@ public class ParseServerListFromJsonResponseTest {
|
|||
public void testApplyInputStream() {
|
||||
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
|
||||
|
||||
List<Server> expects = ImmutableList.of(new Server(1234, "sample-server"), new Server(5678, "sample-server2"));
|
||||
List<Server> expects = ImmutableList.of(Server.builder().id(1234).name("sample-server").build(),
|
||||
Server.builder().id(5678).name("sample-server2").build());
|
||||
|
||||
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
||||
|
@ -80,9 +81,7 @@ public class ParseServerListFromJsonResponseTest {
|
|||
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
|
||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||
Addresses addresses1 = new Addresses();
|
||||
addresses1.getPrivateAddresses().addAll(privateAddresses);
|
||||
addresses1.getPublicAddresses().addAll(publicAddresses);
|
||||
Addresses addresses1 = Addresses.builder().privateAddresses(privateAddresses).publicAddresses(publicAddresses).build();
|
||||
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(1).getId(), 5678);
|
||||
|
@ -94,9 +93,7 @@ public class ParseServerListFromJsonResponseTest {
|
|||
assertEquals(response.get(1).getProgress(), null);
|
||||
List<String> publicAddresses2 = Lists.newArrayList("67.23.10.133");
|
||||
List<String> privateAddresses2 = Lists.newArrayList("10.176.42.17");
|
||||
Addresses addresses2 = new Addresses();
|
||||
addresses2.getPrivateAddresses().addAll(privateAddresses2);
|
||||
addresses2.getPublicAddresses().addAll(publicAddresses2);
|
||||
Addresses addresses2 = Addresses.builder().privateAddresses(privateAddresses2).publicAddresses(publicAddresses2).build();
|
||||
assertEquals(response.get(1).getAddresses(), addresses2);
|
||||
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ public class ParseSharedIpGroupListFromJsonResponseTest {
|
|||
public void testApplyInputStream() {
|
||||
InputStream is = getClass().getResourceAsStream("/test_list_sharedipgroups.json");
|
||||
|
||||
List<SharedIpGroup> expects = ImmutableList.of(new SharedIpGroup(1234, "Shared IP Group 1"), new SharedIpGroup(
|
||||
5678, "Shared IP Group 2"));
|
||||
List<SharedIpGroup> expects = ImmutableList.of(SharedIpGroup.builder().id(1234).name("Shared IP Group 1").build(),
|
||||
SharedIpGroup.builder().id(5678).name("Shared IP Group 2").build());
|
||||
|
||||
UnwrapOnlyJsonValue<List<SharedIpGroup>> parser = i.getInstance(Key
|
||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<SharedIpGroup>>>() {
|
||||
|
|
Loading…
Reference in New Issue