mirror of https://github.com/apache/jclouds.git
Merge pull request #760 from aplowe/openstack-nova2
Issue 971: more deserialization adjustments
This commit is contained in:
commit
3c2a9c9614
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,30 +18,109 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
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
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class AbsoluteLimit {
|
public class AbsoluteLimit {
|
||||||
|
|
||||||
protected String name;
|
public static Builder<?> builder() {
|
||||||
protected int value;
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public Builder<?> toBuilder() {
|
||||||
return name;
|
return new ConcreteBuilder().fromAbsoluteLimit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String value) {
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
this.name = value;
|
protected abstract T self();
|
||||||
}
|
|
||||||
|
|
||||||
public int getValue() {
|
protected String name;
|
||||||
return value;
|
protected int value;
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(int value) {
|
/**
|
||||||
this.value = value;
|
* @see AbsoluteLimit#getName()
|
||||||
}
|
*/
|
||||||
|
public T name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see AbsoluteLimit#getValue()
|
||||||
|
*/
|
||||||
|
public T value(int value) {
|
||||||
|
this.value = value;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbsoluteLimit build() {
|
||||||
|
return new AbsoluteLimit(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromAbsoluteLimit(AbsoluteLimit in) {
|
||||||
|
return this
|
||||||
|
.name(in.getName())
|
||||||
|
.value(in.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
@ConstructorProperties({
|
||||||
|
"name", "value"
|
||||||
|
})
|
||||||
|
protected AbsoluteLimit(String name, int value) {
|
||||||
|
this.name = checkNotNull(name, "name");
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
AbsoluteLimit that = AbsoluteLimit.class.cast(obj);
|
||||||
|
return Objects.equal(this.name, that.name)
|
||||||
|
&& Objects.equal(this.value, that.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("name", name).add("value", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,81 +18,128 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
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 java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import javax.inject.Named;
|
||||||
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.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Class Addresses
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Addresses {
|
public class Addresses {
|
||||||
|
|
||||||
@SerializedName("public")
|
public static Builder<?> builder() {
|
||||||
private Set<String> publicAddresses = Sets.newLinkedHashSet();
|
return new ConcreteBuilder();
|
||||||
@SerializedName("private")
|
|
||||||
private Set<String> privateAddresses = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
public Addresses() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Addresses(Set<String> publicAddresses, Set<String> privateAddresses) {
|
public Builder<?> toBuilder() {
|
||||||
this.publicAddresses = publicAddresses;
|
return new ConcreteBuilder().fromAddresses(this);
|
||||||
this.privateAddresses = privateAddresses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPublicAddresses(Set<String> publicAddresses) {
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
this.publicAddresses = publicAddresses;
|
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 T publicAddresses(String... in) {
|
||||||
|
return publicAddresses(ImmutableSet.copyOf(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Addresses#getPrivateAddresses()
|
||||||
|
*/
|
||||||
|
public T privateAddresses(Collection<String> privateAddresses) {
|
||||||
|
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
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() {
|
public Set<String> getPublicAddresses() {
|
||||||
return publicAddresses;
|
return this.publicAddresses;
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrivateAddresses(Set<String> privateAddresses) {
|
|
||||||
this.privateAddresses = privateAddresses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Set<String> getPrivateAddresses() {
|
public Set<String> getPrivateAddresses() {
|
||||||
return privateAddresses;
|
return this.privateAddresses;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Addresses [privateAddresses=" + privateAddresses + ", publicAddresses="
|
|
||||||
+ publicAddresses + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(publicAddresses, privateAddresses);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
|
|
||||||
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Addresses that = Addresses.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.publicAddresses, that.publicAddresses)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.privateAddresses, that.privateAddresses);
|
||||||
return false;
|
}
|
||||||
Addresses other = (Addresses) obj;
|
|
||||||
if (privateAddresses == null) {
|
protected ToStringHelper string() {
|
||||||
if (other.privateAddresses != null)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("publicAddresses", publicAddresses).add("privateAddresses", privateAddresses);
|
||||||
} else if (!privateAddresses.equals(other.privateAddresses))
|
}
|
||||||
return false;
|
|
||||||
if (publicAddresses == null) {
|
@Override
|
||||||
if (other.publicAddresses != null)
|
public String toString() {
|
||||||
return false;
|
return string().toString();
|
||||||
} else if (!publicAddresses.equals(other.publicAddresses))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,87 +18,131 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
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).
|
* A backup schedule can be defined to create server images at regular intervals (daily and weekly).
|
||||||
* Backup schedules are configurable per server.
|
* Backup schedules are configurable per server.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BackupSchedule {
|
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() {
|
||||||
this.weekly = weekly;
|
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.daily = daily;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
|
this.weekly = weekly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public DailyBackup getDaily() {
|
public DailyBackup getDaily() {
|
||||||
return daily;
|
return this.daily;
|
||||||
}
|
|
||||||
|
|
||||||
public void setDaily(DailyBackup value) {
|
|
||||||
this.daily = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
return this.enabled;
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(boolean value) {
|
|
||||||
this.enabled = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public WeeklyBackup getWeekly() {
|
public WeeklyBackup getWeekly() {
|
||||||
return weekly;
|
return this.weekly;
|
||||||
}
|
|
||||||
|
|
||||||
public void setWeekly(WeeklyBackup value) {
|
|
||||||
this.weekly = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "[daily=" + daily + ", enabled=" + enabled + ", weekly=" + weekly + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(daily, enabled, weekly);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
BackupSchedule that = BackupSchedule.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.daily, that.daily)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.enabled, that.enabled)
|
||||||
return false;
|
&& Objects.equal(this.weekly, that.weekly);
|
||||||
BackupSchedule other = (BackupSchedule) obj;
|
}
|
||||||
if (daily == null) {
|
|
||||||
if (other.daily != null)
|
protected ToStringHelper string() {
|
||||||
return false;
|
return Objects.toStringHelper(this)
|
||||||
} else if (!daily.equals(other.daily))
|
.add("daily", daily).add("enabled", enabled).add("weekly", weekly);
|
||||||
return false;
|
}
|
||||||
if (enabled != other.enabled)
|
|
||||||
return false;
|
@Override
|
||||||
if (weekly == null) {
|
public String toString() {
|
||||||
if (other.weekly != null)
|
return string().toString();
|
||||||
return false;
|
|
||||||
} else if (!weekly.equals(other.weekly))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,103 +18,148 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
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
|
* A flavor is an available hardware configuration for a server. Each flavor has a unique
|
||||||
* combination of disk space and memory capacity.
|
* combination of disk space and memory capacity.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Flavor {
|
public class Flavor {
|
||||||
|
|
||||||
public Flavor() {
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Builder<?> toBuilder() {
|
||||||
public String toString() {
|
return new ConcreteBuilder().fromFlavor(this);
|
||||||
return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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.id = id;
|
||||||
this.name = name;
|
this.name = checkNotNull(name, "name");
|
||||||
}
|
this.disk = disk;
|
||||||
|
this.ram = ram;
|
||||||
private int id;
|
|
||||||
private String name;
|
|
||||||
private Integer disk;
|
|
||||||
private Integer ram;
|
|
||||||
|
|
||||||
public Integer getDisk() {
|
|
||||||
return disk;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDisk(Integer value) {
|
|
||||||
this.disk = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int value) {
|
|
||||||
this.id = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String value) {
|
@Nullable
|
||||||
this.name = value;
|
public Integer getDisk() {
|
||||||
|
return this.disk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Integer getRam() {
|
public Integer getRam() {
|
||||||
return ram;
|
return this.ram;
|
||||||
}
|
|
||||||
|
|
||||||
public void setRam(Integer value) {
|
|
||||||
this.ram = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(id, name, disk, ram);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Flavor that = Flavor.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.id, that.id)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.name, that.name)
|
||||||
return false;
|
&& Objects.equal(this.disk, that.disk)
|
||||||
Flavor other = (Flavor) obj;
|
&& Objects.equal(this.ram, that.ram);
|
||||||
if (disk == null) {
|
}
|
||||||
if (other.disk != null)
|
|
||||||
return false;
|
protected ToStringHelper string() {
|
||||||
} else if (!disk.equals(other.disk))
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("id", id).add("name", name).add("disk", disk).add("ram", ram);
|
||||||
if (id != other.id)
|
}
|
||||||
return false;
|
|
||||||
if (name == null) {
|
@Override
|
||||||
if (other.name != null)
|
public String toString() {
|
||||||
return false;
|
return string().toString();
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,8 +18,16 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
package org.jclouds.cloudservers.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Date;
|
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
|
* 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
|
* of pre-built OS images by default. You may also create custom images from cloud servers you have
|
||||||
|
@ -27,119 +35,188 @@ import java.util.Date;
|
||||||
* if you plan to deploy a particular server configuration frequently.
|
* if you plan to deploy a particular server configuration frequently.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Image {
|
public class Image {
|
||||||
|
|
||||||
private Date created;
|
public static Builder<?> builder() {
|
||||||
private int id;
|
return new ConcreteBuilder();
|
||||||
private String name;
|
|
||||||
private Integer progress;
|
|
||||||
private Integer serverId;
|
|
||||||
private ImageStatus status;
|
|
||||||
private Date updated;
|
|
||||||
|
|
||||||
public Image() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image(int id, String name) {
|
public Builder<?> toBuilder() {
|
||||||
this.id = id;
|
return new ConcreteBuilder().fromImage(this);
|
||||||
this.name = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getId()
|
||||||
|
*/
|
||||||
|
public T id(int id) {
|
||||||
|
this.id = id;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getName()
|
||||||
|
*/
|
||||||
|
public T name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getProgress()
|
||||||
|
*/
|
||||||
|
public T progress(Integer progress) {
|
||||||
|
this.progress = progress;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getServerId()
|
||||||
|
*/
|
||||||
|
public T serverId(Integer serverId) {
|
||||||
|
this.serverId = serverId;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getStatus()
|
||||||
|
*/
|
||||||
|
public T status(ImageStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getUpdated()
|
||||||
|
*/
|
||||||
|
public T updated(Date updated) {
|
||||||
|
this.updated = updated;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
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.created = created;
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreated() {
|
|
||||||
return created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
this.name = checkNotNull(name, "name");
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProgress(Integer progress) {
|
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getProgress() {
|
|
||||||
return progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServerId(Integer serverId) {
|
|
||||||
this.serverId = serverId;
|
this.serverId = serverId;
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getServerId() {
|
|
||||||
return serverId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(ImageStatus status) {
|
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
|
||||||
|
|
||||||
public ImageStatus getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdated(Date updated) {
|
|
||||||
this.updated = updated;
|
this.updated = updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getUpdated() {
|
@Nullable
|
||||||
return updated;
|
public Date getCreated() {
|
||||||
}
|
return this.created;
|
||||||
/**
|
}
|
||||||
* note that this ignores the create time
|
|
||||||
*/
|
public int getId() {
|
||||||
@Override
|
return this.id;
|
||||||
public int hashCode() {
|
}
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
public String getName() {
|
||||||
result = prime * result + id;
|
return this.name;
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
}
|
||||||
result = prime * result + ((serverId == null) ? 0 : serverId.hashCode());
|
|
||||||
return result;
|
@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
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Image that = Image.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.created, that.created)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.id, that.id)
|
||||||
return false;
|
&& Objects.equal(this.name, that.name)
|
||||||
Image other = (Image) obj;
|
&& Objects.equal(this.progress, that.progress)
|
||||||
if (id != other.id)
|
&& Objects.equal(this.serverId, that.serverId)
|
||||||
return false;
|
&& Objects.equal(this.status, that.status)
|
||||||
if (name == null) {
|
&& Objects.equal(this.updated, that.updated);
|
||||||
if (other.name != null)
|
}
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
protected ToStringHelper string() {
|
||||||
return false;
|
return Objects.toStringHelper(this)
|
||||||
return true;
|
.add("created", created).add("id", id).add("name", name).add("progress", progress).add("serverId", serverId).add("status", status).add("updated", updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Image [created=" + created + ", id=" + id + ", name=" + name + ", serverId=" + serverId + ", status="
|
return string().toString();
|
||||||
+ status + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,59 +18,115 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
package org.jclouds.cloudservers.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Limits
|
||||||
|
*/
|
||||||
public class Limits {
|
public class Limits {
|
||||||
|
|
||||||
private Set<RateLimit> rate = Sets.newLinkedHashSet();
|
public static Builder<?> builder() {
|
||||||
private Map<String, Integer> absolute = Maps.newLinkedHashMap();
|
return new ConcreteBuilder();
|
||||||
|
|
||||||
public Set<RateLimit> getRate() {
|
|
||||||
return rate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Builder<?> toBuilder() {
|
||||||
public String toString() {
|
return new ConcreteBuilder().fromLimits(this);
|
||||||
return "Limits [rate=" + rate + ", absolute=" + absolute + "]";
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
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
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(rate, absolute);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((absolute == null) ? 0 : absolute.hashCode());
|
|
||||||
result = prime * result + ((rate == null) ? 0 : rate.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Limits that = Limits.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.rate, that.rate)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.absolute, that.absolute);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Integer> getAbsolute() {
|
protected ToStringHelper string() {
|
||||||
return absolute;
|
return Objects.toStringHelper(this)
|
||||||
|
.add("rate", rate).add("absolute", absolute);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,8 +18,16 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
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.
|
* RateLimit.
|
||||||
* <p/>
|
* <p/>
|
||||||
* we specify rate limits in terms of both a human readable wild-card URI and a machine processable
|
* we specify rate limits in terms of both a human readable wild-card URI and a machine processable
|
||||||
|
@ -34,73 +42,121 @@ package org.jclouds.cloudservers.domain;
|
||||||
* will be returned with a Reply-After header to notify the client when theyagain.
|
* will be returned with a Reply-After header to notify the client when theyagain.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class RateLimit {
|
public class RateLimit {
|
||||||
|
|
||||||
@Override
|
public static Builder<?> builder() {
|
||||||
public int hashCode() {
|
return new ConcreteBuilder();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Builder<?> toBuilder() {
|
||||||
public boolean equals(Object obj) {
|
return new ConcreteBuilder().fromRateLimit(this);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String uri;
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
private String regex;
|
protected abstract T self();
|
||||||
private int remaining;
|
|
||||||
private long resetTime;
|
|
||||||
private RateLimitUnit unit;
|
|
||||||
private int value;
|
|
||||||
private String verb;
|
|
||||||
|
|
||||||
// for deserializer
|
protected String uri;
|
||||||
public RateLimit() {
|
protected String regex;
|
||||||
|
protected int remaining;
|
||||||
|
protected long resetTime;
|
||||||
|
protected RateLimitUnit unit;
|
||||||
|
protected int value;
|
||||||
|
protected 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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit, int value, String verb) {
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
this.uri = uri;
|
@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.regex = regex;
|
||||||
this.remaining = remaining;
|
this.remaining = remaining;
|
||||||
this.resetTime = resetTime;
|
this.resetTime = resetTime;
|
||||||
|
@ -110,37 +166,63 @@ public class RateLimit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return this.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getRegex() {
|
public String getRegex() {
|
||||||
return regex;
|
return this.regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRemaining() {
|
public int getRemaining() {
|
||||||
return remaining;
|
return this.remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getResetTime() {
|
public long getResetTime() {
|
||||||
return resetTime;
|
return this.resetTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public RateLimitUnit getUnit() {
|
public RateLimitUnit getUnit() {
|
||||||
return unit;
|
return this.unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getVerb() {
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[uri=" + uri + ", regex=" + regex + ", remaining=" + remaining + ", resetTime=" + resetTime + ", unit="
|
return string().toString();
|
||||||
+ unit + ", value=" + value + ", verb=" + verb + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,72 +18,220 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
package org.jclouds.cloudservers.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
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
|
* A server is a virtual machine instance in the Cloud Servers system. Flavor and image are
|
||||||
* requisite elements when creating a server.
|
* requisite elements when creating a server.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Server {
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getMetadata()
|
||||||
|
*/
|
||||||
|
public T metadata(Map<String, String> metadata) {
|
||||||
|
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getAddresses()
|
||||||
|
*/
|
||||||
|
public T addresses(Addresses addresses) {
|
||||||
|
this.addresses = addresses;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getAdminPass()
|
||||||
|
*/
|
||||||
|
public T adminPass(String adminPass) {
|
||||||
|
this.adminPass = adminPass;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getFlavorId()
|
||||||
|
*/
|
||||||
|
public T flavorId(Integer flavorId) {
|
||||||
|
this.flavorId = flavorId;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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.id = id;
|
||||||
this.name = name;
|
this.name = checkNotNull(name, "name");
|
||||||
}
|
this.metadata = metadata == null ? null : ImmutableMap.copyOf(metadata);
|
||||||
|
|
||||||
public void setMetadata(Map<String, String> metadata) {
|
|
||||||
this.metadata = metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getMetadata() {
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAddresses(Addresses addresses) {
|
|
||||||
this.addresses = addresses;
|
this.addresses = addresses;
|
||||||
}
|
|
||||||
|
|
||||||
public Addresses getAddresses() {
|
|
||||||
return addresses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAdminPass(String adminPass) {
|
|
||||||
this.adminPass = adminPass;
|
this.adminPass = adminPass;
|
||||||
}
|
|
||||||
|
|
||||||
public String getAdminPass() {
|
|
||||||
return adminPass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFlavorId(Integer flavorId) {
|
|
||||||
this.flavorId = flavorId;
|
this.flavorId = flavorId;
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getFlavorId() {
|
|
||||||
return flavorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHostId(String hostId) {
|
|
||||||
this.hostId = hostId;
|
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/>
|
* <p/>
|
||||||
* Note: hostId is unique PER ACCOUNT and is not globally unique.
|
* Note: hostId is unique PER ACCOUNT and is not globally unique.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getHostId() {
|
public String getHostId() {
|
||||||
return hostId;
|
return this.hostId;
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImageId(Integer imageId) {
|
|
||||||
this.imageId = imageId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Integer getImageId() {
|
public Integer getImageId() {
|
||||||
return imageId;
|
return this.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Integer getSharedIpGroupId() {
|
public Integer getSharedIpGroupId() {
|
||||||
return sharedIpGroupId;
|
return this.sharedIpGroupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(ServerStatus status) {
|
@Nullable
|
||||||
this.status = status;
|
public Integer getProgress() {
|
||||||
|
return this.progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,13 +267,12 @@ public class Server {
|
||||||
* state. Servers with an ACTIVE status are available for use.
|
* state. Servers with an ACTIVE status are available for use.
|
||||||
*/
|
*/
|
||||||
public ServerStatus getStatus() {
|
public ServerStatus getStatus() {
|
||||||
return status;
|
return this.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(id, name);
|
return Objects.hashCode(id, name, metadata, addresses, adminPass, flavorId, hostId, imageId, sharedIpGroupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -157,21 +280,25 @@ public class Server {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (obj == null || getClass() != obj.getClass()) return false;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
Server that = Server.class.cast(obj);
|
Server that = Server.class.cast(obj);
|
||||||
return Objects.equal(this.getId(), that.getId())
|
return Objects.equal(this.id, that.id)
|
||||||
&& Objects.equal(this.name, that.name);
|
&& 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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Objects.toStringHelper("")
|
return string().toString();
|
||||||
.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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,25 +18,105 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
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 {
|
public class ShareIp {
|
||||||
|
|
||||||
private boolean configureServer;
|
public static Builder<?> builder() {
|
||||||
private int sharedIpGroupId;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ShareIp#getSharedIpGroupId()
|
||||||
|
*/
|
||||||
|
public T sharedIpGroupId(int sharedIpGroupId) {
|
||||||
|
this.sharedIpGroupId = sharedIpGroupId;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
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.configureServer = configureServer;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isConfigureServer() {
|
|
||||||
return configureServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSharedIpGroupId(int sharedIpGroupId) {
|
|
||||||
this.sharedIpGroupId = sharedIpGroupId;
|
this.sharedIpGroupId = sharedIpGroupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConfigureServer() {
|
||||||
|
return this.configureServer;
|
||||||
|
}
|
||||||
|
|
||||||
public int getSharedIpGroupId() {
|
public int getSharedIpGroupId() {
|
||||||
return sharedIpGroupId;
|
return this.sharedIpGroupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(configureServer, sharedIpGroupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
ShareIp that = ShareIp.class.cast(obj);
|
||||||
|
return Objects.equal(this.configureServer, that.configureServer)
|
||||||
|
&& Objects.equal(this.sharedIpGroupId, that.sharedIpGroupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("configureServer", configureServer).add("sharedIpGroupId", sharedIpGroupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,9 +18,16 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
package org.jclouds.cloudservers.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import 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.
|
* A shared IP group is a collection of servers that can share IPs with other members of the group.
|
||||||
|
@ -29,83 +36,120 @@ import com.google.common.collect.Lists;
|
||||||
* groups. A server may only be a member of one shared IP group.
|
* groups. A server may only be a member of one shared IP group.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class SharedIpGroup {
|
public class SharedIpGroup {
|
||||||
|
|
||||||
private int id;
|
public static Builder<?> builder() {
|
||||||
private String name;
|
return new ConcreteBuilder();
|
||||||
|
|
||||||
private List<Integer> servers = Lists.newArrayList();
|
|
||||||
|
|
||||||
public SharedIpGroup() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SharedIpGroup(int id, String name) {
|
public Builder<?> toBuilder() {
|
||||||
this.id = id;
|
return new ConcreteBuilder().fromSharedIpGroup(this);
|
||||||
this.name = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(int id) {
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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.id = id;
|
||||||
|
this.name = checkNotNull(name, "name");
|
||||||
|
this.servers = servers == null ? null : ImmutableList.copyOf(servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
|
||||||
|
|
||||||
public void setServers(List<Integer> servers) {
|
|
||||||
this.servers = servers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public List<Integer> getServers() {
|
public List<Integer> getServers() {
|
||||||
return servers;
|
return this.servers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(id, name, servers);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
SharedIpGroup that = SharedIpGroup.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.id, that.id)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.name, that.name)
|
||||||
return false;
|
&& Objects.equal(this.servers, that.servers);
|
||||||
SharedIpGroup other = (SharedIpGroup) obj;
|
}
|
||||||
if (id != other.id)
|
|
||||||
return false;
|
protected ToStringHelper string() {
|
||||||
if (name == null) {
|
return Objects.toStringHelper(this)
|
||||||
if (other.name != null)
|
.add("id", id).add("name", name).add("servers", servers);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SharedIpGroup [id=" + id + ", name=" + name + ", servers=" + servers + "]";
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,42 +18,144 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudservers.domain;
|
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 {
|
public class Version {
|
||||||
|
|
||||||
private String docURL;
|
public static Builder<?> builder() {
|
||||||
private String id = "v1.0";
|
return new ConcreteBuilder();
|
||||||
private VersionStatus status;
|
|
||||||
private String wadl;
|
|
||||||
|
|
||||||
public void setDocURL(String docURL) {
|
|
||||||
this.docURL = docURL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDocURL() {
|
public Builder<?> toBuilder() {
|
||||||
return docURL;
|
return new ConcreteBuilder().fromVersion(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
this.id = id;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Version#getId()
|
||||||
|
*/
|
||||||
|
public T id(String id) {
|
||||||
|
this.id = id;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Version#getStatus()
|
||||||
|
*/
|
||||||
|
public T status(VersionStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Version#getWadl()
|
||||||
|
*/
|
||||||
|
public T wadl(String wadl) {
|
||||||
|
this.wadl = wadl;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
return id;
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(VersionStatus status) {
|
private final String docURL;
|
||||||
this.status = status;
|
private final String id;
|
||||||
}
|
private final VersionStatus status;
|
||||||
|
private final String wadl;
|
||||||
|
|
||||||
public VersionStatus getStatus() {
|
@ConstructorProperties({
|
||||||
return status;
|
"docURL", "id", "status", "wadl"
|
||||||
}
|
})
|
||||||
|
protected Version(String docURL, String id, @Nullable VersionStatus status, @Nullable String wadl) {
|
||||||
public void setWadl(String wadl) {
|
this.docURL = checkNotNull(docURL, "docURL");
|
||||||
|
this.id = checkNotNull(id, "id");
|
||||||
|
this.status = status == null ? VersionStatus.UNRECOGNIZED : status;
|
||||||
this.wadl = wadl;
|
this.wadl = wadl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWadl() {
|
public String getDocURL() {
|
||||||
return wadl;
|
return this.docURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VersionStatus getStatus() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getWadl() {
|
||||||
|
return this.wadl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(docURL, id, status, wadl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
Version that = Version.class.cast(obj);
|
||||||
|
return Objects.equal(this.docURL, that.docURL)
|
||||||
|
&& Objects.equal(this.id, that.id)
|
||||||
|
&& Objects.equal(this.status, that.status)
|
||||||
|
&& Objects.equal(this.wadl, that.wadl);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("docURL", docURL).add("id", id).add("status", status).add("wadl", wadl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.jclouds.rest.MapBinder;
|
||||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
@ -105,9 +106,7 @@ public class CreateServerOptions implements MapBinder {
|
||||||
if (sharedIpGroupId != null)
|
if (sharedIpGroupId != null)
|
||||||
server.sharedIpGroupId = this.sharedIpGroupId;
|
server.sharedIpGroupId = this.sharedIpGroupId;
|
||||||
if (publicIp != null) {
|
if (publicIp != null) {
|
||||||
server.addresses = new Addresses();
|
server.addresses = Addresses.builder().publicAddresses(ImmutableSet.of(publicIp)).build();
|
||||||
server.addresses.getPublicAddresses().add(publicIp);
|
|
||||||
server.addresses.setPrivateAddresses(null);
|
|
||||||
}
|
}
|
||||||
return bindToRequest(request, ImmutableMap.of("server", server));
|
return bindToRequest(request, ImmutableMap.of("server", server));
|
||||||
}
|
}
|
||||||
|
|
|
@ -502,8 +502,8 @@ public class CloudServersAsyncClientTest extends BaseAsyncClientTest<CloudServer
|
||||||
|
|
||||||
public void testReplaceBackupSchedule() throws IOException, SecurityException, NoSuchMethodException {
|
public void testReplaceBackupSchedule() throws IOException, SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("replaceBackupSchedule", int.class, BackupSchedule.class);
|
Method method = CloudServersAsyncClient.class.getMethod("replaceBackupSchedule", int.class, BackupSchedule.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2, new BackupSchedule(WeeklyBackup.MONDAY,
|
HttpRequest request = processor.createRequest(method, 2, BackupSchedule.builder().weekly(WeeklyBackup.MONDAY)
|
||||||
DailyBackup.H_0800_1000, true));
|
.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");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/backup_schedule HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
|
|
|
@ -503,11 +503,8 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
||||||
|
|
||||||
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareNoConfig")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareNoConfig")
|
||||||
public void testBackup() throws Exception {
|
public void testBackup() throws Exception {
|
||||||
assertEquals(new BackupSchedule(), client.getBackupSchedule(serverId));
|
assertEquals(BackupSchedule.builder().build(), client.getBackupSchedule(serverId));
|
||||||
BackupSchedule dailyWeekly = new BackupSchedule();
|
BackupSchedule dailyWeekly = BackupSchedule.builder().enabled(true).weekly(WeeklyBackup.FRIDAY).daily(DailyBackup.H_0400_0600).build();
|
||||||
dailyWeekly.setEnabled(true);
|
|
||||||
dailyWeekly.setWeekly(WeeklyBackup.FRIDAY);
|
|
||||||
dailyWeekly.setDaily(DailyBackup.H_0400_0600);
|
|
||||||
client.replaceBackupSchedule(serverId, dailyWeekly);
|
client.replaceBackupSchedule(serverId, dailyWeekly);
|
||||||
client.deleteBackupSchedule(serverId);
|
client.deleteBackupSchedule(serverId);
|
||||||
// disables, doesn't delete: Web Hosting #119571
|
// disables, doesn't delete: Web Hosting #119571
|
||||||
|
|
|
@ -30,18 +30,14 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ServerTest {
|
public class ServerTest {
|
||||||
public void testStatusDoesntAffectEquals() {
|
public void testStatusDoesntAffectEquals() {
|
||||||
Server server1 = new Server(1, "hello");
|
Server server1 = Server.builder().id(1).name("hello").status(ServerStatus.ACTIVE).build();
|
||||||
server1.setStatus(ServerStatus.ACTIVE);
|
Server server2 = Server.builder().id(1).name("hello").status(ServerStatus.BUILD).build();
|
||||||
Server server2 = new Server(1, "hello");
|
|
||||||
server2.setStatus(ServerStatus.BUILD);
|
|
||||||
assertEquals(server1, server2);
|
assertEquals(server1, server2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testProgressDoesntAffectEquals() {
|
public void testProgressDoesntAffectEquals() {
|
||||||
Server server1 = new Server(1, "hello");
|
Server server1 = Server.builder().id(1).name("hello").progress(1).build();
|
||||||
server1.setProgress(1);
|
Server server2 = Server.builder().id(1).name("hello").progress(2).build();
|
||||||
Server server2 = new Server(1, "hello");
|
|
||||||
server2.setProgress(2);
|
|
||||||
assertEquals(server1, server2);
|
assertEquals(server1, server2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class ParseBackupScheduleFromJsonResponseTest {
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<BackupSchedule>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<BackupSchedule>>() {
|
||||||
}));
|
}));
|
||||||
BackupSchedule response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
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 {
|
public void testNoSchedule() throws UnknownHostException {
|
||||||
|
@ -63,6 +63,6 @@ public class ParseBackupScheduleFromJsonResponseTest {
|
||||||
BackupSchedule response = parser.apply(HttpResponse.builder()
|
BackupSchedule response = parser.apply(HttpResponse.builder()
|
||||||
.statusCode(200).message("ok")
|
.statusCode(200).message("ok")
|
||||||
.payload("{\"backupSchedule\":{\"enabled\" : false}}").build());
|
.payload("{\"backupSchedule\":{\"enabled\" : false}}").build());
|
||||||
assertEquals(new BackupSchedule(), response);
|
assertEquals(BackupSchedule.builder().build(), response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,8 @@ public class ParseFlavorListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
|
||||||
|
|
||||||
List<Flavor> expects = ImmutableList.of(new Flavor(1, "256 MB Server"), 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
|
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
|
||||||
|
|
|
@ -61,7 +61,8 @@ public class ParseImageListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
|
||||||
|
|
||||||
List<Image> expects = ImmutableList.of(new Image(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
|
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
|
||||||
|
|
|
@ -59,9 +59,7 @@ public class ParseServerFromJsonResponseTest {
|
||||||
assertEquals(response.getProgress(), Integer.valueOf(60));
|
assertEquals(response.getProgress(), Integer.valueOf(60));
|
||||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
||||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||||
Addresses addresses1 = new Addresses();
|
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
|
||||||
addresses1.getPrivateAddresses().addAll(privateAddresses);
|
|
||||||
addresses1.getPublicAddresses().addAll(publicAddresses);
|
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,8 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
|
||||||
|
|
||||||
List<Server> expects = ImmutableList.of(new Server(1234, "sample-server"), new Server(5678, "sample-server2"));
|
List<Server> expects = ImmutableList.of(Server.builder().id(1234).name("sample-server").build(),
|
||||||
|
Server.builder().id(5678).name("sample-server2").build());
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
||||||
|
@ -80,9 +81,7 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
|
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
|
||||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
||||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||||
Addresses addresses1 = new Addresses();
|
Addresses addresses1 = Addresses.builder().privateAddresses(privateAddresses).publicAddresses(publicAddresses).build();
|
||||||
addresses1.getPrivateAddresses().addAll(privateAddresses);
|
|
||||||
addresses1.getPublicAddresses().addAll(publicAddresses);
|
|
||||||
assertEquals(response.get(0).getAddresses(), addresses1);
|
assertEquals(response.get(0).getAddresses(), addresses1);
|
||||||
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
assertEquals(response.get(1).getId(), 5678);
|
assertEquals(response.get(1).getId(), 5678);
|
||||||
|
@ -94,9 +93,7 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
assertEquals(response.get(1).getProgress(), null);
|
assertEquals(response.get(1).getProgress(), null);
|
||||||
List<String> publicAddresses2 = Lists.newArrayList("67.23.10.133");
|
List<String> publicAddresses2 = Lists.newArrayList("67.23.10.133");
|
||||||
List<String> privateAddresses2 = Lists.newArrayList("10.176.42.17");
|
List<String> privateAddresses2 = Lists.newArrayList("10.176.42.17");
|
||||||
Addresses addresses2 = new Addresses();
|
Addresses addresses2 = Addresses.builder().privateAddresses(privateAddresses2).publicAddresses(publicAddresses2).build();
|
||||||
addresses2.getPrivateAddresses().addAll(privateAddresses2);
|
|
||||||
addresses2.getPublicAddresses().addAll(publicAddresses2);
|
|
||||||
assertEquals(response.get(1).getAddresses(), addresses2);
|
assertEquals(response.get(1).getAddresses(), addresses2);
|
||||||
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ public class ParseSharedIpGroupListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_sharedipgroups.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_sharedipgroups.json");
|
||||||
|
|
||||||
List<SharedIpGroup> expects = ImmutableList.of(new SharedIpGroup(1234, "Shared IP Group 1"), new SharedIpGroup(
|
List<SharedIpGroup> expects = ImmutableList.of(SharedIpGroup.builder().id(1234).name("Shared IP Group 1").build(),
|
||||||
5678, "Shared IP Group 2"));
|
SharedIpGroup.builder().id(5678).name("Shared IP Group 2").build());
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<List<SharedIpGroup>> parser = i.getInstance(Key
|
UnwrapOnlyJsonValue<List<SharedIpGroup>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<SharedIpGroup>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<SharedIpGroup>>>() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,30 +18,108 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class AbsoluteLimit {
|
public class AbsoluteLimit {
|
||||||
|
|
||||||
protected String name;
|
public static Builder<?> builder() {
|
||||||
protected int value;
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public Builder<?> toBuilder() {
|
||||||
return name;
|
return new ConcreteBuilder().fromAbsoluteLimit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String value) {
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
this.name = value;
|
protected abstract T self();
|
||||||
}
|
|
||||||
|
|
||||||
public int getValue() {
|
protected String name;
|
||||||
return value;
|
protected int value;
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(int value) {
|
/**
|
||||||
this.value = value;
|
* @see AbsoluteLimit#getName()
|
||||||
}
|
*/
|
||||||
|
public T name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see AbsoluteLimit#getValue()
|
||||||
|
*/
|
||||||
|
public T value(int value) {
|
||||||
|
this.value = value;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbsoluteLimit build() {
|
||||||
|
return new AbsoluteLimit(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromAbsoluteLimit(AbsoluteLimit in) {
|
||||||
|
return this
|
||||||
|
.name(in.getName())
|
||||||
|
.value(in.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
@ConstructorProperties({
|
||||||
|
"name", "value"
|
||||||
|
})
|
||||||
|
protected AbsoluteLimit(String name, int value) {
|
||||||
|
this.name = checkNotNull(name, "name");
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
AbsoluteLimit that = AbsoluteLimit.class.cast(obj);
|
||||||
|
return Objects.equal(this.name, that.name)
|
||||||
|
&& Objects.equal(this.value, that.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("name", name).add("value", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,60 +18,27 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dmitri Babaev
|
* @author Dmitri Babaev
|
||||||
*/
|
*/
|
||||||
public class Address {
|
public class Address {
|
||||||
@SerializedName("addr")
|
|
||||||
private String address;
|
|
||||||
private int version;
|
|
||||||
|
|
||||||
//for de-serialization
|
public static Builder<?> builder() {
|
||||||
@SuppressWarnings("unused")
|
return new ConcreteBuilder();
|
||||||
private Address() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Address(String address, int version) {
|
public Builder<?> toBuilder() {
|
||||||
this.address = address;
|
return new ConcreteBuilder().fromAddress(this);
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
|
|
||||||
Address address1 = (Address) o;
|
|
||||||
|
|
||||||
if (version != address1.version) return false;
|
|
||||||
if (address != null ? !address.equals(address1.address) : address1.address != null) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = address != null ? address.hashCode() : 0;
|
|
||||||
result = 31 * result + version;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Function<Address, String> newAddress2StringFunction() {
|
public static Function<Address, String> newAddress2StringFunction() {
|
||||||
|
@ -95,4 +62,88 @@ public class Address {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
|
protected abstract T self();
|
||||||
|
|
||||||
|
protected String address;
|
||||||
|
protected int version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Address#getAddress()
|
||||||
|
*/
|
||||||
|
public T address(String address) {
|
||||||
|
this.address = address;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Address#getVersion()
|
||||||
|
*/
|
||||||
|
public T version(int version) {
|
||||||
|
this.version = version;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Address build() {
|
||||||
|
return new Address(address, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromAddress(Address in) {
|
||||||
|
return this
|
||||||
|
.address(in.getAddress())
|
||||||
|
.version(in.getVersion());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String address;
|
||||||
|
private final int version;
|
||||||
|
|
||||||
|
@ConstructorProperties({
|
||||||
|
"addr", "version"
|
||||||
|
})
|
||||||
|
protected Address(String address, int version) {
|
||||||
|
this.address = checkNotNull(address, "address");
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return this.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVersion() {
|
||||||
|
return this.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(address, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
Address that = Address.class.cast(obj);
|
||||||
|
return Objects.equal(this.address, that.address)
|
||||||
|
&& Objects.equal(this.version, that.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("address", address).add("version", version);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,81 +18,119 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.base.Objects;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Addresses {
|
public class Addresses {
|
||||||
|
|
||||||
@SerializedName("public")
|
public static Builder<?> builder() {
|
||||||
private Set<Address> publicAddresses = Sets.newLinkedHashSet();
|
return new ConcreteBuilder();
|
||||||
@SerializedName("private")
|
|
||||||
private Set<Address> privateAddresses = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
public Addresses() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Addresses(Set<Address> publicAddresses, Set<Address> privateAddresses) {
|
public Builder<?> toBuilder() {
|
||||||
this.publicAddresses = publicAddresses;
|
return new ConcreteBuilder().fromAddresses(this);
|
||||||
this.privateAddresses = privateAddresses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPublicAddresses(Set<Address> publicAddresses) {
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
this.publicAddresses = publicAddresses;
|
protected abstract T self();
|
||||||
|
|
||||||
|
protected Set<Address> publicAddresses = ImmutableSet.of();
|
||||||
|
protected Set<Address> privateAddresses = ImmutableSet.of();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Addresses#getPublicAddresses()
|
||||||
|
*/
|
||||||
|
public T publicAddresses(Collection<Address> publicAddresses) {
|
||||||
|
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T publicAddresses(Address... in) {
|
||||||
|
return publicAddresses(ImmutableSet.copyOf(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Addresses#getPrivateAddresses()
|
||||||
|
*/
|
||||||
|
public T privateAddresses(Collection<Address> privateAddresses) {
|
||||||
|
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T privateAddresses(Address... in) {
|
||||||
|
return privateAddresses(ImmutableSet.copyOf(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Addresses build() {
|
||||||
|
return new Addresses(publicAddresses, privateAddresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromAddresses(Addresses in) {
|
||||||
|
return this
|
||||||
|
.publicAddresses(in.getPublicAddresses())
|
||||||
|
.privateAddresses(in.getPrivateAddresses());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Set<Address> publicAddresses;
|
||||||
|
private final Set<Address> privateAddresses;
|
||||||
|
|
||||||
|
@ConstructorProperties({
|
||||||
|
"public", "private"
|
||||||
|
})
|
||||||
|
protected Addresses(Set<Address> publicAddresses, Set<Address> privateAddresses) {
|
||||||
|
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
|
||||||
|
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Address> getPublicAddresses() {
|
public Set<Address> getPublicAddresses() {
|
||||||
return publicAddresses;
|
return this.publicAddresses;
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrivateAddresses(Set<Address> privateAddresses) {
|
|
||||||
this.privateAddresses = privateAddresses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Address> getPrivateAddresses() {
|
public Set<Address> getPrivateAddresses() {
|
||||||
return privateAddresses;
|
return this.privateAddresses;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Addresses [privateAddresses=" + privateAddresses + ", publicAddresses="
|
|
||||||
+ publicAddresses + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(publicAddresses, privateAddresses);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
|
|
||||||
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Addresses that = Addresses.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.publicAddresses, that.publicAddresses)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.privateAddresses, that.privateAddresses);
|
||||||
return false;
|
}
|
||||||
Addresses other = (Addresses) obj;
|
|
||||||
if (privateAddresses == null) {
|
protected ToStringHelper string() {
|
||||||
if (other.privateAddresses != null)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("publicAddresses", publicAddresses).add("privateAddresses", privateAddresses);
|
||||||
} else if (!privateAddresses.equals(other.privateAddresses))
|
}
|
||||||
return false;
|
|
||||||
if (publicAddresses == null) {
|
@Override
|
||||||
if (other.publicAddresses != null)
|
public String toString() {
|
||||||
return false;
|
return string().toString();
|
||||||
} else if (!publicAddresses.equals(other.publicAddresses))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,8 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* A flavor is an available hardware configuration for a server. Each flavor has a unique
|
* A flavor is an available hardware configuration for a server. Each flavor has a unique
|
||||||
* combination of disk space and memory capacity.
|
* combination of disk space and memory capacity.
|
||||||
*
|
*
|
||||||
|
@ -27,97 +36,128 @@ package org.jclouds.openstack.nova.domain;
|
||||||
*/
|
*/
|
||||||
public class Flavor extends Resource {
|
public class Flavor extends Resource {
|
||||||
|
|
||||||
private final int id;
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder<?> toBuilder() {
|
||||||
|
return new ConcreteBuilder().fromFlavor(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
|
||||||
|
protected String name;
|
||||||
|
protected Integer disk;
|
||||||
|
protected Integer ram;
|
||||||
|
protected Integer vcpus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Flavor#getName()
|
||||||
|
*/
|
||||||
|
public T name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Flavor#getDisk()
|
||||||
|
*/
|
||||||
|
public T disk(Integer disk) {
|
||||||
|
this.disk = disk;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Flavor#getRam()
|
||||||
|
*/
|
||||||
|
public T ram(Integer ram) {
|
||||||
|
this.ram = ram;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Flavor#getVcpus()
|
||||||
|
*/
|
||||||
|
public T vcpus(Integer vcpus) {
|
||||||
|
this.vcpus = vcpus;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Flavor build() {
|
||||||
|
return new Flavor(id, links, orderedSelfReferences, name, disk, ram, vcpus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromFlavor(Flavor in) {
|
||||||
|
return super.fromResource(in)
|
||||||
|
.name(in.getName())
|
||||||
|
.disk(in.getDisk())
|
||||||
|
.ram(in.getRam())
|
||||||
|
.vcpus(in.getVcpus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Integer disk;
|
private final Integer disk;
|
||||||
private final Integer ram;
|
private final Integer ram;
|
||||||
private final Integer vcpus;
|
private final Integer vcpus;
|
||||||
|
|
||||||
//Required because of how Gson is being used to do wire marshalling with the Server class
|
@ConstructorProperties({
|
||||||
private Flavor(){
|
"id", "links", "orderedSelfReferences", "name", "disk", "ram", "vcpus"
|
||||||
id=0;
|
})
|
||||||
name=null;
|
protected Flavor(int id, List<Map<String, String>> links, @Nullable Map<LinkType, URI> orderedSelfReferences,
|
||||||
disk=null;
|
@Nullable String name, @Nullable Integer disk, @Nullable Integer ram, @Nullable Integer vcpus) {
|
||||||
ram=null;
|
super(id, links, orderedSelfReferences);
|
||||||
vcpus=null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Flavor(int id, String name, Integer disk, Integer ram, Integer vcpus) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.disk = disk;
|
this.disk = disk;
|
||||||
this.ram = ram;
|
this.ram = ram;
|
||||||
this.vcpus = vcpus;
|
this.vcpus = vcpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDisk() {
|
@Nullable
|
||||||
return disk;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Integer getDisk() {
|
||||||
|
return this.disk;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Integer getRam() {
|
public Integer getRam() {
|
||||||
return ram;
|
return this.ram;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Integer getVcpus() {
|
public Integer getVcpus() {
|
||||||
return vcpus;
|
return this.vcpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(super.hashCode(), name, disk, ram, vcpus);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((disk == null) ? 0 : disk.hashCode());
|
|
||||||
result = prime * result + id;
|
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
|
||||||
result = prime * result + ((ram == null) ? 0 : ram.hashCode());
|
|
||||||
result = prime * result + ((vcpus == null) ? 0 : vcpus.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Flavor that = Flavor.class.cast(obj);
|
||||||
return false;
|
return super.equals(that)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.name, that.name)
|
||||||
return false;
|
&& Objects.equal(this.disk, that.disk)
|
||||||
Flavor other = (Flavor) obj;
|
&& Objects.equal(this.ram, that.ram)
|
||||||
if (disk == null) {
|
&& Objects.equal(this.vcpus, that.vcpus);
|
||||||
if (other.disk != null)
|
|
||||||
return false;
|
|
||||||
} else if (!disk.equals(other.disk))
|
|
||||||
return false;
|
|
||||||
if (id != other.id)
|
|
||||||
return false;
|
|
||||||
if (name == null) {
|
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
|
||||||
return false;
|
|
||||||
if (ram == null) {
|
|
||||||
if (other.ram != null)
|
|
||||||
return false;
|
|
||||||
} else if (!ram.equals(other.ram))
|
|
||||||
return false;
|
|
||||||
if (vcpus == null) {
|
|
||||||
if (other.vcpus != null)
|
|
||||||
return false;
|
|
||||||
} else if (!vcpus.equals(other.vcpus))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected ToStringHelper string() {
|
||||||
public String toString() {
|
return super.string().add("name", name).add("disk", disk).add("ram", ram).add("vcpus", vcpus);
|
||||||
return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + ", vcpus=" + vcpus +"]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,153 +18,134 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check <a href="http://wiki.openstack.org/os_api_floating_ip">Floating IP Wiki
|
* Check <a href="http://wiki.openstack.org/os_api_floating_ip">Floating IP Wiki
|
||||||
* page</a>. Available since OpenStack Diablo release and API 1.1.
|
* page</a>. Available since OpenStack Diablo release and API 1.1.
|
||||||
*
|
*
|
||||||
* @author chamerling
|
* @author chamerling
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
public class FloatingIP extends Resource {
|
public class FloatingIP extends Resource {
|
||||||
|
|
||||||
private int id;
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
private String ip;
|
public Builder<?> toBuilder() {
|
||||||
|
return new ConcreteBuilder().fromFloatingIP(this);
|
||||||
|
}
|
||||||
|
|
||||||
@SerializedName(value="fixed_ip")
|
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
|
||||||
private String fixedIP;
|
protected String ip;
|
||||||
|
protected String fixedIP;
|
||||||
|
protected int instanceID;
|
||||||
|
|
||||||
@SerializedName(value = "instance_id")
|
/**
|
||||||
private int instanceID;
|
* @see FloatingIP#getIp()
|
||||||
|
*/
|
||||||
|
public T ip(String ip) {
|
||||||
|
this.ip = ip;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
/**
|
||||||
private FloatingIP() {
|
* @see FloatingIP#getFixedIP()
|
||||||
}
|
*/
|
||||||
|
public T fixedIP(String fixedIP) {
|
||||||
|
this.fixedIP = fixedIP;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
public FloatingIP(int id, String ip, String fixedIP, int instanceID) {
|
/**
|
||||||
this.id = id;
|
* @see FloatingIP#getInstanceID()
|
||||||
this.ip = ip;
|
*/
|
||||||
this.fixedIP = fixedIP;
|
public T instanceID(int instanceID) {
|
||||||
this.instanceID = instanceID;
|
this.instanceID = instanceID;
|
||||||
}
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public FloatingIP build() {
|
||||||
* @return the id
|
return new FloatingIP(id, links, orderedSelfReferences, ip, fixedIP, instanceID);
|
||||||
*/
|
}
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public T fromFloatingIP(FloatingIP in) {
|
||||||
* @param id the id to set
|
return super.fromResource(in)
|
||||||
*/
|
.ip(in.getIp())
|
||||||
public void setId(int id) {
|
.fixedIP(in.getFixedIP())
|
||||||
this.id = id;
|
.instanceID(in.getInstanceID());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
* @return the ip
|
@Override
|
||||||
*/
|
protected ConcreteBuilder self() {
|
||||||
public String getIp() {
|
return this;
|
||||||
return ip;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private final String ip;
|
||||||
* @param ip the ip to set
|
private final String fixedIP;
|
||||||
*/
|
private final int instanceID;
|
||||||
public void setIp(String ip) {
|
|
||||||
this.ip = ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@ConstructorProperties({
|
||||||
* @return the fixedIP
|
"id", "links", "orderedSelfReferences", "ip", "fixed_ip", "instance_id"
|
||||||
*/
|
})
|
||||||
public String getFixedIP() {
|
protected FloatingIP(int id, List<Map<String, String>> links, Map<LinkType, URI> orderedSelfReferences, String ip,
|
||||||
return fixedIP;
|
String fixedIP, int instanceID) {
|
||||||
}
|
super(id, links, orderedSelfReferences);
|
||||||
|
this.ip = checkNotNull(ip, "ip");
|
||||||
|
this.fixedIP = checkNotNull(fixedIP, "fixedIP");
|
||||||
|
this.instanceID = instanceID;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param fixedIP the fixedIP to set
|
* @return the ip
|
||||||
*/
|
*/
|
||||||
public void setFixedIP(String fixedIP) {
|
public String getIp() {
|
||||||
this.fixedIP = fixedIP;
|
return this.ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the instanceID
|
* @return the fixedIP
|
||||||
*/
|
*/
|
||||||
public int getInstanceID() {
|
public String getFixedIP() {
|
||||||
return instanceID;
|
return this.fixedIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param instanceID the instanceID to set
|
* @return the instanceID
|
||||||
*/
|
*/
|
||||||
public void setInstanceID(int instanceID) {
|
public int getInstanceID() {
|
||||||
this.instanceID = instanceID;
|
return this.instanceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
@Override
|
||||||
* @see java.lang.Object#toString()
|
public int hashCode() {
|
||||||
*/
|
return Objects.hashCode(super.hashCode(), ip, fixedIP, instanceID);
|
||||||
@Override
|
}
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("FloatingIP [id=");
|
|
||||||
builder.append(id);
|
|
||||||
builder.append(", ip=");
|
|
||||||
builder.append(ip);
|
|
||||||
builder.append(", fixedIP=");
|
|
||||||
builder.append(fixedIP);
|
|
||||||
builder.append(", instanceID=");
|
|
||||||
builder.append(instanceID);
|
|
||||||
builder.append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
@Override
|
||||||
* @see java.lang.Object#hashCode()
|
public boolean equals(Object obj) {
|
||||||
*/
|
if (this == obj) return true;
|
||||||
@Override
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
public int hashCode() {
|
FloatingIP that = FloatingIP.class.cast(obj);
|
||||||
final int prime = 31;
|
return super.equals(that)
|
||||||
int result = 1;
|
&& Objects.equal(this.ip, that.ip)
|
||||||
result = prime * result + ((fixedIP == null) ? 0 : fixedIP.hashCode());
|
&& Objects.equal(this.fixedIP, that.fixedIP)
|
||||||
result = prime * result + id;
|
&& Objects.equal(this.instanceID, that.instanceID);
|
||||||
result = prime * result + instanceID;
|
}
|
||||||
result = prime * result + ((ip == null) ? 0 : ip.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
protected ToStringHelper string() {
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
return super.string().add("ip", ip).add("fixedIP", fixedIP).add("instanceID", instanceID);
|
||||||
*/
|
}
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
FloatingIP other = (FloatingIP) obj;
|
|
||||||
if (fixedIP == null) {
|
|
||||||
if (other.fixedIP != null)
|
|
||||||
return false;
|
|
||||||
} else if (!fixedIP.equals(other.fixedIP))
|
|
||||||
return false;
|
|
||||||
if (id != other.id)
|
|
||||||
return false;
|
|
||||||
if (instanceID != other.instanceID)
|
|
||||||
return false;
|
|
||||||
if (ip == null) {
|
|
||||||
if (other.ip != null)
|
|
||||||
return false;
|
|
||||||
} else if (!ip.equals(other.ip))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,11 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
import java.util.Collections;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
import java.net.URI;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An image is a collection of files used to create or rebuild a server. Rackspace provides a number
|
* An image is a collection of files used to create or rebuild a server. Rackspace provides a number
|
||||||
|
@ -34,122 +42,179 @@ import com.google.common.collect.Maps;
|
||||||
*/
|
*/
|
||||||
public class Image extends Resource {
|
public class Image extends Resource {
|
||||||
|
|
||||||
private int id;
|
public static Builder<?> builder() {
|
||||||
private String name;
|
return new ConcreteBuilder();
|
||||||
private Integer progress;
|
|
||||||
private String serverRef;
|
|
||||||
private ImageStatus status;
|
|
||||||
private Map<String, String> metadata = Maps.newHashMap();
|
|
||||||
|
|
||||||
private Date created;
|
|
||||||
private Date updated;
|
|
||||||
|
|
||||||
public Date getCreated() {
|
|
||||||
return created;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getUpdated() {
|
public Builder<?> toBuilder() {
|
||||||
return updated;
|
return new ConcreteBuilder().fromImage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
|
||||||
|
protected String name;
|
||||||
|
protected Integer progress;
|
||||||
|
protected String serverRef;
|
||||||
|
protected ImageStatus status;
|
||||||
|
protected Map<String, String> metadata = ImmutableMap.of();
|
||||||
|
protected Date created;
|
||||||
|
protected Date updated;
|
||||||
|
|
||||||
public Image() {
|
/**
|
||||||
|
* @see Image#getName()
|
||||||
|
*/
|
||||||
|
public T name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getProgress()
|
||||||
|
*/
|
||||||
|
public T progress(Integer progress) {
|
||||||
|
this.progress = progress;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getServerRef()
|
||||||
|
*/
|
||||||
|
public T serverRef(String serverRef) {
|
||||||
|
this.serverRef = serverRef;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getStatus()
|
||||||
|
*/
|
||||||
|
public T status(ImageStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getMetadata()
|
||||||
|
*/
|
||||||
|
public T metadata(Map<String, String> metadata) {
|
||||||
|
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getCreated()
|
||||||
|
*/
|
||||||
|
public T created(Date created) {
|
||||||
|
this.created = created;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Image#getUpdated()
|
||||||
|
*/
|
||||||
|
public T updated(Date updated) {
|
||||||
|
this.updated = updated;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image build() {
|
||||||
|
return new Image(id, links, orderedSelfReferences, name, progress, serverRef, status, metadata, created, updated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromImage(Image in) {
|
||||||
|
return super.fromResource(in)
|
||||||
|
.id(in.getId())
|
||||||
|
.name(in.getName())
|
||||||
|
.progress(in.getProgress())
|
||||||
|
.serverRef(in.getServerRef())
|
||||||
|
.status(in.getStatus())
|
||||||
|
.metadata(in.getMetadata())
|
||||||
|
.created(in.getCreated())
|
||||||
|
.updated(in.getUpdated());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image(int id, String name) {
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
this.id = id;
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final Integer progress;
|
||||||
|
private final String serverRef;
|
||||||
|
private final ImageStatus status;
|
||||||
|
private final Map<String, String> metadata;
|
||||||
|
private final Date created;
|
||||||
|
private final Date updated;
|
||||||
|
|
||||||
|
@ConstructorProperties({
|
||||||
|
"id", "links", "orderedSelfReferences", "name", "progress", "serverRef", "status", "metadata", "created", "updated"
|
||||||
|
})
|
||||||
|
protected Image(int id, List<Map<String, String>> links, @Nullable Map<LinkType, URI> orderedSelfReferences, @Nullable String name,
|
||||||
|
@Nullable Integer progress, @Nullable String serverRef, @Nullable ImageStatus status, @Nullable Map<String, String> metadata,
|
||||||
|
@Nullable Date created, @Nullable Date updated) {
|
||||||
|
super(id, links, orderedSelfReferences);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProgress(Integer progress) {
|
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getProgress() {
|
|
||||||
return progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServerRef(String serverRef) {
|
|
||||||
this.serverRef = serverRef;
|
this.serverRef = serverRef;
|
||||||
|
this.status = status == null ? ImageStatus.UNKNOWN : status;
|
||||||
|
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
|
||||||
|
this.created = created;
|
||||||
|
this.updated = updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Integer getProgress() {
|
||||||
|
return this.progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getServerRef() {
|
public String getServerRef() {
|
||||||
return serverRef;
|
return this.serverRef;
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(ImageStatus status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public ImageStatus getStatus() {
|
public ImageStatus getStatus() {
|
||||||
return status;
|
return this.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, String> getMetadata() {
|
public Map<String, String> getMetadata() {
|
||||||
return Collections.unmodifiableMap(metadata);
|
return this.metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMetadata(Map<String, String> metadata) {
|
@Nullable
|
||||||
this.metadata = Maps.newHashMap(metadata);
|
public Date getCreated() {
|
||||||
|
return this.created;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Date getUpdated() {
|
||||||
|
return this.updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* note that this ignores some fields
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(super.hashCode(), name, serverRef);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + id;
|
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
|
||||||
result = prime * result + ((serverRef == null) ? 0 : serverRef.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* note that this ignores some fields
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Image that = Image.class.cast(obj);
|
||||||
return false;
|
return super.equals(that)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.name, that.name)
|
||||||
return false;
|
&& Objects.equal(this.serverRef, that.serverRef);
|
||||||
Image other = (Image) obj;
|
|
||||||
if (id != other.id)
|
|
||||||
return false;
|
|
||||||
if (name == null) {
|
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected ToStringHelper string() {
|
||||||
public String toString() {
|
return super.string().add("name", name).add("progress", progress).add("serverRef", serverRef).add("status", status)
|
||||||
return "Image [created=" + getCreated() + ", id=" + id + ", name=" + name + ", serverRef="
|
.add("metadata", metadata).add("created", created).add("updated", updated);
|
||||||
+ serverRef + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,29 +18,114 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
public class Limits {
|
public class Limits {
|
||||||
|
|
||||||
private List<RateLimit> rate = Lists.newArrayList();
|
public static Builder<?> builder() {
|
||||||
private List<AbsoluteLimit> absolute = Lists.newArrayList();
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
public void setRate(List<RateLimit> rate) {
|
public Builder<?> toBuilder() {
|
||||||
this.rate = rate;
|
return new ConcreteBuilder().fromLimits(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
|
protected abstract T self();
|
||||||
|
|
||||||
|
protected List<RateLimit> rate = ImmutableList.of();
|
||||||
|
protected List<AbsoluteLimit> absolute = ImmutableList.of();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Limits#getRate()
|
||||||
|
*/
|
||||||
|
public T rate(List<RateLimit> rate) {
|
||||||
|
this.rate = ImmutableList.copyOf(checkNotNull(rate, "rate"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T rate(RateLimit... in) {
|
||||||
|
return rate(ImmutableList.copyOf(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Limits#getAbsolute()
|
||||||
|
*/
|
||||||
|
public T absolute(List<AbsoluteLimit> absolute) {
|
||||||
|
this.absolute = ImmutableList.copyOf(checkNotNull(absolute, "absolute"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T absolute(AbsoluteLimit... in) {
|
||||||
|
return absolute(ImmutableList.copyOf(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Limits build() {
|
||||||
|
return new Limits(rate, absolute);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromLimits(Limits in) {
|
||||||
|
return this
|
||||||
|
.rate(in.getRate())
|
||||||
|
.absolute(in.getAbsolute());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final List<RateLimit> rate;
|
||||||
|
private final List<AbsoluteLimit> absolute;
|
||||||
|
|
||||||
|
@ConstructorProperties({
|
||||||
|
"rate", "absolute"
|
||||||
|
})
|
||||||
|
protected Limits(List<RateLimit> rate, List<AbsoluteLimit> absolute) {
|
||||||
|
this.rate = ImmutableList.copyOf(checkNotNull(rate, "rate"));
|
||||||
|
this.absolute = ImmutableList.copyOf(checkNotNull(absolute, "absolute"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RateLimit> getRate() {
|
public List<RateLimit> getRate() {
|
||||||
return rate;
|
return this.rate;
|
||||||
}
|
|
||||||
|
|
||||||
public void setAbsolute(List<AbsoluteLimit> absolute) {
|
|
||||||
this.absolute = absolute;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AbsoluteLimit> getAbsolute() {
|
public List<AbsoluteLimit> getAbsolute() {
|
||||||
return absolute;
|
return this.absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(rate, absolute);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
Limits that = Limits.class.cast(obj);
|
||||||
|
return Objects.equal(this.rate, that.rate)
|
||||||
|
&& Objects.equal(this.absolute, that.absolute);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("rate", rate).add("absolute", absolute);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,10 +18,16 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* RateLimit.
|
* RateLimit.
|
||||||
* <p/>
|
* <p/>
|
||||||
* we specify rate limits in terms of both a human readable wild-card URI and a machine processable
|
* we specify rate limits in terms of both a human readable wild-card URI and a machine processable
|
||||||
|
@ -36,9 +42,107 @@ import javax.ws.rs.HttpMethod;
|
||||||
* will be returned with a Reply-After header to notify the client when theyagain.
|
* will be returned with a Reply-After header to notify the client when theyagain.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class RateLimit {
|
public class RateLimit {
|
||||||
|
|
||||||
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder<?> toBuilder() {
|
||||||
|
return new ConcreteBuilder().fromRateLimit(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
|
protected abstract T self();
|
||||||
|
|
||||||
|
protected String uri;
|
||||||
|
protected String regex;
|
||||||
|
protected int remaining;
|
||||||
|
protected long resetTime;
|
||||||
|
protected RateLimitUnit unit;
|
||||||
|
protected int value;
|
||||||
|
protected HttpMethod verb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RateLimit#getUri()
|
||||||
|
*/
|
||||||
|
public T uri(String uri) {
|
||||||
|
this.uri = uri;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RateLimit#getRegex()
|
||||||
|
*/
|
||||||
|
public T regex(String regex) {
|
||||||
|
this.regex = regex;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RateLimit#getRemaining()
|
||||||
|
*/
|
||||||
|
public T remaining(int remaining) {
|
||||||
|
this.remaining = remaining;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RateLimit#getResetTime()
|
||||||
|
*/
|
||||||
|
public T resetTime(long resetTime) {
|
||||||
|
this.resetTime = resetTime;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RateLimit#getUnit()
|
||||||
|
*/
|
||||||
|
public T unit(RateLimitUnit unit) {
|
||||||
|
this.unit = unit;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RateLimit#getValue()
|
||||||
|
*/
|
||||||
|
public T value(int value) {
|
||||||
|
this.value = value;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RateLimit#getVerb()
|
||||||
|
*/
|
||||||
|
public T verb(HttpMethod verb) {
|
||||||
|
this.verb = verb;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RateLimit build() {
|
||||||
|
return new RateLimit(uri, regex, remaining, resetTime, unit, value, verb);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromRateLimit(RateLimit in) {
|
||||||
|
return this
|
||||||
|
.uri(in.getUri())
|
||||||
|
.regex(in.getRegex())
|
||||||
|
.remaining(in.getRemaining())
|
||||||
|
.resetTime(in.getResetTime())
|
||||||
|
.unit(in.getUnit())
|
||||||
|
.value(in.getValue())
|
||||||
|
.verb(in.getVerb());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final String uri;
|
private final String uri;
|
||||||
private final String regex;
|
private final String regex;
|
||||||
private final int remaining;
|
private final int remaining;
|
||||||
|
@ -47,43 +151,74 @@ public class RateLimit {
|
||||||
private final int value;
|
private final int value;
|
||||||
private final HttpMethod verb;
|
private final HttpMethod verb;
|
||||||
|
|
||||||
public RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit,
|
@ConstructorProperties({
|
||||||
int value, HttpMethod verb) {
|
"uri", "regex", "remaining", "resetTime", "unit", "value", "verb"
|
||||||
this.uri = uri;
|
})
|
||||||
this.regex = regex;
|
protected RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit, int value, HttpMethod verb) {
|
||||||
|
this.uri = checkNotNull(uri, "uri");
|
||||||
|
this.regex = checkNotNull(regex, "regex");
|
||||||
this.remaining = remaining;
|
this.remaining = remaining;
|
||||||
this.resetTime = resetTime;
|
this.resetTime = resetTime;
|
||||||
this.unit = unit;
|
this.unit = checkNotNull(unit, "unit");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.verb = verb;
|
this.verb = checkNotNull(verb, "verb");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return this.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRegex() {
|
public String getRegex() {
|
||||||
return regex;
|
return this.regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRemaining() {
|
public int getRemaining() {
|
||||||
return remaining;
|
return this.remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getResetTime() {
|
public long getResetTime() {
|
||||||
return resetTime;
|
return this.resetTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RateLimitUnit getUnit() {
|
public RateLimitUnit getUnit() {
|
||||||
return unit;
|
return this.unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpMethod getVerb() {
|
public HttpMethod getVerb() {
|
||||||
return verb;
|
return this.verb;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(uri, regex, remaining, resetTime, unit, value, verb);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
RateLimit that = RateLimit.class.cast(obj);
|
||||||
|
return Objects.equal(this.uri, that.uri)
|
||||||
|
&& Objects.equal(this.regex, that.regex)
|
||||||
|
&& Objects.equal(this.remaining, that.remaining)
|
||||||
|
&& Objects.equal(this.resetTime, that.resetTime)
|
||||||
|
&& Objects.equal(this.unit, that.unit)
|
||||||
|
&& Objects.equal(this.value, that.value)
|
||||||
|
&& Objects.equal(this.verb, that.verb);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("uri", uri).add("regex", regex).add("remaining", remaining).add("resetTime", resetTime).add("unit", unit).add("value", value).add("verb", verb);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,65 +18,127 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Functions;
|
import com.google.common.base.Functions;
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dmitri Babaev
|
* @author Dmitri Babaev
|
||||||
* @author Matt Stephenson
|
* @author Matt Stephenson
|
||||||
*/
|
*/
|
||||||
public class Resource {
|
public abstract class Resource {
|
||||||
|
|
||||||
private List<Map<String, String>> links = Lists.newArrayList();
|
public static enum LinkType {
|
||||||
|
BOOKMARK_JSON(new Predicate<Map<String, String>>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(@Nullable Map<String, String> linkMap) {
|
||||||
|
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark") &&
|
||||||
|
Functions.forMap(linkMap, "").apply("type").contains("json");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
BOOKMARK_ANY(new Predicate<Map<String, String>>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(@Nullable Map<String, String> linkMap) {
|
||||||
|
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
SELF(new Predicate<Map<String, String>>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(@Nullable Map<String, String> linkMap) {
|
||||||
|
return Functions.forMap(linkMap, "").apply("rel").equals("self");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//This is the preference order for returning a URI in getURI
|
Predicate<Map<String, String>> linkPredicate;
|
||||||
private enum LinkType {
|
|
||||||
BOOKMARK_JSON(new Predicate<Map<String, String>>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(@Nullable Map<String, String> linkMap) {
|
|
||||||
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark") &&
|
|
||||||
Functions.forMap(linkMap, "").apply("type").contains("json");
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
BOOKMARK_ANY(new Predicate<Map<String, String>>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(@Nullable Map<String, String> linkMap) {
|
|
||||||
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark");
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
SELF(new Predicate<Map<String, String>>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(@Nullable Map<String, String> linkMap) {
|
|
||||||
return Functions.forMap(linkMap, "").apply("rel").equals("self");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Predicate<Map<String,String>> linkPredicate;
|
LinkType(Predicate<Map<String, String>> linkPredicate) {
|
||||||
|
this.linkPredicate = linkPredicate;
|
||||||
LinkType(Predicate<Map<String,String>> linkPredicate) {
|
}
|
||||||
this.linkPredicate = linkPredicate;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ConcurrentSkipListMap<LinkType,URI> orderedSelfReferences;
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
|
protected abstract T self();
|
||||||
|
|
||||||
public Resource(){
|
protected int id;
|
||||||
orderedSelfReferences = new ConcurrentSkipListMap<LinkType,URI>();
|
protected List<Map<String, String>> links = ImmutableList.of();
|
||||||
|
protected Map<Resource.LinkType, URI> orderedSelfReferences;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Resource#getId()
|
||||||
|
*/
|
||||||
|
public T id(int id) {
|
||||||
|
this.id = id;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Resource#getLinks()
|
||||||
|
*/
|
||||||
|
public T links(List<Map<String, String>> links) {
|
||||||
|
this.links = ImmutableList.copyOf(checkNotNull(links, "links"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T links(Map<String, String>... in) {
|
||||||
|
return links(ImmutableList.copyOf(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Resource#getOrderedSelfReferences()
|
||||||
|
*/
|
||||||
|
public T orderedSelfReferences(Map<Resource.LinkType, URI> orderedSelfReferences) {
|
||||||
|
this.orderedSelfReferences = ImmutableMap.copyOf(orderedSelfReferences);
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromResource(Resource in) {
|
||||||
|
return this
|
||||||
|
.links(in.getLinks())
|
||||||
|
.orderedSelfReferences(in.getOrderedSelfReferences());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
private final List<Map<String, String>> links;
|
||||||
|
private final ConcurrentSkipListMap<Resource.LinkType, URI> orderedSelfReferences;
|
||||||
|
|
||||||
|
protected Resource(int id, List<Map<String, String>> links, @Nullable Map<Resource.LinkType, URI> orderedSelfReferences) {
|
||||||
|
this.id = id;
|
||||||
|
this.links = links == null ? ImmutableList.<Map<String, String>>of() : ImmutableList.copyOf(checkNotNull(links, "links"));
|
||||||
|
this.orderedSelfReferences = orderedSelfReferences == null ? new ConcurrentSkipListMap<LinkType, URI>() : new ConcurrentSkipListMap<LinkType, URI>(orderedSelfReferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Map<String, String>> getLinks() {
|
||||||
|
return this.links;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Resource.LinkType, URI> getOrderedSelfReferences() {
|
||||||
|
return this.orderedSelfReferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateOrderedSelfReferences() {
|
private void populateOrderedSelfReferences() {
|
||||||
for (Map<String, String> linkProperties : links) {
|
for (Map<String, String> linkProperties : links) {
|
||||||
for (LinkType type : LinkType.values()) {
|
for (LinkType type : LinkType.values()) {
|
||||||
if(type.linkPredicate.apply(linkProperties)) {
|
if (type.linkPredicate.apply(linkProperties)) {
|
||||||
try {
|
try {
|
||||||
orderedSelfReferences.put(type, new URI(linkProperties.get("href")));
|
orderedSelfReferences.put(type, new URI(linkProperties.get("href")));
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
|
@ -85,21 +147,45 @@ public class Resource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(orderedSelfReferences.isEmpty())
|
if (orderedSelfReferences.isEmpty())
|
||||||
throw new IllegalStateException("URI is not available");
|
throw new IllegalStateException("URI is not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI getURI() {
|
public URI getURI() {
|
||||||
if(orderedSelfReferences.isEmpty())
|
if (orderedSelfReferences.isEmpty())
|
||||||
populateOrderedSelfReferences();
|
populateOrderedSelfReferences();
|
||||||
|
|
||||||
return orderedSelfReferences.firstEntry().getValue();
|
return orderedSelfReferences.firstEntry().getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI getSelfURI() {
|
public URI getSelfURI() {
|
||||||
if(orderedSelfReferences.isEmpty())
|
if (orderedSelfReferences.isEmpty())
|
||||||
populateOrderedSelfReferences();
|
populateOrderedSelfReferences();
|
||||||
|
|
||||||
return orderedSelfReferences.get(LinkType.SELF);
|
return orderedSelfReferences.get(LinkType.SELF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(id, orderedSelfReferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
Resource that = Resource.class.cast(obj);
|
||||||
|
return Objects.equal(id, that.id) && Objects.equal(this.orderedSelfReferences, that.orderedSelfReferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("id", id).add("links", links).add("orderedSelfReferences", orderedSelfReferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,148 +18,159 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a security group
|
* Defines a security group
|
||||||
*
|
*
|
||||||
* @author chamerling
|
* @author chamerling
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
public class SecurityGroup {
|
public class SecurityGroup {
|
||||||
|
|
||||||
private int id;
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
private String name;
|
public Builder<?> toBuilder() {
|
||||||
|
return new ConcreteBuilder().fromSecurityGroup(this);
|
||||||
|
}
|
||||||
|
|
||||||
private String description;
|
public static abstract class Builder<T extends Builder<T>> {
|
||||||
|
protected abstract T self();
|
||||||
|
|
||||||
@SerializedName(value="tenant_id")
|
protected int id;
|
||||||
private String tenantId;
|
protected String name;
|
||||||
|
protected String description;
|
||||||
|
protected String tenantId;
|
||||||
|
|
||||||
public SecurityGroup() {
|
/**
|
||||||
}
|
* @see SecurityGroup#getId()
|
||||||
|
*/
|
||||||
|
public T id(int id) {
|
||||||
|
this.id = id;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the id
|
* @see SecurityGroup#getName()
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public T name(String name) {
|
||||||
return id;
|
this.name = name;
|
||||||
}
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id the id to set
|
* @see SecurityGroup#getDescription()
|
||||||
*/
|
*/
|
||||||
public void setId(int id) {
|
public T description(String description) {
|
||||||
this.id = id;
|
this.description = description;
|
||||||
}
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the name
|
* @see SecurityGroup#getTenantId()
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public T tenantId(String tenantId) {
|
||||||
return name;
|
this.tenantId = tenantId;
|
||||||
}
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public SecurityGroup build() {
|
||||||
* @param name the name to set
|
return new SecurityGroup(id, name, description, tenantId);
|
||||||
*/
|
}
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public T fromSecurityGroup(SecurityGroup in) {
|
||||||
* @return the description
|
return this
|
||||||
*/
|
.id(in.getId())
|
||||||
public String getDescription() {
|
.name(in.getName())
|
||||||
return description;
|
.description(in.getDescription())
|
||||||
}
|
.tenantId(in.getTenantId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
* @param description the description to set
|
@Override
|
||||||
*/
|
protected ConcreteBuilder self() {
|
||||||
public void setDescription(String description) {
|
return this;
|
||||||
this.description = description;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private final int id;
|
||||||
* @return the tenantId
|
private final String name;
|
||||||
*/
|
private final String description;
|
||||||
public String getTenantId() {
|
private final String tenantId;
|
||||||
return tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@ConstructorProperties({
|
||||||
* @param tenantId the tenantId to set
|
"id", "name", "description", "tenant_id"
|
||||||
*/
|
})
|
||||||
public void setTenantId(String tenantId) {
|
protected SecurityGroup(int id, String name, @Nullable String description, @Nullable String tenantId) {
|
||||||
this.tenantId = tenantId;
|
this.id = id;
|
||||||
}
|
this.name = checkNotNull(name, "name");
|
||||||
|
this.description = description;
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see java.lang.Object#toString()
|
* @return the id
|
||||||
*/
|
*/
|
||||||
@Override
|
public int getId() {
|
||||||
public String toString() {
|
return this.id;
|
||||||
StringBuilder builder = new StringBuilder();
|
}
|
||||||
builder.append("SecurityGroup [id=");
|
|
||||||
builder.append(id);
|
|
||||||
builder.append(", name=");
|
|
||||||
builder.append(name);
|
|
||||||
builder.append(", description=");
|
|
||||||
builder.append(description);
|
|
||||||
builder.append(", tenantId=");
|
|
||||||
builder.append(tenantId);
|
|
||||||
builder.append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see java.lang.Object#hashCode()
|
* @return the name
|
||||||
*/
|
*/
|
||||||
@Override
|
public String getName() {
|
||||||
public int hashCode() {
|
return this.name;
|
||||||
final int prime = 31;
|
}
|
||||||
int result = 1;
|
|
||||||
result = prime * result
|
/**
|
||||||
+ ((description == null) ? 0 : description.hashCode());
|
* @return the description
|
||||||
result = prime * result + id;
|
*/
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
@Nullable
|
||||||
result = prime * result
|
public String getDescription() {
|
||||||
+ ((tenantId == null) ? 0 : tenantId.hashCode());
|
return this.description;
|
||||||
return result;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @return the tenantId
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getTenantId() {
|
||||||
|
return this.tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(id, name, description, tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
SecurityGroup that = SecurityGroup.class.cast(obj);
|
||||||
|
return Objects.equal(this.id, that.id)
|
||||||
|
&& Objects.equal(this.name, that.name)
|
||||||
|
&& Objects.equal(this.description, that.description)
|
||||||
|
&& Objects.equal(this.tenantId, that.tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("id", id).add("name", name).add("description", description).add("tenantId", tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
SecurityGroup other = (SecurityGroup) obj;
|
|
||||||
if (description == null) {
|
|
||||||
if (other.description != null)
|
|
||||||
return false;
|
|
||||||
} else if (!description.equals(other.description))
|
|
||||||
return false;
|
|
||||||
if (id != other.id)
|
|
||||||
return false;
|
|
||||||
if (name == null) {
|
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
|
||||||
return false;
|
|
||||||
if (tenantId == null) {
|
|
||||||
if (other.tenantId != null)
|
|
||||||
return false;
|
|
||||||
} else if (!tenantId.equals(other.tenantId))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,13 +18,21 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.domain;
|
package org.jclouds.openstack.nova.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
import java.net.URI;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A server is a virtual machine instance in the OpenStack Nova system. Flavor and image are
|
* A server is a virtual machine instance in the OpenStack Nova system. Flavor and image are
|
||||||
|
@ -33,102 +41,323 @@ import com.google.gson.annotations.SerializedName;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Server extends Resource {
|
public class Server extends Resource {
|
||||||
private int id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private Map<String, String> metadata = Maps.newHashMap();
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
private Addresses addresses;
|
|
||||||
private String accessIPv4;
|
|
||||||
private String accessIPv6;
|
|
||||||
private String adminPass;
|
|
||||||
private String flavorRef;
|
|
||||||
private String hostId;
|
|
||||||
private String imageRef;
|
|
||||||
private String affinityId;
|
|
||||||
private String uuid;
|
|
||||||
private Flavor flavor;
|
|
||||||
private Image image;
|
|
||||||
|
|
||||||
@SerializedName(value="key_name")
|
|
||||||
private String keyName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Actually, security groups are not returned by nova on server query but is
|
|
||||||
* needed when creating a server to specify a set of groups
|
|
||||||
*/
|
|
||||||
@SerializedName(value="security_groups")
|
|
||||||
private Set<SecurityGroup> securityGroups = Sets.newHashSet();
|
|
||||||
|
|
||||||
private Date created;
|
|
||||||
private Date updated;
|
|
||||||
|
|
||||||
public Date getCreated() {
|
|
||||||
return created;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getUpdated() {
|
public Builder<?> toBuilder() {
|
||||||
return updated;
|
return new ConcreteBuilder().fromServer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
|
||||||
|
protected String name;
|
||||||
|
protected Map<String, String> metadata = ImmutableMap.of();
|
||||||
|
protected Addresses addresses;
|
||||||
|
protected String accessIPv4;
|
||||||
|
protected String accessIPv6;
|
||||||
|
protected String adminPass;
|
||||||
|
protected String flavorRef;
|
||||||
|
protected String hostId;
|
||||||
|
protected String imageRef;
|
||||||
|
protected String affinityId;
|
||||||
|
protected String uuid;
|
||||||
|
protected Flavor flavor;
|
||||||
|
protected Image image;
|
||||||
|
protected String keyName;
|
||||||
|
protected Set<SecurityGroup> securityGroups = ImmutableSet.of();
|
||||||
|
protected Date created;
|
||||||
|
protected Date updated;
|
||||||
|
protected Integer progress;
|
||||||
|
protected ServerStatus status;
|
||||||
|
|
||||||
private Integer progress;
|
/**
|
||||||
private ServerStatus status;
|
* @see Server#getName()
|
||||||
|
*/
|
||||||
|
public T name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
public Server() {
|
/**
|
||||||
|
* @see Server#getMetadata()
|
||||||
|
*/
|
||||||
|
public T metadata(Map<String, String> metadata) {
|
||||||
|
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getAddresses()
|
||||||
|
*/
|
||||||
|
public T addresses(Addresses addresses) {
|
||||||
|
this.addresses = addresses;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getAccessIPv4()
|
||||||
|
*/
|
||||||
|
public T accessIPv4(String accessIPv4) {
|
||||||
|
this.accessIPv4 = accessIPv4;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getAccessIPv6()
|
||||||
|
*/
|
||||||
|
public T accessIPv6(String accessIPv6) {
|
||||||
|
this.accessIPv6 = accessIPv6;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getAdminPass()
|
||||||
|
*/
|
||||||
|
public T adminPass(String adminPass) {
|
||||||
|
this.adminPass = adminPass;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getFlavorRef()
|
||||||
|
*/
|
||||||
|
public T flavorRef(String flavorRef) {
|
||||||
|
this.flavorRef = flavorRef;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getHostId()
|
||||||
|
*/
|
||||||
|
public T hostId(String hostId) {
|
||||||
|
this.hostId = hostId;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getImageRef()
|
||||||
|
*/
|
||||||
|
public T imageRef(String imageRef) {
|
||||||
|
this.imageRef = imageRef;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getAffinityId()
|
||||||
|
*/
|
||||||
|
public T affinityId(String affinityId) {
|
||||||
|
this.affinityId = affinityId;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getUuid()
|
||||||
|
*/
|
||||||
|
public T uuid(String uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getFlavor()
|
||||||
|
*/
|
||||||
|
public T flavor(Flavor flavor) {
|
||||||
|
this.flavor = flavor;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getImage()
|
||||||
|
*/
|
||||||
|
public T image(Image image) {
|
||||||
|
this.image = image;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getKeyName()
|
||||||
|
*/
|
||||||
|
public T keyName(String keyName) {
|
||||||
|
this.keyName = keyName;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getSecurityGroups()
|
||||||
|
*/
|
||||||
|
public T securityGroups(Set<SecurityGroup> securityGroups) {
|
||||||
|
this.securityGroups = ImmutableSet.copyOf(checkNotNull(securityGroups, "securityGroups"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T securityGroups(SecurityGroup... in) {
|
||||||
|
return securityGroups(ImmutableSet.copyOf(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getCreated()
|
||||||
|
*/
|
||||||
|
public T created(Date created) {
|
||||||
|
this.created = created;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getUpdated()
|
||||||
|
*/
|
||||||
|
public T updated(Date updated) {
|
||||||
|
this.updated = updated;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getProgress()
|
||||||
|
*/
|
||||||
|
public T progress(Integer progress) {
|
||||||
|
this.progress = progress;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getStatus()
|
||||||
|
*/
|
||||||
|
public T status(ServerStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server build() {
|
||||||
|
return new Server(id, links, orderedSelfReferences, name, metadata, addresses, accessIPv4, accessIPv6, adminPass,
|
||||||
|
flavorRef, hostId, imageRef, affinityId, uuid, flavor, image, keyName, securityGroups, created, updated,
|
||||||
|
progress, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromServer(Server in) {
|
||||||
|
return super.fromResource(in)
|
||||||
|
.id(in.getId())
|
||||||
|
.name(in.getName())
|
||||||
|
.metadata(in.getMetadata())
|
||||||
|
.addresses(in.getAddresses())
|
||||||
|
.accessIPv4(in.getAccessIPv4())
|
||||||
|
.accessIPv6(in.getAccessIPv6())
|
||||||
|
.adminPass(in.getAdminPass())
|
||||||
|
.flavorRef(in.getFlavorRef())
|
||||||
|
.hostId(in.getHostId())
|
||||||
|
.imageRef(in.getImageRef())
|
||||||
|
.affinityId(in.getAffinityId())
|
||||||
|
.uuid(in.getUuid())
|
||||||
|
.flavor(in.getFlavor())
|
||||||
|
.image(in.getImage())
|
||||||
|
.keyName(in.getKeyName())
|
||||||
|
.securityGroups(in.getSecurityGroups())
|
||||||
|
.created(in.getCreated())
|
||||||
|
.updated(in.getUpdated())
|
||||||
|
.progress(in.getProgress())
|
||||||
|
.status(in.getStatus());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Server(int id, String name) {
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
this.id = id;
|
@Override
|
||||||
this.name = name;
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAffinityId() {
|
private final String name;
|
||||||
return affinityId;
|
private final Map<String, String> metadata;
|
||||||
}
|
private final Addresses addresses;
|
||||||
|
private final String accessIPv4;
|
||||||
|
private final String accessIPv6;
|
||||||
|
private final String adminPass;
|
||||||
|
private final String flavorRef;
|
||||||
|
private final String hostId;
|
||||||
|
private final String imageRef;
|
||||||
|
private final String affinityId;
|
||||||
|
private final String uuid;
|
||||||
|
private final Flavor flavor;
|
||||||
|
private final Image image;
|
||||||
|
private final String keyName;
|
||||||
|
private final Set<SecurityGroup> securityGroups;
|
||||||
|
private final Date created;
|
||||||
|
private final Date updated;
|
||||||
|
private final Integer progress;
|
||||||
|
private final ServerStatus status;
|
||||||
|
|
||||||
public void setAffinityId(String affinityId) {
|
@ConstructorProperties({
|
||||||
|
"id", "links", "orderedSelfReferences", "name", "metadata", "addresses", "accessIPv4", "accessIPv6", "adminPass",
|
||||||
|
"flavorRef", "hostId", "imageRef", "affinityId", "uuid", "flavor", "image", "key_name", "security_groups",
|
||||||
|
"created", "updated", "progress", "status"
|
||||||
|
})
|
||||||
|
protected Server(int id, List<Map<String, String>> links, Map<LinkType, URI> orderedSelfReferences, String name,
|
||||||
|
@Nullable Map<String, String> metadata, @Nullable Addresses addresses, @Nullable String accessIPv4,
|
||||||
|
@Nullable String accessIPv6, @Nullable String adminPass, @Nullable String flavorRef, @Nullable String hostId,
|
||||||
|
@Nullable String imageRef, @Nullable String affinityId, @Nullable String uuid, @Nullable Flavor flavor,
|
||||||
|
@Nullable Image image, @Nullable String keyName, @Nullable Set<SecurityGroup> securityGroups,
|
||||||
|
@Nullable Date created, @Nullable Date updated, @Nullable Integer progress, @Nullable ServerStatus status) {
|
||||||
|
super(id, links, orderedSelfReferences);
|
||||||
|
this.name = checkNotNull(name, "name");
|
||||||
|
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(metadata);
|
||||||
|
this.addresses = addresses;
|
||||||
|
this.accessIPv4 = accessIPv4;
|
||||||
|
this.accessIPv6 = accessIPv6;
|
||||||
|
this.adminPass = adminPass;
|
||||||
|
this.flavorRef = flavorRef;
|
||||||
|
this.hostId = hostId;
|
||||||
|
this.imageRef = imageRef;
|
||||||
this.affinityId = affinityId;
|
this.affinityId = affinityId;
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.flavor = flavor;
|
||||||
|
this.image = image;
|
||||||
|
this.keyName = keyName;
|
||||||
|
this.securityGroups = securityGroups == null ? ImmutableSet.<SecurityGroup>of() : ImmutableSet.copyOf(securityGroups);
|
||||||
|
this.created = created;
|
||||||
|
this.updated = updated;
|
||||||
|
this.progress = progress;
|
||||||
|
this.status = status == null ? ServerStatus.UNKNOWN : status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMetadata(Map<String, String> metadata) {
|
public String getName() {
|
||||||
this.metadata = metadata;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getMetadata() {
|
public Map<String, String> getMetadata() {
|
||||||
return metadata;
|
return this.metadata;
|
||||||
}
|
|
||||||
|
|
||||||
public void setAddresses(Addresses addresses) {
|
|
||||||
this.addresses = addresses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Addresses getAddresses() {
|
public Addresses getAddresses() {
|
||||||
return addresses;
|
return this.addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdminPass(String adminPass) {
|
/**
|
||||||
this.adminPass = adminPass;
|
* @return the accessIPv4
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getAccessIPv4() {
|
||||||
|
return this.accessIPv4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the accessIPv6
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getAccessIPv6() {
|
||||||
|
return this.accessIPv6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getAdminPass() {
|
public String getAdminPass() {
|
||||||
return adminPass;
|
return this.adminPass;
|
||||||
}
|
|
||||||
|
|
||||||
public void setFlavorRef(String flavorRef) {
|
|
||||||
this.flavorRef = flavorRef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getFlavor()}
|
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getFlavor()}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Nullable
|
||||||
public String getFlavorRef() {
|
public String getFlavorRef() {
|
||||||
return flavorRef;
|
return this.flavorRef;
|
||||||
}
|
|
||||||
|
|
||||||
public void setHostId(String hostId) {
|
|
||||||
this.hostId = hostId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,40 +368,64 @@ public class Server extends Resource {
|
||||||
* <p/>
|
* <p/>
|
||||||
* Note: hostId is unique PER ACCOUNT and is not globally unique.
|
* Note: hostId is unique PER ACCOUNT and is not globally unique.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getHostId() {
|
public String getHostId() {
|
||||||
return hostId;
|
return this.hostId;
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImageRef(String imageRef) {
|
|
||||||
this.imageRef = imageRef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getImage()}.
|
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getImage()}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Nullable
|
||||||
public String getImageRef() {
|
public String getImageRef() {
|
||||||
return imageRef;
|
return this.imageRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
@Nullable
|
||||||
return name;
|
public String getAffinityId() {
|
||||||
|
return this.affinityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgress(Integer progress) {
|
@Nullable
|
||||||
this.progress = progress;
|
public String getUuid() {
|
||||||
|
return this.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Flavor getFlavor() {
|
||||||
|
return this.flavor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image getImage() {
|
||||||
|
return this.image;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getKeyName() {
|
||||||
|
return this.keyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actually, security groups are not returned by nova on server query but is
|
||||||
|
* needed when creating a server to specify a set of groups
|
||||||
|
*/
|
||||||
|
public Set<SecurityGroup> getSecurityGroups() {
|
||||||
|
return this.securityGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Date getCreated() {
|
||||||
|
return this.created;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Date getUpdated() {
|
||||||
|
return this.updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Integer getProgress() {
|
public Integer getProgress() {
|
||||||
return progress;
|
return this.progress;
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(ServerStatus status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,196 +433,48 @@ public class Server extends Resource {
|
||||||
* state. Servers with an ACTIVE status are available for use.
|
* state. Servers with an ACTIVE status are available for use.
|
||||||
*/
|
*/
|
||||||
public ServerStatus getStatus() {
|
public ServerStatus getStatus() {
|
||||||
return status;
|
return this.status;
|
||||||
}
|
|
||||||
|
|
||||||
public String getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUuid(String uuid) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Flavor getFlavor() {
|
|
||||||
return flavor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFlavor(Flavor flavor) {
|
|
||||||
this.flavor = flavor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image getImage() {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImage(Image image) {
|
|
||||||
this.image = image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKeyName() {
|
|
||||||
return keyName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeyName(String keyName) {
|
|
||||||
this.keyName = keyName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<SecurityGroup> getSecurityGroups() {
|
|
||||||
return securityGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSecurityGroups(Set<SecurityGroup> securityGroups) {
|
|
||||||
this.securityGroups = securityGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the accessIPv4
|
|
||||||
*/
|
|
||||||
public String getAccessIPv4() {
|
|
||||||
return accessIPv4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param accessIPv4
|
|
||||||
* the accessIPv4 to set
|
|
||||||
*/
|
|
||||||
public void setAccessIPv4(String accessIPv4) {
|
|
||||||
this.accessIPv4 = accessIPv4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the accessIPv6
|
|
||||||
*/
|
|
||||||
public String getAccessIPv6() {
|
|
||||||
return accessIPv6;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param accessIPv6
|
|
||||||
* the accessIPv6 to set
|
|
||||||
*/
|
|
||||||
public void setAccessIPv6(String accessIPv6) {
|
|
||||||
this.accessIPv6 = accessIPv6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(super.hashCode(), name, metadata, addresses, accessIPv4, accessIPv6, adminPass, flavorRef,
|
||||||
int result = 1;
|
hostId, imageRef, affinityId, uuid, flavor, image, keyName, securityGroups, created, updated);
|
||||||
result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
|
|
||||||
result = prime * result + ((adminPass == null) ? 0 : adminPass.hashCode());
|
|
||||||
result = prime * result + ((flavorRef == null) ? 0 : flavorRef.hashCode());
|
|
||||||
result = prime * result + ((hostId == null) ? 0 : hostId.hashCode());
|
|
||||||
result = prime * result + id;
|
|
||||||
result = prime * result + ((imageRef == null) ? 0 : imageRef.hashCode());
|
|
||||||
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
|
||||||
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
|
|
||||||
result = prime * result + ((keyName == null) ? 0 : keyName.hashCode());
|
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
|
||||||
result = prime * result + ((flavor == null) ? 0 : flavor.hashCode());
|
|
||||||
result = prime * result + ((image == null) ? 0 : image.hashCode());
|
|
||||||
result = prime * result + ((accessIPv4 == null) ? 0 : accessIPv4.hashCode());
|
|
||||||
result = prime * result + ((accessIPv6 == null) ? 0 : accessIPv6.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Server that = Server.class.cast(obj);
|
||||||
return false;
|
return super.equals(that)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.name, that.name)
|
||||||
return false;
|
&& Objects.equal(this.metadata, that.metadata)
|
||||||
Server other = (Server) obj;
|
&& Objects.equal(this.addresses, that.addresses)
|
||||||
if (addresses == null) {
|
&& Objects.equal(this.accessIPv4, that.accessIPv4)
|
||||||
if (other.addresses != null)
|
&& Objects.equal(this.accessIPv6, that.accessIPv6)
|
||||||
return false;
|
&& Objects.equal(this.adminPass, that.adminPass)
|
||||||
} else if (!addresses.equals(other.addresses))
|
&& Objects.equal(this.flavorRef, that.flavorRef)
|
||||||
return false;
|
&& Objects.equal(this.hostId, that.hostId)
|
||||||
if (adminPass == null) {
|
&& Objects.equal(this.imageRef, that.imageRef)
|
||||||
if (other.adminPass != null)
|
&& Objects.equal(this.affinityId, that.affinityId)
|
||||||
return false;
|
&& Objects.equal(this.uuid, that.uuid)
|
||||||
} else if (!adminPass.equals(other.adminPass))
|
&& Objects.equal(this.flavor, that.flavor)
|
||||||
return false;
|
&& Objects.equal(this.image, that.image)
|
||||||
if (flavorRef == null) {
|
&& Objects.equal(this.keyName, that.keyName)
|
||||||
if (other.flavorRef != null)
|
&& Objects.equal(this.securityGroups, that.securityGroups)
|
||||||
return false;
|
&& Objects.equal(this.created, that.created)
|
||||||
} else if (!flavorRef.equals(other.flavorRef))
|
&& Objects.equal(this.updated, that.updated);
|
||||||
return false;
|
|
||||||
if (hostId == null) {
|
|
||||||
if (other.hostId != null)
|
|
||||||
return false;
|
|
||||||
} else if (!hostId.equals(other.hostId))
|
|
||||||
return false;
|
|
||||||
if (id != other.id)
|
|
||||||
return false;
|
|
||||||
if (imageRef == null) {
|
|
||||||
if (other.imageRef != null)
|
|
||||||
return false;
|
|
||||||
} else if (!imageRef.equals(other.imageRef))
|
|
||||||
return false;
|
|
||||||
if (metadata == null) {
|
|
||||||
if (other.metadata != null)
|
|
||||||
return false;
|
|
||||||
} else if (!metadata.equals(other.metadata))
|
|
||||||
return false;
|
|
||||||
if (securityGroups == null) {
|
|
||||||
if (other.securityGroups != null)
|
|
||||||
return false;
|
|
||||||
} else if (!securityGroups.equals(other.securityGroups))
|
|
||||||
return false;
|
|
||||||
if (uuid == null) {
|
|
||||||
if (other.uuid != null)
|
|
||||||
return false;
|
|
||||||
} else if (!uuid.equals(other.uuid))
|
|
||||||
return false;
|
|
||||||
if (keyName == null) {
|
|
||||||
if (other.keyName != null)
|
|
||||||
return false;
|
|
||||||
} else if (!keyName.equals(other.keyName))
|
|
||||||
return false;
|
|
||||||
if (name == null) {
|
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
|
||||||
return false;
|
|
||||||
if (flavor == null) {
|
|
||||||
if (other.flavor != null)
|
|
||||||
return false;
|
|
||||||
} else if (!flavor.equals(other.flavor))
|
|
||||||
return false;
|
|
||||||
if (image == null) {
|
|
||||||
if (other.image != null)
|
|
||||||
return false;
|
|
||||||
} else if (!image.equals(other.image))
|
|
||||||
return false;
|
|
||||||
if (accessIPv4 == null) {
|
|
||||||
if (other.accessIPv4 != null)
|
|
||||||
return false;
|
|
||||||
} else if (!accessIPv4.equals(other.accessIPv4))
|
|
||||||
return false;
|
|
||||||
if (accessIPv6 == null) {
|
|
||||||
if (other.accessIPv6 != null)
|
|
||||||
return false;
|
|
||||||
} else if (!accessIPv6.equals(other.accessIPv6))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
protected ToStringHelper string() {
|
||||||
this.name = name;
|
return super.string()
|
||||||
|
.add("name", name).add("metadata", metadata).add("addresses", addresses)
|
||||||
|
.add("accessIPv4", accessIPv4).add("accessIPv6", accessIPv6).add("adminPass", adminPass)
|
||||||
|
.add("flavorRef", flavorRef).add("hostId", hostId).add("imageRef", imageRef).add("affinityId", affinityId)
|
||||||
|
.add("uuid", uuid).add("flavor", flavor).add("image", image).add("keyName", keyName)
|
||||||
|
.add("securityGroups", securityGroups).add("created", created).add("updated", updated)
|
||||||
|
.add("progress", progress).add("status", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Server [addresses=" + addresses + ", accessIPv4=" + accessIPv4
|
|
||||||
+ ", accessIPv6=" + accessIPv6 + ", adminPass=" + adminPass
|
|
||||||
+ ", flavorRef=" + flavorRef + ", hostId=" + hostId + ", id="
|
|
||||||
+ id + ", imageRef=" + imageRef + ", metadata=" + metadata
|
|
||||||
+ ", uuid=" + uuid + ", name=" + name + ", keyName=" + keyName
|
|
||||||
+ " , securityGroups=" + securityGroups + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,14 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.encryption.internal.Base64;
|
import org.jclouds.encryption.internal.Base64;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
@ -39,12 +41,9 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CreateServerOptions implements MapBinder {
|
public class CreateServerOptions implements MapBinder {
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -73,24 +72,30 @@ public class CreateServerOptions implements MapBinder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private class ServerRequest {
|
private class ServerRequest {
|
||||||
final String name;
|
final String name;
|
||||||
final String imageRef;
|
final String imageRef;
|
||||||
final String flavorRef;
|
final String flavorRef;
|
||||||
String adminPass;
|
final String adminPass;
|
||||||
Map<String, String> metadata;
|
final Map<String, String> metadata;
|
||||||
List<File> personality;
|
final List<File> personality;
|
||||||
String key_name;
|
@Named("key_name")
|
||||||
@SerializedName(value="security_groups")
|
final String keyName;
|
||||||
Set<SecurityGroup> securityGroups;
|
@Named("security_groups")
|
||||||
|
final Set<SecurityGroup> securityGroups;
|
||||||
|
|
||||||
private ServerRequest(String name, String imageRef, String flavorRef) {
|
@ConstructorProperties({"name", "imageRef", "flavorRef", "adminPass", "metadata", "personality", "key_name", "security_groups"})
|
||||||
|
private ServerRequest(String name, String imageRef, String flavorRef, String adminPass, Map<String, String> metadata,
|
||||||
|
List<File> personality, String keyName, Set<SecurityGroup> securityGroups) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.imageRef = imageRef;
|
this.imageRef = imageRef;
|
||||||
this.flavorRef = flavorRef;
|
this.flavorRef = flavorRef;
|
||||||
|
this.adminPass = adminPass;
|
||||||
|
this.metadata = metadata.isEmpty() ? null : metadata;
|
||||||
|
this.personality = personality.isEmpty() ? null : personality;
|
||||||
|
this.keyName = keyName;
|
||||||
|
this.securityGroups = securityGroups.isEmpty() ? null : securityGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> metadata = Maps.newHashMap();
|
private Map<String, String> metadata = Maps.newHashMap();
|
||||||
|
@ -101,26 +106,19 @@ public class CreateServerOptions implements MapBinder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||||
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present").toString(),
|
Set<SecurityGroup> groups = Sets.newLinkedHashSet();
|
||||||
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
|
for (String groupName : securityGroups) {
|
||||||
checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString());
|
groups.add(SecurityGroup.builder().name(groupName).build());
|
||||||
if (metadata.size() > 0)
|
|
||||||
server.metadata = metadata;
|
|
||||||
if (files.size() > 0)
|
|
||||||
server.personality = files;
|
|
||||||
if (keyName != null)
|
|
||||||
server.key_name = keyName;
|
|
||||||
if (securityGroups.size() > 0) {
|
|
||||||
server.securityGroups = Sets.newHashSet();
|
|
||||||
for (String groupName : securityGroups) {
|
|
||||||
SecurityGroup group = new SecurityGroup();
|
|
||||||
group.setName(groupName);
|
|
||||||
server.securityGroups.add(group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (adminPass != null) {
|
|
||||||
server.adminPass = adminPass;
|
|
||||||
}
|
}
|
||||||
|
ServerRequest server = new ServerRequest(
|
||||||
|
checkNotNull(postParams.get("name"), "name parameter not present").toString(),
|
||||||
|
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
|
||||||
|
checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString(),
|
||||||
|
adminPass,
|
||||||
|
metadata,
|
||||||
|
files,
|
||||||
|
keyName,
|
||||||
|
groups);
|
||||||
|
|
||||||
return bindToRequest(request, ImmutableMap.of("server", server));
|
return bindToRequest(request, ImmutableMap.of("server", server));
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,19 +30,17 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ServerTest {
|
public class ServerTest {
|
||||||
public void testStatusDoesntAffectEquals() {
|
public void testStatusDoesntAffectEquals() {
|
||||||
Server server1 = new Server(1, "hello");
|
Server server1 = Server.builder().id(1).name("hello").status(ServerStatus.ACTIVE).build();
|
||||||
server1.setStatus(ServerStatus.ACTIVE);
|
Server server2 = Server.builder().id(1).name("hello").status(ServerStatus.BUILD).build();
|
||||||
Server server2 = new Server(1, "hello");
|
|
||||||
server2.setStatus(ServerStatus.BUILD);
|
|
||||||
assertEquals(server1, server2);
|
assertEquals(server1, server2);
|
||||||
|
assertEquals(server1.hashCode(), server2.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testProgressDoesntAffectEquals() {
|
public void testProgressDoesntAffectEquals() {
|
||||||
Server server1 = new Server(1, "hello");
|
Server server1 = Server.builder().id(1).name("hello").progress(1).build();
|
||||||
server1.setProgress(1);
|
Server server2 = Server.builder().id(1).name("hello").progress(2).build();
|
||||||
Server server2 = new Server(1, "hello");
|
|
||||||
server2.setProgress(2);
|
|
||||||
assertEquals(server1, server2);
|
assertEquals(server1, server2);
|
||||||
|
assertEquals(server1.hashCode(), server2.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,8 @@ public class ParseFlavorListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
|
||||||
|
|
||||||
List<Flavor> expects = ImmutableList.of(new Flavor(1, "256 MB Server", null, null, null), new Flavor(2,
|
List<Flavor> expects = ImmutableList.of(Flavor.builder().id(1).name("256 MB Server").build(),
|
||||||
"512 MB Server", null, null, null));
|
Flavor.builder().id(2).name("512 MB Server").build());
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
|
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class ParseFloatingIPListFromJsonResponse {
|
||||||
.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
||||||
|
|
||||||
assertEquals(response.size(), 1);
|
assertEquals(response.size(), 1);
|
||||||
FloatingIP floatingIP = new FloatingIP(1, "10.0.0.3", "11.0.0.1", 12);
|
FloatingIP floatingIP = FloatingIP.builder().id(1).ip("10.0.0.3").fixedIP("11.0.0.1").instanceID(12).build();
|
||||||
assertEquals(response.get(0), floatingIP);
|
assertEquals(response.get(0), floatingIP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,8 @@ public class ParseImageListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
|
||||||
|
|
||||||
List<Image> expects = ImmutableList.of(new Image(1, "CentOS 5.2"), new Image(743, "My Server Backup"));
|
List<Image> expects = ImmutableList.of(Image.builder().id(1).name("CentOS 5.2").build(),
|
||||||
|
Image.builder().id(743).name("My Server Backup").build());
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
|
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.SimpleTimeZone;
|
import java.util.SimpleTimeZone;
|
||||||
|
@ -74,9 +73,9 @@ public class ParseServerFromJsonResponseDiabloTest {
|
||||||
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||||
Address.newString2AddressFunction()));
|
Address.newString2AddressFunction()));
|
||||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
||||||
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
|
|
||||||
new HashSet<Address>(privateAddresses));
|
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.io.InputStream;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.SimpleTimeZone;
|
import java.util.SimpleTimeZone;
|
||||||
|
@ -75,9 +74,8 @@ public class ParseServerFromJsonResponseTest {
|
||||||
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||||
Address.newString2AddressFunction()));
|
Address.newString2AddressFunction()));
|
||||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
||||||
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
|
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
|
||||||
new HashSet<Address>(privateAddresses));
|
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
@ -62,11 +61,12 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
|
||||||
|
|
||||||
List<Server> expects = ImmutableList.of(new Server(1234, "sample-server"), new Server(5678, "sample-server2"));
|
List<Server> expects = ImmutableList.of(Server.builder().id(1234).name("sample-server").build(),
|
||||||
|
Server.builder().id(5678).name("sample-server2").build());
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
||||||
}));
|
}));
|
||||||
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
||||||
|
|
||||||
assertEquals(response, expects);
|
assertEquals(response, expects);
|
||||||
|
@ -77,8 +77,8 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json");
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
|
||||||
}));
|
}));
|
||||||
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
||||||
|
|
||||||
assertEquals(response.get(0).getId(), 1234);
|
assertEquals(response.get(0).getId(), 1234);
|
||||||
|
@ -91,12 +91,11 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
|
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
|
||||||
|
|
||||||
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
|
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||||
Address.newString2AddressFunction()));
|
Address.newString2AddressFunction()));
|
||||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
||||||
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses),
|
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
|
||||||
new HashSet<Address>(privateAddresses));
|
|
||||||
|
|
||||||
assertEquals(response.get(0).getAddresses(), addresses1);
|
assertEquals(response.get(0).getAddresses(), addresses1);
|
||||||
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
|
@ -111,11 +110,11 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
assertEquals(response.get(1).getProgress(), null);
|
assertEquals(response.get(1).getProgress(), null);
|
||||||
|
|
||||||
List<Address> publicAddresses2 = ImmutableList.copyOf(Iterables.transform(
|
List<Address> publicAddresses2 = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("67.23.10.133", "::babe:67.23.10.133"), Address.newString2AddressFunction()));
|
ImmutableList.of("67.23.10.133", "::babe:67.23.10.133"), Address.newString2AddressFunction()));
|
||||||
List<Address> privateAddresses2 = ImmutableList.copyOf(Iterables.transform(
|
List<Address> privateAddresses2 = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("10.176.42.17", "::babe:10.176.42.17"), Address.newString2AddressFunction()));
|
ImmutableList.of("10.176.42.17", "::babe:10.176.42.17"), Address.newString2AddressFunction()));
|
||||||
Addresses addresses2 = new Addresses(new HashSet<Address>(publicAddresses2), new HashSet<Address>(
|
|
||||||
privateAddresses2));
|
Addresses addresses2 = Addresses.builder().publicAddresses(publicAddresses2).privateAddresses(privateAddresses2).build();
|
||||||
|
|
||||||
assertEquals(response.get(1).getAddresses(), addresses2);
|
assertEquals(response.get(1).getAddresses(), addresses2);
|
||||||
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,6 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.swift.domain;
|
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
|
* @author James Murty
|
||||||
|
@ -25,64 +30,94 @@ package org.jclouds.openstack.swift.domain;
|
||||||
*/
|
*/
|
||||||
public class AccountMetadata {
|
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.containerCount = containerCount;
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountMetadata() {
|
public long getContainerCount() {
|
||||||
|
return this.containerCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public long getBytes() {
|
||||||
public String toString() {
|
return this.bytes;
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("ResourceMetadata [bytes=").append(bytes)
|
|
||||||
.append(", containerCount=").append(containerCount).append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(containerCount, bytes);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (int) (bytes ^ (bytes >>> 32));
|
|
||||||
result = prime * result + (int) (containerCount ^ (containerCount >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
AccountMetadata that = AccountMetadata.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.containerCount, that.containerCount)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.bytes, that.bytes);
|
||||||
return false;
|
|
||||||
AccountMetadata other = (AccountMetadata) obj;
|
|
||||||
if (bytes != other.bytes)
|
|
||||||
return false;
|
|
||||||
if (containerCount != other.containerCount)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private long containerCount;
|
protected ToStringHelper string() {
|
||||||
private long bytes;
|
return Objects.toStringHelper(this)
|
||||||
|
.add("containerCount", containerCount).add("bytes", bytes);
|
||||||
public void setContainerCount(long count) {
|
|
||||||
this.containerCount = count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getContainerCount() {
|
@Override
|
||||||
return containerCount;
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBytes(long bytes) {
|
|
||||||
this.bytes = bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getBytes() {
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,117 +18,163 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.swift.domain;
|
package org.jclouds.openstack.swift.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Class ContainerMetadata
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ContainerMetadata implements Comparable<ContainerMetadata> {
|
public class 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 static Builder<?> builder() {
|
||||||
public ContainerMetadata() {
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContainerMetadata(String name, long count, long bytes, String readACL, Map<String, String> metadata) {
|
public Builder<?> toBuilder() {
|
||||||
this.name = name;
|
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.count = count;
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
this.readACL = readACL;
|
this.readACL = readACL;
|
||||||
this.metadata = metadata;
|
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(metadata);
|
||||||
}
|
|
||||||
|
|
||||||
public long getCount() {
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCount(long count) {
|
|
||||||
this.count = count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public long getCount() {
|
||||||
this.name = name;
|
return this.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getBytes() {
|
public long getBytes() {
|
||||||
return bytes;
|
return this.bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBytes(long bytes) {
|
@Nullable
|
||||||
this.bytes = bytes;
|
public String getReadACL() {
|
||||||
}
|
return this.readACL;
|
||||||
|
|
||||||
public boolean isPublic() {
|
|
||||||
if (readACL == null)
|
|
||||||
return false;
|
|
||||||
return readACL.equals(".r:*,.rlistings");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReadACL(String readACL) {
|
|
||||||
this.readACL = readACL;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getMetadata() {
|
public Map<String, String> getMetadata() {
|
||||||
return metadata;
|
return this.metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(name, count, bytes);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
ContainerMetadata that = ContainerMetadata.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.name, that.name)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.count, that.count)
|
||||||
return false;
|
&& Objects.equal(this.bytes, that.bytes);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(ContainerMetadata o) {
|
protected ToStringHelper string() {
|
||||||
if (getName() == null)
|
return Objects.toStringHelper(this)
|
||||||
return -1;
|
.add("name", name).add("count", count).add("bytes", bytes).add("readACL", readACL).add("metadata", metadata);
|
||||||
return (this == o) ? 0 : getName().compareTo(o.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ContainerMetadata [name=" + name + ", count=" + count + ", bytes="
|
return string().toString();
|
||||||
+ bytes + ", isPublic=" + isPublic() + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,86 +18,141 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.swift.domain.internal;
|
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.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.openstack.swift.domain.ObjectInfo;
|
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 class ObjectInfoImpl implements ObjectInfo {
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private String name;
|
return new ConcreteBuilder().fromObjectInfoImpl(this);
|
||||||
private String container;
|
}
|
||||||
private URI uri;
|
|
||||||
private byte[] hash;
|
|
||||||
private Long bytes;
|
|
||||||
private String contentType;
|
|
||||||
private Date lastModified;
|
|
||||||
|
|
||||||
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;
|
this.name = name;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder container(String container) {
|
/**
|
||||||
|
* @see ObjectInfoImpl#getContainer()
|
||||||
|
*/
|
||||||
|
public T container(String container) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder uri(URI uri) {
|
/**
|
||||||
|
* @see ObjectInfoImpl#getUri()
|
||||||
|
*/
|
||||||
|
public T uri(URI uri) {
|
||||||
this.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;
|
this.hash = hash;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder bytes(Long bytes) {
|
/**
|
||||||
|
* @see ObjectInfoImpl#getBytes()
|
||||||
|
*/
|
||||||
|
public T bytes(Long bytes) {
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder contentType(String contentType) {
|
/**
|
||||||
|
* @see ObjectInfoImpl#getContentType()
|
||||||
|
*/
|
||||||
|
public T contentType(String contentType) {
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder lastModified(Date lastModified) {
|
/**
|
||||||
|
* @see ObjectInfoImpl#getLastModified()
|
||||||
|
*/
|
||||||
|
public T lastModified(Date lastModified) {
|
||||||
this.lastModified = lastModified;
|
this.lastModified = lastModified;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectInfoImpl build() {
|
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) {
|
public T fromObjectInfoImpl(ObjectInfoImpl in) {
|
||||||
return name(in.getName()).container(in.getContainer()).uri(uri).hash(in.getHash()).bytes(in.getBytes())
|
return this
|
||||||
.contentType(in.getContentType()).lastModified(in.getLastModified());
|
.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 static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private String container;
|
@Override
|
||||||
private URI uri;
|
protected ConcreteBuilder self() {
|
||||||
private byte[] hash;
|
return this;
|
||||||
private Long bytes;
|
}
|
||||||
@SerializedName("content_type")
|
}
|
||||||
private String contentType;
|
|
||||||
@SerializedName("last_modified")
|
|
||||||
private Date lastModified;
|
|
||||||
|
|
||||||
public ObjectInfoImpl(String name, URI uri, String container, byte[] hash, Long bytes, String contentType,
|
private final String name;
|
||||||
Date lastModified) {
|
private final String container;
|
||||||
this.name = name;
|
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.container = container;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
|
@ -106,110 +161,88 @@ public class ObjectInfoImpl implements ObjectInfo {
|
||||||
this.lastModified = lastModified;
|
this.lastModified = lastModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectInfoImpl() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Nullable
|
||||||
public String getContainer() {
|
public String getContainer() {
|
||||||
return container;
|
return this.container;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Nullable
|
||||||
public URI getUri() {
|
public URI getUri() {
|
||||||
return uri;
|
return this.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Nullable
|
||||||
public byte[] getHash() {
|
public byte[] getHash() {
|
||||||
return hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Nullable
|
||||||
public Long getBytes() {
|
public Long getBytes() {
|
||||||
return bytes;
|
return this.bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Nullable
|
||||||
public String getContentType() {
|
public String getContentType() {
|
||||||
return contentType;
|
return this.contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Nullable
|
||||||
public Date getLastModified() {
|
public Date getLastModified() {
|
||||||
return lastModified;
|
return this.lastModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(name, container);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((container == null) ? 0 : container.hashCode());
|
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
ObjectInfoImpl that = ObjectInfoImpl.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.name, that.name)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.container, that.container);
|
||||||
return false;
|
}
|
||||||
ObjectInfoImpl other = (ObjectInfoImpl) obj;
|
|
||||||
if (container == null) {
|
protected ToStringHelper string() {
|
||||||
if (other.container != null)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("name", name).add("container", container).add("uri", uri).add("hash", Arrays.toString(hash))
|
||||||
} else if (!container.equals(other.container))
|
.add("bytes", bytes).add("contentType", contentType).add("lastModified", lastModified);
|
||||||
return false;
|
|
||||||
if (name == null) {
|
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("[name=%s, container=%s, uri=%s, bytes=%s, contentType=%s, lastModified=%s, hash=%s]", name,
|
return string().toString();
|
||||||
container, uri, bytes, contentType, lastModified, Arrays.toString(hash));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder toBuilder() {
|
|
||||||
return builder().fromObjectInfo(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(ObjectInfo o) {
|
public int compareTo(ObjectInfo other) {
|
||||||
return name.compareTo(o.getName());
|
return ComparisonChain.start().compare(name, other.getName()).compare(container, other.getContainer()).result();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,10 @@ public class ParseAccountMetadataResponseFromHeaders implements Function<HttpRes
|
||||||
*/
|
*/
|
||||||
public AccountMetadata apply(final HttpResponse from) {
|
public AccountMetadata apply(final HttpResponse from) {
|
||||||
String bytesString = checkNotNull(from.getFirstHeaderOrNull(SwiftHeaders.ACCOUNT_BYTES_USED),
|
String bytesString = checkNotNull(from.getFirstHeaderOrNull(SwiftHeaders.ACCOUNT_BYTES_USED),
|
||||||
SwiftHeaders.ACCOUNT_BYTES_USED);
|
SwiftHeaders.ACCOUNT_BYTES_USED);
|
||||||
String containersCountString = checkNotNull(from.getFirstHeaderOrNull(SwiftHeaders.ACCOUNT_CONTAINER_COUNT),
|
String containersCountString = checkNotNull(from.getFirstHeaderOrNull(SwiftHeaders.ACCOUNT_CONTAINER_COUNT),
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,8 @@ public class ParseContainerListFromJsonResponseTest {
|
||||||
.toInputStream("[ {\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}, {\"name\":\"test_container_2\",\"count\":1,\"bytes\":17} ] ");
|
.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>();
|
Map<String, String> meta = new HashMap<String, String>();
|
||||||
|
|
||||||
List<ContainerMetadata> expects = ImmutableList.of(new ContainerMetadata("test_container_1", 2, 78, null, meta),
|
List<ContainerMetadata> expects = ImmutableList.of(ContainerMetadata.builder().name("test_container_1").count( 2).bytes(78).metadata(meta).build(),
|
||||||
new ContainerMetadata("test_container_2", 1, 17, null, meta));
|
ContainerMetadata.builder().name("test_container_2").count(1).bytes(17).metadata(meta).build());
|
||||||
ParseJson<List<ContainerMetadata>> parser = i.getInstance(Key
|
ParseJson<List<ContainerMetadata>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<ParseJson<List<ContainerMetadata>>>() {
|
.get(new TypeLiteral<ParseJson<List<ContainerMetadata>>>() {
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
|
||||||
return immediateFuture(Sets.newHashSet(Iterables.transform(listing,
|
return immediateFuture(Sets.newHashSet(Iterables.transform(listing,
|
||||||
new Function<StorageMetadata, ContainerMetadata>() {
|
new Function<StorageMetadata, ContainerMetadata>() {
|
||||||
public ContainerMetadata apply(StorageMetadata md) {
|
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();
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,19 +18,24 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.gogrid.functions;
|
package org.jclouds.gogrid.functions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.gogrid.domain.Server;
|
import org.jclouds.gogrid.domain.Server;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.functions.ParseJson;
|
import org.jclouds.http.functions.ParseJson;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
|
@ -49,10 +54,17 @@ public class ParseServerNameToCredentialsMapFromJsonResponse implements
|
||||||
// incidental view class to assist in getting the correct data
|
// incidental view class to assist in getting the correct data
|
||||||
// deserialized from json
|
// deserialized from json
|
||||||
private static class Password implements Comparable<Password> {
|
private static class Password implements Comparable<Password> {
|
||||||
@SerializedName("username")
|
@Named("username")
|
||||||
private String userName;
|
private final String userName;
|
||||||
private String password;
|
private final String password;
|
||||||
private Server server;
|
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() {
|
public String getUserName() {
|
||||||
return userName;
|
return userName;
|
||||||
|
@ -73,33 +85,22 @@ public class ParseServerNameToCredentialsMapFromJsonResponse implements
|
||||||
if (o == null || getClass() != o.getClass())
|
if (o == null || getClass() != o.getClass())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Password password1 = (Password) o;
|
Password other = (Password) o;
|
||||||
|
return Objects.equal(userName, other.userName)
|
||||||
if (password != null ? !password.equals(password1.password)
|
&& Objects.equal(password, other.password)
|
||||||
: password1.password != null)
|
&& Objects.equal(server, other.server);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = userName != null ? userName.hashCode() : 0;
|
return Objects.hashCode(userName, password, server);
|
||||||
result = 31 * result + (password != null ? password.hashCode() : 0);
|
|
||||||
result = 31 * result + (server != null ? server.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Password o) {
|
public int compareTo(Password o) {
|
||||||
if (null == o.getServer() || null == server) return -1;
|
if (null == o.getServer()) return null == server ? 0 : -1;
|
||||||
return server.getName().compareTo(o.getServer().getName());
|
if (server == null) return 1;
|
||||||
|
return server.getName().compareTo(o.getServer().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +108,9 @@ public class ParseServerNameToCredentialsMapFromJsonResponse implements
|
||||||
public Map<String, Credentials> apply(HttpResponse arg0) {
|
public Map<String, Credentials> apply(HttpResponse arg0) {
|
||||||
Map<String, Credentials> serverNameToCredentials = Maps.newHashMap();
|
Map<String, Credentials> serverNameToCredentials = Maps.newHashMap();
|
||||||
for (Password password : json.apply(arg0).getList()) {
|
for (Password password : json.apply(arg0).getList()) {
|
||||||
if( null != password.getServer())
|
if (null != password.getServer())
|
||||||
serverNameToCredentials.put(password.getServer().getName(),
|
serverNameToCredentials.put(password.getServer().getName(),
|
||||||
new Credentials(password.getUserName(), password.getPassword()));
|
new Credentials(password.getUserName(), password.getPassword()));
|
||||||
}
|
}
|
||||||
return serverNameToCredentials;
|
return serverNameToCredentials;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,57 +18,198 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.hpcloud.objectstorage.domain;
|
package org.jclouds.hpcloud.objectstorage.domain;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.net.URI;
|
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
|
* @author James Murty
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
|
public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
|
||||||
|
|
||||||
protected ContainerCDNMetadata() {
|
public static Builder<?> builder() {
|
||||||
// we want serializers like Gson to work w/o using sun.misc.Unsafe,
|
return new ConcreteBuilder();
|
||||||
// prohibited in GAE. This also implies fields are not final.
|
|
||||||
// see http://code.google.com/p/jclouds/issues/detail?id=925
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String name;
|
public Builder<?> toBuilder() {
|
||||||
private boolean cdn_enabled;
|
return new ConcreteBuilder().fromContainerCDNMetadata(this);
|
||||||
private long ttl;
|
}
|
||||||
@SerializedName("x-cdn-uri")
|
|
||||||
private URI cdn_uri;
|
|
||||||
private String referrer_acl;
|
|
||||||
private String useragent_acl;
|
|
||||||
private boolean log_retention;
|
|
||||||
|
|
||||||
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;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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.name = name;
|
||||||
this.cdn_enabled = cdnEnabled;
|
this.cdnEnabled = cdnEnabled;
|
||||||
this.ttl = ttl;
|
this.ttl = ttl;
|
||||||
this.cdn_uri = cdnUri;
|
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
|
* Beware: The container name is not available from HEAD CDN responses and will be null.
|
||||||
* the name of the container to which these CDN settings apply.
|
*
|
||||||
|
* @return the name of the container to which these CDN settings apply.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
|
||||||
|
|
||||||
public URI getCDNUri() {
|
|
||||||
return cdn_uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTTL() {
|
|
||||||
return ttl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCDNEnabled() {
|
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) {
|
public int compareTo(ContainerCDNMetadata o) {
|
||||||
|
@ -76,48 +217,4 @@ public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
|
||||||
return -1;
|
return -1;
|
||||||
return (this == o) ? 0 : getName().compareTo(o.getName());
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,11 +58,12 @@ public class ParseContainerCDNMetadataFromHeaders implements
|
||||||
// CDN is not enabled for this container.
|
// CDN is not enabled for this container.
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
// just need the name from the path
|
// just need the name from the path
|
||||||
List<String> parts = newArrayList(Splitter.on('/').split(request.getEndpoint().getPath()));
|
List<String> parts = newArrayList(Splitter.on('/').split(request.getEndpoint().getPath()));
|
||||||
|
|
||||||
return new ContainerCDNMetadata(parts.get(parts.size()-1), Boolean
|
return ContainerCDNMetadata.builder().name(parts.get(parts.size() - 1))
|
||||||
.parseBoolean(cdnEnabled), Long.parseLong(cdnTTL), URI.create(cdnUri));
|
.CDNEnabled(Boolean.parseBoolean(cdnEnabled)).ttl(Long.parseLong(cdnTTL)).CDNUri(URI.create(cdnUri))
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.hpcloud.objectstorage.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
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.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
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.
|
* HTTP headers.
|
||||||
*
|
*
|
||||||
* @author Jeremy Daggett
|
* @author Jeremy Daggett
|
||||||
|
@ -43,28 +45,23 @@ public class ParseContainerMetadataFromHeaders implements Function<HttpResponse,
|
||||||
private GeneratedHttpRequest request;
|
private GeneratedHttpRequest request;
|
||||||
|
|
||||||
public ContainerMetadata apply(HttpResponse from) {
|
public ContainerMetadata apply(HttpResponse from) {
|
||||||
ContainerMetadata to = new ContainerMetadata();
|
return ContainerMetadata.builder().name(request.getArgs().get(0).toString())
|
||||||
|
.readACL(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_READ))
|
||||||
to.setName(request.getArgs().get(0).toString());
|
.bytes(Long.valueOf(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_BYTES_USED)))
|
||||||
|
.count(Long.valueOf(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_OBJECT_COUNT)))
|
||||||
to.setReadACL(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_READ));
|
.metadata(extractUserMetadata(from)).build();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@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()) {
|
for (Entry<String, String> header : from.getHeaders().entries()) {
|
||||||
if (header.getKey() != null && header.getKey().startsWith(SwiftHeaders.CONTAINER_METADATA_PREFIX))
|
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());
|
header.getValue());
|
||||||
}
|
}
|
||||||
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -92,7 +92,8 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes
|
||||||
assertTrue(cdnMetadataList.size() >= 1);
|
assertTrue(cdnMetadataList.size() >= 1);
|
||||||
|
|
||||||
final long initialTTL = cdnMetadata.getTTL();
|
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 =
|
* Test listing with options FIXFIX cdnMetadataList =
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.http.functions.ParseJson;
|
||||||
import org.jclouds.json.config.GsonModule;
|
import org.jclouds.json.config.GsonModule;
|
||||||
import org.testng.annotations.Test;
|
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.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
|
@ -51,17 +51,17 @@ public class ParseContainerCDNMetadataListFromJsonResponseTest {
|
||||||
|
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_cdn.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_cdn.json");
|
||||||
|
|
||||||
Set<ContainerCDNMetadata> expects = ImmutableSortedSet.of(
|
Set<ContainerCDNMetadata> expects = ImmutableSet.of(
|
||||||
new ContainerCDNMetadata("hpcloud-blobstore.testCDNOperationsContainerWithCDN", false, 3600,
|
ContainerCDNMetadata.builder().name("hpcloud-blobstore.testCDNOperationsContainerWithCDN").CDNEnabled(false).ttl(3600)
|
||||||
URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")),
|
.CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build(),
|
||||||
new ContainerCDNMetadata("hpcloud-blobstore5", true, 28800,
|
ContainerCDNMetadata.builder().name("hpcloud-blobstore5").CDNEnabled(true).ttl(28800)
|
||||||
URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")),
|
.CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build(),
|
||||||
new ContainerCDNMetadata("hpcloud-cfcdnint.testCDNOperationsContainerWithCDN", false, 3600,
|
ContainerCDNMetadata.builder().name("hpcloud-cfcdnint.testCDNOperationsContainerWithCDN").CDNEnabled(false).ttl(3600)
|
||||||
URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")));
|
.CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build());
|
||||||
|
|
||||||
ParseJson<SortedSet<ContainerCDNMetadata>> parser = i.getInstance(Key
|
ParseJson<SortedSet<ContainerCDNMetadata>> parser = i.getInstance(
|
||||||
.get(new TypeLiteral<ParseJson<SortedSet<ContainerCDNMetadata>>>() {
|
Key.get(new TypeLiteral<ParseJson<SortedSet<ContainerCDNMetadata>>>() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
assertEquals(parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()), expects);
|
assertEquals(parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()), expects);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class ProductItems {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function to get the ProductItemPrice for the ProductItem. Currently returns the
|
* 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() {
|
public static Function<ProductItem, ProductItemPrice> price() {
|
||||||
return new Function<ProductItem, ProductItemPrice>() {
|
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
|
* 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.
|
* ProductItems.
|
||||||
*/
|
*/
|
||||||
public static Function<ProductItemPrice, ProductItem> item() {
|
public static Function<ProductItemPrice, ProductItem> item() {
|
||||||
|
@ -80,7 +80,7 @@ public class ProductItems {
|
||||||
public ProductItem apply(ProductItemPrice productItemPrice) {
|
public ProductItem apply(ProductItemPrice productItemPrice) {
|
||||||
Set<ProductItemCategory> categories = productItemPrice.getCategories();
|
Set<ProductItemCategory> categories = productItemPrice.getCategories();
|
||||||
ProductItem item = productItemPrice.getItem();
|
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) {
|
if (item.getCategories().size() == 0 && categories.size() != 0) {
|
||||||
builder.categories(categories);
|
builder.categories(categories);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* 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
|
* @author Jason King
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class SoftLayerComputeServiceAdapter implements
|
||||||
|
|
||||||
ProductOrder order = ProductOrder.builder().packageId(productPackageSupplier.get().getId())
|
ProductOrder order = ProductOrder.builder().packageId(productPackageSupplier.get().getId())
|
||||||
.location(template.getLocation().getId()).quantity(1).useHourlyPricing(true).prices(getPrices(template))
|
.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);
|
logger.debug(">> ordering new virtualGuest domain(%s) hostname(%s)", domainName, name);
|
||||||
ProductOrderReceipt productOrderReceipt = client.getVirtualGuestClient().orderVirtualGuest(order);
|
ProductOrderReceipt productOrderReceipt = client.getVirtualGuestClient().orderVirtualGuest(order);
|
||||||
|
|
|
@ -18,28 +18,10 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.config;
|
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.DateAdapter;
|
||||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
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.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -47,72 +29,6 @@ import com.google.inject.Provides;
|
||||||
*/
|
*/
|
||||||
public class SoftLayerParserModule extends AbstractModule {
|
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
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -21,135 +21,156 @@ package org.jclouds.softlayer.domain;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Strings.emptyToNull;
|
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
|
* @author Jason King
|
||||||
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account_Address"
|
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account_Address"
|
||||||
* />
|
/>
|
||||||
*/
|
*/
|
||||||
public class Address implements Comparable<Address> {
|
public class Address {
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int id = -1;
|
return new ConcreteBuilder().fromAddress(this);
|
||||||
private String country;
|
}
|
||||||
private String state;
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
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;
|
this.id = id;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder country(String country) {
|
/**
|
||||||
|
* @see Address#getCountry()
|
||||||
|
*/
|
||||||
|
public T country(String country) {
|
||||||
this.country = country;
|
this.country = country;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder state(String state) {
|
/**
|
||||||
|
* @see Address#getState()
|
||||||
|
*/
|
||||||
|
public T state(String state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder description(String description) {
|
/**
|
||||||
|
* @see Address#getDescription()
|
||||||
|
*/
|
||||||
|
public T description(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Address build() {
|
public Address build() {
|
||||||
return new Address(id, country, state, description);
|
return new Address(id, country, state, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromAddress(Address in) {
|
public T fromAddress(Address in) {
|
||||||
return Address.builder().id(in.getId())
|
return this
|
||||||
.country(in.getCountry())
|
.id(in.getId())
|
||||||
.state(in.getState())
|
.country(in.getCountry())
|
||||||
.description(in.getDescription());
|
.state(in.getState())
|
||||||
|
.description(in.getDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private String country;
|
@Override
|
||||||
private String state;
|
protected ConcreteBuilder self() {
|
||||||
private String description;
|
return this;
|
||||||
|
}
|
||||||
// for deserializer
|
|
||||||
Address() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.id = id;
|
||||||
this.country = checkNotNull(emptyToNull(country),"country cannot be null or empty:"+country);
|
this.country = checkNotNull(emptyToNull(country),"country cannot be null or empty:"+country);
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Address arg0) {
|
|
||||||
return Integer.valueOf(id).compareTo(arg0.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The unique id of the address.
|
* @return The unique id of the address.
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The country of the address.
|
* @return The country of the address.
|
||||||
*/
|
*/
|
||||||
public String getCountry() {
|
public String getCountry() {
|
||||||
return country;
|
return this.country;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The state of the address.
|
* @return The state of the address.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getState() {
|
public String getState() {
|
||||||
return state;
|
return this.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The description of the address.
|
* @return The description of the address.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return this.description;
|
||||||
}
|
|
||||||
|
|
||||||
public Builder toBuilder() {
|
|
||||||
return Builder.fromAddress(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(id);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (id ^ (id >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Address that = Address.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.id, that.id);
|
||||||
if (getClass() != obj.getClass())
|
}
|
||||||
return false;
|
|
||||||
Address other = (Address) obj;
|
protected ToStringHelper string() {
|
||||||
if (id != other.id)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("id", id).add("country", country).add("state", state).add("description", description);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[id=" + id + ", country=" + country + ", state=" + state + ", description=" + description + "]";
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -20,161 +20,186 @@ package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Set;
|
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.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Class Datacenter
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Location_Datacenter"
|
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Location_Datacenter"
|
||||||
* />
|
/>
|
||||||
*/
|
*/
|
||||||
public class Datacenter implements Comparable<Datacenter> {
|
public class Datacenter {
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int id = -1;
|
return new ConcreteBuilder().fromDatacenter(this);
|
||||||
private String name;
|
}
|
||||||
private String longName;
|
|
||||||
private Address locationAddress;
|
|
||||||
private Set<Region> regions = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
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;
|
this.id = id;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder name(String name) {
|
/**
|
||||||
|
* @see Datacenter#getName()
|
||||||
|
*/
|
||||||
|
public T name(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder longName(String longName) {
|
/**
|
||||||
|
* @see Datacenter#getLongName()
|
||||||
|
*/
|
||||||
|
public T longName(String longName) {
|
||||||
this.longName = longName;
|
this.longName = longName;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder locationAddress(Address locationAddress) {
|
/**
|
||||||
|
* @see Datacenter#getLocationAddress()
|
||||||
|
*/
|
||||||
|
public T locationAddress(Address locationAddress) {
|
||||||
this.locationAddress = locationAddress;
|
this.locationAddress = locationAddress;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder region(Region regions) {
|
/**
|
||||||
this.regions.add(checkNotNull(regions, "regions"));
|
* @see Datacenter#getRegions()
|
||||||
return this;
|
*/
|
||||||
|
public T regions(Set<Region> regions) {
|
||||||
|
this.regions = ImmutableSet.copyOf(checkNotNull(regions, "regions"));
|
||||||
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder regions(Iterable<Region> regions) {
|
public T regions(Region... in) {
|
||||||
this.regions = ImmutableSet.<Region> copyOf(checkNotNull(regions, "regions"));
|
return regions(ImmutableSet.copyOf(in));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Datacenter build() {
|
public Datacenter build() {
|
||||||
return new Datacenter(id, name, longName, locationAddress, regions);
|
return new Datacenter(id, name, longName, locationAddress, regions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromDatacenter(Datacenter in) {
|
public T fromDatacenter(Datacenter in) {
|
||||||
return Datacenter.builder().id(in.getId()).name(in.getName())
|
return this
|
||||||
.longName(in.getLongName()).locationAddress(in.getLocationAddress())
|
.id(in.getId())
|
||||||
|
.name(in.getName())
|
||||||
|
.longName(in.getLongName())
|
||||||
|
.locationAddress(in.getLocationAddress())
|
||||||
.regions(in.getRegions());
|
.regions(in.getRegions());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private String name;
|
@Override
|
||||||
private String longName;
|
protected ConcreteBuilder self() {
|
||||||
private Address locationAddress;
|
return this;
|
||||||
private Set<Region> regions = Sets.newLinkedHashSet();
|
}
|
||||||
// for deserializer
|
|
||||||
Datacenter() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.longName = longName;
|
this.longName = longName;
|
||||||
this.locationAddress = locationAddress;
|
this.locationAddress = locationAddress;
|
||||||
this.regions = ImmutableSet.<Region> copyOf(checkNotNull(regions, "regions"));
|
this.regions = regions == null ? ImmutableSet.<Region>of() : ImmutableSet.copyOf(regions);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Datacenter arg0) {
|
|
||||||
return Integer.valueOf(id).compareTo(arg0.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The unique identifier of a specific location.
|
* @return The unique identifier of a specific location.
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A short location description.
|
* @return A short location description.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A longer location description.
|
* @return A longer location description.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getLongName() {
|
public String getLongName() {
|
||||||
return longName;
|
return this.longName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A location's physical address (optional).
|
* @return A location's physical address (optional).
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Address getLocationAddress() {
|
public Address getLocationAddress() {
|
||||||
return locationAddress;
|
return this.locationAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A location can be a member of 1 or more regions.
|
* 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.
|
* 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.
|
* The list of regions usually contains one with keyName=FIRST_AVAILABLE which should be ignored.
|
||||||
|
*
|
||||||
* @return The regions to which a location belongs.
|
* @return The regions to which a location belongs.
|
||||||
*/
|
*/
|
||||||
public Set<Region> getRegions() {
|
public Set<Region> getRegions() {
|
||||||
return regions;
|
return this.regions;
|
||||||
}
|
|
||||||
|
|
||||||
public Builder toBuilder() {
|
|
||||||
return Builder.fromDatacenter(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(id);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (id ^ (id >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Datacenter that = Datacenter.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.id, that.id);
|
||||||
if (getClass() != obj.getClass())
|
}
|
||||||
return false;
|
|
||||||
Datacenter other = (Datacenter) obj;
|
protected ToStringHelper string() {
|
||||||
if (id != other.id)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("id", id).add("name", name).add("longName", longName).add("locationAddress", locationAddress).add("regions", regions);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[id=" + id + ", country=" + name + ", state=" + longName + "], locationAddress=" + locationAddress + ", regions="+regions+"]";
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -20,118 +20,123 @@ package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Set;
|
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.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends the SoftLayer_Software_Component data type to include operating system specific properties.
|
* Extends the SoftLayer_Software_Component data type to include operating system specific properties.
|
||||||
*
|
*
|
||||||
* @author Jason King
|
* @author Jason King
|
||||||
* @see <a href=
|
* @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 ConcreteBuilder();
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int id = -1;
|
return new ConcreteBuilder().fromOperatingSystem(this);
|
||||||
private Set<Password> passwords = Sets.newLinkedHashSet();
|
}
|
||||||
|
|
||||||
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;
|
this.id = id;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder password(Password password) {
|
/**
|
||||||
this.passwords.add(checkNotNull(password, "password"));
|
* @see OperatingSystem#getPasswords()
|
||||||
return this;
|
*/
|
||||||
|
public T passwords(Set<Password> passwords) {
|
||||||
|
this.passwords = ImmutableSet.copyOf(checkNotNull(passwords, "passwords"));
|
||||||
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder passwords(Iterable<Password> passwords) {
|
public T passwords(Password... in) {
|
||||||
this.passwords = ImmutableSet.<Password> copyOf(checkNotNull(passwords, "passwords"));
|
return passwords(ImmutableSet.copyOf(in));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperatingSystem build() {
|
public OperatingSystem build() {
|
||||||
return new OperatingSystem(id, passwords);
|
return new OperatingSystem(id, passwords);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromOperatingSystem(OperatingSystem in) {
|
public T fromOperatingSystem(OperatingSystem in) {
|
||||||
return OperatingSystem.builder()
|
return this
|
||||||
.id(in.getId())
|
.id(in.getId())
|
||||||
.passwords(in.getPasswords());
|
.passwords(in.getPasswords());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private Set<Password> passwords = Sets.newLinkedHashSet();
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
// for deserializer
|
return this;
|
||||||
OperatingSystem() {
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperatingSystem(int id,Iterable<Password> passwords) {
|
private final int id;
|
||||||
|
private final Set<Password> passwords;
|
||||||
|
|
||||||
|
@ConstructorProperties({
|
||||||
|
"id", "passwords"
|
||||||
|
})
|
||||||
|
protected OperatingSystem(int id, @Nullable Set<Password> passwords) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.passwords = ImmutableSet.<Password> copyOf(checkNotNull(passwords, "passwords"));
|
this.passwords = passwords == null ? ImmutableSet.<Password>of() : ImmutableSet.copyOf(passwords);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(OperatingSystem arg0) {
|
|
||||||
return Integer.valueOf(id).compareTo(arg0.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return An ID number identifying this Software Component (Software Installation)
|
* @return An ID number identifying this Software Component (Software Installation)
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return Username/Password pairs used for access to this Software Installation.
|
* @return Username/Password pairs used for access to this Software Installation.
|
||||||
*/
|
*/
|
||||||
public Set<Password> getPasswords() {
|
public Set<Password> getPasswords() {
|
||||||
return passwords;
|
return this.passwords;
|
||||||
}
|
|
||||||
|
|
||||||
public Builder toBuilder() {
|
|
||||||
return Builder.fromOperatingSystem(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(id);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (id ^ (id >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
OperatingSystem that = OperatingSystem.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.id, that.id);
|
||||||
if (getClass() != obj.getClass())
|
}
|
||||||
return false;
|
|
||||||
OperatingSystem other = (OperatingSystem) obj;
|
protected ToStringHelper string() {
|
||||||
if (id != other.id)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("id", id).add("passwords", passwords);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[id=" + id + ", passwords=" + passwords + "]";
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -21,121 +21,134 @@ package org.jclouds.softlayer.domain;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Strings.emptyToNull;
|
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
|
* Contains a password for a specific software component instance
|
||||||
*
|
*
|
||||||
* @author Jason King
|
* @author Jason King
|
||||||
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_Password"
|
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_Password"
|
||||||
* />
|
/>
|
||||||
*/
|
*/
|
||||||
public class Password implements Comparable<Password> {
|
public class Password {
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int id = -1;
|
return new ConcreteBuilder().fromPassword(this);
|
||||||
private String username;
|
}
|
||||||
private String password;
|
|
||||||
|
|
||||||
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;
|
this.id = id;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder username(String username) {
|
/**
|
||||||
|
* @see Password#getUsername()
|
||||||
|
*/
|
||||||
|
public T username(String username) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder password(String password) {
|
/**
|
||||||
|
* @see Password#getPassword()
|
||||||
|
*/
|
||||||
|
public T password(String password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Password build() {
|
public Password build() {
|
||||||
return new Password(id, username, password);
|
return new Password(id, username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromPassword(Password in) {
|
public T fromPassword(Password in) {
|
||||||
return Password.builder().id(in.getId())
|
return this
|
||||||
.username(in.getUsername())
|
.id(in.getId())
|
||||||
.password(in.getPassword());
|
.username(in.getUsername())
|
||||||
|
.password(in.getPassword());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private String username;
|
@Override
|
||||||
private String password;
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
// for deserializer
|
}
|
||||||
Password() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.id = id;
|
||||||
this.username = checkNotNull(emptyToNull(username),"username cannot be null or empty:"+username);
|
this.username = checkNotNull(emptyToNull(username),"username cannot be null or empty:"+username);
|
||||||
this.password = password;
|
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.
|
* @return An id number for this specific username/password pair.
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The username part of the username/password pair.
|
* @return The username part of the username/password pair.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return this.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The password part of the username/password pair.
|
* @return The password part of the username/password pair.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return this.password;
|
||||||
}
|
|
||||||
|
|
||||||
public Builder toBuilder() {
|
|
||||||
return Builder.fromPassword(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(id);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (id ^ (id >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
Password that = Password.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.id, that.id);
|
||||||
if (getClass() != obj.getClass())
|
}
|
||||||
return false;
|
|
||||||
Password other = (Password) obj;
|
protected ToStringHelper string() {
|
||||||
if (id != other.id)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("id", id).add("username", username).add("password", password);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Password [id=" + id + ", username=" + username + ", password=**********]";
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -20,83 +20,98 @@ package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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.
|
* 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
|
* @author Jason King
|
||||||
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Power_State"
|
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Power_State"
|
||||||
* />
|
/>
|
||||||
*/
|
*/
|
||||||
public class PowerState implements Comparable<PowerState> {
|
public class PowerState {
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private VirtualGuest.State keyName;
|
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;
|
this.keyName = keyName;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PowerState build() {
|
public PowerState build() {
|
||||||
return new PowerState(keyName);
|
return new PowerState(keyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromAddress(PowerState in) {
|
public T fromPowerState(PowerState in) {
|
||||||
return PowerState.builder().keyName(in.getKeyName());
|
return this
|
||||||
|
.keyName(in.getKeyName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private VirtualGuest.State keyName;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
// for deserializer
|
protected ConcreteBuilder self() {
|
||||||
PowerState() {
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final VirtualGuest.State keyName;
|
||||||
|
|
||||||
|
@ConstructorProperties("keyName")
|
||||||
public PowerState(VirtualGuest.State keyName) {
|
public PowerState(VirtualGuest.State keyName) {
|
||||||
this.keyName = checkNotNull(keyName,"keyName cannot be null or empty:"+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}
|
* 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() {
|
public VirtualGuest.State getKeyName() {
|
||||||
return keyName;
|
return this.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[keyName=" + keyName + "]";
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -20,12 +20,14 @@ package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
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.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SoftLayer_Product_Item data type contains general information relating to
|
* The SoftLayer_Product_Item data type contains general information relating to
|
||||||
|
@ -33,118 +35,139 @@ import com.google.common.collect.Sets;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @see <a href=
|
* @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 ConcreteBuilder();
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int id = -1;
|
return new ConcreteBuilder().fromProductItem(this);
|
||||||
private String description;
|
}
|
||||||
private String units;
|
|
||||||
private Float capacity;
|
|
||||||
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
|
|
||||||
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
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;
|
this.id = id;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder description(String description) {
|
/**
|
||||||
|
* @see ProductItem#getDescription()
|
||||||
|
*/
|
||||||
|
public T description(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder units(String units) {
|
/**
|
||||||
|
* @see ProductItem#getUnits()
|
||||||
|
*/
|
||||||
|
public T units(String units) {
|
||||||
this.units = units;
|
this.units = units;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder capacity(Float capacity) {
|
/**
|
||||||
|
* @see ProductItem#getCapacity()
|
||||||
|
*/
|
||||||
|
public T capacity(Float capacity) {
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder price(ProductItemPrice prices) {
|
/**
|
||||||
this.prices.add(checkNotNull(prices, "prices"));
|
* @see ProductItem#getPrices()
|
||||||
return this;
|
*/
|
||||||
|
public T prices(Set<ProductItemPrice> prices) {
|
||||||
|
this.prices = ImmutableSet.copyOf(checkNotNull(prices, "prices"));
|
||||||
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder prices(Iterable<ProductItemPrice> prices) {
|
public T prices(ProductItemPrice... in) {
|
||||||
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
|
return prices(ImmutableSet.copyOf(in));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder category(ProductItemCategory categories) {
|
/**
|
||||||
this.categories.add(checkNotNull(categories, "categories"));
|
* @see ProductItem#getCategories()
|
||||||
return this;
|
*/
|
||||||
|
public T categories(Set<ProductItemCategory> categories) {
|
||||||
|
this.categories = ImmutableSet.copyOf(checkNotNull(categories, "categories"));
|
||||||
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder categories(Iterable<ProductItemCategory> categories) {
|
public T categories(ProductItemCategory... in) {
|
||||||
this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
|
return categories(ImmutableSet.copyOf(in));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductItem build() {
|
public ProductItem build() {
|
||||||
return new ProductItem(id, description, units, capacity, prices, categories);
|
return new ProductItem(id, description, units, capacity, prices, categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromProductItem(ProductItem in) {
|
public T fromProductItem(ProductItem in) {
|
||||||
return ProductItem.builder().id(in.getId())
|
return this
|
||||||
.description(in.getDescription())
|
.id(in.getId())
|
||||||
.units(in.getUnits())
|
.description(in.getDescription())
|
||||||
.capacity(in.getCapacity())
|
.units(in.getUnits())
|
||||||
.prices(in.getPrices())
|
.capacity(in.getCapacity())
|
||||||
.categories(in.getCategories());
|
.prices(in.getPrices())
|
||||||
|
.categories(in.getCategories());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private String description;
|
@Override
|
||||||
private String units;
|
protected ConcreteBuilder self() {
|
||||||
private Float capacity;
|
return this;
|
||||||
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
|
}
|
||||||
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
// for deserializer
|
|
||||||
ProductItem() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductItem(int id, String description, String units, Float capacity,
|
private final int id;
|
||||||
Iterable<ProductItemPrice> prices, Iterable<ProductItemCategory> categories) {
|
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.id = id;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.units = units;
|
this.units = units;
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
|
this.prices = prices == null ? ImmutableSet.<ProductItemPrice>of() : ImmutableSet.copyOf(prices);
|
||||||
this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
|
this.categories = categories == null ? ImmutableSet.<ProductItemCategory>of() : ImmutableSet.copyOf(categories);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(ProductItem arg0) {
|
|
||||||
return Integer.valueOf(id).compareTo(arg0.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The unique identifier of a specific location.
|
* @return The unique identifier of a specific location.
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A product's description
|
* @return A product's description
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,64 +175,54 @@ public class ProductItem implements Comparable<ProductItem> {
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getUnits() {
|
public String getUnits() {
|
||||||
return units;
|
return this.units;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Some Product Items have capacity information such as RAM and
|
* @return Some Product Items have capacity information such as RAM and
|
||||||
* bandwidth, and others. This provides the numerical representation
|
bandwidth, and others. This provides the numerical representation
|
||||||
* of the capacity given in the description of this product item.
|
of the capacity given in the description of this product item.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Float getCapacity() {
|
public Float getCapacity() {
|
||||||
return capacity;
|
return this.capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return A product item's prices.
|
* @return A product item's prices.
|
||||||
*/
|
*/
|
||||||
public Set<ProductItemPrice> getPrices() {
|
public Set<ProductItemPrice> getPrices() {
|
||||||
return prices;
|
return this.prices;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return An item's associated item categories.
|
* @return An item's associated item categories.
|
||||||
*/
|
*/
|
||||||
public Set<ProductItemCategory> getCategories() {
|
public Set<ProductItemCategory> getCategories() {
|
||||||
return categories;
|
return this.categories;
|
||||||
}
|
|
||||||
|
|
||||||
public Builder toBuilder() {
|
|
||||||
return Builder.fromProductItem(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(id);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (id ^ (id >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
ProductItem that = ProductItem.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.id, that.id);
|
||||||
if (getClass() != obj.getClass())
|
}
|
||||||
return false;
|
|
||||||
ProductItem other = (ProductItem) obj;
|
protected ToStringHelper string() {
|
||||||
if (id != other.id)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("id", id).add("description", description).add("units", units).add("capacity", capacity).add("prices", prices).add("categories", categories);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ProductItem [id=" + id + ", description=" + description + ", units=" + units + ", capacity=" + capacity
|
return string().toString();
|
||||||
+ ", prices=" + prices + ", categories=" + categories + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,123 +18,139 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.domain;
|
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
|
* The SoftLayer_Product_Item_Category data type contains
|
||||||
* general category information for prices.
|
* general category information for prices.
|
||||||
*
|
*
|
||||||
* @author Jason King
|
* @author Jason King
|
||||||
* @see <a href=
|
* @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 ConcreteBuilder();
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int id = -1;
|
return new ConcreteBuilder().fromProductItemCategory(this);
|
||||||
private String name;
|
}
|
||||||
private String categoryCode;
|
|
||||||
|
|
||||||
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;
|
this.id = id;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder name(String name) {
|
/**
|
||||||
|
* @see ProductItemCategory#getName()
|
||||||
|
*/
|
||||||
|
public T name(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder categoryCode(String categoryCode) {
|
/**
|
||||||
|
* @see ProductItemCategory#getCategoryCode()
|
||||||
|
*/
|
||||||
|
public T categoryCode(String categoryCode) {
|
||||||
this.categoryCode = categoryCode;
|
this.categoryCode = categoryCode;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductItemCategory build() {
|
public ProductItemCategory build() {
|
||||||
return new ProductItemCategory(id, name, categoryCode);
|
return new ProductItemCategory(id, name, categoryCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromProductItemCategory(ProductItemCategory in) {
|
public T fromProductItemCategory(ProductItemCategory in) {
|
||||||
return ProductItemCategory.builder().id(in.getId())
|
return this
|
||||||
.name(in.getName())
|
.id(in.getId())
|
||||||
.categoryCode(in.getCategoryCode());
|
.name(in.getName())
|
||||||
|
.categoryCode(in.getCategoryCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private String name;
|
@Override
|
||||||
private String categoryCode;
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
// for deserializer
|
}
|
||||||
ProductItemCategory() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.categoryCode = categoryCode;
|
this.categoryCode = categoryCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(ProductItemCategory arg0) {
|
|
||||||
return Integer.valueOf(id).compareTo(arg0.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The unique identifier of a specific location.
|
* @return The unique identifier of a specific location.
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
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.
|
* @return The friendly, descriptive name of the category as seen on the order forms and on invoices.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The code used to identify this category.
|
* @return The code used to identify this category.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getCategoryCode() {
|
public String getCategoryCode() {
|
||||||
return categoryCode;
|
return this.categoryCode;
|
||||||
}
|
|
||||||
|
|
||||||
public Builder toBuilder() {
|
|
||||||
return Builder.fromProductItemCategory(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(id);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (id ^ (id >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
ProductItemCategory that = ProductItemCategory.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.id, that.id);
|
||||||
if (getClass() != obj.getClass())
|
}
|
||||||
return false;
|
|
||||||
ProductItemCategory other = (ProductItemCategory) obj;
|
protected ToStringHelper string() {
|
||||||
if (id != other.id)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("id", id).add("name", name).add("categoryCode", categoryCode);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ProductItemCategory [id=" + id + ", name=" + name + ", categoryCode=" + categoryCode + "]";
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -20,183 +20,209 @@ package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
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.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SoftLayer_Product_Item_Price data type contains general information
|
* The SoftLayer_Product_Item_Price data type contains general information
|
||||||
* relating to a single SoftLayer product item price. You can find out what
|
* relating to a single SoftLayer product item prices. You can find out what
|
||||||
* packages each price is in as well as which category under which this price is
|
* 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
|
* sold. All prices are returned in Floating point values measured in US Dollars
|
||||||
* ($USD).
|
* ($USD).
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @see <a href=
|
* @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> {
|
public class ProductItemPrice {
|
||||||
// TODO there are more elements than this.
|
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder<?> builder() {
|
||||||
return new Builder();
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int id = -1;
|
return new ConcreteBuilder().fromProductItemPrice(this);
|
||||||
private long itemId = -1;
|
}
|
||||||
private Float recurringFee;
|
|
||||||
private Float hourlyRecurringFee;
|
|
||||||
private ProductItem item;
|
|
||||||
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
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;
|
this.id = id;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder itemId(long itemId) {
|
/**
|
||||||
|
* @see ProductItemPrice#getItemId()
|
||||||
|
*/
|
||||||
|
public T itemId(long itemId) {
|
||||||
this.itemId = itemId;
|
this.itemId = itemId;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder recurringFee(Float recurringFee) {
|
/**
|
||||||
|
* @see ProductItemPrice#getRecurringFee()
|
||||||
|
*/
|
||||||
|
public T recurringFee(Float recurringFee) {
|
||||||
this.recurringFee = recurringFee;
|
this.recurringFee = recurringFee;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder hourlyRecurringFee(Float hourlyRecurringFee) {
|
/**
|
||||||
|
* @see ProductItemPrice#getHourlyRecurringFee()
|
||||||
|
*/
|
||||||
|
public T hourlyRecurringFee(Float hourlyRecurringFee) {
|
||||||
this.hourlyRecurringFee = hourlyRecurringFee;
|
this.hourlyRecurringFee = hourlyRecurringFee;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder item(ProductItem item) {
|
/**
|
||||||
|
* @see ProductItemPrice#getItem()
|
||||||
|
*/
|
||||||
|
public T item(ProductItem item) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder category(ProductItemCategory categories) {
|
/**
|
||||||
this.categories.add(checkNotNull(categories, "categories"));
|
* @see ProductItemPrice#getCategories()
|
||||||
return this;
|
*/
|
||||||
|
public T categories(Set<ProductItemCategory> categories) {
|
||||||
|
this.categories = ImmutableSet.copyOf(checkNotNull(categories, "categories"));
|
||||||
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder categories(Iterable<ProductItemCategory> categories) {
|
public T categories(ProductItemCategory... in) {
|
||||||
this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
|
return categories(ImmutableSet.copyOf(in));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductItemPrice build() {
|
public ProductItemPrice build() {
|
||||||
return new ProductItemPrice(id, itemId, recurringFee, hourlyRecurringFee, item, categories);
|
return new ProductItemPrice(id, itemId, recurringFee, hourlyRecurringFee, item, categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromPrice(ProductItemPrice in) {
|
public T fromProductItemPrice(ProductItemPrice in) {
|
||||||
return ProductItemPrice.builder().id(in.getId()).itemId(in.getItemId())
|
return this
|
||||||
.hourlyRecurringFee(in.getHourlyRecurringFee()).recurringFee(in.getRecurringFee());
|
.id(in.getId())
|
||||||
|
.itemId(in.getItemId())
|
||||||
|
.recurringFee(in.getRecurringFee())
|
||||||
|
.hourlyRecurringFee(in.getHourlyRecurringFee())
|
||||||
|
.item(in.getItem())
|
||||||
|
.categories(in.getCategories());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private long itemId = -1;
|
@Override
|
||||||
private Float recurringFee;
|
protected ConcreteBuilder self() {
|
||||||
private Float hourlyRecurringFee;
|
return this;
|
||||||
private ProductItem item;
|
}
|
||||||
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
// for deserializer
|
|
||||||
ProductItemPrice() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.id = id;
|
||||||
this.itemId = itemId;
|
this.itemId = itemId;
|
||||||
this.recurringFee = recurringFee;
|
this.recurringFee = recurringFee;
|
||||||
this.hourlyRecurringFee = hourlyRecurringFee;
|
this.hourlyRecurringFee = hourlyRecurringFee;
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
|
this.categories = categories == null ? ImmutableSet.<ProductItemCategory>of() : ImmutableSet.copyOf(categories);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(ProductItemPrice arg0) {
|
|
||||||
return Integer.valueOf(id).compareTo(arg0.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The unique identifier of a Product Item Price.
|
* @return The unique identifier of a Product Item Price.
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The unique identifier for a product Item
|
* @return The unique identifier for a product Item
|
||||||
*/
|
*/
|
||||||
public long getItemId() {
|
public long getItemId() {
|
||||||
return itemId;
|
return this.itemId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A recurring fee is a fee that happens every billing period. This
|
* @return A recurring fee is a fee that happens every billing period. This
|
||||||
* fee is represented as a Floating point decimal in US dollars
|
fee is represented as a Floating point decimal in US dollars
|
||||||
* ($USD).
|
($USD).
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Float getRecurringFee() {
|
public Float getRecurringFee() {
|
||||||
return recurringFee;
|
return this.recurringFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The hourly price for this item, should this item be part of an
|
* @return The hourly prices for this item, should this item be part of an
|
||||||
* hourly pricing package.
|
hourly pricing package.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Float getHourlyRecurringFee() {
|
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.
|
* @return An item's associated item categories.
|
||||||
*/
|
*/
|
||||||
public Set<ProductItemCategory> getCategories() {
|
public Set<ProductItemCategory> getCategories() {
|
||||||
return categories;
|
return this.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -20,118 +20,135 @@ package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Set;
|
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.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Class ProductOrder
|
||||||
*
|
*
|
||||||
* @author Jason King
|
* @author Jason King
|
||||||
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest"
|
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest"
|
||||||
* />
|
/>
|
||||||
*/
|
*/
|
||||||
public class ProductOrder {
|
public class ProductOrder {
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int packageId = -1;
|
return new ConcreteBuilder().fromProductOrder(this);
|
||||||
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
|
}
|
||||||
private Set<VirtualGuest> virtualGuests = Sets.newLinkedHashSet();
|
|
||||||
private String location;
|
|
||||||
private int quantity;
|
|
||||||
private boolean useHourlyPricing;
|
|
||||||
|
|
||||||
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;
|
this.packageId = packageId;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a price to the order
|
* @see ProductOrder#getLocation()
|
||||||
* 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
|
|
||||||
*/
|
*/
|
||||||
public Builder price(ProductItemPrice prices) {
|
public T location(String location) {
|
||||||
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) {
|
|
||||||
this.location = 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;
|
this.quantity = quantity;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder useHourlyPricing(Boolean useHourlyPricing) {
|
/**
|
||||||
|
* @see ProductOrder#getUseHourlyPricing()
|
||||||
|
*/
|
||||||
|
public T useHourlyPricing(boolean useHourlyPricing) {
|
||||||
this.useHourlyPricing = useHourlyPricing;
|
this.useHourlyPricing = useHourlyPricing;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductOrder build() {
|
public ProductOrder build() {
|
||||||
return new ProductOrder(packageId, location,prices, virtualGuests, quantity, useHourlyPricing);
|
return new ProductOrder(packageId, location, prices, virtualGuests, quantity, useHourlyPricing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromProductOrder(ProductOrder in) {
|
public T fromProductOrder(ProductOrder in) {
|
||||||
return ProductOrder.builder().packageId(in.getPackageId())
|
return this
|
||||||
.location(in.getLocation())
|
.packageId(in.getPackageId())
|
||||||
.prices(in.getPrices())
|
.location(in.getLocation())
|
||||||
.virtualGuests(in.getVirtualGuests())
|
.prices(in.getPrices())
|
||||||
.quantity(in.getQuantity())
|
.virtualGuests(in.getVirtualGuests())
|
||||||
.useHourlyPricing(in.getUseHourlyPricing());
|
.quantity(in.getQuantity())
|
||||||
|
.useHourlyPricing(in.getUseHourlyPricing());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int packageId = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private String location;
|
@Override
|
||||||
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
|
protected ConcreteBuilder self() {
|
||||||
private Set<VirtualGuest> virtualGuests = Sets.newLinkedHashSet();
|
return this;
|
||||||
private int quantity;
|
}
|
||||||
private boolean useHourlyPricing;
|
|
||||||
|
|
||||||
// for deserializer
|
|
||||||
ProductOrder() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.packageId = packageId;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
|
this.prices = prices == null ? ImmutableSet.<ProductItemPrice>of() : ImmutableSet.copyOf(prices);
|
||||||
this.virtualGuests = ImmutableSet.<VirtualGuest> copyOf(checkNotNull(virtualGuest, "virtualGuest"));
|
this.virtualGuests = virtualGuests == null ? ImmutableSet.<VirtualGuest>of() : ImmutableSet.copyOf(virtualGuests);
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
this.useHourlyPricing = useHourlyPricing;
|
this.useHourlyPricing = useHourlyPricing;
|
||||||
}
|
}
|
||||||
|
@ -140,79 +157,70 @@ public class ProductOrder {
|
||||||
* @return The package id of an order. This is required.
|
* @return The package id of an order. This is required.
|
||||||
*/
|
*/
|
||||||
public int getPackageId() {
|
public int getPackageId() {
|
||||||
return packageId;
|
return this.packageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The region keyname or specific location keyname where the order should be provisioned.
|
* @return The region keyname or specific location keyname where the order should be provisioned.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getLocation() {
|
public String getLocation() {
|
||||||
return location;
|
return this.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the item prices in this order.
|
* 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.
|
* @return the prices.
|
||||||
*/
|
*/
|
||||||
public Set<ProductItemPrice> getPrices() {
|
public Set<ProductItemPrice> getPrices() {
|
||||||
return prices;
|
return this.prices;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the virtual guests in this order.
|
* Gets the virtual guests in this order.
|
||||||
|
*
|
||||||
* @return the the virtual guests.
|
* @return the the virtual guests.
|
||||||
*/
|
*/
|
||||||
public Set<VirtualGuest> getVirtualGuests() {
|
public Set<VirtualGuest> getVirtualGuests() {
|
||||||
return virtualGuests;
|
return this.virtualGuests;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getQuantity() {
|
public int getQuantity() {
|
||||||
return quantity;
|
return this.quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getUseHourlyPricing() {
|
public boolean getUseHourlyPricing() {
|
||||||
return useHourlyPricing;
|
return this.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = (packageId ^ (packageId >>> 32));
|
return Objects.hashCode(packageId, location, prices, virtualGuests, quantity, useHourlyPricing);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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() {
|
public String toString() {
|
||||||
return "[packageId=" + packageId + ", location=" + location + ", prices=" + prices
|
return string().toString();
|
||||||
+ ", virtualGuests=" + virtualGuests +", quantity=" + quantity + ", useHourlyPricing=" + useHourlyPricing + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,63 +18,86 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.domain;
|
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
|
* @author Jason King
|
||||||
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Receipt"
|
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Receipt"
|
||||||
* />
|
/>
|
||||||
*/
|
*/
|
||||||
public class ProductOrderReceipt implements Comparable<ProductOrderReceipt> {
|
public class ProductOrderReceipt {
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int orderId = -1;
|
return new ConcreteBuilder().fromProductOrderReceipt(this);
|
||||||
private ProductOrder orderDetails;
|
}
|
||||||
|
|
||||||
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;
|
this.orderId = orderId;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder orderDetails(ProductOrder orderDetails) {
|
/**
|
||||||
|
* @see ProductOrderReceipt#getOrderDetails()
|
||||||
|
*/
|
||||||
|
public T orderDetails(ProductOrder orderDetails) {
|
||||||
this.orderDetails = orderDetails;
|
this.orderDetails = orderDetails;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductOrderReceipt build() {
|
public ProductOrderReceipt build() {
|
||||||
return new ProductOrderReceipt(orderId,orderDetails);
|
return new ProductOrderReceipt(orderId, orderDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromAddress(ProductOrderReceipt in) {
|
public T fromProductOrderReceipt(ProductOrderReceipt in) {
|
||||||
return ProductOrderReceipt.builder().orderId(in.getOrderId()).orderDetails(in.getOrderDetails());
|
return this
|
||||||
|
.orderId(in.getOrderId())
|
||||||
|
.orderDetails(in.getOrderDetails());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int orderId = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private ProductOrder orderDetails;
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
// for deserializer
|
return this;
|
||||||
ProductOrderReceipt() {
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.orderId = orderId;
|
||||||
this.orderDetails = orderDetails;
|
this.orderDetails = orderDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(ProductOrderReceipt arg0) {
|
|
||||||
return Integer.valueOf(orderId).compareTo(arg0.getOrderId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return unique identifier for the order.
|
* @return unique identifier for the order.
|
||||||
*/
|
*/
|
||||||
public int getOrderId() {
|
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.
|
* 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.
|
* It will contain all the items in an order as well as the order totals.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public ProductOrder getOrderDetails() {
|
public ProductOrder getOrderDetails() {
|
||||||
return orderDetails;
|
return this.orderDetails;
|
||||||
}
|
|
||||||
|
|
||||||
public Builder toBuilder() {
|
|
||||||
return Builder.fromAddress(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(orderId, orderDetails);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (orderId ^ (orderId >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
ProductOrderReceipt that = ProductOrderReceipt.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.orderId, that.orderId)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.orderDetails, that.orderDetails);
|
||||||
return false;
|
}
|
||||||
ProductOrderReceipt other = (ProductOrderReceipt) obj;
|
|
||||||
if (orderId != other.orderId)
|
protected ToStringHelper string() {
|
||||||
return false;
|
return Objects.toStringHelper(this)
|
||||||
return true;
|
.add("orderId", orderId).add("orderDetails", orderDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[orderId=" + orderId + ", orderDetails="+orderDetails+"]";
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -20,10 +20,14 @@ package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Set;
|
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.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SoftLayer_Product_Package data type contains information about packages
|
* The SoftLayer_Product_Package data type contains information about packages
|
||||||
|
@ -33,156 +37,174 @@ import com.google.common.collect.Sets;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @see <a href=
|
* @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 ConcreteBuilder();
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public Builder<?> toBuilder() {
|
||||||
private int id = -1;
|
return new ConcreteBuilder().fromProductPackage(this);
|
||||||
private String name;
|
}
|
||||||
private String description;
|
|
||||||
private Set<ProductItem> items = Sets.newLinkedHashSet();
|
|
||||||
private Set<Datacenter> datacenters = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
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;
|
this.id = id;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder name(String name) {
|
/**
|
||||||
|
* @see ProductPackage#getName()
|
||||||
|
*/
|
||||||
|
public T name(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder description(String description) {
|
/**
|
||||||
|
* @see ProductPackage#getDescription()
|
||||||
|
*/
|
||||||
|
public T description(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
return this;
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder items(Iterable<ProductItem> items) {
|
/**
|
||||||
this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items"));
|
* @see ProductPackage#getItems()
|
||||||
return this;
|
*/
|
||||||
|
public T items(Set<ProductItem> items) {
|
||||||
|
this.items = ImmutableSet.copyOf(checkNotNull(items, "items"));
|
||||||
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder datacenters(Iterable<Datacenter> datacenters) {
|
public T items(ProductItem... in) {
|
||||||
this.datacenters = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters"));
|
return items(ImmutableSet.copyOf(in));
|
||||||
return this;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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() {
|
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) {
|
public T fromProductPackage(ProductPackage in) {
|
||||||
return ProductPackage.builder().id(in.getId())
|
return this
|
||||||
.name(in.getName())
|
.id(in.getId())
|
||||||
.description(in.getDescription())
|
.name(in.getName())
|
||||||
.items(in.getItems())
|
.description(in.getDescription())
|
||||||
.datacenters(in.getDatacenters());
|
.items(in.getItems())
|
||||||
|
.datacenters(in.getDatacenters());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id = -1;
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
private String name;
|
@Override
|
||||||
private String description;
|
protected ConcreteBuilder self() {
|
||||||
private Set<ProductItem> items = Sets.newLinkedHashSet();
|
return this;
|
||||||
private Set<Datacenter> locations = Sets.newLinkedHashSet();
|
}
|
||||||
|
|
||||||
// for deserializer
|
|
||||||
ProductPackage() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items"));
|
this.items = items == null ? ImmutableSet.<ProductItem>of() : ImmutableSet.copyOf(items);
|
||||||
this.locations = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters"));
|
this.locations = locations == null ? ImmutableSet.<Datacenter>of() : ImmutableSet.copyOf(locations);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(ProductPackage arg0) {
|
|
||||||
return Integer.valueOf(id).compareTo(arg0.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A package's internal identifier. Everything regarding a
|
* @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() {
|
public int getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The description of the package. For server packages, this is
|
* @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() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A generic description of the processor type and count. This
|
* @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
|
includes HTML, so you may want to strip these tags if you plan to
|
||||||
* use it.
|
use it.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return A collection of valid items available for purchase in this
|
* @return A collection of valid items available for purchase in this
|
||||||
* package.
|
package.
|
||||||
*/
|
*/
|
||||||
public Set<ProductItem> getItems() {
|
public Set<ProductItem> getItems() {
|
||||||
return items;
|
return this.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return A collection of valid locations for this package.
|
|
||||||
*/
|
|
||||||
public Set<Datacenter> getDatacenters() {
|
public Set<Datacenter> getDatacenters() {
|
||||||
return locations;
|
return this.locations;
|
||||||
}
|
|
||||||
|
|
||||||
public Builder toBuilder() {
|
|
||||||
return Builder.fromProductPackage(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(id);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (id ^ (id >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
ProductPackage that = ProductPackage.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.id, that.id);
|
||||||
if (getClass() != obj.getClass())
|
}
|
||||||
return false;
|
|
||||||
ProductPackage other = (ProductPackage) obj;
|
protected ToStringHelper string() {
|
||||||
if (id != other.id)
|
return Objects.toStringHelper(this)
|
||||||
return false;
|
.add("id", id).add("name", name).add("description", description).add("items", items).add("locations", locations);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ProductPackage [id=" + id + ", name=" + name + ", description=" + description + ", items=" + items + ", datacenters=" + locations + "]";
|
return string().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,12 @@ package org.jclouds.softlayer.domain;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Strings.emptyToNull;
|
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 is made up of a keyname and a description of that region.
|
||||||
* A region keyname can be used as part of an order.
|
* A region keyname can be used as part of an order.
|
||||||
|
@ -50,28 +56,25 @@ public class Region implements Comparable<Region> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Region build() {
|
public Region build() {
|
||||||
return new Region(keyname, description);
|
return new Region(0, keyname, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromAddress(Region in) {
|
public static Builder fromAddress(Region in) {
|
||||||
return Region.builder().keyname(in.getKeyname())
|
return Region.builder().keyname(in.getKeyname())
|
||||||
.description(in.getDescription());
|
.description(in.getDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An integer representing the order in which this element is displayed */
|
/* An integer representing the order in which this element is displayed */
|
||||||
private int sortOrder = 0;
|
private final int sortOrder;
|
||||||
private String keyname;
|
private final String keyname;
|
||||||
private String description;
|
private final String description;
|
||||||
|
|
||||||
// for deserializer
|
@ConstructorProperties({"sortOrder", "keyname", "description"})
|
||||||
Region() {
|
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 = description;
|
||||||
public Region(String keyname, String description) {
|
|
||||||
this.keyname = checkNotNull(emptyToNull(keyname),"keyname cannot be null or empty:"+keyname);
|
|
||||||
this.description = checkNotNull(emptyToNull(description),"country cannot be null or empty:"+description);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.
|
* @return A short description of a region's name. This description is seen on the order forms.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
@ -103,20 +107,13 @@ public class Region implements Comparable<Region> {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
Region region = (Region) o;
|
Region region = (Region) o;
|
||||||
|
return Objects.equal(keyname, region.keyname)
|
||||||
if (sortOrder != region.sortOrder) return false;
|
&& Objects.equal(description, region.description);
|
||||||
if (!description.equals(region.description)) return false;
|
|
||||||
if (!keyname.equals(region.keyname)) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = sortOrder;
|
return Objects.hashCode(keyname, description);
|
||||||
result = 31 * result + keyname.hashCode();
|
|
||||||
result = 31 * result + description.hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -20,10 +20,14 @@ package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
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.
|
* The virtual guest data type presents the structure in which all virtual guests will be presented.
|
||||||
|
@ -45,196 +49,10 @@ import com.google.gson.annotations.SerializedName;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @see <a href=
|
* @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 class VirtualGuest {
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 Builder id(int id) {
|
|
||||||
this.id = id;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder accountId(int accountId) {
|
|
||||||
this.accountId = accountId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder createDate(Date createDate) {
|
|
||||||
this.createDate = createDate;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder dedicatedAccountHostOnly(boolean dedicatedAccountHostOnly) {
|
|
||||||
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder hostname(String hostname) {
|
|
||||||
this.hostname = hostname;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder domain(String domain) {
|
|
||||||
this.domain = domain;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder fullyQualifiedDomainName(String fullyQualifiedDomainName) {
|
|
||||||
this.fullyQualifiedDomainName = fullyQualifiedDomainName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder lastVerifiedDate(Date lastVerifiedDate) {
|
|
||||||
this.lastVerifiedDate = lastVerifiedDate;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder maxCpu(int maxCpu) {
|
|
||||||
this.maxCpu = maxCpu;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder maxCpuUnits(String maxCpuUnits) {
|
|
||||||
this.maxCpuUnits = maxCpuUnits;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder maxMemory(int maxMemory) {
|
|
||||||
this.maxMemory = maxMemory;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder metricPollDate(Date metricPollDate) {
|
|
||||||
this.metricPollDate = metricPollDate;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder modifyDate(Date modifyDate) {
|
|
||||||
this.modifyDate = modifyDate;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder notes(String notes) {
|
|
||||||
this.notes = notes;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder privateNetworkOnly(boolean privateNetworkOnly) {
|
|
||||||
this.privateNetworkOnly = privateNetworkOnly;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder startCpus(int startCpus) {
|
|
||||||
this.startCpus = startCpus;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder statusId(int statusId) {
|
|
||||||
this.statusId = statusId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder uuid(String uuid) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder primaryBackendIpAddress(String primaryBackendIpAddress) {
|
|
||||||
this.primaryBackendIpAddress = primaryBackendIpAddress;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder primaryIpAddress(String primaryIpAddress) {
|
|
||||||
this.primaryIpAddress = primaryIpAddress;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder billingItemId(int billingItemId) {
|
|
||||||
this.billingItemId = billingItemId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder operatingSystem(OperatingSystem operatingSystem) {
|
|
||||||
this.operatingSystem = operatingSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder datacenter(Datacenter datacenter) {
|
|
||||||
this.datacenter = datacenter;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder powerState(PowerState powerState) {
|
|
||||||
this.powerState = powerState;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder fromVirtualGuest(VirtualGuest in) {
|
|
||||||
return VirtualGuest.builder()
|
|
||||||
.accountId(in.getAccountId())
|
|
||||||
.createDate(in.getCreateDate())
|
|
||||||
.dedicatedAccountHostOnly(in.isDedicatedAccountHostOnly())
|
|
||||||
.domain(in.getDomain())
|
|
||||||
.fullyQualifiedDomainName(in.getFullyQualifiedDomainName())
|
|
||||||
.hostname(in.getHostname())
|
|
||||||
.id(in.getId())
|
|
||||||
.lastVerifiedDate(in.getLastVerifiedDate())
|
|
||||||
.maxCpu(in.getMaxCpu())
|
|
||||||
.maxCpuUnits(in.getMaxCpuUnits())
|
|
||||||
.maxMemory(in.getMaxMemory())
|
|
||||||
.metricPollDate(in.getMetricPollDate())
|
|
||||||
.modifyDate(in.getModifyDate())
|
|
||||||
.notes(in.getNotes())
|
|
||||||
.privateNetworkOnly(in.isPrivateNetworkOnly())
|
|
||||||
.startCpus(in.getStartCpus())
|
|
||||||
.statusId(in.getStatusId())
|
|
||||||
.uuid(in.getUuid())
|
|
||||||
.primaryBackendIpAddress(in.getPrimaryBackendIpAddress())
|
|
||||||
.primaryIpAddress(in.getPrimaryIpAddress())
|
|
||||||
.billingItemId(in.getBillingItemId())
|
|
||||||
.operatingSystem(in.getOperatingSystem())
|
|
||||||
.datacenter(in.getDatacenter())
|
|
||||||
.powerState(in.getPowerState());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These states come from the powerState field. i.e.
|
* These states come from the powerState field. i.e.
|
||||||
|
@ -260,44 +78,325 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int accountId = -1;
|
public static class BillingItem {
|
||||||
private Date createDate;
|
private final int id;
|
||||||
@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 int billingItemId = -1;
|
@ConstructorProperties("id")
|
||||||
private OperatingSystem operatingSystem;
|
public BillingItem(int id) {
|
||||||
private Datacenter datacenter;
|
this.id = id;
|
||||||
private PowerState powerState;
|
}
|
||||||
|
|
||||||
// for deserializer
|
|
||||||
VirtualGuest() {
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "[id=" + id + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualGuest(int accountId, Date createDate, boolean dedicatedAccountHostOnly, String domain,
|
public static Builder<?> builder() {
|
||||||
String fullyQualifiedDomainName, String hostname, int id, Date lastVerifiedDate, int maxCpu,
|
return new ConcreteBuilder();
|
||||||
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) {
|
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 self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getCreateDate()
|
||||||
|
*/
|
||||||
|
public T createDate(Date createDate) {
|
||||||
|
this.createDate = createDate;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#isDedicatedAccountHostOnly()
|
||||||
|
*/
|
||||||
|
public T dedicatedAccountHostOnly(boolean dedicatedAccountHostOnly) {
|
||||||
|
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getDomain()
|
||||||
|
*/
|
||||||
|
public T domain(String domain) {
|
||||||
|
this.domain = domain;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getFullyQualifiedDomainName()
|
||||||
|
*/
|
||||||
|
public T fullyQualifiedDomainName(String fullyQualifiedDomainName) {
|
||||||
|
this.fullyQualifiedDomainName = fullyQualifiedDomainName;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getMaxCpu()
|
||||||
|
*/
|
||||||
|
public T maxCpu(int maxCpu) {
|
||||||
|
this.maxCpu = maxCpu;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getMaxCpuUnits()
|
||||||
|
*/
|
||||||
|
public T maxCpuUnits(String maxCpuUnits) {
|
||||||
|
this.maxCpuUnits = maxCpuUnits;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getMaxMemory()
|
||||||
|
*/
|
||||||
|
public T maxMemory(int maxMemory) {
|
||||||
|
this.maxMemory = maxMemory;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getMetricPollDate()
|
||||||
|
*/
|
||||||
|
public T metricPollDate(Date metricPollDate) {
|
||||||
|
this.metricPollDate = metricPollDate;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getModifyDate()
|
||||||
|
*/
|
||||||
|
public T modifyDate(Date modifyDate) {
|
||||||
|
this.modifyDate = modifyDate;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getNotes()
|
||||||
|
*/
|
||||||
|
public T notes(String notes) {
|
||||||
|
this.notes = notes;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#isPrivateNetworkOnly()
|
||||||
|
*/
|
||||||
|
public T privateNetworkOnly(boolean privateNetworkOnly) {
|
||||||
|
this.privateNetworkOnly = privateNetworkOnly;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getStartCpus()
|
||||||
|
*/
|
||||||
|
public T startCpus(int startCpus) {
|
||||||
|
this.startCpus = startCpus;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getStatusId()
|
||||||
|
*/
|
||||||
|
public T statusId(int statusId) {
|
||||||
|
this.statusId = statusId;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getUuid()
|
||||||
|
*/
|
||||||
|
public T uuid(String uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getPrimaryBackendIpAddress()
|
||||||
|
*/
|
||||||
|
public T primaryBackendIpAddress(String primaryBackendIpAddress) {
|
||||||
|
this.primaryBackendIpAddress = primaryBackendIpAddress;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getPrimaryIpAddress()
|
||||||
|
*/
|
||||||
|
public T primaryIpAddress(String primaryIpAddress) {
|
||||||
|
this.primaryIpAddress = primaryIpAddress;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getBillingItemId()
|
||||||
|
*/
|
||||||
|
public T billingItemId(int billingItemId) {
|
||||||
|
this.billingItemId = billingItemId;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getOperatingSystem()
|
||||||
|
*/
|
||||||
|
public T operatingSystem(OperatingSystem operatingSystem) {
|
||||||
|
this.operatingSystem = operatingSystem;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getDatacenter()
|
||||||
|
*/
|
||||||
|
public T datacenter(Datacenter datacenter) {
|
||||||
|
this.datacenter = datacenter;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualGuest#getPowerState()
|
||||||
|
*/
|
||||||
|
public T powerState(PowerState powerState) {
|
||||||
|
this.powerState = powerState;
|
||||||
|
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, new BillingItem(billingItemId),
|
||||||
|
operatingSystem, datacenter, powerState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromVirtualGuest(VirtualGuest in) {
|
||||||
|
return this
|
||||||
|
.accountId(in.getAccountId())
|
||||||
|
.createDate(in.getCreateDate())
|
||||||
|
.dedicatedAccountHostOnly(in.isDedicatedAccountHostOnly())
|
||||||
|
.domain(in.getDomain())
|
||||||
|
.fullyQualifiedDomainName(in.getFullyQualifiedDomainName())
|
||||||
|
.hostname(in.getHostname())
|
||||||
|
.id(in.getId())
|
||||||
|
.lastVerifiedDate(in.getLastVerifiedDate())
|
||||||
|
.maxCpu(in.getMaxCpu())
|
||||||
|
.maxCpuUnits(in.getMaxCpuUnits())
|
||||||
|
.maxMemory(in.getMaxMemory())
|
||||||
|
.metricPollDate(in.getMetricPollDate())
|
||||||
|
.modifyDate(in.getModifyDate())
|
||||||
|
.notes(in.getNotes())
|
||||||
|
.privateNetworkOnly(in.isPrivateNetworkOnly())
|
||||||
|
.startCpus(in.getStartCpus())
|
||||||
|
.statusId(in.getStatusId())
|
||||||
|
.uuid(in.getUuid())
|
||||||
|
.primaryBackendIpAddress(in.getPrimaryBackendIpAddress())
|
||||||
|
.primaryIpAddress(in.getPrimaryIpAddress())
|
||||||
|
.billingItemId(in.getBillingItemId())
|
||||||
|
.operatingSystem(in.getOperatingSystem())
|
||||||
|
.datacenter(in.getDatacenter())
|
||||||
|
.powerState(in.getPowerState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@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.accountId = accountId;
|
||||||
this.createDate = createDate;
|
this.createDate = createDate;
|
||||||
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
|
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
|
||||||
|
@ -318,336 +417,241 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.primaryBackendIpAddress = primaryBackendIpAddress;
|
this.primaryBackendIpAddress = primaryBackendIpAddress;
|
||||||
this.primaryIpAddress = primaryIpAddress;
|
this.primaryIpAddress = primaryIpAddress;
|
||||||
this.billingItemId = billingItemId;
|
this.billingItemId = billingItem == null ? -1 : billingItem.id;
|
||||||
this.operatingSystem = operatingSystem;
|
this.operatingSystem = operatingSystem;
|
||||||
this.datacenter = datacenter;
|
this.datacenter = datacenter;
|
||||||
this.powerState = powerState;
|
this.powerState = powerState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(VirtualGuest arg0) {
|
|
||||||
return Integer.valueOf(id).compareTo(arg0.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A computing instance's associated account id
|
* @return A computing instance's associated account id
|
||||||
*/
|
*/
|
||||||
public int getAccountId() {
|
public int getAccountId() {
|
||||||
return accountId;
|
return this.accountId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The date a virtual computing instance was created.
|
* @return The date a virtual computing instance was created.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Date getCreateDate() {
|
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
|
* @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() {
|
public boolean isDedicatedAccountHostOnly() {
|
||||||
return dedicatedAccountHostOnly;
|
return this.dedicatedAccountHostOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A computing instance's domain name
|
* @return A computing instance's domain name
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getDomain() {
|
public String getDomain() {
|
||||||
return domain;
|
return this.domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A name reflecting the hostname and domain of the computing instance.
|
* @return A name reflecting the hostname and domain of the computing instance.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getFullyQualifiedDomainName() {
|
public String getFullyQualifiedDomainName() {
|
||||||
return fullyQualifiedDomainName;
|
return this.fullyQualifiedDomainName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A virtual computing instance's hostname
|
* @return A virtual computing instance's hostname
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getHostname() {
|
public String getHostname() {
|
||||||
return hostname;
|
return this.hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Unique ID for a computing instance.
|
* @return Unique ID for a computing instance.
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
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
|
* @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() {
|
public Date getLastVerifiedDate() {
|
||||||
return lastVerifiedDate;
|
return this.lastVerifiedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The maximum amount of CPU resources a computing instance may utilize.
|
* @return The maximum amount of CPU resources a computing instance may utilize.
|
||||||
*/
|
*/
|
||||||
public int getMaxCpu() {
|
public int getMaxCpu() {
|
||||||
return maxCpu;
|
return this.maxCpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The unit of the maximum amount of CPU resources a computing instance may utilize.
|
* @return The unit of the maximum amount of CPU resources a computing instance may utilize.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getMaxCpuUnits() {
|
public String getMaxCpuUnits() {
|
||||||
return maxCpuUnits;
|
return this.maxCpuUnits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The maximum amount of memory a computing instance may utilize.
|
* @return The maximum amount of memory a computing instance may utilize.
|
||||||
*/
|
*/
|
||||||
public int getMaxMemory() {
|
public int getMaxMemory() {
|
||||||
return maxMemory;
|
return this.maxMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The date of the most recent metric tracking poll performed.
|
* @return The date of the most recent metric tracking poll performed.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Date getMetricPollDate() {
|
public Date getMetricPollDate() {
|
||||||
return metricPollDate;
|
return this.metricPollDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The date a virtual computing instance was last modified.
|
* @return The date a virtual computing instance was last modified.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Date getModifyDate() {
|
public Date getModifyDate() {
|
||||||
return modifyDate;
|
return this.modifyDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A small note about a cloud instance to use at your discretion.
|
* @return A small note about a cloud instance to use at your discretion.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getNotes() {
|
public String getNotes() {
|
||||||
return notes;
|
return this.notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Whether the computing instance only has access to the private network.
|
* @return Whether the computing instance only has access to the private network.
|
||||||
*/
|
*/
|
||||||
public boolean isPrivateNetworkOnly() {
|
public boolean isPrivateNetworkOnly() {
|
||||||
return privateNetworkOnly;
|
return this.privateNetworkOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The number of CPUs available to a computing instance upon startup.
|
* @return The number of CPUs available to a computing instance upon startup.
|
||||||
*/
|
*/
|
||||||
public int getStartCpus() {
|
public int getStartCpus() {
|
||||||
return startCpus;
|
return this.startCpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A computing instances status ID
|
* @return A computing instances status ID
|
||||||
*/
|
*/
|
||||||
public int getStatusId() {
|
public int getStatusId() {
|
||||||
return statusId;
|
return this.statusId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Unique ID for a computing instance's record on a virtualization platform.
|
* @return Unique ID for a computing instance's record on a virtualization platform.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getUuid() {
|
public String getUuid() {
|
||||||
return uuid;
|
return this.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return private ip address
|
* @return private ip address
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getPrimaryBackendIpAddress() {
|
public String getPrimaryBackendIpAddress() {
|
||||||
return primaryBackendIpAddress;
|
return this.primaryBackendIpAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return public ip address
|
* @return public ip address
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getPrimaryIpAddress() {
|
public String getPrimaryIpAddress() {
|
||||||
return primaryIpAddress;
|
return this.primaryIpAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The billing item for a CloudLayer Compute Instance.
|
* @return The billing item for a CloudLayer Compute Instance.
|
||||||
*/
|
*/
|
||||||
public int getBillingItemId() {
|
public int getBillingItemId() {
|
||||||
return billingItemId;
|
return this.billingItemId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A guest's operating system.
|
* @return A guest's operating system.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public OperatingSystem getOperatingSystem() {
|
public OperatingSystem getOperatingSystem() {
|
||||||
return operatingSystem;
|
return this.operatingSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The guest's datacenter
|
* @return The guest's datacenter
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Datacenter getDatacenter() {
|
public Datacenter getDatacenter() {
|
||||||
return datacenter;
|
return this.datacenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The current power state of a virtual guest.
|
* @return The current power state of a virtual guest.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public PowerState getPowerState() {
|
public PowerState getPowerState() {
|
||||||
return powerState;
|
return this.powerState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
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);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
if (obj == null)
|
VirtualGuest that = VirtualGuest.class.cast(obj);
|
||||||
return false;
|
return Objects.equal(this.accountId, that.accountId)
|
||||||
if (getClass() != obj.getClass())
|
&& Objects.equal(this.createDate, that.createDate)
|
||||||
return false;
|
&& Objects.equal(this.dedicatedAccountHostOnly, that.dedicatedAccountHostOnly)
|
||||||
VirtualGuest other = (VirtualGuest) obj;
|
&& Objects.equal(this.domain, that.domain)
|
||||||
if (accountId != other.accountId)
|
&& Objects.equal(this.fullyQualifiedDomainName, that.fullyQualifiedDomainName)
|
||||||
return false;
|
&& Objects.equal(this.hostname, that.hostname)
|
||||||
if (createDate == null) {
|
&& Objects.equal(this.id, that.id)
|
||||||
if (other.createDate != null)
|
&& Objects.equal(this.lastVerifiedDate, that.lastVerifiedDate)
|
||||||
return false;
|
&& Objects.equal(this.maxCpu, that.maxCpu)
|
||||||
} else if (!createDate.equals(other.createDate))
|
&& Objects.equal(this.maxCpuUnits, that.maxCpuUnits)
|
||||||
return false;
|
&& Objects.equal(this.maxMemory, that.maxMemory)
|
||||||
if (dedicatedAccountHostOnly != other.dedicatedAccountHostOnly)
|
&& Objects.equal(this.metricPollDate, that.metricPollDate)
|
||||||
return false;
|
&& Objects.equal(this.modifyDate, that.modifyDate)
|
||||||
if (domain == null) {
|
&& Objects.equal(this.notes, that.notes)
|
||||||
if (other.domain != null)
|
&& Objects.equal(this.privateNetworkOnly, that.privateNetworkOnly)
|
||||||
return false;
|
&& Objects.equal(this.startCpus, that.startCpus)
|
||||||
} else if (!domain.equals(other.domain))
|
&& Objects.equal(this.statusId, that.statusId)
|
||||||
return false;
|
&& Objects.equal(this.uuid, that.uuid)
|
||||||
if (fullyQualifiedDomainName == null) {
|
&& Objects.equal(this.primaryBackendIpAddress, that.primaryBackendIpAddress)
|
||||||
if (other.fullyQualifiedDomainName != null)
|
&& Objects.equal(this.primaryIpAddress, that.primaryIpAddress)
|
||||||
return false;
|
&& Objects.equal(this.billingItemId, that.billingItemId)
|
||||||
} else if (!fullyQualifiedDomainName.equals(other.fullyQualifiedDomainName))
|
&& Objects.equal(this.operatingSystem, that.operatingSystem)
|
||||||
return false;
|
&& Objects.equal(this.datacenter, that.datacenter)
|
||||||
if (hostname == null) {
|
&& Objects.equal(this.powerState, that.powerState);
|
||||||
if (other.hostname != null)
|
}
|
||||||
return false;
|
|
||||||
} else if (!hostname.equals(other.hostname))
|
protected ToStringHelper string() {
|
||||||
return false;
|
return Objects.toStringHelper(this)
|
||||||
if (id != other.id)
|
.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);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[accountId=" + accountId + ", createDate=" + createDate + ", dedicatedAccountHostOnly="
|
return string().toString();
|
||||||
+ 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+"]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class ProductOrderToJsonTest {
|
||||||
.quantity(99)
|
.quantity(99)
|
||||||
.useHourlyPricing(true)
|
.useHourlyPricing(true)
|
||||||
.prices(ImmutableSet.of(price1,price2))
|
.prices(ImmutableSet.of(price1,price2))
|
||||||
.virtualGuest(guest)
|
.virtualGuests(guest)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String expected = String.format(FORMAT.replaceAll("'","\""),
|
String expected = String.format(FORMAT.replaceAll("'","\""),
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class ProductItemToImageTest {
|
||||||
{
|
{
|
||||||
ProductItem item = ProductItem.builder()
|
ProductItem item = ProductItem.builder()
|
||||||
.description(description)
|
.description(description)
|
||||||
.price(ProductItemPrice.builder().id(1234).build())
|
.prices(ProductItemPrice.builder().id(1234).build())
|
||||||
.build();
|
.build();
|
||||||
Image i = new ProductItemToImage().apply(item);
|
Image i = new ProductItemToImage().apply(item);
|
||||||
OperatingSystem os = i.getOperatingSystem();
|
OperatingSystem os = i.getOperatingSystem();
|
||||||
|
@ -122,7 +122,7 @@ public class ProductItemToImageTest {
|
||||||
public void testUbuntu() {
|
public void testUbuntu() {
|
||||||
ProductItem item = ProductItem.builder()
|
ProductItem item = ProductItem.builder()
|
||||||
.description("Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install (64 bit)")
|
.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();
|
.build();
|
||||||
Image i = new ProductItemToImage().apply(item);
|
Image i = new ProductItemToImage().apply(item);
|
||||||
OperatingSystem os = i.getOperatingSystem();
|
OperatingSystem os = i.getOperatingSystem();
|
||||||
|
@ -136,7 +136,7 @@ public class ProductItemToImageTest {
|
||||||
public void testUbuntuNoBitCount() {
|
public void testUbuntuNoBitCount() {
|
||||||
ProductItem item = ProductItem.builder()
|
ProductItem item = ProductItem.builder()
|
||||||
.description("Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install")
|
.description("Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install")
|
||||||
.price(ProductItemPrice.builder().id(1234).build())
|
.prices(ProductItemPrice.builder().id(1234).build())
|
||||||
.build();
|
.build();
|
||||||
Image i = new ProductItemToImage().apply(item);
|
Image i = new ProductItemToImage().apply(item);
|
||||||
OperatingSystem os = i.getOperatingSystem();
|
OperatingSystem os = i.getOperatingSystem();
|
||||||
|
@ -151,7 +151,7 @@ public class ProductItemToImageTest {
|
||||||
public void testCompletelyUnknown() {
|
public void testCompletelyUnknown() {
|
||||||
ProductItem item = ProductItem.builder()
|
ProductItem item = ProductItem.builder()
|
||||||
.description("This fails to match anything!!!")
|
.description("This fails to match anything!!!")
|
||||||
.price(ProductItemPrice.builder().id(1234).build())
|
.prices(ProductItemPrice.builder().id(1234).build())
|
||||||
.build();
|
.build();
|
||||||
Image i = new ProductItemToImage().apply(item);
|
Image i = new ProductItemToImage().apply(item);
|
||||||
OperatingSystem os = i.getOperatingSystem();
|
OperatingSystem os = i.getOperatingSystem();
|
||||||
|
@ -165,7 +165,7 @@ public class ProductItemToImageTest {
|
||||||
public void test64BitUnknown() {
|
public void test64BitUnknown() {
|
||||||
ProductItem item = ProductItem.builder()
|
ProductItem item = ProductItem.builder()
|
||||||
.description("This only has the bit-count (64 bit)")
|
.description("This only has the bit-count (64 bit)")
|
||||||
.price(ProductItemPrice.builder().id(1234).build())
|
.prices(ProductItemPrice.builder().id(1234).build())
|
||||||
.build();
|
.build();
|
||||||
Image i = new ProductItemToImage().apply(item);
|
Image i = new ProductItemToImage().apply(item);
|
||||||
OperatingSystem os = i.getOperatingSystem();
|
OperatingSystem os = i.getOperatingSystem();
|
||||||
|
@ -183,7 +183,7 @@ public class ProductItemToImageTest {
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testNoDescription() {
|
public void testNoDescription() {
|
||||||
ProductItem item = ProductItem.builder()
|
ProductItem item = ProductItem.builder()
|
||||||
.price(ProductItemPrice.builder().id(1234).build())
|
.prices(ProductItemPrice.builder().id(1234).build())
|
||||||
.build();
|
.build();
|
||||||
new ProductItemToImage().apply(item);
|
new ProductItemToImage().apply(item);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ public class ProductItemToImageTest {
|
||||||
@Test
|
@Test
|
||||||
public void testId() {
|
public void testId() {
|
||||||
ProductItemPrice price = ProductItemPrice.builder().id(1234).build();
|
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));
|
assertEquals("1234",imageId().apply(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class ProductItemsTest {
|
||||||
item = ProductItem.builder().id(1)
|
item = ProductItem.builder().id(1)
|
||||||
.capacity(2.0f)
|
.capacity(2.0f)
|
||||||
.description("an item")
|
.description("an item")
|
||||||
.price(price)
|
.prices(price)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ public class ProductItemsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testItemCallGetsCategory() {
|
public void testItemCallGetsCategory() {
|
||||||
ProductItemPrice price = ProductItemPrice.builder().id(1)
|
ProductItemPrice price = ProductItemPrice.builder().id(1)
|
||||||
.category(category)
|
.categories(category)
|
||||||
.item(item)
|
.item(item)
|
||||||
.build();
|
.build();
|
||||||
ProductItem newItem = item().apply(price);
|
ProductItem newItem = item().apply(price);
|
||||||
|
@ -114,8 +114,7 @@ public class ProductItemsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testItemCallNoCategoryOnPrice() {
|
public void testItemCallNoCategoryOnPrice() {
|
||||||
|
|
||||||
ProductItem item1 = ProductItem.Builder.fromProductItem(item)
|
ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category)).build();
|
||||||
.categories(ImmutableSet.of(category)).build();
|
|
||||||
|
|
||||||
ProductItemPrice price = ProductItemPrice.builder().id(1)
|
ProductItemPrice price = ProductItemPrice.builder().id(1)
|
||||||
.item(item1)
|
.item(item1)
|
||||||
|
@ -132,11 +131,10 @@ public class ProductItemsTest {
|
||||||
.categoryCode("new category")
|
.categoryCode("new category")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ProductItem item1 = ProductItem.Builder.fromProductItem(item)
|
ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category2)).build();
|
||||||
.categories(ImmutableSet.of(category2)).build();
|
|
||||||
|
|
||||||
ProductItemPrice price = ProductItemPrice.builder().id(1)
|
ProductItemPrice price = ProductItemPrice.builder().id(1)
|
||||||
.category(category)
|
.categories(category)
|
||||||
.item(item1)
|
.item(item1)
|
||||||
.build();
|
.build();
|
||||||
ProductItem newItem = item().apply(price);
|
ProductItem newItem = item().apply(price);
|
||||||
|
|
|
@ -67,26 +67,26 @@ public class ProductItemsToHardwareTest {
|
||||||
.id(1)
|
.id(1)
|
||||||
.description("2 x 2.0 GHz Cores")
|
.description("2 x 2.0 GHz Cores")
|
||||||
.capacity(2F)
|
.capacity(2F)
|
||||||
.category(ProductItemCategory.builder().categoryCode("guest_core").build())
|
.categories(ProductItemCategory.builder().categoryCode("guest_core").build())
|
||||||
.price(ProductItemPrice.builder().id(123).build())
|
.prices(ProductItemPrice.builder().id(123).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ramItem = ProductItem.builder().id(2).description("2GB ram").capacity(2F).category(
|
ramItem = ProductItem.builder().id(2).description("2GB ram").capacity(2F).categories(
|
||||||
ProductItemCategory.builder().categoryCode("ram").build()).price(
|
ProductItemCategory.builder().categoryCode("ram").build()).prices(
|
||||||
ProductItemPrice.builder().id(456).build()).build();
|
ProductItemPrice.builder().id(456).build()).build();
|
||||||
|
|
||||||
volumeItem = ProductItem.builder().id(3).description("100 GB (SAN)").capacity(100F).price(
|
volumeItem = ProductItem.builder().id(3).description("100 GB (SAN)").capacity(100F).prices(
|
||||||
ProductItemPrice.builder().id(789).build()).category(
|
ProductItemPrice.builder().id(789).build()).categories(
|
||||||
ProductItemCategory.builder().categoryCode("guest_disk0").build()).build();
|
ProductItemCategory.builder().categoryCode("guest_disk0").build()).build();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHardwareId() {
|
public void testHardwareId() {
|
||||||
ProductItem item1 = ProductItem.builder().price(ProductItemPrice.builder().id(123).build()).build();
|
ProductItem item1 = ProductItem.builder().prices(ProductItemPrice.builder().id(123).build()).build();
|
||||||
ProductItem item2 = ProductItem.builder().price(ProductItemPrice.builder().id(456).build()).build();
|
ProductItem item2 = ProductItem.builder().prices(ProductItemPrice.builder().id(456).build()).build();
|
||||||
ProductItem item3 = ProductItem.builder().price(ProductItemPrice.builder().id(789).build()).build();
|
ProductItem item3 = ProductItem.builder().prices(ProductItemPrice.builder().id(789).build()).build();
|
||||||
|
|
||||||
String id = hardwareId().apply(ImmutableList.of(item1, item2, item3));
|
String id = hardwareId().apply(ImmutableList.of(item1, item2, item3));
|
||||||
assertEquals("123,456,789", id);
|
assertEquals("123,456,789", id);
|
||||||
|
@ -138,9 +138,9 @@ public class ProductItemsToHardwareTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHardwareWithTwoDisks() {
|
public void testHardwareWithTwoDisks() {
|
||||||
ProductItem localVolumeItem = ProductItem.builder().id(4).description("25 GB").capacity(25F).price(
|
ProductItem localVolumeItem = ProductItem.builder().id(4).description("25 GB").capacity(25F).prices(
|
||||||
ProductItemPrice.builder().id(987).build()).category(
|
ProductItemPrice.builder().id(987).build()).categories(
|
||||||
ProductItemCategory.builder().categoryCode("guest_disk1").build()).build();
|
ProductItemCategory.builder().categoryCode("guest_disk1").build()).build();
|
||||||
|
|
||||||
Hardware hardware = toHardware.apply(ImmutableSet.of(cpuItem, ramItem, volumeItem,localVolumeItem));
|
Hardware hardware = toHardware.apply(ImmutableSet.of(cpuItem, ramItem, volumeItem,localVolumeItem));
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||||
|
|
||||||
for (ProductItemPrice price : item.getPrices()) {
|
for (ProductItemPrice price : item.getPrices()) {
|
||||||
// ProductItemPrice newDetails =
|
// ProductItemPrice newDetails =
|
||||||
// client.getProductItemPrice(price.getId());
|
// client.getProductItemPrice(prices.getId());
|
||||||
// assertEquals(item.getId(), newDetails.getId());
|
// assertEquals(item.getId(), newDetails.getId());
|
||||||
checkPrice(price);
|
checkPrice(price);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||||
TEST_HOSTNAME_PREFIX + new Random().nextInt()).build();
|
TEST_HOSTNAME_PREFIX + new Random().nextInt()).build();
|
||||||
|
|
||||||
ProductOrder order = ProductOrder.builder().packageId(pkgId).quantity(1).useHourlyPricing(true).prices(
|
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);
|
ProductOrderReceipt receipt = socontext.getApi().getVirtualGuestClient().orderVirtualGuest(order);
|
||||||
ProductOrder order2 = receipt.getOrderDetails();
|
ProductOrder order2 = receipt.getOrderDetails();
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class ParseVirtualGuestHaltedTest extends BaseItemParserTest<VirtualGuest
|
||||||
.primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001)
|
.primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001)
|
||||||
.uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
|
.uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
|
||||||
.operatingSystem(OperatingSystem.builder().id(913824)
|
.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())
|
.build())
|
||||||
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
|
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
|
||||||
//TODO: maybe powerState can be flattened like billingItemId
|
//TODO: maybe powerState can be flattened like billingItemId
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class ParseVirtualGuestPausedTest extends BaseItemParserTest<VirtualGuest
|
||||||
.primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001)
|
.primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001)
|
||||||
.uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
|
.uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
|
||||||
.operatingSystem(OperatingSystem.builder().id(913824)
|
.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())
|
.build())
|
||||||
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
|
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
|
||||||
//TODO: maybe powerState can be flattened like billingItemId
|
//TODO: maybe powerState can be flattened like billingItemId
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class ParseVirtualGuestRunningTest extends BaseItemParserTest<VirtualGues
|
||||||
.primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001)
|
.primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001)
|
||||||
.uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
|
.uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
|
||||||
.operatingSystem(OperatingSystem.builder().id(913824)
|
.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())
|
.build())
|
||||||
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
|
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
|
||||||
//TODO: maybe powerState can be flattened like billingItemId
|
//TODO: maybe powerState can be flattened like billingItemId
|
||||||
|
|
Loading…
Reference in New Issue