Merge pull request #760 from aplowe/openstack-nova2

Issue 971: more deserialization adjustments
This commit is contained in:
Adrian Cole 2012-07-30 08:34:01 -07:00
commit 3c2a9c9614
78 changed files with 5019 additions and 3272 deletions

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,30 +18,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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,81 +18,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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,8 +18,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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,8 +18,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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,8 +18,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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,10 +18,16 @@
*/
package org.jclouds.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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,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();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,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();
}
}

View File

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

View File

@ -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, "");

View File

@ -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

View File

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

View File

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

View File

@ -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>>>() {

View File

@ -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>>>() {

View File

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

View File

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

View File

@ -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>>>() {

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,6 +18,12 @@
*/
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;
/**
*
@ -25,23 +31,95 @@ package org.jclouds.openstack.nova.domain;
*/
public class AbsoluteLimit {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAbsoluteLimit(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected int value;
public String getName() {
return name;
/**
* @see AbsoluteLimit#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
public void setName(String value) {
this.name = value;
/**
* @see AbsoluteLimit#getValue()
*/
public T value(int value) {
this.value = value;
return self();
}
public int getValue() {
return value;
public AbsoluteLimit build() {
return new AbsoluteLimit(name, value);
}
public void setValue(int value) {
public T fromAbsoluteLimit(AbsoluteLimit in) {
return this
.name(in.getName())
.value(in.getValue());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final int value;
@ConstructorProperties({
"name", "value"
})
protected AbsoluteLimit(String name, int value) {
this.name = checkNotNull(name, "name");
this.value = value;
}
public String getName() {
return this.name;
}
public int getValue() {
return this.value;
}
@Override
public int hashCode() {
return Objects.hashCode(name, value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
AbsoluteLimit that = AbsoluteLimit.class.cast(obj);
return Objects.equal(this.name, that.name)
&& Objects.equal(this.value, that.value);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("value", value);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,60 +18,27 @@
*/
package org.jclouds.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.gson.annotations.SerializedName;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* @author Dmitri Babaev
*/
public class Address {
@SerializedName("addr")
private String address;
private int version;
//for de-serialization
@SuppressWarnings("unused")
private Address() {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Address(String address, int version) {
this.address = address;
this.version = version;
}
public String getAddress() {
return address;
}
public int getVersion() {
return version;
}
@Override
public String toString() {
return address;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Address address1 = (Address) o;
if (version != address1.version) return false;
if (address != null ? !address.equals(address1.address) : address1.address != null) return false;
return true;
}
@Override
public int hashCode() {
int result = address != null ? address.hashCode() : 0;
result = 31 * result + version;
return result;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAddress(this);
}
public static Function<Address, String> newAddress2StringFunction() {
@ -95,4 +62,88 @@ public class Address {
}
};
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String address;
protected int version;
/**
* @see Address#getAddress()
*/
public T address(String address) {
this.address = address;
return self();
}
/**
* @see Address#getVersion()
*/
public T version(int version) {
this.version = version;
return self();
}
public Address build() {
return new Address(address, version);
}
public T fromAddress(Address in) {
return this
.address(in.getAddress())
.version(in.getVersion());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String address;
private final int version;
@ConstructorProperties({
"addr", "version"
})
protected Address(String address, int version) {
this.address = checkNotNull(address, "address");
this.version = version;
}
public String getAddress() {
return this.address;
}
public int getVersion() {
return this.version;
}
@Override
public int hashCode() {
return Objects.hashCode(address, version);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Address that = Address.class.cast(obj);
return Objects.equal(this.address, that.address)
&& Objects.equal(this.version, that.version);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("address", address).add("version", version);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,10 +18,15 @@
*/
package org.jclouds.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Collection;
import java.util.Set;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
/**
*
@ -29,70 +34,103 @@ import com.google.gson.annotations.SerializedName;
*/
public class Addresses {
@SerializedName("public")
private Set<Address> publicAddresses = Sets.newLinkedHashSet();
@SerializedName("private")
private Set<Address> privateAddresses = Sets.newLinkedHashSet();
public Addresses() {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Addresses(Set<Address> publicAddresses, Set<Address> privateAddresses) {
this.publicAddresses = publicAddresses;
this.privateAddresses = privateAddresses;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAddresses(this);
}
public void setPublicAddresses(Set<Address> publicAddresses) {
this.publicAddresses = publicAddresses;
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected Set<Address> publicAddresses = ImmutableSet.of();
protected Set<Address> privateAddresses = ImmutableSet.of();
/**
* @see Addresses#getPublicAddresses()
*/
public T publicAddresses(Collection<Address> publicAddresses) {
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
return self();
}
public T publicAddresses(Address... in) {
return publicAddresses(ImmutableSet.copyOf(in));
}
/**
* @see Addresses#getPrivateAddresses()
*/
public T privateAddresses(Collection<Address> privateAddresses) {
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
return self();
}
public T privateAddresses(Address... in) {
return privateAddresses(ImmutableSet.copyOf(in));
}
public Addresses build() {
return new Addresses(publicAddresses, privateAddresses);
}
public T fromAddresses(Addresses in) {
return this
.publicAddresses(in.getPublicAddresses())
.privateAddresses(in.getPrivateAddresses());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final Set<Address> publicAddresses;
private final Set<Address> privateAddresses;
@ConstructorProperties({
"public", "private"
})
protected Addresses(Set<Address> publicAddresses, Set<Address> privateAddresses) {
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
}
public Set<Address> getPublicAddresses() {
return publicAddresses;
}
public void setPrivateAddresses(Set<Address> privateAddresses) {
this.privateAddresses = privateAddresses;
return this.publicAddresses;
}
public Set<Address> getPrivateAddresses() {
return privateAddresses;
}
@Override
public String toString() {
return "Addresses [privateAddresses=" + privateAddresses + ", publicAddresses="
+ publicAddresses + "]";
return this.privateAddresses;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
return result;
return Objects.hashCode(publicAddresses, privateAddresses);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Addresses other = (Addresses) obj;
if (privateAddresses == null) {
if (other.privateAddresses != null)
return false;
} else if (!privateAddresses.equals(other.privateAddresses))
return false;
if (publicAddresses == null) {
if (other.publicAddresses != null)
return false;
} else if (!publicAddresses.equals(other.publicAddresses))
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Addresses that = Addresses.class.cast(obj);
return Objects.equal(this.publicAddresses, that.publicAddresses)
&& Objects.equal(this.privateAddresses, that.privateAddresses);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("publicAddresses", publicAddresses).add("privateAddresses", privateAddresses);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,8 +18,17 @@
*/
package org.jclouds.openstack.nova.domain;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
*
* A flavor is an available hardware configuration for a server. Each flavor has a unique
* combination of disk space and memory capacity.
*
@ -27,97 +36,128 @@ package org.jclouds.openstack.nova.domain;
*/
public class Flavor extends Resource {
private final int id;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromFlavor(this);
}
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String name;
protected Integer disk;
protected Integer ram;
protected Integer vcpus;
/**
* @see Flavor#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see Flavor#getDisk()
*/
public T disk(Integer disk) {
this.disk = disk;
return self();
}
/**
* @see Flavor#getRam()
*/
public T ram(Integer ram) {
this.ram = ram;
return self();
}
/**
* @see Flavor#getVcpus()
*/
public T vcpus(Integer vcpus) {
this.vcpus = vcpus;
return self();
}
public Flavor build() {
return new Flavor(id, links, orderedSelfReferences, name, disk, ram, vcpus);
}
public T fromFlavor(Flavor in) {
return super.fromResource(in)
.name(in.getName())
.disk(in.getDisk())
.ram(in.getRam())
.vcpus(in.getVcpus());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final Integer disk;
private final Integer ram;
private final Integer vcpus;
//Required because of how Gson is being used to do wire marshalling with the Server class
private Flavor(){
id=0;
name=null;
disk=null;
ram=null;
vcpus=null;
}
public Flavor(int id, String name, Integer disk, Integer ram, Integer vcpus) {
this.id = id;
@ConstructorProperties({
"id", "links", "orderedSelfReferences", "name", "disk", "ram", "vcpus"
})
protected Flavor(int id, List<Map<String, String>> links, @Nullable Map<LinkType, URI> orderedSelfReferences,
@Nullable String name, @Nullable Integer disk, @Nullable Integer ram, @Nullable Integer vcpus) {
super(id, links, orderedSelfReferences);
this.name = name;
this.disk = disk;
this.ram = ram;
this.vcpus = vcpus;
}
public Integer getDisk() {
return disk;
}
public int getId() {
return id;
}
@Nullable
public String getName() {
return name;
return this.name;
}
@Nullable
public Integer getDisk() {
return this.disk;
}
@Nullable
public Integer getRam() {
return ram;
return this.ram;
}
@Nullable
public Integer getVcpus() {
return vcpus;
return this.vcpus;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((disk == null) ? 0 : disk.hashCode());
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((ram == null) ? 0 : ram.hashCode());
result = prime * result + ((vcpus == null) ? 0 : vcpus.hashCode());
return result;
return Objects.hashCode(super.hashCode(), name, disk, ram, vcpus);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Flavor other = (Flavor) obj;
if (disk == null) {
if (other.disk != null)
return false;
} else if (!disk.equals(other.disk))
return false;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (ram == null) {
if (other.ram != null)
return false;
} else if (!ram.equals(other.ram))
return false;
if (vcpus == null) {
if (other.vcpus != null)
return false;
} else if (!vcpus.equals(other.vcpus))
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Flavor that = Flavor.class.cast(obj);
return super.equals(that)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.disk, that.disk)
&& Objects.equal(this.ram, that.ram)
&& Objects.equal(this.vcpus, that.vcpus);
}
@Override
public String toString() {
return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + ", vcpus=" + vcpus +"]";
protected ToStringHelper string() {
return super.string().add("name", name).add("disk", disk).add("ram", ram).add("vcpus", vcpus);
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,153 +18,134 @@
*/
package org.jclouds.openstack.nova.domain;
import com.google.gson.annotations.SerializedName;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.List;
import java.util.Map;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* Check <a href="http://wiki.openstack.org/os_api_floating_ip">Floating IP Wiki
* page</a>. Available since OpenStack Diablo release and API 1.1.
*
* @author chamerling
*
*/
public class FloatingIP extends Resource {
private int id;
private String ip;
@SerializedName(value="fixed_ip")
private String fixedIP;
@SerializedName(value = "instance_id")
private int instanceID;
@SuppressWarnings("unused")
private FloatingIP() {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public FloatingIP(int id, String ip, String fixedIP, int instanceID) {
this.id = id;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromFloatingIP(this);
}
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String ip;
protected String fixedIP;
protected int instanceID;
/**
* @see FloatingIP#getIp()
*/
public T ip(String ip) {
this.ip = ip;
return self();
}
/**
* @see FloatingIP#getFixedIP()
*/
public T fixedIP(String fixedIP) {
this.fixedIP = fixedIP;
return self();
}
/**
* @see FloatingIP#getInstanceID()
*/
public T instanceID(int instanceID) {
this.instanceID = instanceID;
return self();
}
/**
* @return the id
*/
public int getId() {
return id;
public FloatingIP build() {
return new FloatingIP(id, links, orderedSelfReferences, ip, fixedIP, instanceID);
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
public T fromFloatingIP(FloatingIP in) {
return super.fromResource(in)
.ip(in.getIp())
.fixedIP(in.getFixedIP())
.instanceID(in.getInstanceID());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String ip;
private final String fixedIP;
private final int instanceID;
@ConstructorProperties({
"id", "links", "orderedSelfReferences", "ip", "fixed_ip", "instance_id"
})
protected FloatingIP(int id, List<Map<String, String>> links, Map<LinkType, URI> orderedSelfReferences, String ip,
String fixedIP, int instanceID) {
super(id, links, orderedSelfReferences);
this.ip = checkNotNull(ip, "ip");
this.fixedIP = checkNotNull(fixedIP, "fixedIP");
this.instanceID = instanceID;
}
/**
* @return the ip
*/
public String getIp() {
return ip;
}
/**
* @param ip the ip to set
*/
public void setIp(String ip) {
this.ip = ip;
return this.ip;
}
/**
* @return the fixedIP
*/
public String getFixedIP() {
return fixedIP;
}
/**
* @param fixedIP the fixedIP to set
*/
public void setFixedIP(String fixedIP) {
this.fixedIP = fixedIP;
return this.fixedIP;
}
/**
* @return the instanceID
*/
public int getInstanceID() {
return instanceID;
return this.instanceID;
}
/**
* @param instanceID the instanceID to set
*/
public void setInstanceID(int instanceID) {
this.instanceID = instanceID;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FloatingIP [id=");
builder.append(id);
builder.append(", ip=");
builder.append(ip);
builder.append(", fixedIP=");
builder.append(fixedIP);
builder.append(", instanceID=");
builder.append(instanceID);
builder.append("]");
return builder.toString();
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((fixedIP == null) ? 0 : fixedIP.hashCode());
result = prime * result + id;
result = prime * result + instanceID;
result = prime * result + ((ip == null) ? 0 : ip.hashCode());
return result;
return Objects.hashCode(super.hashCode(), ip, fixedIP, instanceID);
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FloatingIP other = (FloatingIP) obj;
if (fixedIP == null) {
if (other.fixedIP != null)
return false;
} else if (!fixedIP.equals(other.fixedIP))
return false;
if (id != other.id)
return false;
if (instanceID != other.instanceID)
return false;
if (ip == null) {
if (other.ip != null)
return false;
} else if (!ip.equals(other.ip))
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
FloatingIP that = FloatingIP.class.cast(obj);
return super.equals(that)
&& Objects.equal(this.ip, that.ip)
&& Objects.equal(this.fixedIP, that.fixedIP)
&& Objects.equal(this.instanceID, that.instanceID);
}
protected ToStringHelper string() {
return super.string().add("ip", ip).add("fixedIP", fixedIP).add("instanceID", instanceID);
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,11 +18,19 @@
*/
package org.jclouds.openstack.nova.domain;
import java.util.Collections;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Maps;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableMap;
/**
* An image is a collection of files used to create or rebuild a server. Rackspace provides a number
@ -34,122 +42,179 @@ import com.google.common.collect.Maps;
*/
public class Image extends Resource {
private int id;
private String name;
private Integer progress;
private String serverRef;
private ImageStatus status;
private Map<String, String> metadata = Maps.newHashMap();
private Date created;
private Date updated;
public Date getCreated() {
return created;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Date getUpdated() {
return updated;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromImage(this);
}
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String name;
protected Integer progress;
protected String serverRef;
protected ImageStatus status;
protected Map<String, String> metadata = ImmutableMap.of();
protected Date created;
protected Date updated;
public Image() {
}
public Image(int id, String name) {
this.id = id;
/**
* @see Image#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setProgress(Integer progress) {
/**
* @see Image#getProgress()
*/
public T progress(Integer progress) {
this.progress = progress;
return self();
}
public Integer getProgress() {
return progress;
}
public void setServerRef(String serverRef) {
/**
* @see Image#getServerRef()
*/
public T serverRef(String serverRef) {
this.serverRef = serverRef;
return self();
}
public String getServerRef() {
return serverRef;
}
public void setStatus(ImageStatus status) {
/**
* @see Image#getStatus()
*/
public T status(ImageStatus status) {
this.status = status;
return self();
}
/**
* @see Image#getMetadata()
*/
public T metadata(Map<String, String> metadata) {
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self();
}
/**
* @see Image#getCreated()
*/
public T created(Date created) {
this.created = created;
return self();
}
/**
* @see Image#getUpdated()
*/
public T updated(Date updated) {
this.updated = updated;
return self();
}
public Image build() {
return new Image(id, links, orderedSelfReferences, name, progress, serverRef, status, metadata, created, updated);
}
public T fromImage(Image in) {
return super.fromResource(in)
.id(in.getId())
.name(in.getName())
.progress(in.getProgress())
.serverRef(in.getServerRef())
.status(in.getStatus())
.metadata(in.getMetadata())
.created(in.getCreated())
.updated(in.getUpdated());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final Integer progress;
private final String serverRef;
private final ImageStatus status;
private final Map<String, String> metadata;
private final Date created;
private final Date updated;
@ConstructorProperties({
"id", "links", "orderedSelfReferences", "name", "progress", "serverRef", "status", "metadata", "created", "updated"
})
protected Image(int id, List<Map<String, String>> links, @Nullable Map<LinkType, URI> orderedSelfReferences, @Nullable String name,
@Nullable Integer progress, @Nullable String serverRef, @Nullable ImageStatus status, @Nullable Map<String, String> metadata,
@Nullable Date created, @Nullable Date updated) {
super(id, links, orderedSelfReferences);
this.name = name;
this.progress = progress;
this.serverRef = serverRef;
this.status = status == null ? ImageStatus.UNKNOWN : status;
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
this.created = created;
this.updated = updated;
}
@Nullable
public String getName() {
return this.name;
}
@Nullable
public Integer getProgress() {
return this.progress;
}
@Nullable
public String getServerRef() {
return this.serverRef;
}
@Nullable
public ImageStatus getStatus() {
return status;
return this.status;
}
public Map<String, String> getMetadata() {
return Collections.unmodifiableMap(metadata);
return this.metadata;
}
public void setMetadata(Map<String, String> metadata) {
this.metadata = Maps.newHashMap(metadata);
@Nullable
public Date getCreated() {
return this.created;
}
@Nullable
public Date getUpdated() {
return this.updated;
}
/**
* note that this ignores some fields
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((serverRef == null) ? 0 : serverRef.hashCode());
return result;
return Objects.hashCode(super.hashCode(), name, serverRef);
}
/**
* note that this ignores some fields
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Image other = (Image) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Image that = Image.class.cast(obj);
return super.equals(that)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.serverRef, that.serverRef);
}
@Override
public String toString() {
return "Image [created=" + getCreated() + ", id=" + id + ", name=" + name + ", serverRef="
+ serverRef + "]";
protected ToStringHelper string() {
return super.string().add("name", name).add("progress", progress).add("serverRef", serverRef).add("status", status)
.add("metadata", metadata).add("created", created).add("updated", updated);
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,29 +18,114 @@
*/
package org.jclouds.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.List;
import com.google.common.collect.Lists;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableList;
public class Limits {
private List<RateLimit> rate = Lists.newArrayList();
private List<AbsoluteLimit> absolute = Lists.newArrayList();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public void setRate(List<RateLimit> rate) {
this.rate = rate;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromLimits(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected List<RateLimit> rate = ImmutableList.of();
protected List<AbsoluteLimit> absolute = ImmutableList.of();
/**
* @see Limits#getRate()
*/
public T rate(List<RateLimit> rate) {
this.rate = ImmutableList.copyOf(checkNotNull(rate, "rate"));
return self();
}
public T rate(RateLimit... in) {
return rate(ImmutableList.copyOf(in));
}
/**
* @see Limits#getAbsolute()
*/
public T absolute(List<AbsoluteLimit> absolute) {
this.absolute = ImmutableList.copyOf(checkNotNull(absolute, "absolute"));
return self();
}
public T absolute(AbsoluteLimit... in) {
return absolute(ImmutableList.copyOf(in));
}
public Limits build() {
return new Limits(rate, absolute);
}
public T fromLimits(Limits in) {
return this
.rate(in.getRate())
.absolute(in.getAbsolute());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final List<RateLimit> rate;
private final List<AbsoluteLimit> absolute;
@ConstructorProperties({
"rate", "absolute"
})
protected Limits(List<RateLimit> rate, List<AbsoluteLimit> absolute) {
this.rate = ImmutableList.copyOf(checkNotNull(rate, "rate"));
this.absolute = ImmutableList.copyOf(checkNotNull(absolute, "absolute"));
}
public List<RateLimit> getRate() {
return rate;
}
public void setAbsolute(List<AbsoluteLimit> absolute) {
this.absolute = absolute;
return this.rate;
}
public List<AbsoluteLimit> getAbsolute() {
return absolute;
return this.absolute;
}
@Override
public int hashCode() {
return Objects.hashCode(rate, absolute);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Limits that = Limits.class.cast(obj);
return Objects.equal(this.rate, that.rate)
&& Objects.equal(this.absolute, that.absolute);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("rate", rate).add("absolute", absolute);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,10 +18,16 @@
*/
package org.jclouds.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import javax.ws.rs.HttpMethod;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
*
* RateLimit.
* <p/>
* we specify rate limits in terms of both a human readable wild-card URI and a machine processable
@ -39,6 +45,104 @@ import javax.ws.rs.HttpMethod;
*/
public class RateLimit {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromRateLimit(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String uri;
protected String regex;
protected int remaining;
protected long resetTime;
protected RateLimitUnit unit;
protected int value;
protected HttpMethod verb;
/**
* @see RateLimit#getUri()
*/
public T uri(String uri) {
this.uri = uri;
return self();
}
/**
* @see RateLimit#getRegex()
*/
public T regex(String regex) {
this.regex = regex;
return self();
}
/**
* @see RateLimit#getRemaining()
*/
public T remaining(int remaining) {
this.remaining = remaining;
return self();
}
/**
* @see RateLimit#getResetTime()
*/
public T resetTime(long resetTime) {
this.resetTime = resetTime;
return self();
}
/**
* @see RateLimit#getUnit()
*/
public T unit(RateLimitUnit unit) {
this.unit = unit;
return self();
}
/**
* @see RateLimit#getValue()
*/
public T value(int value) {
this.value = value;
return self();
}
/**
* @see RateLimit#getVerb()
*/
public T verb(HttpMethod verb) {
this.verb = verb;
return self();
}
public RateLimit build() {
return new RateLimit(uri, regex, remaining, resetTime, unit, value, verb);
}
public T fromRateLimit(RateLimit in) {
return this
.uri(in.getUri())
.regex(in.getRegex())
.remaining(in.getRemaining())
.resetTime(in.getResetTime())
.unit(in.getUnit())
.value(in.getValue())
.verb(in.getVerb());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String uri;
private final String regex;
private final int remaining;
@ -47,43 +151,74 @@ public class RateLimit {
private final int value;
private final HttpMethod verb;
public RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit,
int value, HttpMethod verb) {
this.uri = uri;
this.regex = regex;
@ConstructorProperties({
"uri", "regex", "remaining", "resetTime", "unit", "value", "verb"
})
protected RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit, int value, HttpMethod verb) {
this.uri = checkNotNull(uri, "uri");
this.regex = checkNotNull(regex, "regex");
this.remaining = remaining;
this.resetTime = resetTime;
this.unit = unit;
this.unit = checkNotNull(unit, "unit");
this.value = value;
this.verb = verb;
this.verb = checkNotNull(verb, "verb");
}
public String getUri() {
return uri;
return this.uri;
}
public String getRegex() {
return regex;
return this.regex;
}
public int getRemaining() {
return remaining;
return this.remaining;
}
public long getResetTime() {
return resetTime;
return this.resetTime;
}
public RateLimitUnit getUnit() {
return unit;
return this.unit;
}
public int getValue() {
return value;
return this.value;
}
public HttpMethod getVerb() {
return verb;
return this.verb;
}
@Override
public int hashCode() {
return Objects.hashCode(uri, regex, remaining, resetTime, unit, value, verb);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
RateLimit that = RateLimit.class.cast(obj);
return Objects.equal(this.uri, that.uri)
&& Objects.equal(this.regex, that.regex)
&& Objects.equal(this.remaining, that.remaining)
&& Objects.equal(this.resetTime, that.resetTime)
&& Objects.equal(this.unit, that.unit)
&& Objects.equal(this.value, that.value)
&& Objects.equal(this.verb, that.verb);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("uri", uri).add("regex", regex).add("remaining", remaining).add("resetTime", resetTime).add("unit", unit).add("value", value).add("verb", verb);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,28 +18,31 @@
*/
package org.jclouds.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
import javax.annotation.Nullable;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Functions;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
/**
* @author Dmitri Babaev
* @author Matt Stephenson
*/
public class Resource {
public abstract class Resource {
private List<Map<String, String>> links = Lists.newArrayList();
//This is the preference order for returning a URI in getURI
private enum LinkType {
public static enum LinkType {
BOOKMARK_JSON(new Predicate<Map<String, String>>() {
@Override
public boolean apply(@Nullable Map<String, String> linkMap) {
@ -64,13 +67,72 @@ public class Resource {
LinkType(Predicate<Map<String, String>> linkPredicate) {
this.linkPredicate = linkPredicate;
};
}
}
private final ConcurrentSkipListMap<LinkType,URI> orderedSelfReferences;
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
public Resource(){
orderedSelfReferences = new ConcurrentSkipListMap<LinkType,URI>();
protected int id;
protected List<Map<String, String>> links = ImmutableList.of();
protected Map<Resource.LinkType, URI> orderedSelfReferences;
/**
* @see Resource#getId()
*/
public T id(int id) {
this.id = id;
return self();
}
/**
* @see Resource#getLinks()
*/
public T links(List<Map<String, String>> links) {
this.links = ImmutableList.copyOf(checkNotNull(links, "links"));
return self();
}
public T links(Map<String, String>... in) {
return links(ImmutableList.copyOf(in));
}
/**
* @see Resource#getOrderedSelfReferences()
*/
public T orderedSelfReferences(Map<Resource.LinkType, URI> orderedSelfReferences) {
this.orderedSelfReferences = ImmutableMap.copyOf(orderedSelfReferences);
return self();
}
public T fromResource(Resource in) {
return this
.links(in.getLinks())
.orderedSelfReferences(in.getOrderedSelfReferences());
}
}
private final int id;
private final List<Map<String, String>> links;
private final ConcurrentSkipListMap<Resource.LinkType, URI> orderedSelfReferences;
protected Resource(int id, List<Map<String, String>> links, @Nullable Map<Resource.LinkType, URI> orderedSelfReferences) {
this.id = id;
this.links = links == null ? ImmutableList.<Map<String, String>>of() : ImmutableList.copyOf(checkNotNull(links, "links"));
this.orderedSelfReferences = orderedSelfReferences == null ? new ConcurrentSkipListMap<LinkType, URI>() : new ConcurrentSkipListMap<LinkType, URI>(orderedSelfReferences);
}
public int getId() {
return id;
}
public List<Map<String, String>> getLinks() {
return this.links;
}
public Map<Resource.LinkType, URI> getOrderedSelfReferences() {
return this.orderedSelfReferences;
}
private void populateOrderedSelfReferences() {
@ -102,4 +164,28 @@ public class Resource {
return orderedSelfReferences.get(LinkType.SELF);
}
@Override
public int hashCode() {
return Objects.hashCode(id, orderedSelfReferences);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Resource that = Resource.class.cast(obj);
return Objects.equal(id, that.id) && Objects.equal(this.orderedSelfReferences, that.orderedSelfReferences);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("links", links).add("orderedSelfReferences", orderedSelfReferences);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,148 +18,159 @@
*/
package org.jclouds.openstack.nova.domain;
import com.google.gson.annotations.SerializedName;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* Defines a security group
*
* @author chamerling
*
*/
public class SecurityGroup {
private int id;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
private String name;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromSecurityGroup(this);
}
private String description;
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
@SerializedName(value="tenant_id")
private String tenantId;
protected int id;
protected String name;
protected String description;
protected String tenantId;
public SecurityGroup() {
/**
* @see SecurityGroup#getId()
*/
public T id(int id) {
this.id = id;
return self();
}
/**
* @see SecurityGroup#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see SecurityGroup#getDescription()
*/
public T description(String description) {
this.description = description;
return self();
}
/**
* @see SecurityGroup#getTenantId()
*/
public T tenantId(String tenantId) {
this.tenantId = tenantId;
return self();
}
public SecurityGroup build() {
return new SecurityGroup(id, name, description, tenantId);
}
public T fromSecurityGroup(SecurityGroup in) {
return this
.id(in.getId())
.name(in.getName())
.description(in.getDescription())
.tenantId(in.getTenantId());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final int id;
private final String name;
private final String description;
private final String tenantId;
@ConstructorProperties({
"id", "name", "description", "tenant_id"
})
protected SecurityGroup(int id, String name, @Nullable String description, @Nullable String tenantId) {
this.id = id;
this.name = checkNotNull(name, "name");
this.description = description;
this.tenantId = tenantId;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
return this.id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
return this.name;
}
/**
* @return the description
*/
@Nullable
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
return this.description;
}
/**
* @return the tenantId
*/
@Nullable
public String getTenantId() {
return tenantId;
return this.tenantId;
}
/**
* @param tenantId the tenantId to set
*/
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("SecurityGroup [id=");
builder.append(id);
builder.append(", name=");
builder.append(name);
builder.append(", description=");
builder.append(description);
builder.append(", tenantId=");
builder.append(tenantId);
builder.append("]");
return builder.toString();
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((description == null) ? 0 : description.hashCode());
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result
+ ((tenantId == null) ? 0 : tenantId.hashCode());
return result;
return Objects.hashCode(id, name, description, tenantId);
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SecurityGroup other = (SecurityGroup) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (tenantId == null) {
if (other.tenantId != null)
return false;
} else if (!tenantId.equals(other.tenantId))
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
SecurityGroup that = SecurityGroup.class.cast(obj);
return Objects.equal(this.id, that.id)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.description, that.description)
&& Objects.equal(this.tenantId, that.tenantId);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("name", name).add("description", description).add("tenantId", tenantId);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,13 +18,21 @@
*/
package org.jclouds.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* A server is a virtual machine instance in the OpenStack Nova system. Flavor and image are
@ -33,102 +41,323 @@ import com.google.gson.annotations.SerializedName;
* @author Adrian Cole
*/
public class Server extends Resource {
private int id;
private String name;
private Map<String, String> metadata = Maps.newHashMap();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
private Addresses addresses;
private String accessIPv4;
private String accessIPv6;
private String adminPass;
private String flavorRef;
private String hostId;
private String imageRef;
private String affinityId;
private String uuid;
private Flavor flavor;
private Image image;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromServer(this);
}
@SerializedName(value="key_name")
private String keyName;
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String name;
protected Map<String, String> metadata = ImmutableMap.of();
protected Addresses addresses;
protected String accessIPv4;
protected String accessIPv6;
protected String adminPass;
protected String flavorRef;
protected String hostId;
protected String imageRef;
protected String affinityId;
protected String uuid;
protected Flavor flavor;
protected Image image;
protected String keyName;
protected Set<SecurityGroup> securityGroups = ImmutableSet.of();
protected Date created;
protected Date updated;
protected Integer progress;
protected ServerStatus status;
/**
* Actually, security groups are not returned by nova on server query but is
* needed when creating a server to specify a set of groups
* @see Server#getName()
*/
@SerializedName(value="security_groups")
private Set<SecurityGroup> securityGroups = Sets.newHashSet();
private Date created;
private Date updated;
public Date getCreated() {
return created;
}
public Date getUpdated() {
return updated;
}
private Integer progress;
private ServerStatus status;
public Server() {
}
public Server(int id, String name) {
this.id = id;
public T name(String name) {
this.name = name;
return self();
}
public String getAffinityId() {
return affinityId;
/**
* @see Server#getMetadata()
*/
public T metadata(Map<String, String> metadata) {
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self();
}
public void setAffinityId(String affinityId) {
/**
* @see Server#getAddresses()
*/
public T addresses(Addresses addresses) {
this.addresses = addresses;
return self();
}
/**
* @see Server#getAccessIPv4()
*/
public T accessIPv4(String accessIPv4) {
this.accessIPv4 = accessIPv4;
return self();
}
/**
* @see Server#getAccessIPv6()
*/
public T accessIPv6(String accessIPv6) {
this.accessIPv6 = accessIPv6;
return self();
}
/**
* @see Server#getAdminPass()
*/
public T adminPass(String adminPass) {
this.adminPass = adminPass;
return self();
}
/**
* @see Server#getFlavorRef()
*/
public T flavorRef(String flavorRef) {
this.flavorRef = flavorRef;
return self();
}
/**
* @see Server#getHostId()
*/
public T hostId(String hostId) {
this.hostId = hostId;
return self();
}
/**
* @see Server#getImageRef()
*/
public T imageRef(String imageRef) {
this.imageRef = imageRef;
return self();
}
/**
* @see Server#getAffinityId()
*/
public T affinityId(String affinityId) {
this.affinityId = affinityId;
return self();
}
public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
/**
* @see Server#getUuid()
*/
public T uuid(String uuid) {
this.uuid = uuid;
return self();
}
/**
* @see Server#getFlavor()
*/
public T flavor(Flavor flavor) {
this.flavor = flavor;
return self();
}
/**
* @see Server#getImage()
*/
public T image(Image image) {
this.image = image;
return self();
}
/**
* @see Server#getKeyName()
*/
public T keyName(String keyName) {
this.keyName = keyName;
return self();
}
/**
* @see Server#getSecurityGroups()
*/
public T securityGroups(Set<SecurityGroup> securityGroups) {
this.securityGroups = ImmutableSet.copyOf(checkNotNull(securityGroups, "securityGroups"));
return self();
}
public T securityGroups(SecurityGroup... in) {
return securityGroups(ImmutableSet.copyOf(in));
}
/**
* @see Server#getCreated()
*/
public T created(Date created) {
this.created = created;
return self();
}
/**
* @see Server#getUpdated()
*/
public T updated(Date updated) {
this.updated = updated;
return self();
}
/**
* @see Server#getProgress()
*/
public T progress(Integer progress) {
this.progress = progress;
return self();
}
/**
* @see Server#getStatus()
*/
public T status(ServerStatus status) {
this.status = status;
return self();
}
public Server build() {
return new Server(id, links, orderedSelfReferences, name, metadata, addresses, accessIPv4, accessIPv6, adminPass,
flavorRef, hostId, imageRef, affinityId, uuid, flavor, image, keyName, securityGroups, created, updated,
progress, status);
}
public T fromServer(Server in) {
return super.fromResource(in)
.id(in.getId())
.name(in.getName())
.metadata(in.getMetadata())
.addresses(in.getAddresses())
.accessIPv4(in.getAccessIPv4())
.accessIPv6(in.getAccessIPv6())
.adminPass(in.getAdminPass())
.flavorRef(in.getFlavorRef())
.hostId(in.getHostId())
.imageRef(in.getImageRef())
.affinityId(in.getAffinityId())
.uuid(in.getUuid())
.flavor(in.getFlavor())
.image(in.getImage())
.keyName(in.getKeyName())
.securityGroups(in.getSecurityGroups())
.created(in.getCreated())
.updated(in.getUpdated())
.progress(in.getProgress())
.status(in.getStatus());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final Map<String, String> metadata;
private final Addresses addresses;
private final String accessIPv4;
private final String accessIPv6;
private final String adminPass;
private final String flavorRef;
private final String hostId;
private final String imageRef;
private final String affinityId;
private final String uuid;
private final Flavor flavor;
private final Image image;
private final String keyName;
private final Set<SecurityGroup> securityGroups;
private final Date created;
private final Date updated;
private final Integer progress;
private final ServerStatus status;
@ConstructorProperties({
"id", "links", "orderedSelfReferences", "name", "metadata", "addresses", "accessIPv4", "accessIPv6", "adminPass",
"flavorRef", "hostId", "imageRef", "affinityId", "uuid", "flavor", "image", "key_name", "security_groups",
"created", "updated", "progress", "status"
})
protected Server(int id, List<Map<String, String>> links, Map<LinkType, URI> orderedSelfReferences, String name,
@Nullable Map<String, String> metadata, @Nullable Addresses addresses, @Nullable String accessIPv4,
@Nullable String accessIPv6, @Nullable String adminPass, @Nullable String flavorRef, @Nullable String hostId,
@Nullable String imageRef, @Nullable String affinityId, @Nullable String uuid, @Nullable Flavor flavor,
@Nullable Image image, @Nullable String keyName, @Nullable Set<SecurityGroup> securityGroups,
@Nullable Date created, @Nullable Date updated, @Nullable Integer progress, @Nullable ServerStatus status) {
super(id, links, orderedSelfReferences);
this.name = checkNotNull(name, "name");
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(metadata);
this.addresses = addresses;
this.accessIPv4 = accessIPv4;
this.accessIPv6 = accessIPv6;
this.adminPass = adminPass;
this.flavorRef = flavorRef;
this.hostId = hostId;
this.imageRef = imageRef;
this.affinityId = affinityId;
this.uuid = uuid;
this.flavor = flavor;
this.image = image;
this.keyName = keyName;
this.securityGroups = securityGroups == null ? ImmutableSet.<SecurityGroup>of() : ImmutableSet.copyOf(securityGroups);
this.created = created;
this.updated = updated;
this.progress = progress;
this.status = status == null ? ServerStatus.UNKNOWN : status;
}
public String getName() {
return this.name;
}
public Map<String, String> getMetadata() {
return metadata;
}
public void setAddresses(Addresses addresses) {
this.addresses = addresses;
return this.metadata;
}
@Nullable
public Addresses getAddresses() {
return addresses;
return this.addresses;
}
public void setAdminPass(String adminPass) {
this.adminPass = adminPass;
/**
* @return the accessIPv4
*/
@Nullable
public String getAccessIPv4() {
return this.accessIPv4;
}
/**
* @return the accessIPv6
*/
@Nullable
public String getAccessIPv6() {
return this.accessIPv6;
}
@Nullable
public String getAdminPass() {
return adminPass;
}
public void setFlavorRef(String flavorRef) {
this.flavorRef = flavorRef;
return this.adminPass;
}
/**
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getFlavor()}
*/
@Deprecated
@Nullable
public String getFlavorRef() {
return flavorRef;
}
public void setHostId(String hostId) {
this.hostId = hostId;
return this.flavorRef;
}
/**
@ -139,40 +368,64 @@ public class Server extends Resource {
* <p/>
* Note: hostId is unique PER ACCOUNT and is not globally unique.
*/
@Nullable
public String getHostId() {
return hostId;
}
public int getId() {
return id;
}
public void setImageRef(String imageRef) {
this.imageRef = imageRef;
return this.hostId;
}
/**
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getImage()}.
*/
@Deprecated
@Nullable
public String getImageRef() {
return imageRef;
return this.imageRef;
}
public String getName() {
return name;
@Nullable
public String getAffinityId() {
return this.affinityId;
}
public void setProgress(Integer progress) {
this.progress = progress;
@Nullable
public String getUuid() {
return this.uuid;
}
@Nullable
public Flavor getFlavor() {
return this.flavor;
}
public Image getImage() {
return this.image;
}
@Nullable
public String getKeyName() {
return this.keyName;
}
/**
* Actually, security groups are not returned by nova on server query but is
* needed when creating a server to specify a set of groups
*/
public Set<SecurityGroup> getSecurityGroups() {
return this.securityGroups;
}
@Nullable
public Date getCreated() {
return this.created;
}
@Nullable
public Date getUpdated() {
return this.updated;
}
@Nullable
public Integer getProgress() {
return progress;
}
public void setStatus(ServerStatus status) {
this.status = status;
return this.progress;
}
/**
@ -180,196 +433,48 @@ public class Server extends Resource {
* state. Servers with an ACTIVE status are available for use.
*/
public ServerStatus getStatus() {
return status;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public Flavor getFlavor() {
return flavor;
}
public void setFlavor(Flavor flavor) {
this.flavor = flavor;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public String getKeyName() {
return keyName;
}
public void setKeyName(String keyName) {
this.keyName = keyName;
}
public Set<SecurityGroup> getSecurityGroups() {
return securityGroups;
}
public void setSecurityGroups(Set<SecurityGroup> securityGroups) {
this.securityGroups = securityGroups;
}
/**
* @return the accessIPv4
*/
public String getAccessIPv4() {
return accessIPv4;
}
/**
* @param accessIPv4
* the accessIPv4 to set
*/
public void setAccessIPv4(String accessIPv4) {
this.accessIPv4 = accessIPv4;
}
/**
* @return the accessIPv6
*/
public String getAccessIPv6() {
return accessIPv6;
}
/**
* @param accessIPv6
* the accessIPv6 to set
*/
public void setAccessIPv6(String accessIPv6) {
this.accessIPv6 = accessIPv6;
return this.status;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
result = prime * result + ((adminPass == null) ? 0 : adminPass.hashCode());
result = prime * result + ((flavorRef == null) ? 0 : flavorRef.hashCode());
result = prime * result + ((hostId == null) ? 0 : hostId.hashCode());
result = prime * result + id;
result = prime * result + ((imageRef == null) ? 0 : imageRef.hashCode());
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
result = prime * result + ((keyName == null) ? 0 : keyName.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((flavor == null) ? 0 : flavor.hashCode());
result = prime * result + ((image == null) ? 0 : image.hashCode());
result = prime * result + ((accessIPv4 == null) ? 0 : accessIPv4.hashCode());
result = prime * result + ((accessIPv6 == null) ? 0 : accessIPv6.hashCode());
return result;
return Objects.hashCode(super.hashCode(), name, metadata, addresses, accessIPv4, accessIPv6, adminPass, flavorRef,
hostId, imageRef, affinityId, uuid, flavor, image, keyName, securityGroups, created, updated);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Server other = (Server) obj;
if (addresses == null) {
if (other.addresses != null)
return false;
} else if (!addresses.equals(other.addresses))
return false;
if (adminPass == null) {
if (other.adminPass != null)
return false;
} else if (!adminPass.equals(other.adminPass))
return false;
if (flavorRef == null) {
if (other.flavorRef != null)
return false;
} else if (!flavorRef.equals(other.flavorRef))
return false;
if (hostId == null) {
if (other.hostId != null)
return false;
} else if (!hostId.equals(other.hostId))
return false;
if (id != other.id)
return false;
if (imageRef == null) {
if (other.imageRef != null)
return false;
} else if (!imageRef.equals(other.imageRef))
return false;
if (metadata == null) {
if (other.metadata != null)
return false;
} else if (!metadata.equals(other.metadata))
return false;
if (securityGroups == null) {
if (other.securityGroups != null)
return false;
} else if (!securityGroups.equals(other.securityGroups))
return false;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
if (keyName == null) {
if (other.keyName != null)
return false;
} else if (!keyName.equals(other.keyName))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (flavor == null) {
if (other.flavor != null)
return false;
} else if (!flavor.equals(other.flavor))
return false;
if (image == null) {
if (other.image != null)
return false;
} else if (!image.equals(other.image))
return false;
if (accessIPv4 == null) {
if (other.accessIPv4 != null)
return false;
} else if (!accessIPv4.equals(other.accessIPv4))
return false;
if (accessIPv6 == null) {
if (other.accessIPv6 != null)
return false;
} else if (!accessIPv6.equals(other.accessIPv6))
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Server that = Server.class.cast(obj);
return super.equals(that)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.metadata, that.metadata)
&& Objects.equal(this.addresses, that.addresses)
&& Objects.equal(this.accessIPv4, that.accessIPv4)
&& Objects.equal(this.accessIPv6, that.accessIPv6)
&& Objects.equal(this.adminPass, that.adminPass)
&& Objects.equal(this.flavorRef, that.flavorRef)
&& Objects.equal(this.hostId, that.hostId)
&& Objects.equal(this.imageRef, that.imageRef)
&& Objects.equal(this.affinityId, that.affinityId)
&& Objects.equal(this.uuid, that.uuid)
&& Objects.equal(this.flavor, that.flavor)
&& Objects.equal(this.image, that.image)
&& Objects.equal(this.keyName, that.keyName)
&& Objects.equal(this.securityGroups, that.securityGroups)
&& Objects.equal(this.created, that.created)
&& Objects.equal(this.updated, that.updated);
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Server [addresses=" + addresses + ", accessIPv4=" + accessIPv4
+ ", accessIPv6=" + accessIPv6 + ", adminPass=" + adminPass
+ ", flavorRef=" + flavorRef + ", hostId=" + hostId + ", id="
+ id + ", imageRef=" + imageRef + ", metadata=" + metadata
+ ", uuid=" + uuid + ", name=" + name + ", keyName=" + keyName
+ " , securityGroups=" + securityGroups + "]";
protected ToStringHelper string() {
return super.string()
.add("name", name).add("metadata", metadata).add("addresses", addresses)
.add("accessIPv4", accessIPv4).add("accessIPv6", accessIPv6).add("adminPass", adminPass)
.add("flavorRef", flavorRef).add("hostId", hostId).add("imageRef", imageRef).add("affinityId", affinityId)
.add("uuid", uuid).add("flavor", flavor).add("image", image).add("keyName", keyName)
.add("securityGroups", securityGroups).add("created", created).add("updated", updated)
.add("progress", progress).add("status", status);
}
}

View File

@ -22,12 +22,14 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.beans.ConstructorProperties;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.HttpRequest;
@ -39,12 +41,9 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName;
/**
*
* @author Adrian Cole
*
*/
public class CreateServerOptions implements MapBinder {
@Inject
@ -73,24 +72,30 @@ public class CreateServerOptions implements MapBinder {
}
@SuppressWarnings("unused")
private class ServerRequest {
final String name;
final String imageRef;
final String flavorRef;
String adminPass;
Map<String, String> metadata;
List<File> personality;
String key_name;
@SerializedName(value="security_groups")
Set<SecurityGroup> securityGroups;
final String adminPass;
final Map<String, String> metadata;
final List<File> personality;
@Named("key_name")
final String keyName;
@Named("security_groups")
final Set<SecurityGroup> securityGroups;
private ServerRequest(String name, String imageRef, String flavorRef) {
@ConstructorProperties({"name", "imageRef", "flavorRef", "adminPass", "metadata", "personality", "key_name", "security_groups"})
private ServerRequest(String name, String imageRef, String flavorRef, String adminPass, Map<String, String> metadata,
List<File> personality, String keyName, Set<SecurityGroup> securityGroups) {
this.name = name;
this.imageRef = imageRef;
this.flavorRef = flavorRef;
this.adminPass = adminPass;
this.metadata = metadata.isEmpty() ? null : metadata;
this.personality = personality.isEmpty() ? null : personality;
this.keyName = keyName;
this.securityGroups = securityGroups.isEmpty() ? null : securityGroups;
}
}
private Map<String, String> metadata = Maps.newHashMap();
@ -101,26 +106,19 @@ public class CreateServerOptions implements MapBinder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present").toString(),
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString());
if (metadata.size() > 0)
server.metadata = metadata;
if (files.size() > 0)
server.personality = files;
if (keyName != null)
server.key_name = keyName;
if (securityGroups.size() > 0) {
server.securityGroups = Sets.newHashSet();
Set<SecurityGroup> groups = Sets.newLinkedHashSet();
for (String groupName : securityGroups) {
SecurityGroup group = new SecurityGroup();
group.setName(groupName);
server.securityGroups.add(group);
}
}
if (adminPass != null) {
server.adminPass = adminPass;
groups.add(SecurityGroup.builder().name(groupName).build());
}
ServerRequest server = new ServerRequest(
checkNotNull(postParams.get("name"), "name parameter not present").toString(),
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString(),
adminPass,
metadata,
files,
keyName,
groups);
return bindToRequest(request, ImmutableMap.of("server", server));
}

View File

@ -30,19 +30,17 @@ import org.testng.annotations.Test;
@Test(groups = "unit")
public class ServerTest {
public void testStatusDoesntAffectEquals() {
Server server1 = new Server(1, "hello");
server1.setStatus(ServerStatus.ACTIVE);
Server server2 = new Server(1, "hello");
server2.setStatus(ServerStatus.BUILD);
Server server1 = Server.builder().id(1).name("hello").status(ServerStatus.ACTIVE).build();
Server server2 = Server.builder().id(1).name("hello").status(ServerStatus.BUILD).build();
assertEquals(server1, server2);
assertEquals(server1.hashCode(), server2.hashCode());
}
public void testProgressDoesntAffectEquals() {
Server server1 = new Server(1, "hello");
server1.setProgress(1);
Server server2 = new Server(1, "hello");
server2.setProgress(2);
Server server1 = Server.builder().id(1).name("hello").progress(1).build();
Server server2 = Server.builder().id(1).name("hello").progress(2).build();
assertEquals(server1, server2);
assertEquals(server1.hashCode(), server2.hashCode());
}
}

View File

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

View File

@ -54,7 +54,7 @@ public class ParseFloatingIPListFromJsonResponse {
.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(response.size(), 1);
FloatingIP floatingIP = new FloatingIP(1, "10.0.0.3", "11.0.0.1", 12);
FloatingIP floatingIP = FloatingIP.builder().id(1).ip("10.0.0.3").fixedIP("11.0.0.1").instanceID(12).build();
assertEquals(response.get(0), floatingIP);
}
}

View File

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

View File

@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.SimpleTimeZone;
@ -75,8 +74,8 @@ public class ParseServerFromJsonResponseDiabloTest {
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
new HashSet<Address>(privateAddresses));
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
assertEquals(response.getAddresses(), addresses1);
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
assertEquals(response.getAddresses(), addresses1);

View File

@ -24,7 +24,6 @@ import java.io.InputStream;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.SimpleTimeZone;
@ -76,8 +75,7 @@ public class ParseServerFromJsonResponseTest {
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
new HashSet<Address>(privateAddresses));
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
assertEquals(response.getAddresses(), addresses1);
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
assertEquals(response.getAddresses(), addresses1);

View File

@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.List;
import org.jclouds.http.HttpResponse;
@ -62,7 +61,8 @@ public class ParseServerListFromJsonResponseTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
List<Server> expects = ImmutableList.of(new Server(1234, "sample-server"), new Server(5678, "sample-server2"));
List<Server> expects = ImmutableList.of(Server.builder().id(1234).name("sample-server").build(),
Server.builder().id(5678).name("sample-server2").build());
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
@ -95,8 +95,7 @@ public class ParseServerListFromJsonResponseTest {
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
new HashSet<Address>(privateAddresses));
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
assertEquals(response.get(0).getAddresses(), addresses1);
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
@ -114,8 +113,8 @@ public class ParseServerListFromJsonResponseTest {
ImmutableList.of("67.23.10.133", "::babe:67.23.10.133"), Address.newString2AddressFunction()));
List<Address> privateAddresses2 = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.17", "::babe:10.176.42.17"), Address.newString2AddressFunction()));
Addresses addresses2 = new Addresses(new HashSet<Address>(publicAddresses2), new HashSet<Address>(
privateAddresses2));
Addresses addresses2 = Addresses.builder().publicAddresses(publicAddresses2).privateAddresses(privateAddresses2).build();
assertEquals(response.get(1).getAddresses(), addresses2);
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,6 +18,11 @@
*/
package org.jclouds.openstack.swift.domain;
import java.beans.ConstructorProperties;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
*
* @author James Murty
@ -25,64 +30,94 @@ package org.jclouds.openstack.swift.domain;
*/
public class AccountMetadata {
public AccountMetadata(long containerCount, long bytes) {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAccountMetadata(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected long containerCount;
protected long bytes;
/**
* @see AccountMetadata#getContainerCount()
*/
public T containerCount(long containerCount) {
this.containerCount = containerCount;
return self();
}
/**
* @see AccountMetadata#getBytes()
*/
public T bytes(long bytes) {
this.bytes = bytes;
return self();
}
public AccountMetadata build() {
return new AccountMetadata(containerCount, bytes);
}
public T fromAccountMetadata(AccountMetadata in) {
return this
.containerCount(in.getContainerCount())
.bytes(in.getBytes());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final long containerCount;
private final long bytes;
@ConstructorProperties({
"containerCount", "bytes"
})
protected AccountMetadata(long containerCount, long bytes) {
this.containerCount = containerCount;
this.bytes = bytes;
}
public AccountMetadata() {
public long getContainerCount() {
return this.containerCount;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ResourceMetadata [bytes=").append(bytes)
.append(", containerCount=").append(containerCount).append("]");
return builder.toString();
public long getBytes() {
return this.bytes;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (bytes ^ (bytes >>> 32));
result = prime * result + (int) (containerCount ^ (containerCount >>> 32));
return result;
return Objects.hashCode(containerCount, bytes);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AccountMetadata other = (AccountMetadata) obj;
if (bytes != other.bytes)
return false;
if (containerCount != other.containerCount)
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
AccountMetadata that = AccountMetadata.class.cast(obj);
return Objects.equal(this.containerCount, that.containerCount)
&& Objects.equal(this.bytes, that.bytes);
}
private long containerCount;
private long bytes;
public void setContainerCount(long count) {
this.containerCount = count;
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("containerCount", containerCount).add("bytes", bytes);
}
public long getContainerCount() {
return containerCount;
@Override
public String toString() {
return string().toString();
}
public void setBytes(long bytes) {
this.bytes = bytes;
}
public long getBytes() {
return bytes;
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,117 +18,163 @@
*/
package org.jclouds.openstack.swift.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Map;
import com.google.common.collect.Maps;
import com.google.gson.annotations.SerializedName;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableMap;
/**
* Class ContainerMetadata
*
* @author Adrian Cole
*
*/
public class ContainerMetadata implements Comparable<ContainerMetadata> {
private String name;
private long count;
private long bytes;
@SerializedName("X-Container-Read")
private String readACL;
private Map<String, String> metadata = Maps.newLinkedHashMap();
public class ContainerMetadata {
public ContainerMetadata() {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public ContainerMetadata(String name, long count, long bytes, String readACL, Map<String, String> metadata) {
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromContainerMetadata(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected long count;
protected long bytes;
protected String readACL;
protected Map<String, String> metadata = ImmutableMap.of();
/**
* @see ContainerMetadata#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see ContainerMetadata#getCount()
*/
public T count(long count) {
this.count = count;
return self();
}
/**
* @see ContainerMetadata#getBytes()
*/
public T bytes(long bytes) {
this.bytes = bytes;
return self();
}
/**
* @see ContainerMetadata#getReadACL()
*/
public T readACL(String readACL) {
this.readACL = readACL;
return self();
}
/**
* @see ContainerMetadata#getMetadata()
*/
public T metadata(Map<String, String> metadata) {
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self();
}
public ContainerMetadata build() {
return new ContainerMetadata(name, count, bytes, readACL, metadata);
}
public T fromContainerMetadata(ContainerMetadata in) {
return this
.name(in.getName())
.count(in.getCount())
.bytes(in.getBytes())
.readACL(in.getReadACL())
.metadata(in.getMetadata());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final long count;
private final long bytes;
private final String readACL;
private final Map<String, String> metadata;
@ConstructorProperties({
"name", "count", "bytes", "X-Container-Read", "metadata"
})
protected ContainerMetadata(String name, long count, long bytes, @Nullable String readACL, @Nullable Map<String, String> metadata) {
this.name = checkNotNull(name, "name");
this.count = count;
this.bytes = bytes;
this.readACL = readACL;
this.metadata = metadata;
}
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(metadata);
}
public String getName() {
return name;
return this.name;
}
public void setName(String name) {
this.name = name;
public long getCount() {
return this.count;
}
public long getBytes() {
return bytes;
return this.bytes;
}
public void setBytes(long bytes) {
this.bytes = bytes;
}
public boolean isPublic() {
if (readACL == null)
return false;
return readACL.equals(".r:*,.rlistings");
}
public void setReadACL(String readACL) {
this.readACL = readACL;
@Nullable
public String getReadACL() {
return this.readACL;
}
public Map<String, String> getMetadata() {
return metadata;
return this.metadata;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (bytes ^ (bytes >>> 32));
result = prime * result + (int) (count ^ (count >>> 32));
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
return Objects.hashCode(name, count, bytes);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ContainerMetadata other = (ContainerMetadata) obj;
if (bytes != other.bytes)
return false;
if (count != other.count)
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;
ContainerMetadata that = ContainerMetadata.class.cast(obj);
return Objects.equal(this.name, that.name)
&& Objects.equal(this.count, that.count)
&& Objects.equal(this.bytes, that.bytes);
}
public int compareTo(ContainerMetadata o) {
if (getName() == null)
return -1;
return (this == o) ? 0 : getName().compareTo(o.getName());
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("count", count).add("bytes", bytes).add("readACL", readACL).add("metadata", metadata);
}
@Override
public String toString() {
return "ContainerMetadata [name=" + name + ", count=" + count + ", bytes="
+ bytes + ", isPublic=" + isPublic() + "]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,86 +18,141 @@
*/
package org.jclouds.openstack.swift.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Arrays;
import java.util.Date;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.openstack.swift.domain.ObjectInfo;
import com.google.gson.annotations.SerializedName;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ComparisonChain;
/**
* Class ObjectInfoImpl
*/
public class ObjectInfoImpl implements ObjectInfo {
public static Builder builder() {
return new Builder();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private String name;
private String container;
private URI uri;
private byte[] hash;
private Long bytes;
private String contentType;
private Date lastModified;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromObjectInfoImpl(this);
}
public Builder name(String name) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected String container;
protected URI uri;
protected byte[] hash;
protected Long bytes;
protected String contentType;
protected Date lastModified;
/**
* @see ObjectInfoImpl#getName()
*/
public T name(String name) {
this.name = name;
return this;
return self();
}
public Builder container(String container) {
/**
* @see ObjectInfoImpl#getContainer()
*/
public T container(String container) {
this.container = container;
return this;
return self();
}
public Builder uri(URI uri) {
/**
* @see ObjectInfoImpl#getUri()
*/
public T uri(URI uri) {
this.uri = uri;
return this;
return self();
}
public Builder hash(byte[] hash) {
/**
* @see ObjectInfoImpl#getHash()
*/
public T hash(byte[] hash) {
this.hash = hash;
return this;
return self();
}
public Builder bytes(Long bytes) {
/**
* @see ObjectInfoImpl#getBytes()
*/
public T bytes(Long bytes) {
this.bytes = bytes;
return this;
return self();
}
public Builder contentType(String contentType) {
/**
* @see ObjectInfoImpl#getContentType()
*/
public T contentType(String contentType) {
this.contentType = contentType;
return this;
return self();
}
public Builder lastModified(Date lastModified) {
/**
* @see ObjectInfoImpl#getLastModified()
*/
public T lastModified(Date lastModified) {
this.lastModified = lastModified;
return this;
return self();
}
public ObjectInfoImpl build() {
return new ObjectInfoImpl(name, uri, container, hash, bytes, contentType, lastModified);
return new ObjectInfoImpl(name, container, uri, hash, bytes, contentType, lastModified);
}
public Builder fromObjectInfo(ObjectInfo in) {
return name(in.getName()).container(in.getContainer()).uri(uri).hash(in.getHash()).bytes(in.getBytes())
.contentType(in.getContentType()).lastModified(in.getLastModified());
public T fromObjectInfoImpl(ObjectInfoImpl in) {
return this
.name(in.getName())
.container(in.getContainer())
.uri(in.getUri())
.hash(in.getHash())
.bytes(in.getBytes())
.contentType(in.getContentType())
.lastModified(in.getLastModified());
}
}
private String name;
private String container;
private URI uri;
private byte[] hash;
private Long bytes;
@SerializedName("content_type")
private String contentType;
@SerializedName("last_modified")
private Date lastModified;
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public ObjectInfoImpl(String name, URI uri, String container, byte[] hash, Long bytes, String contentType,
Date lastModified) {
this.name = name;
private final String name;
private final String container;
private final URI uri;
private final byte[] hash;
private final Long bytes;
@Named("content_type")
private final String contentType;
@Named("last_modified")
private final Date lastModified;
@ConstructorProperties({
"name", "container", "uri", "hash", "bytes", "content_type", "last_modified"
})
protected ObjectInfoImpl(String name, @Nullable String container, @Nullable URI uri, @Nullable byte[] hash, @Nullable Long bytes,
@Nullable String contentType, @Nullable Date lastModified) {
this.name = checkNotNull(name, "name");
this.container = container;
this.uri = uri;
this.hash = hash;
@ -106,110 +161,88 @@ public class ObjectInfoImpl implements ObjectInfo {
this.lastModified = lastModified;
}
ObjectInfoImpl() {
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
return this.name;
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public String getContainer() {
return container;
return this.container;
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public URI getUri() {
return uri;
return this.uri;
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public byte[] getHash() {
return hash;
return this.hash;
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public Long getBytes() {
return bytes;
return this.bytes;
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public String getContentType() {
return contentType;
return this.contentType;
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public Date getLastModified() {
return lastModified;
return this.lastModified;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((container == null) ? 0 : container.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
return Objects.hashCode(name, container);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ObjectInfoImpl other = (ObjectInfoImpl) obj;
if (container == null) {
if (other.container != null)
return false;
} else if (!container.equals(other.container))
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;
ObjectInfoImpl that = ObjectInfoImpl.class.cast(obj);
return Objects.equal(this.name, that.name)
&& Objects.equal(this.container, that.container);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("container", container).add("uri", uri).add("hash", Arrays.toString(hash))
.add("bytes", bytes).add("contentType", contentType).add("lastModified", lastModified);
}
@Override
public String toString() {
return String.format("[name=%s, container=%s, uri=%s, bytes=%s, contentType=%s, lastModified=%s, hash=%s]", name,
container, uri, bytes, contentType, lastModified, Arrays.toString(hash));
}
public Builder toBuilder() {
return builder().fromObjectInfo(this);
return string().toString();
}
@Override
public int compareTo(ObjectInfo o) {
return name.compareTo(o.getName());
public int compareTo(ObjectInfo other) {
return ComparisonChain.start().compare(name, other.getName()).compare(container, other.getContainer()).result();
}
}

View File

@ -41,6 +41,7 @@ public class ParseAccountMetadataResponseFromHeaders implements Function<HttpRes
SwiftHeaders.ACCOUNT_BYTES_USED);
String containersCountString = checkNotNull(from.getFirstHeaderOrNull(SwiftHeaders.ACCOUNT_CONTAINER_COUNT),
SwiftHeaders.ACCOUNT_CONTAINER_COUNT);
return new AccountMetadata(Long.parseLong(containersCountString), Long.parseLong(bytesString));
return AccountMetadata.builder().containerCount(Long.parseLong(containersCountString))
.bytes(Long.parseLong(bytesString)).build();
}
}

View File

@ -53,8 +53,8 @@ public class ParseContainerListFromJsonResponseTest {
.toInputStream("[ {\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}, {\"name\":\"test_container_2\",\"count\":1,\"bytes\":17} ] ");
Map<String, String> meta = new HashMap<String, String>();
List<ContainerMetadata> expects = ImmutableList.of(new ContainerMetadata("test_container_1", 2, 78, null, meta),
new ContainerMetadata("test_container_2", 1, 17, null, meta));
List<ContainerMetadata> expects = ImmutableList.of(ContainerMetadata.builder().name("test_container_1").count( 2).bytes(78).metadata(meta).build(),
ContainerMetadata.builder().name("test_container_2").count(1).bytes(17).metadata(meta).build());
ParseJson<List<ContainerMetadata>> parser = i.getInstance(Key
.get(new TypeLiteral<ParseJson<List<ContainerMetadata>>>() {
}));

View File

@ -155,7 +155,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
return immediateFuture(Sets.newHashSet(Iterables.transform(listing,
new Function<StorageMetadata, ContainerMetadata>() {
public ContainerMetadata apply(StorageMetadata md) {
return new ContainerMetadata(md.getName(), -1, -1, null, new HashMap<String,String>());
return ContainerMetadata.builder().name(md.getName()).count(-1).bytes(-1).metadata(new HashMap<String,String>()).build();
}
})));
}

View File

@ -18,19 +18,24 @@
*/
package org.jclouds.gogrid.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.domain.Credentials;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.collect.Maps;
import com.google.gson.annotations.SerializedName;
/**
* @author Oleksiy Yarmula
@ -49,10 +54,17 @@ public class ParseServerNameToCredentialsMapFromJsonResponse implements
// incidental view class to assist in getting the correct data
// deserialized from json
private static class Password implements Comparable<Password> {
@SerializedName("username")
private String userName;
private String password;
private Server server;
@Named("username")
private final String userName;
private final String password;
private final Server server;
@ConstructorProperties({"username", "password", "server"})
public Password(String userName, String password, @Nullable Server server) {
this.userName = checkNotNull(userName, "username");
this.password = checkNotNull(password, "password");
this.server = server;
}
public String getUserName() {
return userName;
@ -73,32 +85,21 @@ public class ParseServerNameToCredentialsMapFromJsonResponse implements
if (o == null || getClass() != o.getClass())
return false;
Password password1 = (Password) o;
if (password != null ? !password.equals(password1.password)
: password1.password != null)
return false;
if (server != null ? !server.equals(password1.server)
: password1.server != null)
return false;
if (userName != null ? !userName.equals(password1.userName)
: password1.userName != null)
return false;
return true;
Password other = (Password) o;
return Objects.equal(userName, other.userName)
&& Objects.equal(password, other.password)
&& Objects.equal(server, other.server);
}
@Override
public int hashCode() {
int result = userName != null ? userName.hashCode() : 0;
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (server != null ? server.hashCode() : 0);
return result;
return Objects.hashCode(userName, password, server);
}
@Override
public int compareTo(Password o) {
if (null == o.getServer() || null == server) return -1;
if (null == o.getServer()) return null == server ? 0 : -1;
if (server == null) return 1;
return server.getName().compareTo(o.getServer().getName());
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,57 +18,198 @@
*/
package org.jclouds.hpcloud.objectstorage.domain;
import java.beans.ConstructorProperties;
import java.net.URI;
import com.google.gson.annotations.SerializedName;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
*
* @author James Murty
*
*/
public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
protected ContainerCDNMetadata() {
// we want serializers like Gson to work w/o using sun.misc.Unsafe,
// prohibited in GAE. This also implies fields are not final.
// see http://code.google.com/p/jclouds/issues/detail?id=925
public static Builder<?> builder() {
return new ConcreteBuilder();
}
private String name;
private boolean cdn_enabled;
private long ttl;
@SerializedName("x-cdn-uri")
private URI cdn_uri;
private String referrer_acl;
private String useragent_acl;
private boolean log_retention;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromContainerCDNMetadata(this);
}
public ContainerCDNMetadata(String name, boolean cdnEnabled, long ttl, URI cdnUri) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected boolean cdnEnabled;
protected long ttl;
protected URI CDNUri;
protected String referrerAcl;
protected String useragentAcl;
protected boolean logRetention;
/**
* @see ContainerCDNMetadata#getName()
*/
public T name(String name) {
this.name = name;
this.cdn_enabled = cdnEnabled;
this.ttl = ttl;
this.cdn_uri = cdnUri;
return self();
}
/**
* Beware: The container name is not available from HEAD CDN responses and will be null. return
* the name of the container to which these CDN settings apply.
* @see ContainerCDNMetadata#isCDNEnabled()
*/
public T CDNEnabled(boolean cdnEnabled) {
this.cdnEnabled = cdnEnabled;
return self();
}
/**
* @see ContainerCDNMetadata#getTTL
*/
public T ttl(long ttl) {
this.ttl = ttl;
return self();
}
/**
* @see ContainerCDNMetadata#getCDNUri()
*/
public T CDNUri(URI CDNUri) {
this.CDNUri = CDNUri;
return self();
}
/**
* @see ContainerCDNMetadata#getReferrerAcl()
*/
public T referrerAcl(String referrerAcl) {
this.referrerAcl = referrerAcl;
return self();
}
/**
* @see ContainerCDNMetadata#getUseragentAcl()
*/
public T useragent_acl(String useragentAcl) {
this.useragentAcl = useragentAcl;
return self();
}
/**
* @see ContainerCDNMetadata#isLogRetention()
*/
public T logRetention(boolean logRetention) {
this.logRetention = logRetention;
return self();
}
public ContainerCDNMetadata build() {
return new ContainerCDNMetadata(name, cdnEnabled, ttl, CDNUri, referrerAcl, useragentAcl, logRetention);
}
public T fromContainerCDNMetadata(ContainerCDNMetadata in) {
return this
.name(in.getName())
.CDNEnabled(in.isCDNEnabled())
.ttl(in.getTTL())
.CDNUri(in.getCDNUri())
.referrerAcl(in.getReferrerAcl())
.useragent_acl(in.getUseragentAcl())
.logRetention(in.isLogRetention());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final boolean cdnEnabled;
private final long ttl;
private final URI CDNUri;
private final String referrerAcl;
private final String useragentAcl;
private final boolean logRetention;
@ConstructorProperties({
"name", "cdn_enabled", "ttl", "x-cdn-uri", "referrer_acl", "useragent_acl", "log_retention"
})
protected ContainerCDNMetadata(@Nullable String name, boolean cdnEnabled, long ttl, @Nullable URI CDNUri,
@Nullable String referrerAcl, @Nullable String useragentAcl, boolean logRetention) {
this.name = name;
this.cdnEnabled = cdnEnabled;
this.ttl = ttl;
this.CDNUri = CDNUri;
this.referrerAcl = referrerAcl;
this.useragentAcl = useragentAcl;
this.logRetention = logRetention;
}
/**
* Beware: The container name is not available from HEAD CDN responses and will be null.
*
* @return the name of the container to which these CDN settings apply.
*/
@Nullable
public String getName() {
return name;
}
public URI getCDNUri() {
return cdn_uri;
}
public long getTTL() {
return ttl;
return this.name;
}
public boolean isCDNEnabled() {
return cdn_enabled;
return this.cdnEnabled;
}
public long getTTL() {
return this.ttl;
}
@Nullable
public URI getCDNUri() {
return this.CDNUri;
}
@Nullable
public String getReferrerAcl() {
return this.referrerAcl;
}
@Nullable
public String getUseragentAcl() {
return this.useragentAcl;
}
public boolean isLogRetention() {
return this.logRetention;
}
@Override
public int hashCode() {
return Objects.hashCode(name, CDNUri);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ContainerCDNMetadata that = ContainerCDNMetadata.class.cast(obj);
return Objects.equal(this.name, that.name) && Objects.equal(this.CDNUri, that.CDNUri);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("cdnEnabled", cdnEnabled).add("ttl", ttl).add("CDNUri", CDNUri)
.add("referrerAcl", referrerAcl).add("useragentAcl", useragentAcl).add("logRetention", logRetention);
}
@Override
public String toString() {
return string().toString();
}
public int compareTo(ContainerCDNMetadata o) {
@ -76,48 +217,4 @@ public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
return -1;
return (this == o) ? 0 : getName().compareTo(o.getName());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cdn_uri == null) ? 0 : cdn_uri.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ContainerCDNMetadata other = (ContainerCDNMetadata) obj;
if (cdn_uri == null) {
if (other.cdn_uri != null)
return false;
} else if (!cdn_uri.equals(other.cdn_uri))
return false;
return true;
}
public String getReferrerACL() {
return referrer_acl;
}
public String getUseragentACL() {
return useragent_acl;
}
public boolean isLogRetention() {
return log_retention;
}
@Override
public String toString() {
return String.format(
"[name=%s, cdn_uri=%s, cdn_enabled=%s, log_retention=%s, referrer_acl=%s, ttl=%s, useragent_acl=%s]",
name, cdn_uri, cdn_enabled, log_retention, referrer_acl, ttl, useragent_acl);
}
}

View File

@ -61,8 +61,9 @@ public class ParseContainerCDNMetadataFromHeaders implements
// just need the name from the path
List<String> parts = newArrayList(Splitter.on('/').split(request.getEndpoint().getPath()));
return new ContainerCDNMetadata(parts.get(parts.size()-1), Boolean
.parseBoolean(cdnEnabled), Long.parseLong(cdnTTL), URI.create(cdnUri));
return ContainerCDNMetadata.builder().name(parts.get(parts.size() - 1))
.CDNEnabled(Boolean.parseBoolean(cdnEnabled)).ttl(Long.parseLong(cdnTTL)).CDNUri(URI.create(cdnUri))
.build();
}
}

View File

@ -20,6 +20,7 @@ package org.jclouds.hpcloud.objectstorage.functions;
import static com.google.common.base.Preconditions.checkArgument;
import java.util.Map;
import java.util.Map.Entry;
import org.jclouds.http.HttpRequest;
@ -31,9 +32,10 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
/**
* This parses @{link {@link org.jclouds.hpcloud.objectstorage.domain.ContainerMetadata} from
* This parses @{link {@link org.jclouds.openstack.swift.domain.ContainerMetadata} from
* HTTP headers.
*
* @author Jeremy Daggett
@ -43,28 +45,23 @@ public class ParseContainerMetadataFromHeaders implements Function<HttpResponse,
private GeneratedHttpRequest request;
public ContainerMetadata apply(HttpResponse from) {
ContainerMetadata to = new ContainerMetadata();
to.setName(request.getArgs().get(0).toString());
to.setReadACL(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_READ));
to.setBytes(Long.valueOf(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_BYTES_USED)));
to.setCount(Long.valueOf(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_OBJECT_COUNT)));
addUserMetadataTo(from, to);
return to;
return ContainerMetadata.builder().name(request.getArgs().get(0).toString())
.readACL(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_READ))
.bytes(Long.valueOf(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_BYTES_USED)))
.count(Long.valueOf(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_OBJECT_COUNT)))
.metadata(extractUserMetadata(from)).build();
}
@VisibleForTesting
void addUserMetadataTo(HttpResponse from, ContainerMetadata metadata) {
Map<String, String> extractUserMetadata(HttpResponse from) {
Map<String, String> metadata = Maps.newHashMap();
for (Entry<String, String> header : from.getHeaders().entries()) {
if (header.getKey() != null && header.getKey().startsWith(SwiftHeaders.CONTAINER_METADATA_PREFIX))
metadata.getMetadata().put((header.getKey().substring(SwiftHeaders.CONTAINER_METADATA_PREFIX.length())).toLowerCase(),
metadata.put((header.getKey().substring(SwiftHeaders.CONTAINER_METADATA_PREFIX.length())).toLowerCase(),
header.getValue());
}
return metadata;
}
@Override

View File

@ -92,7 +92,8 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes
assertTrue(cdnMetadataList.size() >= 1);
final long initialTTL = cdnMetadata.getTTL();
assertTrue(cdnMetadataList.contains(new ContainerCDNMetadata(containerNameWithCDN, true, initialTTL, cdnUri)));
assertTrue(cdnMetadataList.contains(ContainerCDNMetadata.builder().name(containerNameWithCDN)
.CDNEnabled(true).ttl(initialTTL).CDNUri(cdnUri).build()));
/*
* Test listing with options FIXFIX cdnMetadataList =

View File

@ -31,7 +31,7 @@ import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
@ -51,16 +51,16 @@ public class ParseContainerCDNMetadataListFromJsonResponseTest {
InputStream is = getClass().getResourceAsStream("/test_list_cdn.json");
Set<ContainerCDNMetadata> expects = ImmutableSortedSet.of(
new ContainerCDNMetadata("hpcloud-blobstore.testCDNOperationsContainerWithCDN", false, 3600,
URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")),
new ContainerCDNMetadata("hpcloud-blobstore5", true, 28800,
URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")),
new ContainerCDNMetadata("hpcloud-cfcdnint.testCDNOperationsContainerWithCDN", false, 3600,
URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")));
Set<ContainerCDNMetadata> expects = ImmutableSet.of(
ContainerCDNMetadata.builder().name("hpcloud-blobstore.testCDNOperationsContainerWithCDN").CDNEnabled(false).ttl(3600)
.CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build(),
ContainerCDNMetadata.builder().name("hpcloud-blobstore5").CDNEnabled(true).ttl(28800)
.CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build(),
ContainerCDNMetadata.builder().name("hpcloud-cfcdnint.testCDNOperationsContainerWithCDN").CDNEnabled(false).ttl(3600)
.CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build());
ParseJson<SortedSet<ContainerCDNMetadata>> parser = i.getInstance(Key
.get(new TypeLiteral<ParseJson<SortedSet<ContainerCDNMetadata>>>() {
ParseJson<SortedSet<ContainerCDNMetadata>> parser = i.getInstance(
Key.get(new TypeLiteral<ParseJson<SortedSet<ContainerCDNMetadata>>>() {
}));
assertEquals(parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()), expects);

View File

@ -56,7 +56,7 @@ public class ProductItems {
/**
* Creates a function to get the ProductItemPrice for the ProductItem. Currently returns the
* first price. This will need to be changed if more than one price is returned.
* first prices. This will need to be changed if more than one prices is returned.
*/
public static Function<ProductItem, ProductItemPrice> price() {
return new Function<ProductItem, ProductItemPrice>() {
@ -71,7 +71,7 @@ public class ProductItems {
/**
* Creates a function to get the ProductItem for the ProductItemPrice. Copies the category
* information from the price to the item if necessary The ProductItemPrices must have
* information from the prices to the item if necessary The ProductItemPrices must have
* ProductItems.
*/
public static Function<ProductItemPrice, ProductItem> item() {
@ -80,7 +80,7 @@ public class ProductItems {
public ProductItem apply(ProductItemPrice productItemPrice) {
Set<ProductItemCategory> categories = productItemPrice.getCategories();
ProductItem item = productItemPrice.getItem();
ProductItem.Builder builder = ProductItem.Builder.fromProductItem(productItemPrice.getItem());
ProductItem.Builder builder = productItemPrice.getItem().toBuilder();
if (item.getCategories().size() == 0 && categories.size() != 0) {
builder.categories(categories);
}

View File

@ -47,7 +47,7 @@ import com.google.common.collect.Iterables;
/**
* Converts a set of ProductItems to Hardware. All cores have a speed of 2.0Ghz The Hardware Id will
* be a comma separated list containing the price ids: cpus,ram,volume
* be a comma separated list containing the prices ids: cpus,ram,volume
*
* @author Jason King
*/

View File

@ -126,7 +126,7 @@ public class SoftLayerComputeServiceAdapter implements
ProductOrder order = ProductOrder.builder().packageId(productPackageSupplier.get().getId())
.location(template.getLocation().getId()).quantity(1).useHourlyPricing(true).prices(getPrices(template))
.virtualGuest(newGuest).build();
.virtualGuests(newGuest).build();
logger.debug(">> ordering new virtualGuest domain(%s) hostname(%s)", domainName, name);
ProductOrderReceipt productOrderReceipt = client.getVirtualGuestClient().orderVirtualGuest(order);

View File

@ -18,28 +18,10 @@
*/
package org.jclouds.softlayer.config;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.OperatingSystem;
import org.jclouds.softlayer.domain.PowerState;
import org.jclouds.softlayer.domain.VirtualGuest;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
*
@ -47,72 +29,6 @@ import com.google.inject.Provides;
*/
public class SoftLayerParserModule extends AbstractModule {
@Singleton
public static class VirtualGuestAdapter implements JsonSerializer<VirtualGuest>, JsonDeserializer<VirtualGuest> {
public JsonElement serialize(VirtualGuest src, Type typeOfSrc, JsonSerializationContext context) {
return context.serialize(src);
}
public VirtualGuest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
return apply(context.<VirtualGuestInternal> deserialize(json, VirtualGuestInternal.class));
}
public VirtualGuest apply(VirtualGuestInternal in) {
return in;
}
/**
* Internal class that flattens billingItem into billingItemId
*/
public static class VirtualGuestInternal extends VirtualGuest {
private BillingItem billingItem;
public VirtualGuestInternal(int accountId, Date createDate, boolean dedicatedAccountHostOnly, String domain,
String fullyQualifiedDomainName, String hostname, int id, Date lastVerifiedDate, int maxCpu,
String maxCpuUnits, int maxMemory, Date metricPollDate, Date modifyDate, String notes,
boolean privateNetworkOnly, int startCpus, int statusId, String uuid, String primaryBackendIpAddress,
String primaryIpAddress, int billingItemId, OperatingSystem operatingSystem, Datacenter datacenter,
PowerState powerState) {
super(accountId, createDate, dedicatedAccountHostOnly, domain, fullyQualifiedDomainName, hostname, id,
lastVerifiedDate, maxCpu, maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes,
privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress, primaryIpAddress,
billingItemId, operatingSystem, datacenter, powerState);
}
@Override
public int getBillingItemId() {
return billingItem != null ? billingItem.id : -1;
}
}
public static class BillingItem {
private int id = -1;
// for deserializer
BillingItem() {
}
public BillingItem(int id) {
this.id = id;
}
@Override
public String toString() {
return "[id=" + id + "]";
}
}
}
@Provides
@Singleton
public Map<Type, Object> provideCustomAdapterBindings() {
return ImmutableMap.<Type, Object> of(VirtualGuest.class, new VirtualGuestAdapter());
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -21,135 +21,156 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.emptyToNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* Class Address
*
* @author Jason King
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account_Address"
* />
/>
*/
public class Address implements Comparable<Address> {
public static Builder builder() {
return new Builder();
public class Address {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int id = -1;
private String country;
private String state;
private String description;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAddress(this);
}
public Builder id(int id) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected String country;
protected String state;
protected String description;
/**
* @see Address#getId()
*/
public T id(int id) {
this.id = id;
return this;
return self();
}
public Builder country(String country) {
/**
* @see Address#getCountry()
*/
public T country(String country) {
this.country = country;
return this;
return self();
}
public Builder state(String state) {
/**
* @see Address#getState()
*/
public T state(String state) {
this.state = state;
return this;
return self();
}
public Builder description(String description) {
/**
* @see Address#getDescription()
*/
public T description(String description) {
this.description = description;
return this;
return self();
}
public Address build() {
return new Address(id, country, state, description);
}
public static Builder fromAddress(Address in) {
return Address.builder().id(in.getId())
public T fromAddress(Address in) {
return this
.id(in.getId())
.country(in.getCountry())
.state(in.getState())
.description(in.getDescription());
}
}
private int id = -1;
private String country;
private String state;
private String description;
// for deserializer
Address() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public Address(int id, String country, String state, String description) {
private final int id;
private final String country;
private final String state;
private final String description;
@ConstructorProperties({
"id", "country", "state", "description"
})
protected Address(int id, String country, @Nullable String state, @Nullable String description) {
this.id = id;
this.country = checkNotNull(emptyToNull(country),"country cannot be null or empty:"+country);
this.state = state;
this.description = description;
}
@Override
public int compareTo(Address arg0) {
return Integer.valueOf(id).compareTo(arg0.getId());
}
/**
* @return The unique id of the address.
*/
public int getId() {
return id;
return this.id;
}
/**
* @return The country of the address.
*/
public String getCountry() {
return country;
return this.country;
}
/**
* @return The state of the address.
*/
@Nullable
public String getState() {
return state;
return this.state;
}
/**
* @return The description of the address.
*/
@Nullable
public String getDescription() {
return description;
}
public Builder toBuilder() {
return Builder.fromAddress(this);
return this.description;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id ^ (id >>> 32));
return result;
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Address other = (Address) obj;
if (id != other.id)
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Address that = Address.class.cast(obj);
return Objects.equal(this.id, that.id);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("country", country).add("state", state).add("description", description);
}
@Override
public String toString() {
return "[id=" + id + ", country=" + country + ", state=" + state + ", description=" + description + "]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -20,161 +20,186 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* Class Datacenter
*
* @author Adrian Cole
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Location_Datacenter"
* />
/>
*/
public class Datacenter implements Comparable<Datacenter> {
public static Builder builder() {
return new Builder();
public class Datacenter {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int id = -1;
private String name;
private String longName;
private Address locationAddress;
private Set<Region> regions = Sets.newLinkedHashSet();
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromDatacenter(this);
}
public Builder id(int id) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected String name;
protected String longName;
protected Address locationAddress;
protected Set<Region> regions = ImmutableSet.of();
/**
* @see Datacenter#getId()
*/
public T id(int id) {
this.id = id;
return this;
return self();
}
public Builder name(String name) {
/**
* @see Datacenter#getName()
*/
public T name(String name) {
this.name = name;
return this;
return self();
}
public Builder longName(String longName) {
/**
* @see Datacenter#getLongName()
*/
public T longName(String longName) {
this.longName = longName;
return this;
return self();
}
public Builder locationAddress(Address locationAddress) {
/**
* @see Datacenter#getLocationAddress()
*/
public T locationAddress(Address locationAddress) {
this.locationAddress = locationAddress;
return this;
return self();
}
public Builder region(Region regions) {
this.regions.add(checkNotNull(regions, "regions"));
return this;
/**
* @see Datacenter#getRegions()
*/
public T regions(Set<Region> regions) {
this.regions = ImmutableSet.copyOf(checkNotNull(regions, "regions"));
return self();
}
public Builder regions(Iterable<Region> regions) {
this.regions = ImmutableSet.<Region> copyOf(checkNotNull(regions, "regions"));
return this;
public T regions(Region... in) {
return regions(ImmutableSet.copyOf(in));
}
public Datacenter build() {
return new Datacenter(id, name, longName, locationAddress, regions);
}
public static Builder fromDatacenter(Datacenter in) {
return Datacenter.builder().id(in.getId()).name(in.getName())
.longName(in.getLongName()).locationAddress(in.getLocationAddress())
public T fromDatacenter(Datacenter in) {
return this
.id(in.getId())
.name(in.getName())
.longName(in.getLongName())
.locationAddress(in.getLocationAddress())
.regions(in.getRegions());
}
}
private int id = -1;
private String name;
private String longName;
private Address locationAddress;
private Set<Region> regions = Sets.newLinkedHashSet();
// for deserializer
Datacenter() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public Datacenter(int id, String name, String longName, Address locationAddress, Iterable<Region> regions) {
private final int id;
private final String name;
private final String longName;
private final Address locationAddress;
private final Set<Region> regions;
@ConstructorProperties({
"id", "name", "longName", "locationAddress", "regions"
})
protected Datacenter(int id, @Nullable String name, @Nullable String longName, @Nullable Address locationAddress, @Nullable Set<Region> regions) {
this.id = id;
this.name = name;
this.longName = longName;
this.locationAddress = locationAddress;
this.regions = ImmutableSet.<Region> copyOf(checkNotNull(regions, "regions"));
}
@Override
public int compareTo(Datacenter arg0) {
return Integer.valueOf(id).compareTo(arg0.getId());
this.regions = regions == null ? ImmutableSet.<Region>of() : ImmutableSet.copyOf(regions);
}
/**
* @return The unique identifier of a specific location.
*/
public int getId() {
return id;
return this.id;
}
/**
* @return A short location description.
*/
@Nullable
public String getName() {
return name;
return this.name;
}
/**
* @return A longer location description.
*/
@Nullable
public String getLongName() {
return longName;
return this.longName;
}
/**
* @return A location's physical address (optional).
*/
@Nullable
public Address getLocationAddress() {
return locationAddress;
return this.locationAddress;
}
/**
* A location can be a member of 1 or more regions.
* Sometimes the list of regions is empty, for example as a new Datacenter is being added.
* The list of regions usually contains one with keyName=FIRST_AVAILABLE which should be ignored.
*
* @return The regions to which a location belongs.
*/
public Set<Region> getRegions() {
return regions;
}
public Builder toBuilder() {
return Builder.fromDatacenter(this);
return this.regions;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id ^ (id >>> 32));
return result;
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Datacenter other = (Datacenter) obj;
if (id != other.id)
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Datacenter that = Datacenter.class.cast(obj);
return Objects.equal(this.id, that.id);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("name", name).add("longName", longName).add("locationAddress", locationAddress).add("regions", regions);
}
@Override
public String toString() {
return "[id=" + id + ", country=" + name + ", state=" + longName + "], locationAddress=" + locationAddress + ", regions="+regions+"]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -20,118 +20,123 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* Extends the SoftLayer_Software_Component data type to include operating system specific properties.
*
* @author Jason King
* @see <a href=
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_OperatingSystem"
* />
"http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_OperatingSystem"
/>
*/
public class OperatingSystem implements Comparable<OperatingSystem> {
public class OperatingSystem {
// There are other properties
public static Builder builder() {
return new Builder();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int id = -1;
private Set<Password> passwords = Sets.newLinkedHashSet();
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromOperatingSystem(this);
}
public Builder id(int id) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected Set<Password> passwords = ImmutableSet.of();
/**
* @see OperatingSystem#getId()
*/
public T id(int id) {
this.id = id;
return this;
return self();
}
public Builder password(Password password) {
this.passwords.add(checkNotNull(password, "password"));
return this;
/**
* @see OperatingSystem#getPasswords()
*/
public T passwords(Set<Password> passwords) {
this.passwords = ImmutableSet.copyOf(checkNotNull(passwords, "passwords"));
return self();
}
public Builder passwords(Iterable<Password> passwords) {
this.passwords = ImmutableSet.<Password> copyOf(checkNotNull(passwords, "passwords"));
return this;
public T passwords(Password... in) {
return passwords(ImmutableSet.copyOf(in));
}
public OperatingSystem build() {
return new OperatingSystem(id, passwords);
}
public static Builder fromOperatingSystem(OperatingSystem in) {
return OperatingSystem.builder()
public T fromOperatingSystem(OperatingSystem in) {
return this
.id(in.getId())
.passwords(in.getPasswords());
}
}
private int id = -1;
private Set<Password> passwords = Sets.newLinkedHashSet();
// for deserializer
OperatingSystem() {
}
public OperatingSystem(int id,Iterable<Password> passwords) {
this.id = id;
this.passwords = ImmutableSet.<Password> copyOf(checkNotNull(passwords, "passwords"));
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
public int compareTo(OperatingSystem arg0) {
return Integer.valueOf(id).compareTo(arg0.getId());
protected ConcreteBuilder self() {
return this;
}
}
private final int id;
private final Set<Password> passwords;
@ConstructorProperties({
"id", "passwords"
})
protected OperatingSystem(int id, @Nullable Set<Password> passwords) {
this.id = id;
this.passwords = passwords == null ? ImmutableSet.<Password>of() : ImmutableSet.copyOf(passwords);
}
/**
* @return An ID number identifying this Software Component (Software Installation)
*/
public int getId() {
return id;
return this.id;
}
/**
*
* @return Username/Password pairs used for access to this Software Installation.
*/
public Set<Password> getPasswords() {
return passwords;
}
public Builder toBuilder() {
return Builder.fromOperatingSystem(this);
return this.passwords;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id ^ (id >>> 32));
return result;
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OperatingSystem other = (OperatingSystem) obj;
if (id != other.id)
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
OperatingSystem that = OperatingSystem.class.cast(obj);
return Objects.equal(this.id, that.id);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("passwords", passwords);
}
@Override
public String toString() {
return "[id=" + id + ", passwords=" + passwords + "]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -21,121 +21,134 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.emptyToNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
*
* Contains a password for a specific software component instance
*
* @author Jason King
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_Password"
* />
/>
*/
public class Password implements Comparable<Password> {
public static Builder builder() {
return new Builder();
public class Password {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int id = -1;
private String username;
private String password;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromPassword(this);
}
public Builder id(int id) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected String username;
protected String password;
/**
* @see Password#getId()
*/
public T id(int id) {
this.id = id;
return this;
return self();
}
public Builder username(String username) {
/**
* @see Password#getUsername()
*/
public T username(String username) {
this.username = username;
return this;
return self();
}
public Builder password(String password) {
/**
* @see Password#getPassword()
*/
public T password(String password) {
this.password = password;
return this;
return self();
}
public Password build() {
return new Password(id, username, password);
}
public static Builder fromPassword(Password in) {
return Password.builder().id(in.getId())
public T fromPassword(Password in) {
return this
.id(in.getId())
.username(in.getUsername())
.password(in.getPassword());
}
}
private int id = -1;
private String username;
private String password;
// for deserializer
Password() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public Password(int id, String username, String password) {
private final int id;
private final String username;
private final String password;
@ConstructorProperties({"id", "username", "password"})
public Password(int id, String username, @Nullable String password) {
this.id = id;
this.username = checkNotNull(emptyToNull(username),"username cannot be null or empty:"+username);
this.password = password;
}
@Override
public int compareTo(Password arg0) {
return Integer.valueOf(id).compareTo(arg0.getId());
}
/**
* @return An id number for this specific username/password pair.
*/
public int getId() {
return id;
return this.id;
}
/**
* @return The username part of the username/password pair.
*/
@Nullable
public String getUsername() {
return username;
return this.username;
}
/**
* @return The password part of the username/password pair.
*/
@Nullable
public String getPassword() {
return password;
}
public Builder toBuilder() {
return Builder.fromPassword(this);
return this.password;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id ^ (id >>> 32));
return result;
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Password other = (Password) obj;
if (id != other.id)
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Password that = Password.class.cast(obj);
return Objects.equal(this.id, that.id);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("username", username).add("password", password);
}
@Override
public String toString() {
return "Password [id=" + id + ", username=" + username + ", password=**********]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -20,83 +20,98 @@ package org.jclouds.softlayer.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;
/**
* The power state class provides a common set of values for which a guest's power state will be presented in the SoftLayer API.
*
* @author Jason King
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Power_State"
* />
/>
*/
public class PowerState implements Comparable<PowerState> {
public static Builder builder() {
return new Builder();
public class PowerState {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private VirtualGuest.State keyName;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromPowerState(this);
}
public Builder keyName(VirtualGuest.State keyName) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected VirtualGuest.State keyName;
/**
* @see PowerState#getKeyName()
*/
public T keyName(VirtualGuest.State keyName) {
this.keyName = keyName;
return this;
return self();
}
public PowerState build() {
return new PowerState(keyName);
}
public static Builder fromAddress(PowerState in) {
return PowerState.builder().keyName(in.getKeyName());
public T fromPowerState(PowerState in) {
return this
.keyName(in.getKeyName());
}
}
private VirtualGuest.State keyName;
// for deserializer
PowerState() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final VirtualGuest.State keyName;
@ConstructorProperties("keyName")
public PowerState(VirtualGuest.State keyName) {
this.keyName = checkNotNull(keyName,"keyName cannot be null or empty:"+keyName);
}
@Override
public int compareTo(PowerState arg0) {
return keyName.compareTo(arg0.keyName);
}
/**
* Maps onto {@code VirtualGuest.State}
* @return The key name of a power state.
*
* @return The key name of a power state.
*/
@Nullable
public VirtualGuest.State getKeyName() {
return keyName;
}
public Builder toBuilder() {
return Builder.fromAddress(this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PowerState that = (PowerState) o;
if (keyName != null ? !keyName.equals(that.keyName) : that.keyName != null)
return false;
return true;
return this.keyName;
}
@Override
public int hashCode() {
return keyName != null ? keyName.hashCode() : 0;
return Objects.hashCode(keyName);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
PowerState that = PowerState.class.cast(obj);
return Objects.equal(this.keyName, that.keyName);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("keyName", keyName);
}
@Override
public String toString() {
return "[keyName=" + keyName + "]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -20,12 +20,14 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* The SoftLayer_Product_Item data type contains general information relating to
@ -33,71 +35,92 @@ import com.google.common.collect.Sets;
*
* @author Adrian Cole
* @see <a href=
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item"
* />
"http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item"
/>
*/
public class ProductItem implements Comparable<ProductItem> {
public class ProductItem {
// TODO there are more elements than this.
public static Builder builder() {
return new Builder();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int id = -1;
private String description;
private String units;
private Float capacity;
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromProductItem(this);
}
public Builder id(int id) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected String description;
protected String units;
protected Float capacity;
protected Set<ProductItemPrice> prices = ImmutableSet.of();
protected Set<ProductItemCategory> categories = ImmutableSet.of();
/**
* @see ProductItem#getId()
*/
public T id(int id) {
this.id = id;
return this;
return self();
}
public Builder description(String description) {
/**
* @see ProductItem#getDescription()
*/
public T description(String description) {
this.description = description;
return this;
return self();
}
public Builder units(String units) {
/**
* @see ProductItem#getUnits()
*/
public T units(String units) {
this.units = units;
return this;
return self();
}
public Builder capacity(Float capacity) {
/**
* @see ProductItem#getCapacity()
*/
public T capacity(Float capacity) {
this.capacity = capacity;
return this;
return self();
}
public Builder price(ProductItemPrice prices) {
this.prices.add(checkNotNull(prices, "prices"));
return this;
/**
* @see ProductItem#getPrices()
*/
public T prices(Set<ProductItemPrice> prices) {
this.prices = ImmutableSet.copyOf(checkNotNull(prices, "prices"));
return self();
}
public Builder prices(Iterable<ProductItemPrice> prices) {
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
return this;
public T prices(ProductItemPrice... in) {
return prices(ImmutableSet.copyOf(in));
}
public Builder category(ProductItemCategory categories) {
this.categories.add(checkNotNull(categories, "categories"));
return this;
/**
* @see ProductItem#getCategories()
*/
public T categories(Set<ProductItemCategory> categories) {
this.categories = ImmutableSet.copyOf(checkNotNull(categories, "categories"));
return self();
}
public Builder categories(Iterable<ProductItemCategory> categories) {
this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
return this;
public T categories(ProductItemCategory... in) {
return categories(ImmutableSet.copyOf(in));
}
public ProductItem build() {
return new ProductItem(id, description, units, capacity, prices, categories);
}
public static Builder fromProductItem(ProductItem in) {
return ProductItem.builder().id(in.getId())
public T fromProductItem(ProductItem in) {
return this
.id(in.getId())
.description(in.getDescription())
.units(in.getUnits())
.capacity(in.getCapacity())
@ -106,45 +129,45 @@ public class ProductItem implements Comparable<ProductItem> {
}
}
private int id = -1;
private String description;
private String units;
private Float capacity;
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
// for deserializer
ProductItem() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public ProductItem(int id, String description, String units, Float capacity,
Iterable<ProductItemPrice> prices, Iterable<ProductItemCategory> categories) {
private final int id;
private final String description;
private final String units;
private final Float capacity;
private final Set<ProductItemPrice> prices;
private final Set<ProductItemCategory> categories;
@ConstructorProperties({
"id", "description", "units", "capacity", "prices", "categories"
})
protected ProductItem(int id, @Nullable String description, @Nullable String units, @Nullable Float capacity, @Nullable Set<ProductItemPrice> prices, @Nullable Set<ProductItemCategory> categories) {
this.id = id;
this.description = description;
this.units = units;
this.capacity = capacity;
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
}
@Override
public int compareTo(ProductItem arg0) {
return Integer.valueOf(id).compareTo(arg0.getId());
this.prices = prices == null ? ImmutableSet.<ProductItemPrice>of() : ImmutableSet.copyOf(prices);
this.categories = categories == null ? ImmutableSet.<ProductItemCategory>of() : ImmutableSet.copyOf(categories);
}
/**
* @return The unique identifier of a specific location.
*/
public int getId() {
return id;
return this.id;
}
/**
* @return A product's description
*/
@Nullable
public String getDescription() {
return description;
return this.description;
}
/**
@ -152,64 +175,54 @@ public class ProductItem implements Comparable<ProductItem> {
*/
@Nullable
public String getUnits() {
return units;
return this.units;
}
/**
* @return Some Product Items have capacity information such as RAM and
* bandwidth, and others. This provides the numerical representation
* of the capacity given in the description of this product item.
bandwidth, and others. This provides the numerical representation
of the capacity given in the description of this product item.
*/
@Nullable
public Float getCapacity() {
return capacity;
return this.capacity;
}
/**
*
* @return A product item's prices.
*/
public Set<ProductItemPrice> getPrices() {
return prices;
return this.prices;
}
/**
*
* @return An item's associated item categories.
*/
public Set<ProductItemCategory> getCategories() {
return categories;
}
public Builder toBuilder() {
return Builder.fromProductItem(this);
return this.categories;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id ^ (id >>> 32));
return result;
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ProductItem other = (ProductItem) obj;
if (id != other.id)
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ProductItem that = ProductItem.class.cast(obj);
return Objects.equal(this.id, that.id);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("description", description).add("units", units).add("capacity", capacity).add("prices", prices).add("categories", categories);
}
@Override
public String toString() {
return "ProductItem [id=" + id + ", description=" + description + ", units=" + units + ", capacity=" + capacity
+ ", prices=" + prices + ", categories=" + categories + "]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,123 +18,139 @@
*/
package org.jclouds.softlayer.domain;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* The SoftLayer_Product_Item_Category data type contains
* general category information for prices.
*
* @author Jason King
* @see <a href=
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Category"
* />
"http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Category"
/>
*/
public class ProductItemCategory implements Comparable<ProductItemCategory> {
public class ProductItemCategory {
// TODO there are more elements than this.
public static Builder builder() {
return new Builder();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int id = -1;
private String name;
private String categoryCode;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromProductItemCategory(this);
}
public Builder id(int id) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected String name;
protected String categoryCode;
/**
* @see ProductItemCategory#getId()
*/
public T id(int id) {
this.id = id;
return this;
return self();
}
public Builder name(String name) {
/**
* @see ProductItemCategory#getName()
*/
public T name(String name) {
this.name = name;
return this;
return self();
}
public Builder categoryCode(String categoryCode) {
/**
* @see ProductItemCategory#getCategoryCode()
*/
public T categoryCode(String categoryCode) {
this.categoryCode = categoryCode;
return this;
return self();
}
public ProductItemCategory build() {
return new ProductItemCategory(id, name, categoryCode);
}
public static Builder fromProductItemCategory(ProductItemCategory in) {
return ProductItemCategory.builder().id(in.getId())
public T fromProductItemCategory(ProductItemCategory in) {
return this
.id(in.getId())
.name(in.getName())
.categoryCode(in.getCategoryCode());
}
}
private int id = -1;
private String name;
private String categoryCode;
// for deserializer
ProductItemCategory() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public ProductItemCategory(int id, String name, String categoryCode) {
private final int id;
private final String name;
private final String categoryCode;
@ConstructorProperties({
"id", "name", "categoryCode"
})
protected ProductItemCategory(int id, @Nullable String name, @Nullable String categoryCode) {
this.id = id;
this.name = name;
this.categoryCode = categoryCode;
}
@Override
public int compareTo(ProductItemCategory arg0) {
return Integer.valueOf(id).compareTo(arg0.getId());
}
/**
* @return The unique identifier of a specific location.
*/
public int getId() {
return id;
return this.id;
}
/**
* @return The friendly, descriptive name of the category as seen on the order forms and on invoices.
*/
@Nullable
public String getName() {
return name;
return this.name;
}
/**
* @return The code used to identify this category.
*/
@Nullable
public String getCategoryCode() {
return categoryCode;
}
public Builder toBuilder() {
return Builder.fromProductItemCategory(this);
return this.categoryCode;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id ^ (id >>> 32));
return result;
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ProductItemCategory other = (ProductItemCategory) obj;
if (id != other.id)
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ProductItemCategory that = ProductItemCategory.class.cast(obj);
return Objects.equal(this.id, that.id);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("name", name).add("categoryCode", categoryCode);
}
@Override
public String toString() {
return "ProductItemCategory [id=" + id + ", name=" + name + ", categoryCode=" + categoryCode + "]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -20,183 +20,209 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* The SoftLayer_Product_Item_Price data type contains general information
* relating to a single SoftLayer product item price. You can find out what
* packages each price is in as well as which category under which this price is
* relating to a single SoftLayer product item prices. You can find out what
* packages each prices is in as well as which category under which this prices is
* sold. All prices are returned in Floating point values measured in US Dollars
* ($USD).
*
* @author Adrian Cole
* @see <a href=
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price"
* />
"http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price"
/>
*/
public class ProductItemPrice implements Comparable<ProductItemPrice> {
// TODO there are more elements than this.
public class ProductItemPrice {
public static Builder builder() {
return new Builder();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int id = -1;
private long itemId = -1;
private Float recurringFee;
private Float hourlyRecurringFee;
private ProductItem item;
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromProductItemPrice(this);
}
public Builder id(int id) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected long itemId;
protected Float recurringFee;
protected Float hourlyRecurringFee;
protected ProductItem item;
protected Set<ProductItemCategory> categories = ImmutableSet.of();
/**
* @see ProductItemPrice#getId()
*/
public T id(int id) {
this.id = id;
return this;
return self();
}
public Builder itemId(long itemId) {
/**
* @see ProductItemPrice#getItemId()
*/
public T itemId(long itemId) {
this.itemId = itemId;
return this;
return self();
}
public Builder recurringFee(Float recurringFee) {
/**
* @see ProductItemPrice#getRecurringFee()
*/
public T recurringFee(Float recurringFee) {
this.recurringFee = recurringFee;
return this;
return self();
}
public Builder hourlyRecurringFee(Float hourlyRecurringFee) {
/**
* @see ProductItemPrice#getHourlyRecurringFee()
*/
public T hourlyRecurringFee(Float hourlyRecurringFee) {
this.hourlyRecurringFee = hourlyRecurringFee;
return this;
return self();
}
public Builder item(ProductItem item) {
/**
* @see ProductItemPrice#getItem()
*/
public T item(ProductItem item) {
this.item = item;
return this;
return self();
}
public Builder category(ProductItemCategory categories) {
this.categories.add(checkNotNull(categories, "categories"));
return this;
/**
* @see ProductItemPrice#getCategories()
*/
public T categories(Set<ProductItemCategory> categories) {
this.categories = ImmutableSet.copyOf(checkNotNull(categories, "categories"));
return self();
}
public Builder categories(Iterable<ProductItemCategory> categories) {
this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
return this;
public T categories(ProductItemCategory... in) {
return categories(ImmutableSet.copyOf(in));
}
public ProductItemPrice build() {
return new ProductItemPrice(id, itemId, recurringFee, hourlyRecurringFee, item, categories);
}
public static Builder fromPrice(ProductItemPrice in) {
return ProductItemPrice.builder().id(in.getId()).itemId(in.getItemId())
.hourlyRecurringFee(in.getHourlyRecurringFee()).recurringFee(in.getRecurringFee());
public T fromProductItemPrice(ProductItemPrice in) {
return this
.id(in.getId())
.itemId(in.getItemId())
.recurringFee(in.getRecurringFee())
.hourlyRecurringFee(in.getHourlyRecurringFee())
.item(in.getItem())
.categories(in.getCategories());
}
}
private int id = -1;
private long itemId = -1;
private Float recurringFee;
private Float hourlyRecurringFee;
private ProductItem item;
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
// for deserializer
ProductItemPrice() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public ProductItemPrice(int id, long itemId, Float recurringFee, Float hourlyRecurringFee, ProductItem item, Iterable<ProductItemCategory> categories) {
private final int id;
private final long itemId;
private final Float recurringFee;
private final Float hourlyRecurringFee;
private final ProductItem item;
private final Set<ProductItemCategory> categories;
@ConstructorProperties({
"id", "itemId", "recurringFee", "hourlyRecurringFee", "item", "categories"
})
protected ProductItemPrice(int id, long itemId, @Nullable Float recurringFee, @Nullable Float hourlyRecurringFee, @Nullable ProductItem item, @Nullable Set<ProductItemCategory> categories) {
this.id = id;
this.itemId = itemId;
this.recurringFee = recurringFee;
this.hourlyRecurringFee = hourlyRecurringFee;
this.item = item;
this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
}
@Override
public int compareTo(ProductItemPrice arg0) {
return Integer.valueOf(id).compareTo(arg0.getId());
this.categories = categories == null ? ImmutableSet.<ProductItemCategory>of() : ImmutableSet.copyOf(categories);
}
/**
* @return The unique identifier of a Product Item Price.
*/
public int getId() {
return id;
return this.id;
}
/**
* @return The unique identifier for a product Item
*/
public long getItemId() {
return itemId;
return this.itemId;
}
/**
* @return A recurring fee is a fee that happens every billing period. This
* fee is represented as a Floating point decimal in US dollars
* ($USD).
fee is represented as a Floating point decimal in US dollars
($USD).
*/
@Nullable
public Float getRecurringFee() {
return recurringFee;
return this.recurringFee;
}
/**
* @return The hourly price for this item, should this item be part of an
* hourly pricing package.
* @return The hourly prices for this item, should this item be part of an
hourly pricing package.
*/
@Nullable
public Float getHourlyRecurringFee() {
return hourlyRecurringFee;
return this.hourlyRecurringFee;
}
/**
* @return The product item a prices is tied to.
*/
@Nullable
public ProductItem getItem() {
return this.item;
}
/**
*
* @return An item's associated item categories.
*/
public Set<ProductItemCategory> getCategories() {
return categories;
}
/**
* @return The product item a price is tied to.
*/
public ProductItem getItem() {
return item;
}
public Builder toBuilder() {
return Builder.fromPrice(this);
}
@Override
public String toString() {
return "[id=" + id + ", itemId=" + itemId + ", recurringFee=" + recurringFee + ", hourlyRecurringFee="
+ hourlyRecurringFee + ", item="+item+", categories="+categories+"]";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ProductItemPrice that = (ProductItemPrice) o;
if (id != that.id) return false;
return true;
return this.categories;
}
@Override
public int hashCode() {
return (id ^ (id >>> 32));
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ProductItemPrice that = ProductItemPrice.class.cast(obj);
return Objects.equal(this.id, that.id);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("itemId", itemId).add("recurringFee", recurringFee).add("hourlyRecurringFee", hourlyRecurringFee).add("item", item).add("categories", categories);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -20,93 +20,105 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* Class ProductOrder
*
* @author Jason King
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest"
* />
/>
*/
public class ProductOrder {
public static Builder builder() {
return new Builder();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int packageId = -1;
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
private Set<VirtualGuest> virtualGuests = Sets.newLinkedHashSet();
private String location;
private int quantity;
private boolean useHourlyPricing;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromProductOrder(this);
}
public Builder packageId(int packageId) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int packageId;
protected String location;
protected Set<ProductItemPrice> prices = ImmutableSet.of();
protected Set<VirtualGuest> virtualGuests = ImmutableSet.of();
protected int quantity;
protected boolean useHourlyPricing;
/**
* @see ProductOrder#getPackageId()
*/
public T packageId(int packageId) {
this.packageId = packageId;
return this;
return self();
}
/**
* Adds a price to the order
* All that is required to send in is the price ID of each item desired to be ordered.
* @param prices
* The Prices of the item desired to be ordered
* @see ProductOrder#getLocation()
*/
public Builder price(ProductItemPrice prices) {
this.prices.add(checkNotNull(prices, "prices"));
return this;
}
/**
* Adds multiple prices to the order, overwriting any existing ones
* All that is required to send in is the price ID of each item desired to be ordered.
* @param prices
* The Prices of the items desired to be ordered
*/
public Builder prices(Iterable<ProductItemPrice> prices) {
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
return this;
}
/**
* Adds a virtualGuest to the order
* @param virtualGuest
* The virtualGuest to add. Needs domain and hostname.
*/
public Builder virtualGuest(VirtualGuest virtualGuest) {
this.virtualGuests.add(checkNotNull(virtualGuest, "virtualGuest"));
return this;
}
public Builder virtualGuests(Iterable<VirtualGuest> virtualGuests) {
this.virtualGuests = ImmutableSet.<VirtualGuest> copyOf(checkNotNull(virtualGuests, "virtualGuests"));
return this;
}
public Builder location(String location) {
public T location(String location) {
this.location = location;
return this;
return self();
}
public Builder quantity(int quantity) {
/**
* @see ProductOrder#getPrices()
*/
public T prices(Iterable<ProductItemPrice> prices) {
this.prices = ImmutableSet.copyOf(checkNotNull(prices, "prices"));
return self();
}
public T prices(ProductItemPrice... in) {
return prices(ImmutableSet.copyOf(in));
}
/**
* @see ProductOrder#getVirtualGuests()
*/
public T virtualGuests(Set<VirtualGuest> virtualGuests) {
this.virtualGuests = ImmutableSet.copyOf(checkNotNull(virtualGuests, "virtualGuests"));
return self();
}
public T virtualGuests(VirtualGuest... in) {
return virtualGuests(ImmutableSet.copyOf(in));
}
/**
* @see ProductOrder#getQuantity()
*/
public T quantity(int quantity) {
this.quantity = quantity;
return this;
return self();
}
public Builder useHourlyPricing(Boolean useHourlyPricing) {
/**
* @see ProductOrder#getUseHourlyPricing()
*/
public T useHourlyPricing(boolean useHourlyPricing) {
this.useHourlyPricing = useHourlyPricing;
return this;
return self();
}
public ProductOrder build() {
return new ProductOrder(packageId, location, prices, virtualGuests, quantity, useHourlyPricing);
}
public static Builder fromProductOrder(ProductOrder in) {
return ProductOrder.builder().packageId(in.getPackageId())
public T fromProductOrder(ProductOrder in) {
return this
.packageId(in.getPackageId())
.location(in.getLocation())
.prices(in.getPrices())
.virtualGuests(in.getVirtualGuests())
@ -115,23 +127,28 @@ public class ProductOrder {
}
}
private int packageId = -1;
private String location;
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
private Set<VirtualGuest> virtualGuests = Sets.newLinkedHashSet();
private int quantity;
private boolean useHourlyPricing;
// for deserializer
ProductOrder() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public ProductOrder(int packageId, String location, Iterable<ProductItemPrice> prices, Iterable<VirtualGuest> virtualGuest, int quantity, boolean useHourlyPricing) {
private final int packageId;
private final String location;
private final Set<ProductItemPrice> prices;
private final Set<VirtualGuest> virtualGuests;
private final int quantity;
private final boolean useHourlyPricing;
@ConstructorProperties({
"packageId", "location", "prices", "virtualGuest", "quantity", "useHourlyPricing"
})
protected ProductOrder(int packageId, @Nullable String location, @Nullable Set<ProductItemPrice> prices, @Nullable Set<VirtualGuest> virtualGuests, int quantity, boolean useHourlyPricing) {
this.packageId = packageId;
this.location = location;
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
this.virtualGuests = ImmutableSet.<VirtualGuest> copyOf(checkNotNull(virtualGuest, "virtualGuest"));
this.prices = prices == null ? ImmutableSet.<ProductItemPrice>of() : ImmutableSet.copyOf(prices);
this.virtualGuests = virtualGuests == null ? ImmutableSet.<VirtualGuest>of() : ImmutableSet.copyOf(virtualGuests);
this.quantity = quantity;
this.useHourlyPricing = useHourlyPricing;
}
@ -140,79 +157,70 @@ public class ProductOrder {
* @return The package id of an order. This is required.
*/
public int getPackageId() {
return packageId;
return this.packageId;
}
/**
* @return The region keyname or specific location keyname where the order should be provisioned.
*/
@Nullable
public String getLocation() {
return location;
return this.location;
}
/**
* Gets the item prices in this order.
* All that is required to be present is the price ID
* All that is required to be present is the prices ID
*
* @return the prices.
*/
public Set<ProductItemPrice> getPrices() {
return prices;
return this.prices;
}
/**
* Gets the virtual guests in this order.
*
* @return the the virtual guests.
*/
public Set<VirtualGuest> getVirtualGuests() {
return virtualGuests;
return this.virtualGuests;
}
public int getQuantity() {
return quantity;
return this.quantity;
}
public boolean getUseHourlyPricing() {
return useHourlyPricing;
}
public Builder toBuilder() {
return Builder.fromProductOrder(this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ProductOrder that = (ProductOrder) o;
if (packageId != that.packageId) return false;
if (quantity != that.quantity) return false;
if (useHourlyPricing != that.useHourlyPricing) return false;
if (location != null ? !location.equals(that.location) : that.location != null)
return false;
if (prices != null ? !prices.equals(that.prices) : that.prices != null)
return false;
if (virtualGuests != null ? !virtualGuests.equals(that.virtualGuests) : that.virtualGuests != null)
return false;
return true;
return this.useHourlyPricing;
}
@Override
public int hashCode() {
int result = (packageId ^ (packageId >>> 32));
result = 31 * result + (location != null ? location.hashCode() : 0);
result = 31 * result + (prices != null ? prices.hashCode() : 0);
result = 31 * result + (virtualGuests != null ? virtualGuests.hashCode() : 0);
result = 31 * result + (quantity ^ (quantity >>> 32));
result = 31 * result + (useHourlyPricing ? 1 : 0);
return result;
return Objects.hashCode(packageId, location, prices, virtualGuests, quantity, useHourlyPricing);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ProductOrder that = ProductOrder.class.cast(obj);
return Objects.equal(this.packageId, that.packageId)
&& Objects.equal(this.location, that.location)
&& Objects.equal(this.prices, that.prices)
&& Objects.equal(this.virtualGuests, that.virtualGuests)
&& Objects.equal(this.quantity, that.quantity)
&& Objects.equal(this.useHourlyPricing, that.useHourlyPricing);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("packageId", packageId).add("location", location).add("prices", prices).add("virtualGuests", virtualGuests).add("quantity", quantity).add("useHourlyPricing", useHourlyPricing);
}
@Override
public String toString() {
return "[packageId=" + packageId + ", location=" + location + ", prices=" + prices
+ ", virtualGuests=" + virtualGuests +", quantity=" + quantity + ", useHourlyPricing=" + useHourlyPricing + "]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -18,63 +18,86 @@
*/
package org.jclouds.softlayer.domain;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* Class ProductOrderReceipt
*
* @author Jason King
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Receipt"
* />
/>
*/
public class ProductOrderReceipt implements Comparable<ProductOrderReceipt> {
public static Builder builder() {
return new Builder();
public class ProductOrderReceipt {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int orderId = -1;
private ProductOrder orderDetails;
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromProductOrderReceipt(this);
}
public Builder orderId(int orderId) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int orderId;
protected ProductOrder orderDetails;
/**
* @see ProductOrderReceipt#getOrderId()
*/
public T orderId(int orderId) {
this.orderId = orderId;
return this;
return self();
}
public Builder orderDetails(ProductOrder orderDetails) {
/**
* @see ProductOrderReceipt#getOrderDetails()
*/
public T orderDetails(ProductOrder orderDetails) {
this.orderDetails = orderDetails;
return this;
return self();
}
public ProductOrderReceipt build() {
return new ProductOrderReceipt(orderId, orderDetails);
}
public static Builder fromAddress(ProductOrderReceipt in) {
return ProductOrderReceipt.builder().orderId(in.getOrderId()).orderDetails(in.getOrderDetails());
public T fromProductOrderReceipt(ProductOrderReceipt in) {
return this
.orderId(in.getOrderId())
.orderDetails(in.getOrderDetails());
}
}
private int orderId = -1;
private ProductOrder orderDetails;
// for deserializer
ProductOrderReceipt() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public ProductOrderReceipt(int orderId,ProductOrder orderDetails) {
private final int orderId;
private final ProductOrder orderDetails;
@ConstructorProperties({
"orderId", "orderDetails"
})
protected ProductOrderReceipt(int orderId, @Nullable ProductOrder orderDetails) {
this.orderId = orderId;
this.orderDetails = orderDetails;
}
@Override
public int compareTo(ProductOrderReceipt arg0) {
return Integer.valueOf(orderId).compareTo(arg0.getOrderId());
}
/**
* @return unique identifier for the order.
*/
public int getOrderId() {
return orderId;
return this.orderId;
}
/**
@ -83,40 +106,33 @@ public class ProductOrderReceipt implements Comparable<ProductOrderReceipt> {
* This will only return when an order is processed successfully.
* It will contain all the items in an order as well as the order totals.
*/
@Nullable
public ProductOrder getOrderDetails() {
return orderDetails;
}
public Builder toBuilder() {
return Builder.fromAddress(this);
return this.orderDetails;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (orderId ^ (orderId >>> 32));
return result;
return Objects.hashCode(orderId, orderDetails);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ProductOrderReceipt other = (ProductOrderReceipt) obj;
if (orderId != other.orderId)
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ProductOrderReceipt that = ProductOrderReceipt.class.cast(obj);
return Objects.equal(this.orderId, that.orderId)
&& Objects.equal(this.orderDetails, that.orderDetails);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("orderId", orderId).add("orderDetails", orderDetails);
}
@Override
public String toString() {
return "[orderId=" + orderId + ", orderDetails="+orderDetails+"]";
return string().toString();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -20,10 +20,14 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* The SoftLayer_Product_Package data type contains information about packages
@ -33,55 +37,83 @@ import com.google.common.collect.Sets;
*
* @author Adrian Cole
* @see <a href=
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Package"
* />
"http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Package"
/>
*/
public class ProductPackage implements Comparable<ProductPackage> {
public class ProductPackage {
// TODO there are more elements than this.
public static Builder builder() {
return new Builder();
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public static class Builder {
private int id = -1;
private String name;
private String description;
private Set<ProductItem> items = Sets.newLinkedHashSet();
private Set<Datacenter> datacenters = Sets.newLinkedHashSet();
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromProductPackage(this);
}
public Builder id(int id) {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected String name;
protected String description;
protected Set<ProductItem> items = ImmutableSet.of();
protected Set<Datacenter> locations = ImmutableSet.of();
/**
* @see ProductPackage#getId()
*/
public T id(int id) {
this.id = id;
return this;
return self();
}
public Builder name(String name) {
/**
* @see ProductPackage#getName()
*/
public T name(String name) {
this.name = name;
return this;
return self();
}
public Builder description(String description) {
/**
* @see ProductPackage#getDescription()
*/
public T description(String description) {
this.description = description;
return this;
return self();
}
public Builder items(Iterable<ProductItem> items) {
this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items"));
return this;
/**
* @see ProductPackage#getItems()
*/
public T items(Set<ProductItem> items) {
this.items = ImmutableSet.copyOf(checkNotNull(items, "items"));
return self();
}
public Builder datacenters(Iterable<Datacenter> datacenters) {
this.datacenters = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters"));
return this;
public T items(ProductItem... in) {
return items(ImmutableSet.copyOf(in));
}
/**
* @see ProductPackage#getDatacenters()
*/
public T datacenters(Set<Datacenter> locations) {
this.locations = ImmutableSet.copyOf(checkNotNull(locations, "locations"));
return self();
}
public T datacenters(Datacenter... in) {
return datacenters(ImmutableSet.copyOf(in));
}
public ProductPackage build() {
return new ProductPackage(id, name, description, items, datacenters);
return new ProductPackage(id, name, description, items, locations);
}
public static Builder fromProductPackage(ProductPackage in) {
return ProductPackage.builder().id(in.getId())
public T fromProductPackage(ProductPackage in) {
return this
.id(in.getId())
.name(in.getName())
.description(in.getDescription())
.items(in.getItems())
@ -89,100 +121,90 @@ public class ProductPackage implements Comparable<ProductPackage> {
}
}
private int id = -1;
private String name;
private String description;
private Set<ProductItem> items = Sets.newLinkedHashSet();
private Set<Datacenter> locations = Sets.newLinkedHashSet();
// for deserializer
ProductPackage() {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
public ProductPackage(int id, String name, String description, Iterable<ProductItem> items, Iterable<Datacenter> datacenters) {
private final int id;
private final String name;
private final String description;
private final Set<ProductItem> items;
private final Set<Datacenter> locations;
@ConstructorProperties({
"id", "name", "description", "items", "locations"
})
protected ProductPackage(int id, @Nullable String name, @Nullable String description, @Nullable Set<ProductItem> items, Set<Datacenter> locations) {
this.id = id;
this.name = name;
this.description = description;
this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items"));
this.locations = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters"));
}
@Override
public int compareTo(ProductPackage arg0) {
return Integer.valueOf(id).compareTo(arg0.getId());
this.items = items == null ? ImmutableSet.<ProductItem>of() : ImmutableSet.copyOf(items);
this.locations = locations == null ? ImmutableSet.<Datacenter>of() : ImmutableSet.copyOf(locations);
}
/**
* @return A package's internal identifier. Everything regarding a
* SoftLayer_Product_Package is tied back to this id.
SoftLayer_Product_Package is tied back to this id.
*/
public int getId() {
return id;
return this.id;
}
/**
* @return The description of the package. For server packages, this is
* usually a detailed description of processor type and count.
usually a detailed description of processor type and count.
*/
@Nullable
public String getName() {
return name;
return this.name;
}
/**
* @return A generic description of the processor type and count. This
* includes HTML, so you may want to strip these tags if you plan to
* use it.
includes HTML, so you may want to strip these tags if you plan to
use it.
*/
@Nullable
public String getDescription() {
return description;
return this.description;
}
/**
*
* @return A collection of valid items available for purchase in this
* package.
package.
*/
public Set<ProductItem> getItems() {
return items;
return this.items;
}
/**
*
* @return A collection of valid locations for this package.
*/
public Set<Datacenter> getDatacenters() {
return locations;
}
public Builder toBuilder() {
return Builder.fromProductPackage(this);
return this.locations;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id ^ (id >>> 32));
return result;
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ProductPackage other = (ProductPackage) obj;
if (id != other.id)
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ProductPackage that = ProductPackage.class.cast(obj);
return Objects.equal(this.id, that.id);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("name", name).add("description", description).add("items", items).add("locations", locations);
}
@Override
public String toString() {
return "ProductPackage [id=" + id + ", name=" + name + ", description=" + description + ", items=" + items + ", datacenters=" + locations + "]";
return string().toString();
}
}

View File

@ -21,6 +21,12 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.emptyToNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
/**
* A region is made up of a keyname and a description of that region.
* A region keyname can be used as part of an order.
@ -50,7 +56,7 @@ public class Region implements Comparable<Region> {
}
public Region build() {
return new Region(keyname, description);
return new Region(0, keyname, description);
}
public static Builder fromAddress(Region in) {
@ -60,18 +66,15 @@ public class Region implements Comparable<Region> {
}
/* An integer representing the order in which this element is displayed */
private int sortOrder = 0;
private String keyname;
private String description;
private final int sortOrder;
private final String keyname;
private final String description;
// for deserializer
Region() {
}
public Region(String keyname, String description) {
@ConstructorProperties({"sortOrder", "keyname", "description"})
public Region(int sortOrder, String keyname, String description) {
this.sortOrder = sortOrder;
this.keyname = checkNotNull(emptyToNull(keyname), "keyname cannot be null or empty:" + keyname);
this.description = checkNotNull(emptyToNull(description),"country cannot be null or empty:"+description);
this.description = description;
}
@Override
@ -89,6 +92,7 @@ public class Region implements Comparable<Region> {
/**
* @return A short description of a region's name. This description is seen on the order forms.
*/
@Nullable
public String getDescription() {
return description;
}
@ -103,20 +107,13 @@ public class Region implements Comparable<Region> {
if (o == null || getClass() != o.getClass()) return false;
Region region = (Region) o;
if (sortOrder != region.sortOrder) return false;
if (!description.equals(region.description)) return false;
if (!keyname.equals(region.keyname)) return false;
return true;
return Objects.equal(keyname, region.keyname)
&& Objects.equal(description, region.description);
}
@Override
public int hashCode() {
int result = sortOrder;
result = 31 * result + keyname.hashCode();
result = 31 * result + description.hashCode();
return result;
return Objects.hashCode(keyname, description);
}
@Override

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -20,10 +20,14 @@ package org.jclouds.softlayer.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.CaseFormat;
import com.google.gson.annotations.SerializedName;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* The virtual guest data type presents the structure in which all virtual guests will be presented.
@ -45,170 +49,286 @@ import com.google.gson.annotations.SerializedName;
*
* @author Adrian Cole
* @see <a href=
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest"
* />
"http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest"
/>
*/
public class VirtualGuest implements Comparable<VirtualGuest> {
public static Builder builder() {
return new Builder();
public class VirtualGuest {
/**
* These states come from the powerState field. i.e.
* https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests/{id}?objectMask=powerState
*/
public static enum State {
HALTED,
PAUSED,
RUNNING,
UNRECOGNIZED;
@Override
public String toString() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
}
public static class Builder {
private int id = -1;
private int accountId = -1;
private Date createDate;
private boolean dedicatedAccountHostOnly;
private String hostname;
private String domain;
private String fullyQualifiedDomainName;
private Date lastVerifiedDate;
private int maxCpu = -1;
private String maxCpuUnits;
private int maxMemory = -1;
private Date metricPollDate;
private Date modifyDate;
private String notes;
private boolean privateNetworkOnly;
private int startCpus = -1;
private int statusId = -1;
private String uuid;
private String primaryBackendIpAddress;
private String primaryIpAddress;
private int billingItemId;
private OperatingSystem operatingSystem;
private Datacenter datacenter;
private PowerState powerState;
public static State fromValue(String state) {
try {
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
public Builder id(int id) {
public static class BillingItem {
private final int id;
@ConstructorProperties("id")
public BillingItem(int id) {
this.id = id;
return this;
}
public Builder accountId(int accountId) {
@Override
public String toString() {
return "[id=" + id + "]";
}
}
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromVirtualGuest(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int accountId;
protected Date createDate;
protected boolean dedicatedAccountHostOnly;
protected String domain;
protected String fullyQualifiedDomainName;
protected String hostname;
protected int id;
protected Date lastVerifiedDate;
protected int maxCpu;
protected String maxCpuUnits;
protected int maxMemory;
protected Date metricPollDate;
protected Date modifyDate;
protected String notes;
protected boolean privateNetworkOnly;
protected int startCpus;
protected int statusId;
protected String uuid;
protected String primaryBackendIpAddress;
protected String primaryIpAddress;
protected int billingItemId;
protected OperatingSystem operatingSystem;
protected Datacenter datacenter;
protected PowerState powerState;
/**
* @see VirtualGuest#getAccountId()
*/
public T accountId(int accountId) {
this.accountId = accountId;
return this;
return self();
}
public Builder createDate(Date createDate) {
/**
* @see VirtualGuest#getCreateDate()
*/
public T createDate(Date createDate) {
this.createDate = createDate;
return this;
return self();
}
public Builder dedicatedAccountHostOnly(boolean dedicatedAccountHostOnly) {
/**
* @see VirtualGuest#isDedicatedAccountHostOnly()
*/
public T dedicatedAccountHostOnly(boolean dedicatedAccountHostOnly) {
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
return this;
return self();
}
public Builder hostname(String hostname) {
this.hostname = hostname;
return this;
}
public Builder domain(String domain) {
/**
* @see VirtualGuest#getDomain()
*/
public T domain(String domain) {
this.domain = domain;
return this;
return self();
}
public Builder fullyQualifiedDomainName(String fullyQualifiedDomainName) {
/**
* @see VirtualGuest#getFullyQualifiedDomainName()
*/
public T fullyQualifiedDomainName(String fullyQualifiedDomainName) {
this.fullyQualifiedDomainName = fullyQualifiedDomainName;
return this;
return self();
}
public Builder lastVerifiedDate(Date lastVerifiedDate) {
/**
* @see VirtualGuest#getHostname()
*/
public T hostname(String hostname) {
this.hostname = hostname;
return self();
}
/**
* @see VirtualGuest#getId()
*/
public T id(int id) {
this.id = id;
return self();
}
/**
* @see VirtualGuest#getLastVerifiedDate()
*/
public T lastVerifiedDate(Date lastVerifiedDate) {
this.lastVerifiedDate = lastVerifiedDate;
return this;
return self();
}
public Builder maxCpu(int maxCpu) {
/**
* @see VirtualGuest#getMaxCpu()
*/
public T maxCpu(int maxCpu) {
this.maxCpu = maxCpu;
return this;
return self();
}
public Builder maxCpuUnits(String maxCpuUnits) {
/**
* @see VirtualGuest#getMaxCpuUnits()
*/
public T maxCpuUnits(String maxCpuUnits) {
this.maxCpuUnits = maxCpuUnits;
return this;
return self();
}
public Builder maxMemory(int maxMemory) {
/**
* @see VirtualGuest#getMaxMemory()
*/
public T maxMemory(int maxMemory) {
this.maxMemory = maxMemory;
return this;
return self();
}
public Builder metricPollDate(Date metricPollDate) {
/**
* @see VirtualGuest#getMetricPollDate()
*/
public T metricPollDate(Date metricPollDate) {
this.metricPollDate = metricPollDate;
return this;
return self();
}
public Builder modifyDate(Date modifyDate) {
/**
* @see VirtualGuest#getModifyDate()
*/
public T modifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
return this;
return self();
}
public Builder notes(String notes) {
/**
* @see VirtualGuest#getNotes()
*/
public T notes(String notes) {
this.notes = notes;
return this;
return self();
}
public Builder privateNetworkOnly(boolean privateNetworkOnly) {
/**
* @see VirtualGuest#isPrivateNetworkOnly()
*/
public T privateNetworkOnly(boolean privateNetworkOnly) {
this.privateNetworkOnly = privateNetworkOnly;
return this;
return self();
}
public Builder startCpus(int startCpus) {
/**
* @see VirtualGuest#getStartCpus()
*/
public T startCpus(int startCpus) {
this.startCpus = startCpus;
return this;
return self();
}
public Builder statusId(int statusId) {
/**
* @see VirtualGuest#getStatusId()
*/
public T statusId(int statusId) {
this.statusId = statusId;
return this;
return self();
}
public Builder uuid(String uuid) {
/**
* @see VirtualGuest#getUuid()
*/
public T uuid(String uuid) {
this.uuid = uuid;
return this;
return self();
}
public Builder primaryBackendIpAddress(String primaryBackendIpAddress) {
/**
* @see VirtualGuest#getPrimaryBackendIpAddress()
*/
public T primaryBackendIpAddress(String primaryBackendIpAddress) {
this.primaryBackendIpAddress = primaryBackendIpAddress;
return this;
return self();
}
public Builder primaryIpAddress(String primaryIpAddress) {
/**
* @see VirtualGuest#getPrimaryIpAddress()
*/
public T primaryIpAddress(String primaryIpAddress) {
this.primaryIpAddress = primaryIpAddress;
return this;
return self();
}
public Builder billingItemId(int billingItemId) {
/**
* @see VirtualGuest#getBillingItemId()
*/
public T billingItemId(int billingItemId) {
this.billingItemId = billingItemId;
return this;
return self();
}
public Builder operatingSystem(OperatingSystem operatingSystem) {
/**
* @see VirtualGuest#getOperatingSystem()
*/
public T operatingSystem(OperatingSystem operatingSystem) {
this.operatingSystem = operatingSystem;
return this;
return self();
}
public Builder datacenter(Datacenter datacenter) {
/**
* @see VirtualGuest#getDatacenter()
*/
public T datacenter(Datacenter datacenter) {
this.datacenter = datacenter;
return this;
return self();
}
public Builder powerState(PowerState powerState) {
/**
* @see VirtualGuest#getPowerState()
*/
public T powerState(PowerState powerState) {
this.powerState = powerState;
return this;
return self();
}
public VirtualGuest build() {
return new VirtualGuest(accountId, createDate, dedicatedAccountHostOnly, domain,
fullyQualifiedDomainName, hostname, id, lastVerifiedDate, maxCpu,
maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes,
privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress,
primaryIpAddress, billingItemId,operatingSystem,datacenter,powerState);
return new VirtualGuest(accountId, createDate, dedicatedAccountHostOnly, domain, fullyQualifiedDomainName, hostname,
id, lastVerifiedDate, maxCpu, maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes, privateNetworkOnly,
startCpus, statusId, uuid, primaryBackendIpAddress, primaryIpAddress, new BillingItem(billingItemId),
operatingSystem, datacenter, powerState);
}
public static Builder fromVirtualGuest(VirtualGuest in) {
return VirtualGuest.builder()
public T fromVirtualGuest(VirtualGuest in) {
return this
.accountId(in.getAccountId())
.createDate(in.getCreateDate())
.dedicatedAccountHostOnly(in.isDedicatedAccountHostOnly())
@ -236,68 +356,47 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
}
}
/**
* These states come from the powerState field. i.e.
* https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests/{id}?objectMask=powerState
*/
public static enum State {
HALTED,
PAUSED,
RUNNING,
UNRECOGNIZED;
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
public String toString() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
}
public static State fromValue(String state) {
try {
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
protected ConcreteBuilder self() {
return this;
}
}
private int accountId = -1;
private Date createDate;
@SerializedName("dedicatedAccountHostOnlyFlag")
private boolean dedicatedAccountHostOnly;
private String domain;
private String fullyQualifiedDomainName;
private String hostname;
private int id = -1;
private Date lastVerifiedDate;
private int maxCpu = -1;
private String maxCpuUnits;
private int maxMemory = -1;
private Date metricPollDate;
private Date modifyDate;
private String notes;
@SerializedName("privateNetworkOnlyFlag")
private boolean privateNetworkOnly;
private int startCpus = -1;
private int statusId = -1;
private String uuid;
private String primaryBackendIpAddress;
private String primaryIpAddress;
private final int accountId;
private final Date createDate;
private final boolean dedicatedAccountHostOnly;
private final String domain;
private final String fullyQualifiedDomainName;
private final String hostname;
private final int id;
private final Date lastVerifiedDate;
private final int maxCpu;
private final String maxCpuUnits;
private final int maxMemory;
private final Date metricPollDate;
private final Date modifyDate;
private final String notes;
private final boolean privateNetworkOnly;
private final int startCpus;
private final int statusId;
private final String uuid;
private final String primaryBackendIpAddress;
private final String primaryIpAddress;
private final int billingItemId;
private final OperatingSystem operatingSystem;
private final Datacenter datacenter;
private final PowerState powerState;
private int billingItemId = -1;
private OperatingSystem operatingSystem;
private Datacenter datacenter;
private PowerState powerState;
// for deserializer
VirtualGuest() {
}
public VirtualGuest(int accountId, Date createDate, boolean dedicatedAccountHostOnly, String domain,
String fullyQualifiedDomainName, String hostname, int id, Date lastVerifiedDate, int maxCpu,
String maxCpuUnits, int maxMemory, Date metricPollDate, Date modifyDate, String notes,
boolean privateNetworkOnly, int startCpus, int statusId, String uuid, String primaryBackendIpAddress,
String primaryIpAddress,int billingItemId, OperatingSystem operatingSystem, Datacenter datacenter, PowerState powerState) {
@ConstructorProperties({
"accountId", "createDate", "dedicatedAccountHostOnlyFlag", "domain", "fullyQualifiedDomainName", "hostname", "id", "lastVerifiedDate", "maxCpu", "maxCpuUnits", "maxMemory", "metricPollDate", "modifyDate", "notes", "privateNetworkOnlyFlag", "startCpus", "statusId", "uuid", "primaryBackendIpAddress", "primaryIpAddress", "billingItem", "operatingSystem", "datacenter", "powerState"
})
protected VirtualGuest(int accountId, @Nullable Date createDate, boolean dedicatedAccountHostOnly, @Nullable String domain,
@Nullable String fullyQualifiedDomainName, @Nullable String hostname, int id, @Nullable Date lastVerifiedDate,
int maxCpu, @Nullable String maxCpuUnits, int maxMemory, @Nullable Date metricPollDate, @Nullable Date modifyDate,
@Nullable String notes, boolean privateNetworkOnly, int startCpus, int statusId, @Nullable String uuid,
@Nullable String primaryBackendIpAddress, @Nullable String primaryIpAddress, @Nullable BillingItem billingItem,
@Nullable OperatingSystem operatingSystem, @Nullable Datacenter datacenter, @Nullable PowerState powerState) {
this.accountId = accountId;
this.createDate = createDate;
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
@ -318,336 +417,241 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
this.uuid = uuid;
this.primaryBackendIpAddress = primaryBackendIpAddress;
this.primaryIpAddress = primaryIpAddress;
this.billingItemId = billingItemId;
this.billingItemId = billingItem == null ? -1 : billingItem.id;
this.operatingSystem = operatingSystem;
this.datacenter = datacenter;
this.powerState = powerState;
}
@Override
public int compareTo(VirtualGuest arg0) {
return Integer.valueOf(id).compareTo(arg0.getId());
}
/**
* @return A computing instance's associated account id
*/
public int getAccountId() {
return accountId;
return this.accountId;
}
/**
* @return The date a virtual computing instance was created.
*/
@Nullable
public Date getCreateDate() {
return createDate;
return this.createDate;
}
/**
* @return When true this flag specifies that a compute instance is to run on hosts that only
* have guests from the same account.
have guests from the same account.
*/
public boolean isDedicatedAccountHostOnly() {
return dedicatedAccountHostOnly;
return this.dedicatedAccountHostOnly;
}
/**
* @return A computing instance's domain name
*/
@Nullable
public String getDomain() {
return domain;
return this.domain;
}
/**
* @return A name reflecting the hostname and domain of the computing instance.
*/
@Nullable
public String getFullyQualifiedDomainName() {
return fullyQualifiedDomainName;
return this.fullyQualifiedDomainName;
}
/**
* @return A virtual computing instance's hostname
*/
@Nullable
public String getHostname() {
return hostname;
return this.hostname;
}
/**
* @return Unique ID for a computing instance.
*/
public int getId() {
return id;
return this.id;
}
/**
* @return The last timestamp of when the guest was verified as a resident virtual machine on the
* host's hypervisor platform.
host's hypervisor platform.
*/
@Nullable
public Date getLastVerifiedDate() {
return lastVerifiedDate;
return this.lastVerifiedDate;
}
/**
* @return The maximum amount of CPU resources a computing instance may utilize.
*/
public int getMaxCpu() {
return maxCpu;
return this.maxCpu;
}
/**
* @return The unit of the maximum amount of CPU resources a computing instance may utilize.
*/
@Nullable
public String getMaxCpuUnits() {
return maxCpuUnits;
return this.maxCpuUnits;
}
/**
* @return The maximum amount of memory a computing instance may utilize.
*/
public int getMaxMemory() {
return maxMemory;
return this.maxMemory;
}
/**
* @return The date of the most recent metric tracking poll performed.
*/
@Nullable
public Date getMetricPollDate() {
return metricPollDate;
return this.metricPollDate;
}
/**
* @return The date a virtual computing instance was last modified.
*/
@Nullable
public Date getModifyDate() {
return modifyDate;
return this.modifyDate;
}
/**
* @return A small note about a cloud instance to use at your discretion.
*/
@Nullable
public String getNotes() {
return notes;
return this.notes;
}
/**
* @return Whether the computing instance only has access to the private network.
*/
public boolean isPrivateNetworkOnly() {
return privateNetworkOnly;
return this.privateNetworkOnly;
}
/**
* @return The number of CPUs available to a computing instance upon startup.
*/
public int getStartCpus() {
return startCpus;
return this.startCpus;
}
/**
* @return A computing instances status ID
*/
public int getStatusId() {
return statusId;
return this.statusId;
}
/**
* @return Unique ID for a computing instance's record on a virtualization platform.
*/
@Nullable
public String getUuid() {
return uuid;
return this.uuid;
}
/**
* @return private ip address
*/
@Nullable
public String getPrimaryBackendIpAddress() {
return primaryBackendIpAddress;
return this.primaryBackendIpAddress;
}
/**
* @return public ip address
*/
@Nullable
public String getPrimaryIpAddress() {
return primaryIpAddress;
return this.primaryIpAddress;
}
/**
* @return The billing item for a CloudLayer Compute Instance.
*/
public int getBillingItemId() {
return billingItemId;
return this.billingItemId;
}
/**
* @return A guest's operating system.
*/
@Nullable
public OperatingSystem getOperatingSystem() {
return operatingSystem;
return this.operatingSystem;
}
/**
* @return The guest's datacenter
*/
@Nullable
public Datacenter getDatacenter() {
return datacenter;
return this.datacenter;
}
/**
* @return The current power state of a virtual guest.
*/
@Nullable
public PowerState getPowerState() {
return powerState;
return this.powerState;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (accountId ^ (accountId >>> 32));
result = prime * result + ((createDate == null) ? 0 : createDate.hashCode());
result = prime * result + (dedicatedAccountHostOnly ? 1231 : 1237);
result = prime * result + ((domain == null) ? 0 : domain.hashCode());
result = prime * result + ((fullyQualifiedDomainName == null) ? 0 : fullyQualifiedDomainName.hashCode());
result = prime * result + ((hostname == null) ? 0 : hostname.hashCode());
result = prime * result + (id ^ (id >>> 32));
result = prime * result + ((lastVerifiedDate == null) ? 0 : lastVerifiedDate.hashCode());
result = prime * result + maxCpu;
result = prime * result + ((maxCpuUnits == null) ? 0 : maxCpuUnits.hashCode());
result = prime * result + maxMemory;
result = prime * result + ((metricPollDate == null) ? 0 : metricPollDate.hashCode());
result = prime * result + ((modifyDate == null) ? 0 : modifyDate.hashCode());
result = prime * result + ((notes == null) ? 0 : notes.hashCode());
result = prime * result + ((primaryBackendIpAddress == null) ? 0 : primaryBackendIpAddress.hashCode());
result = prime * result + ((primaryIpAddress == null) ? 0 : primaryIpAddress.hashCode());
result = prime * result + (privateNetworkOnly ? 1231 : 1237);
result = prime * result + startCpus;
result = prime * result + statusId;
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
result = prime * result + (getBillingItemId() ^ (getBillingItemId() >>> 32));
result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode());
result = prime * result + ((datacenter == null) ? 0 : datacenter.hashCode());
result = prime * result + ((powerState == null) ? 0 : powerState.hashCode());
return result;
return Objects.hashCode(accountId, createDate, dedicatedAccountHostOnly, domain, fullyQualifiedDomainName, hostname, id, lastVerifiedDate, maxCpu, maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes, privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress, primaryIpAddress, billingItemId, operatingSystem, datacenter, powerState);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VirtualGuest other = (VirtualGuest) obj;
if (accountId != other.accountId)
return false;
if (createDate == null) {
if (other.createDate != null)
return false;
} else if (!createDate.equals(other.createDate))
return false;
if (dedicatedAccountHostOnly != other.dedicatedAccountHostOnly)
return false;
if (domain == null) {
if (other.domain != null)
return false;
} else if (!domain.equals(other.domain))
return false;
if (fullyQualifiedDomainName == null) {
if (other.fullyQualifiedDomainName != null)
return false;
} else if (!fullyQualifiedDomainName.equals(other.fullyQualifiedDomainName))
return false;
if (hostname == null) {
if (other.hostname != null)
return false;
} else if (!hostname.equals(other.hostname))
return false;
if (id != other.id)
return false;
if (lastVerifiedDate == null) {
if (other.lastVerifiedDate != null)
return false;
} else if (!lastVerifiedDate.equals(other.lastVerifiedDate))
return false;
if (maxCpu != other.maxCpu)
return false;
if (maxCpuUnits == null) {
if (other.maxCpuUnits != null)
return false;
} else if (!maxCpuUnits.equals(other.maxCpuUnits))
return false;
if (maxMemory != other.maxMemory)
return false;
if (metricPollDate == null) {
if (other.metricPollDate != null)
return false;
} else if (!metricPollDate.equals(other.metricPollDate))
return false;
if (modifyDate == null) {
if (other.modifyDate != null)
return false;
} else if (!modifyDate.equals(other.modifyDate))
return false;
if (notes == null) {
if (other.notes != null)
return false;
} else if (!notes.equals(other.notes))
return false;
if (primaryBackendIpAddress == null) {
if (other.primaryBackendIpAddress != null)
return false;
} else if (!primaryBackendIpAddress.equals(other.primaryBackendIpAddress))
return false;
if (primaryIpAddress == null) {
if (other.primaryIpAddress != null)
return false;
} else if (!primaryIpAddress.equals(other.primaryIpAddress))
return false;
if (privateNetworkOnly != other.privateNetworkOnly)
return false;
if (startCpus != other.startCpus)
return false;
if (statusId != other.statusId)
return false;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
if (getBillingItemId() != other.getBillingItemId())
return false;
if (operatingSystem == null) {
if (other.operatingSystem != null)
return false;
} else if (!operatingSystem.equals(other.operatingSystem))
return false;
if (datacenter == null) {
if (other.datacenter != null)
return false;
} else if (!datacenter.equals(other.datacenter))
return false;
if (powerState == null) {
if (other.powerState != null)
return false;
} else if (!powerState.equals(other.powerState))
return false;
return true;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
VirtualGuest that = VirtualGuest.class.cast(obj);
return Objects.equal(this.accountId, that.accountId)
&& Objects.equal(this.createDate, that.createDate)
&& Objects.equal(this.dedicatedAccountHostOnly, that.dedicatedAccountHostOnly)
&& Objects.equal(this.domain, that.domain)
&& Objects.equal(this.fullyQualifiedDomainName, that.fullyQualifiedDomainName)
&& Objects.equal(this.hostname, that.hostname)
&& Objects.equal(this.id, that.id)
&& Objects.equal(this.lastVerifiedDate, that.lastVerifiedDate)
&& Objects.equal(this.maxCpu, that.maxCpu)
&& Objects.equal(this.maxCpuUnits, that.maxCpuUnits)
&& Objects.equal(this.maxMemory, that.maxMemory)
&& Objects.equal(this.metricPollDate, that.metricPollDate)
&& Objects.equal(this.modifyDate, that.modifyDate)
&& Objects.equal(this.notes, that.notes)
&& Objects.equal(this.privateNetworkOnly, that.privateNetworkOnly)
&& Objects.equal(this.startCpus, that.startCpus)
&& Objects.equal(this.statusId, that.statusId)
&& Objects.equal(this.uuid, that.uuid)
&& Objects.equal(this.primaryBackendIpAddress, that.primaryBackendIpAddress)
&& Objects.equal(this.primaryIpAddress, that.primaryIpAddress)
&& Objects.equal(this.billingItemId, that.billingItemId)
&& Objects.equal(this.operatingSystem, that.operatingSystem)
&& Objects.equal(this.datacenter, that.datacenter)
&& Objects.equal(this.powerState, that.powerState);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("accountId", accountId).add("createDate", createDate).add("dedicatedAccountHostOnly", dedicatedAccountHostOnly).add("domain", domain).add("fullyQualifiedDomainName", fullyQualifiedDomainName).add("hostname", hostname).add("id", id).add("lastVerifiedDate", lastVerifiedDate).add("maxCpu", maxCpu).add("maxCpuUnits", maxCpuUnits).add("maxMemory", maxMemory).add("metricPollDate", metricPollDate).add("modifyDate", modifyDate).add("notes", notes).add("privateNetworkOnly", privateNetworkOnly).add("startCpus", startCpus).add("statusId", statusId).add("uuid", uuid).add("primaryBackendIpAddress", primaryBackendIpAddress).add("primaryIpAddress", primaryIpAddress).add("billingItemId", billingItemId).add("operatingSystem", operatingSystem).add("datacenter", datacenter).add("powerState", powerState);
}
@Override
public String toString() {
return "[accountId=" + accountId + ", createDate=" + createDate + ", dedicatedAccountHostOnly="
+ dedicatedAccountHostOnly + ", domain=" + domain + ", fullyQualifiedDomainName="
+ fullyQualifiedDomainName + ", hostname=" + hostname + ", id=" + id + ", lastVerifiedDate="
+ lastVerifiedDate + ", maxCpu=" + maxCpu + ", maxCpuUnits=" + maxCpuUnits + ", maxMemory=" + maxMemory
+ ", metricPollDate=" + metricPollDate + ", modifyDate=" + modifyDate + ", notes=" + notes
+ ", primaryBackendIpAddress=" + primaryBackendIpAddress + ", primaryIpAddress=" + primaryIpAddress
+ ", privateNetworkOnly=" + privateNetworkOnly + ", startCpus=" + startCpus + ", statusId=" + statusId
+ ", uuid=" + uuid + ", billingItemId="+getBillingItemId()+", operatingSystem="+operatingSystem+", datacenter="+datacenter
+ ", powerState="+powerState+"]";
return string().toString();
}
}

View File

@ -82,7 +82,7 @@ public class ProductOrderToJsonTest {
.quantity(99)
.useHourlyPricing(true)
.prices(ImmutableSet.of(price1,price2))
.virtualGuest(guest)
.virtualGuests(guest)
.build();
String expected = String.format(FORMAT.replaceAll("'","\""),

View File

@ -107,7 +107,7 @@ public class ProductItemToImageTest {
{
ProductItem item = ProductItem.builder()
.description(description)
.price(ProductItemPrice.builder().id(1234).build())
.prices(ProductItemPrice.builder().id(1234).build())
.build();
Image i = new ProductItemToImage().apply(item);
OperatingSystem os = i.getOperatingSystem();
@ -122,7 +122,7 @@ public class ProductItemToImageTest {
public void testUbuntu() {
ProductItem item = ProductItem.builder()
.description("Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install (64 bit)")
.price(ProductItemPrice.builder().id(1234).build())
.prices(ProductItemPrice.builder().id(1234).build())
.build();
Image i = new ProductItemToImage().apply(item);
OperatingSystem os = i.getOperatingSystem();
@ -136,7 +136,7 @@ public class ProductItemToImageTest {
public void testUbuntuNoBitCount() {
ProductItem item = ProductItem.builder()
.description("Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install")
.price(ProductItemPrice.builder().id(1234).build())
.prices(ProductItemPrice.builder().id(1234).build())
.build();
Image i = new ProductItemToImage().apply(item);
OperatingSystem os = i.getOperatingSystem();
@ -151,7 +151,7 @@ public class ProductItemToImageTest {
public void testCompletelyUnknown() {
ProductItem item = ProductItem.builder()
.description("This fails to match anything!!!")
.price(ProductItemPrice.builder().id(1234).build())
.prices(ProductItemPrice.builder().id(1234).build())
.build();
Image i = new ProductItemToImage().apply(item);
OperatingSystem os = i.getOperatingSystem();
@ -165,7 +165,7 @@ public class ProductItemToImageTest {
public void test64BitUnknown() {
ProductItem item = ProductItem.builder()
.description("This only has the bit-count (64 bit)")
.price(ProductItemPrice.builder().id(1234).build())
.prices(ProductItemPrice.builder().id(1234).build())
.build();
Image i = new ProductItemToImage().apply(item);
OperatingSystem os = i.getOperatingSystem();
@ -183,7 +183,7 @@ public class ProductItemToImageTest {
@Test(expectedExceptions = NullPointerException.class)
public void testNoDescription() {
ProductItem item = ProductItem.builder()
.price(ProductItemPrice.builder().id(1234).build())
.prices(ProductItemPrice.builder().id(1234).build())
.build();
new ProductItemToImage().apply(item);
}
@ -191,7 +191,7 @@ public class ProductItemToImageTest {
@Test
public void testId() {
ProductItemPrice price = ProductItemPrice.builder().id(1234).build();
ProductItem item = ProductItem.builder().price(price).build();
ProductItem item = ProductItem.builder().prices(price).build();
assertEquals("1234",imageId().apply(item));
}

View File

@ -57,7 +57,7 @@ public class ProductItemsTest {
item = ProductItem.builder().id(1)
.capacity(2.0f)
.description("an item")
.price(price)
.prices(price)
.build();
}
@ -104,7 +104,7 @@ public class ProductItemsTest {
@Test
public void testItemCallGetsCategory() {
ProductItemPrice price = ProductItemPrice.builder().id(1)
.category(category)
.categories(category)
.item(item)
.build();
ProductItem newItem = item().apply(price);
@ -114,8 +114,7 @@ public class ProductItemsTest {
@Test
public void testItemCallNoCategoryOnPrice() {
ProductItem item1 = ProductItem.Builder.fromProductItem(item)
.categories(ImmutableSet.of(category)).build();
ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category)).build();
ProductItemPrice price = ProductItemPrice.builder().id(1)
.item(item1)
@ -132,11 +131,10 @@ public class ProductItemsTest {
.categoryCode("new category")
.build();
ProductItem item1 = ProductItem.Builder.fromProductItem(item)
.categories(ImmutableSet.of(category2)).build();
ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category2)).build();
ProductItemPrice price = ProductItemPrice.builder().id(1)
.category(category)
.categories(category)
.item(item1)
.build();
ProductItem newItem = item().apply(price);

View File

@ -67,16 +67,16 @@ public class ProductItemsToHardwareTest {
.id(1)
.description("2 x 2.0 GHz Cores")
.capacity(2F)
.category(ProductItemCategory.builder().categoryCode("guest_core").build())
.price(ProductItemPrice.builder().id(123).build())
.categories(ProductItemCategory.builder().categoryCode("guest_core").build())
.prices(ProductItemPrice.builder().id(123).build())
.build();
ramItem = ProductItem.builder().id(2).description("2GB ram").capacity(2F).category(
ProductItemCategory.builder().categoryCode("ram").build()).price(
ramItem = ProductItem.builder().id(2).description("2GB ram").capacity(2F).categories(
ProductItemCategory.builder().categoryCode("ram").build()).prices(
ProductItemPrice.builder().id(456).build()).build();
volumeItem = ProductItem.builder().id(3).description("100 GB (SAN)").capacity(100F).price(
ProductItemPrice.builder().id(789).build()).category(
volumeItem = ProductItem.builder().id(3).description("100 GB (SAN)").capacity(100F).prices(
ProductItemPrice.builder().id(789).build()).categories(
ProductItemCategory.builder().categoryCode("guest_disk0").build()).build();
@ -84,9 +84,9 @@ public class ProductItemsToHardwareTest {
@Test
public void testHardwareId() {
ProductItem item1 = ProductItem.builder().price(ProductItemPrice.builder().id(123).build()).build();
ProductItem item2 = ProductItem.builder().price(ProductItemPrice.builder().id(456).build()).build();
ProductItem item3 = ProductItem.builder().price(ProductItemPrice.builder().id(789).build()).build();
ProductItem item1 = ProductItem.builder().prices(ProductItemPrice.builder().id(123).build()).build();
ProductItem item2 = ProductItem.builder().prices(ProductItemPrice.builder().id(456).build()).build();
ProductItem item3 = ProductItem.builder().prices(ProductItemPrice.builder().id(789).build()).build();
String id = hardwareId().apply(ImmutableList.of(item1, item2, item3));
assertEquals("123,456,789", id);
@ -138,8 +138,8 @@ public class ProductItemsToHardwareTest {
@Test
public void testHardwareWithTwoDisks() {
ProductItem localVolumeItem = ProductItem.builder().id(4).description("25 GB").capacity(25F).price(
ProductItemPrice.builder().id(987).build()).category(
ProductItem localVolumeItem = ProductItem.builder().id(4).description("25 GB").capacity(25F).prices(
ProductItemPrice.builder().id(987).build()).categories(
ProductItemCategory.builder().categoryCode("guest_disk1").build()).build();
Hardware hardware = toHardware.apply(ImmutableSet.of(cpuItem, ramItem, volumeItem,localVolumeItem));

View File

@ -178,7 +178,7 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
for (ProductItemPrice price : item.getPrices()) {
// ProductItemPrice newDetails =
// client.getProductItemPrice(price.getId());
// client.getProductItemPrice(prices.getId());
// assertEquals(item.getId(), newDetails.getId());
checkPrice(price);
}

View File

@ -126,7 +126,7 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
TEST_HOSTNAME_PREFIX + new Random().nextInt()).build();
ProductOrder order = ProductOrder.builder().packageId(pkgId).quantity(1).useHourlyPricing(true).prices(
prices.build()).virtualGuest(guest).build();
prices.build()).virtualGuests(guest).build();
ProductOrderReceipt receipt = socontext.getApi().getVirtualGuestClient().orderVirtualGuest(order);
ProductOrder order2 = receipt.getOrderDetails();

View File

@ -61,7 +61,7 @@ public class ParseVirtualGuestHaltedTest extends BaseItemParserTest<VirtualGuest
.primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001)
.uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
.operatingSystem(OperatingSystem.builder().id(913824)
.password(Password.builder().id(729122).username("root").password("KnJqhC2l").build())
.passwords(Password.builder().id(729122).username("root").password("KnJqhC2l").build())
.build())
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
//TODO: maybe powerState can be flattened like billingItemId

View File

@ -61,7 +61,7 @@ public class ParseVirtualGuestPausedTest extends BaseItemParserTest<VirtualGuest
.primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001)
.uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
.operatingSystem(OperatingSystem.builder().id(913824)
.password(Password.builder().id(729122).username("root").password("KnJqhC2l").build())
.passwords(Password.builder().id(729122).username("root").password("KnJqhC2l").build())
.build())
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
//TODO: maybe powerState can be flattened like billingItemId

View File

@ -61,7 +61,7 @@ public class ParseVirtualGuestRunningTest extends BaseItemParserTest<VirtualGues
.primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001)
.uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
.operatingSystem(OperatingSystem.builder().id(913824)
.password(Password.builder().id(729122).username("root").password("KnJqhC2l").build())
.passwords(Password.builder().id(729122).username("root").password("KnJqhC2l").build())
.build())
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
//TODO: maybe powerState can be flattened like billingItemId