Merge pull request #77 from jsonking/master

Issue 158 refactoring/tidy-up and a start on the node states.
This commit is contained in:
Adrian Cole 2011-09-23 09:24:27 -07:00
commit 27ba77e611
17 changed files with 416 additions and 161 deletions

View File

@ -33,6 +33,8 @@ import org.jclouds.softlayer.domain.VirtualGuest;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.Set; import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Converts a ProductOrder into a json string * Converts a ProductOrder into a json string
* valid for placing an order via the softlayer api * valid for placing an order via the softlayer api
@ -51,6 +53,7 @@ public class ProductOrderToJson implements Binder {
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) { public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkNotNull(input,"order");
ProductOrder order = ProductOrder.class.cast(input); ProductOrder order = ProductOrder.class.cast(input);
request.setPayload(buildJson(order)); request.setPayload(buildJson(order));
return request; return request;

View File

@ -49,13 +49,14 @@ import com.google.common.collect.ImmutableSet;
@Singleton @Singleton
public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMetadata> { public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMetadata> {
//TODO: There may be more states than this.
public static final Map<VirtualGuest.State, NodeState> serverStateToNodeState = ImmutableMap public static final Map<VirtualGuest.State, NodeState> serverStateToNodeState = ImmutableMap
.<VirtualGuest.State, NodeState> builder().put(VirtualGuest.State.RUNNING, NodeState.RUNNING)// .<VirtualGuest.State, NodeState> builder()
.put(VirtualGuest.State.STARTING, NodeState.PENDING)// .put(VirtualGuest.State.RUNNING, NodeState.RUNNING)
.put(VirtualGuest.State.DESTROYED, NodeState.TERMINATED)// .put(VirtualGuest.State.PAUSED, NodeState.SUSPENDED)
// TODO other states .put(VirtualGuest.State.HALTED, NodeState.PENDING)
.put(VirtualGuest.State.UNRECOGNIZED, NodeState.UNRECOGNIZED)// .put(VirtualGuest.State.UNRECOGNIZED, NodeState.UNRECOGNIZED)
.build(); .build();
private final FindHardwareForVirtualGuest findHardwareForVirtualGuest; private final FindHardwareForVirtualGuest findHardwareForVirtualGuest;
private final FindLocationForVirtualGuest findLocationForVirtualGuest; private final FindLocationForVirtualGuest findLocationForVirtualGuest;

View File

@ -33,12 +33,12 @@ public class Address implements Comparable<Address> {
} }
public static class Builder { public static class Builder {
private long id = -1; private int id = -1;
private String country; private String country;
private String state; private String state;
private String description; private String description;
public Builder id(long id) { public Builder id(int id) {
this.id = id; this.id = id;
return this; return this;
} }
@ -70,7 +70,7 @@ public class Address implements Comparable<Address> {
} }
} }
private long id = -1; private int id = -1;
private String country; private String country;
private String state; private String state;
private String description; private String description;
@ -80,7 +80,7 @@ public class Address implements Comparable<Address> {
} }
public Address(long id, String country, String state, String description) { public Address(int id, String country, String state, 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;
@ -89,13 +89,13 @@ public class Address implements Comparable<Address> {
@Override @Override
public int compareTo(Address arg0) { public int compareTo(Address arg0) {
return new Long(id).compareTo(arg0.getId()); return new Integer(id).compareTo(arg0.getId());
} }
/** /**
* @return The unique id of the address. * @return The unique id of the address.
*/ */
public long getId() { public int getId() {
return id; return id;
} }
@ -128,7 +128,7 @@ public class Address implements Comparable<Address> {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (int) (id ^ (id >>> 32)); result = prime * result + (id ^ (id >>> 32));
return result; return result;
} }

View File

@ -33,9 +33,9 @@ public class BillingItemVirtualGuest implements Comparable<BillingItemVirtualGue
} }
public static class Builder { public static class Builder {
private long id = -1; private int id = -1;
public Builder id(long id) { public Builder id(int id) {
this.id = id; this.id = id;
return this; return this;
} }
@ -45,26 +45,26 @@ public class BillingItemVirtualGuest implements Comparable<BillingItemVirtualGue
} }
} }
private long id = -1; private int id = -1;
// for deserializer // for deserializer
BillingItemVirtualGuest() { BillingItemVirtualGuest() {
} }
public BillingItemVirtualGuest(long id) { public BillingItemVirtualGuest(int id) {
this.id = id; this.id = id;
} }
@Override @Override
public int compareTo(BillingItemVirtualGuest arg0) { public int compareTo(BillingItemVirtualGuest arg0) {
return new Long(id).compareTo(arg0.getId()); return new Integer(id).compareTo(arg0.getId());
} }
/** /**
* @return The unique identifier for this billing item. * @return The unique identifier for this billing item.
*/ */
public long getId() { public int getId() {
return id; return id;
} }
@ -76,7 +76,7 @@ public class BillingItemVirtualGuest implements Comparable<BillingItemVirtualGue
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (int) (id ^ (id >>> 32)); result = prime * result + (id ^ (id >>> 32));
return result; return result;
} }

View File

@ -30,12 +30,12 @@ public class Datacenter implements Comparable<Datacenter> {
} }
public static class Builder { public static class Builder {
private long id = -1; private int id = -1;
private String name; private String name;
private String longName; private String longName;
private Address locationAddress; private Address locationAddress;
public Builder id(long id) { public Builder id(int id) {
this.id = id; this.id = id;
return this; return this;
} }
@ -64,7 +64,7 @@ public class Datacenter implements Comparable<Datacenter> {
} }
} }
private long id = -1; private int id = -1;
private String name; private String name;
private String longName; private String longName;
private Address locationAddress; private Address locationAddress;
@ -74,7 +74,7 @@ public class Datacenter implements Comparable<Datacenter> {
} }
public Datacenter(long id, String name, String longName, Address locationAddress) { public Datacenter(int id, String name, String longName, Address locationAddress) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.longName = longName; this.longName = longName;
@ -83,13 +83,13 @@ public class Datacenter implements Comparable<Datacenter> {
@Override @Override
public int compareTo(Datacenter arg0) { public int compareTo(Datacenter arg0) {
return new Long(id).compareTo(arg0.getId()); return new Integer(id).compareTo(arg0.getId());
} }
/** /**
* @return The unique identifier of a specific location. * @return The unique identifier of a specific location.
*/ */
public long getId() { public int getId() {
return id; return id;
} }
@ -122,7 +122,7 @@ public class Datacenter implements Comparable<Datacenter> {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (int) (id ^ (id >>> 32)); result = prime * result + (id ^ (id >>> 32));
return result; return result;
} }

View File

@ -44,14 +44,14 @@ public class ProductItem implements Comparable<ProductItem> {
} }
public static class Builder { public static class Builder {
private long id = -1; private int id = -1;
private String description; private String description;
private String units; private String units;
private Float capacity; private Float capacity;
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet(); private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet(); private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
public Builder id(long id) { public Builder id(int id) {
this.id = id; this.id = id;
return this; return this;
} }
@ -105,7 +105,7 @@ public class ProductItem implements Comparable<ProductItem> {
} }
} }
private long id = -1; private int id = -1;
private String description; private String description;
private String units; private String units;
private Float capacity; private Float capacity;
@ -117,7 +117,7 @@ public class ProductItem implements Comparable<ProductItem> {
} }
public ProductItem(long id, String description, String units, Float capacity, public ProductItem(int id, String description, String units, Float capacity,
Iterable<ProductItemPrice> prices, Iterable<ProductItemCategory> categories) { Iterable<ProductItemPrice> prices, Iterable<ProductItemCategory> categories) {
this.id = id; this.id = id;
this.description = description; this.description = description;
@ -129,13 +129,13 @@ public class ProductItem implements Comparable<ProductItem> {
@Override @Override
public int compareTo(ProductItem arg0) { public int compareTo(ProductItem arg0) {
return new Long(id).compareTo(arg0.getId()); return new Integer(id).compareTo(arg0.getId());
} }
/** /**
* @return The unique identifier of a specific location. * @return The unique identifier of a specific location.
*/ */
public long getId() { public int getId() {
return id; return id;
} }
@ -188,7 +188,7 @@ public class ProductItem implements Comparable<ProductItem> {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (int) (id ^ (id >>> 32)); result = prime * result + (id ^ (id >>> 32));
return result; return result;
} }

View File

@ -36,11 +36,11 @@ public class ProductItemCategory implements Comparable<ProductItemCategory> {
} }
public static class Builder { public static class Builder {
private long id = -1; private int id = -1;
private String name; private String name;
private String categoryCode; private String categoryCode;
public Builder id(long id) { public Builder id(int id) {
this.id = id; this.id = id;
return this; return this;
} }
@ -66,7 +66,7 @@ public class ProductItemCategory implements Comparable<ProductItemCategory> {
} }
} }
private long id = -1; private int id = -1;
private String name; private String name;
private String categoryCode; private String categoryCode;
@ -75,7 +75,7 @@ public class ProductItemCategory implements Comparable<ProductItemCategory> {
} }
public ProductItemCategory(long id, String name, String categoryCode) { public ProductItemCategory(int id, String name, String categoryCode) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.categoryCode = categoryCode; this.categoryCode = categoryCode;
@ -83,13 +83,13 @@ public class ProductItemCategory implements Comparable<ProductItemCategory> {
@Override @Override
public int compareTo(ProductItemCategory arg0) { public int compareTo(ProductItemCategory arg0) {
return new Long(id).compareTo(arg0.getId()); return new Integer(id).compareTo(arg0.getId());
} }
/** /**
* @return The unique identifier of a specific location. * @return The unique identifier of a specific location.
*/ */
public long getId() { public int getId() {
return id; return id;
} }
@ -115,7 +115,7 @@ public class ProductItemCategory implements Comparable<ProductItemCategory> {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (int) (id ^ (id >>> 32)); result = prime * result + (id ^ (id >>> 32));
return result; return result;
} }

View File

@ -40,12 +40,12 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
} }
public static class Builder { public static class Builder {
private long id = -1; private int id = -1;
private long itemId = -1; private long itemId = -1;
private Float recurringFee; private Float recurringFee;
private Float hourlyRecurringFee; private Float hourlyRecurringFee;
public Builder id(long id) { public Builder id(int id) {
this.id = id; this.id = id;
return this; return this;
} }
@ -75,7 +75,7 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
} }
} }
private long id = -1; private int id = -1;
private long itemId = -1; private long itemId = -1;
private Float recurringFee; private Float recurringFee;
private Float hourlyRecurringFee; private Float hourlyRecurringFee;
@ -85,7 +85,7 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
} }
public ProductItemPrice(long id, long itemId, Float recurringFee, Float hourlyRecurringFee) { public ProductItemPrice(int id, long itemId, Float recurringFee, Float hourlyRecurringFee) {
this.id = id; this.id = id;
this.itemId = itemId; this.itemId = itemId;
this.recurringFee = recurringFee; this.recurringFee = recurringFee;
@ -94,13 +94,13 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
@Override @Override
public int compareTo(ProductItemPrice arg0) { public int compareTo(ProductItemPrice arg0) {
return new Long(id).compareTo(arg0.getId()); return new Integer(id).compareTo(arg0.getId());
} }
/** /**
* @return The unique identifier of a Product Item Price. * @return The unique identifier of a Product Item Price.
*/ */
public long getId() { public int getId() {
return id; return id;
} }
@ -154,6 +154,6 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
@Override @Override
public int hashCode() { public int hashCode() {
return (int) (id ^ (id >>> 32)); return (id ^ (id >>> 32));
} }
} }

View File

@ -38,14 +38,14 @@ public class ProductOrder {
} }
public static class Builder { public static class Builder {
private long packageId = -1; private int packageId = -1;
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet(); private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
private Set<VirtualGuest> virtualGuests = Sets.newLinkedHashSet(); private Set<VirtualGuest> virtualGuests = Sets.newLinkedHashSet();
private String location; private String location;
private long quantity; private int quantity;
private boolean useHourlyPricing; private boolean useHourlyPricing;
public Builder packageId(long packageId) { public Builder packageId(int packageId) {
this.packageId = packageId; this.packageId = packageId;
return this; return this;
} }
@ -92,7 +92,7 @@ public class ProductOrder {
return this; return this;
} }
public Builder quantity(long quantity) { public Builder quantity(int quantity) {
this.quantity = quantity; this.quantity = quantity;
return this; return this;
} }
@ -116,11 +116,11 @@ public class ProductOrder {
} }
} }
private long packageId = -1; private int packageId = -1;
private String location; private String location;
private Set<ProductItemPrice> prices = Sets.newLinkedHashSet(); private Set<ProductItemPrice> prices = Sets.newLinkedHashSet();
private Set<VirtualGuest> virtualGuests = Sets.newLinkedHashSet(); private Set<VirtualGuest> virtualGuests = Sets.newLinkedHashSet();
private long quantity; private int quantity;
private boolean useHourlyPricing; private boolean useHourlyPricing;
// for deserializer // for deserializer
@ -128,7 +128,7 @@ public class ProductOrder {
} }
public ProductOrder(long packageId, String location, Iterable<ProductItemPrice> prices, Iterable<VirtualGuest> virtualGuest, long quantity, boolean useHourlyPricing) { public ProductOrder(int packageId, String location, Iterable<ProductItemPrice> prices, Iterable<VirtualGuest> virtualGuest, int quantity, boolean useHourlyPricing) {
this.packageId = packageId; this.packageId = packageId;
this.location = checkNotNull(emptyToNull(location),"location cannot be null or empty:"+location); this.location = checkNotNull(emptyToNull(location),"location cannot be null or empty:"+location);
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices")); this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
@ -140,7 +140,7 @@ public class ProductOrder {
/** /**
* @return The package id of an order. This is required. * @return The package id of an order. This is required.
*/ */
public long getPackageId() { public int getPackageId() {
return packageId; return packageId;
} }
@ -168,7 +168,7 @@ public class ProductOrder {
return virtualGuests; return virtualGuests;
} }
public long getQuantity() { public int getQuantity() {
return quantity; return quantity;
} }
@ -202,11 +202,11 @@ public class ProductOrder {
@Override @Override
public int hashCode() { public int hashCode() {
int result = (int) (packageId ^ (packageId >>> 32)); int result = (packageId ^ (packageId >>> 32));
result = 31 * result + (location != null ? location.hashCode() : 0); result = 31 * result + (location != null ? location.hashCode() : 0);
result = 31 * result + (prices != null ? prices.hashCode() : 0); result = 31 * result + (prices != null ? prices.hashCode() : 0);
result = 31 * result + (virtualGuests != null ? virtualGuests.hashCode() : 0); result = 31 * result + (virtualGuests != null ? virtualGuests.hashCode() : 0);
result = 31 * result + (int) (quantity ^ (quantity >>> 32)); result = 31 * result + (quantity ^ (quantity >>> 32));
result = 31 * result + (useHourlyPricing ? 1 : 0); result = 31 * result + (useHourlyPricing ? 1 : 0);
return result; return result;
} }

View File

@ -30,9 +30,9 @@ public class ProductOrderReceipt implements Comparable<ProductOrderReceipt> {
} }
public static class Builder { public static class Builder {
private long orderId = -1; private int orderId = -1;
public Builder orderId(long orderId) { public Builder orderId(int orderId) {
this.orderId = orderId; this.orderId = orderId;
return this; return this;
} }
@ -46,26 +46,26 @@ public class ProductOrderReceipt implements Comparable<ProductOrderReceipt> {
} }
} }
private long orderId = -1; private int orderId = -1;
// for deserializer // for deserializer
ProductOrderReceipt() { ProductOrderReceipt() {
} }
public ProductOrderReceipt(long orderId) { public ProductOrderReceipt(int orderId) {
this.orderId = orderId; this.orderId = orderId;
} }
@Override @Override
public int compareTo(ProductOrderReceipt arg0) { public int compareTo(ProductOrderReceipt arg0) {
return new Long(orderId).compareTo(arg0.getOrderId()); return new Integer(orderId).compareTo(arg0.getOrderId());
} }
/** /**
* @return unique identifier for the order. * @return unique identifier for the order.
*/ */
public long getOrderId() { public int getOrderId() {
return orderId; return orderId;
} }
@ -77,7 +77,7 @@ public class ProductOrderReceipt implements Comparable<ProductOrderReceipt> {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (int) (orderId ^ (orderId >>> 32)); result = prime * result + (orderId ^ (orderId >>> 32));
return result; return result;
} }

View File

@ -45,13 +45,13 @@ public class ProductPackage implements Comparable<ProductPackage> {
} }
public static class Builder { public static class Builder {
private long id = -1; private int id = -1;
private String name; private String name;
private String description; private String description;
private Set<ProductItem> items = Sets.newLinkedHashSet(); private Set<ProductItem> items = Sets.newLinkedHashSet();
private Set<Datacenter> datacenters = Sets.newLinkedHashSet(); private Set<Datacenter> datacenters = Sets.newLinkedHashSet();
public Builder id(long id) { public Builder id(int id) {
this.id = id; this.id = id;
return this; return this;
} }
@ -89,7 +89,7 @@ public class ProductPackage implements Comparable<ProductPackage> {
} }
} }
private long id = -1; private int id = -1;
private String name; private String name;
private String description; private String description;
private Set<ProductItem> items = Sets.newLinkedHashSet(); private Set<ProductItem> items = Sets.newLinkedHashSet();
@ -100,7 +100,7 @@ public class ProductPackage implements Comparable<ProductPackage> {
} }
public ProductPackage(long id, String name, String description, Iterable<ProductItem> items, Iterable<Datacenter> datacenters) { public ProductPackage(int id, String name, String description, Iterable<ProductItem> items, Iterable<Datacenter> datacenters) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.description = description; this.description = description;
@ -110,14 +110,14 @@ public class ProductPackage implements Comparable<ProductPackage> {
@Override @Override
public int compareTo(ProductPackage arg0) { public int compareTo(ProductPackage arg0) {
return new Long(id).compareTo(arg0.getId()); return new Integer(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 long getId() { public int getId() {
return id; return id;
} }
@ -163,7 +163,7 @@ public class ProductPackage implements Comparable<ProductPackage> {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (int) (id ^ (id >>> 32)); result = prime * result + (id ^ (id >>> 32));
return result; return result;
} }

View File

@ -34,7 +34,7 @@ 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#Local_Properties" * "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest"
* /> * />
*/ */
public class VirtualGuest implements Comparable<VirtualGuest> { public class VirtualGuest implements Comparable<VirtualGuest> {
@ -43,12 +43,45 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
} }
public static class Builder { public static class Builder {
private String domain; private int id = -1;
private int accountId = -1;
private Date createDate;
private boolean dedicatedAccountHostOnly;
private String hostname; 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 BillingItemVirtualGuest billingItem;
public Builder id(int id) {
this.id = id;
return this;
}
public Builder domain(String domain) { public Builder accountId(int accountId) {
this.domain = domain; 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; return this;
} }
@ -57,21 +90,131 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return this; 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 billingItem(BillingItemVirtualGuest billingItem) {
this.billingItem = billingItem;
return this;
}
public VirtualGuest build() { public VirtualGuest build() {
return new VirtualGuest(-1, null, true, domain,null,hostname, return new VirtualGuest(accountId, createDate, dedicatedAccountHostOnly, domain,
-1,null,-1, null,-1,null,null,null, fullyQualifiedDomainName, hostname, id, lastVerifiedDate, maxCpu,
true,-1,-1,null,null,null,null); maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes,
privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress,
primaryIpAddress,billingItem);
} }
public static Builder fromVirtualGuest(VirtualGuest in) { public static Builder fromVirtualGuest(VirtualGuest in) {
return VirtualGuest.builder() return VirtualGuest.builder()
.accountId(in.getAccountId())
.createDate(in.getCreateDate())
.dedicatedAccountHostOnly(in.isDedicatedAccountHostOnly())
.domain(in.getDomain()) .domain(in.getDomain())
.hostname(in.getHostname()); .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())
.billingItem(in.getBillingItem());
} }
} }
/**
* TBD: These states come from the powerState field. i.e.
* https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests/{id}?objectMask=powerState
*/
public static enum State { public static enum State {
STARTING, RUNNING, STOPPING, STOPPED, DESTROYED, EXPUNGING, MIGRATING, ERROR, UNKNOWN, SHUTDOWNED, UNRECOGNIZED; //ACTIVE, // Get this from https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/{id}/getStatus
PAUSED,
RUNNING,
HALTED,
UNRECOGNIZED;
@Override @Override
public String toString() { public String toString() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
@ -84,17 +227,16 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return UNRECOGNIZED; return UNRECOGNIZED;
} }
} }
} }
private long accountId = -1; private int accountId = -1;
private Date createDate; private Date createDate;
@SerializedName("dedicatedAccountHostOnlyFlag") @SerializedName("dedicatedAccountHostOnlyFlag")
private boolean dedicatedAccountHostOnly; private boolean dedicatedAccountHostOnly;
private String domain; private String domain;
private String fullyQualifiedDomainName; private String fullyQualifiedDomainName;
private String hostname; private String hostname;
private long id = -1; private int id = -1;
private Date lastVerifiedDate; private Date lastVerifiedDate;
private int maxCpu = -1; private int maxCpu = -1;
private String maxCpuUnits; private String maxCpuUnits;
@ -117,8 +259,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
} }
public VirtualGuest(long accountId, Date createDate, boolean dedicatedAccountHostOnly, String domain, public VirtualGuest(int accountId, Date createDate, boolean dedicatedAccountHostOnly, String domain,
String fullyQualifiedDomainName, String hostname, long id, Date lastVerifiedDate, int maxCpu, String fullyQualifiedDomainName, String hostname, int id, Date lastVerifiedDate, int maxCpu,
String maxCpuUnits, int maxMemory, Date metricPollDate, Date modifyDate, String notes, String maxCpuUnits, int maxMemory, Date metricPollDate, Date modifyDate, String notes,
boolean privateNetworkOnly, int startCpus, int statusId, String uuid, String primaryBackendIpAddress, boolean privateNetworkOnly, int startCpus, int statusId, String uuid, String primaryBackendIpAddress,
String primaryIpAddress,BillingItemVirtualGuest billingItem) { String primaryIpAddress,BillingItemVirtualGuest billingItem) {
@ -147,13 +289,13 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
@Override @Override
public int compareTo(VirtualGuest arg0) { public int compareTo(VirtualGuest arg0) {
return new Long(id).compareTo(arg0.getId()); return new Integer(id).compareTo(arg0.getId());
} }
/** /**
* @return A computing instance's associated account id * @return A computing instance's associated account id
*/ */
public long getAccountId() { public int getAccountId() {
return accountId; return accountId;
} }
@ -196,7 +338,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
/** /**
* @return Unique ID for a computing instance. * @return Unique ID for a computing instance.
*/ */
public long getId() { public int getId() {
return id; return id;
} }
@ -304,13 +446,13 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (int) (accountId ^ (accountId >>> 32)); result = prime * result + (accountId ^ (accountId >>> 32));
result = prime * result + ((createDate == null) ? 0 : createDate.hashCode()); result = prime * result + ((createDate == null) ? 0 : createDate.hashCode());
result = prime * result + (dedicatedAccountHostOnly ? 1231 : 1237); result = prime * result + (dedicatedAccountHostOnly ? 1231 : 1237);
result = prime * result + ((domain == null) ? 0 : domain.hashCode()); result = prime * result + ((domain == null) ? 0 : domain.hashCode());
result = prime * result + ((fullyQualifiedDomainName == null) ? 0 : fullyQualifiedDomainName.hashCode()); result = prime * result + ((fullyQualifiedDomainName == null) ? 0 : fullyQualifiedDomainName.hashCode());
result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); result = prime * result + ((hostname == null) ? 0 : hostname.hashCode());
result = prime * result + (int) (id ^ (id >>> 32)); result = prime * result + (id ^ (id >>> 32));
result = prime * result + ((lastVerifiedDate == null) ? 0 : lastVerifiedDate.hashCode()); result = prime * result + ((lastVerifiedDate == null) ? 0 : lastVerifiedDate.hashCode());
result = prime * result + maxCpu; result = prime * result + maxCpu;
result = prime * result + ((maxCpuUnits == null) ? 0 : maxCpuUnits.hashCode()); result = prime * result + ((maxCpuUnits == null) ? 0 : maxCpuUnits.hashCode());
@ -430,7 +572,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
+ ", metricPollDate=" + metricPollDate + ", modifyDate=" + modifyDate + ", notes=" + notes + ", metricPollDate=" + metricPollDate + ", modifyDate=" + modifyDate + ", notes=" + notes
+ ", primaryBackendIpAddress=" + primaryBackendIpAddress + ", primaryIpAddress=" + primaryIpAddress + ", primaryBackendIpAddress=" + primaryBackendIpAddress + ", primaryIpAddress=" + primaryIpAddress
+ ", privateNetworkOnly=" + privateNetworkOnly + ", startCpus=" + startCpus + ", statusId=" + statusId + ", privateNetworkOnly=" + privateNetworkOnly + ", startCpus=" + startCpus + ", statusId=" + statusId
+ ", uuid=" + uuid + "]"; + ", uuid=" + uuid + ", billingItem="+billingItem+"]";
} }
} }

View File

@ -31,7 +31,7 @@ import org.jclouds.softlayer.domain.ProductPackage;
* @see <a href="http://sldn.softlayer.com/article/REST" /> * @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole * @author Adrian Cole
*/ */
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 45, timeUnit = TimeUnit.SECONDS)
public interface ProductPackageClient { public interface ProductPackageClient {
/** /**

View File

@ -34,16 +34,21 @@ public interface SoftLayerConstants {
*/ */
public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME = "jclouds.softlayer.virtualguest.package-name"; public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME = "jclouds.softlayer.virtualguest.package-name";
/**
* Name of the package used for ordering virtual guests.
*/
public static final String CLOUD_SERVER_PACKAGE_NAME = "Cloud Server";
public static final Set<ProductItemPrice> DEFAULT_VIRTUAL_GUEST_PRICES = ImmutableSet.<ProductItemPrice>builder() public static final Set<ProductItemPrice> DEFAULT_VIRTUAL_GUEST_PRICES = ImmutableSet.<ProductItemPrice>builder()
.add(ProductItemPrice.builder().id(1639L).build()) // 100 GB (SAN) .add(ProductItemPrice.builder().id(1639).build()) // 100 GB (SAN)
.add(ProductItemPrice.builder().id(21L).build()) // 1 IP Address .add(ProductItemPrice.builder().id(21).build()) // 1 IP Address
.add(ProductItemPrice.builder().id(55L).build()) // Host Ping .add(ProductItemPrice.builder().id(55).build()) // Host Ping
.add(ProductItemPrice.builder().id(58L).build()) // Automated Notification .add(ProductItemPrice.builder().id(58).build()) // Automated Notification
.add(ProductItemPrice.builder().id(1800L).build()) // 0 GB Bandwidth .add(ProductItemPrice.builder().id(1800).build()) // 0 GB Bandwidth
.add(ProductItemPrice.builder().id(57L).build()) // Email and Ticket .add(ProductItemPrice.builder().id(57).build()) // Email and Ticket
.add(ProductItemPrice.builder().id(274L).build()) // 1000 Mbps Public & Private Networks .add(ProductItemPrice.builder().id(274).build()) // 1000 Mbps Public & Private Networks
.add(ProductItemPrice.builder().id(905L).build()) // Reboot / Remote Console .add(ProductItemPrice.builder().id(905).build()) // Reboot / Remote Console
.add(ProductItemPrice.builder().id(418L).build()) // Nessus Vulnerability Assessment & Reporting .add(ProductItemPrice.builder().id(418).build()) // Nessus Vulnerability Assessment & Reporting
.add(ProductItemPrice.builder().id(420L).build()) // Unlimited SSL VPN Users & 1 PPTP VPN User per account .add(ProductItemPrice.builder().id(420).build()) // Unlimited SSL VPN Users & 1 PPTP VPN User per account
.build(); .build();
} }

View File

@ -0,0 +1,79 @@
package org.jclouds.softlayer.binders;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.json.internal.GsonWrapper;
import org.jclouds.rest.Binder;
import org.jclouds.softlayer.domain.ProductItemPrice;
import org.jclouds.softlayer.domain.ProductOrder;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.net.URI;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code ProductOrderToJsonTest}
*
* @author Jason King
*/
@Test(groups = "unit")
public class ProductOrderToJsonTest {
private static final String FORMAT =
"{'parameters':[{'complexType':'SoftLayer_Container_Product_Order_Virtual_Guest'," +
"'packageId':%d," +
"'location':'%s'," +
"'prices':[{'id':%d},{'id':%d}]," +
"'virtualGuests':[{'hostname':'%s','domain':'%s'}]," +
"'quantity':%d," +
"'useHourlyPricing':%b}" +
"]}";
private HttpRequest request;
private Binder binder;
@BeforeGroups(groups = { "unit" })
public void setup() {
request = HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).build();
Json json = new GsonWrapper(new Gson());
binder = new ProductOrderToJson(json);
}
@Test(expectedExceptions = NullPointerException.class)
public void testNullOrder() {
binder.bindToRequest(request, null);
}
@Test
public void testCorrect() {
ProductItemPrice price1 = ProductItemPrice.builder().id(100).build();
ProductItemPrice price2 = ProductItemPrice.builder().id(101).build();
VirtualGuest guest = VirtualGuest.builder().hostname("myhost")
.domain("mydomain")
.build();
ProductOrder order = ProductOrder.builder()
.packageId(123)
.location("loc456")
.quantity(99)
.useHourlyPricing(true)
.prices(ImmutableSet.of(price1,price2))
.virtualGuest(guest)
.build();
String expected = String.format(FORMAT.replaceAll("'","\""),
123,"loc456",100,101,"myhost","mydomain",99,true);
HttpRequest req = binder.bindToRequest(request, order);
assertEquals(req.getPayload().getRawContent(), expected);
}
}

View File

@ -22,10 +22,8 @@ import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.jclouds.softlayer.compute.functions.ProductItems; import org.jclouds.softlayer.compute.functions.ProductItems;
import org.jclouds.softlayer.domain.*; import org.jclouds.softlayer.domain.*;
import org.jclouds.softlayer.reference.SoftLayerConstants;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -34,6 +32,7 @@ import java.util.Set;
import static org.jclouds.softlayer.predicates.ProductItemPredicates.*; import static org.jclouds.softlayer.predicates.ProductItemPredicates.*;
import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named; import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named;
import static org.jclouds.softlayer.reference.SoftLayerConstants.CLOUD_SERVER_PACKAGE_NAME;
import static org.testng.Assert.*; import static org.testng.Assert.*;
/** /**
@ -54,12 +53,10 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
cloudServerProductPackage = client.getProductPackage(cloudServerPackageId); cloudServerProductPackage = client.getProductPackage(cloudServerPackageId);
} }
private static final String CLOUD_SERVER_PACKAGE_NAME = "Cloud Server";
private ProductPackageClient client; private ProductPackageClient client;
private AccountClient accountClient; private AccountClient accountClient;
private long cloudServerPackageId; private int cloudServerPackageId;
private ProductPackage cloudServerProductPackage; private ProductPackage cloudServerProductPackage;
@Test @Test
@ -119,7 +116,7 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
Map<Float, ProductItem> ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity()); Map<Float, ProductItem> ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity());
ProductItemPrice price = ProductItems.price().apply(ramToProductItem.get(1.0f)); ProductItemPrice price = ProductItems.price().apply(ramToProductItem.get(1.0f));
assert new Long(1644L).equals(price.getId()); assert new Integer(1644).equals(price.getId());
} }
@Test @Test
@ -131,7 +128,7 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
Map<Float, ProductItem> coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity()); Map<Float, ProductItem> coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity());
ProductItemPrice price = ProductItems.price().apply(coresToProductItem.get(2.0f)); ProductItemPrice price = ProductItems.price().apply(coresToProductItem.get(2.0f));
assert new Long(1963L).equals(price.getId()); assert new Integer(1963).equals(price.getId());
} }
@Test @Test
@ -141,49 +138,7 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
Map<String, ProductItem> osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description()); Map<String, ProductItem> osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description());
ProductItemPrice price = ProductItems.price().apply(osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)")); ProductItemPrice price = ProductItems.price().apply(osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)"));
assert new Long(1693L).equals(price.getId()); assert new Integer(1693).equals(price.getId());
}
@Test
public void testPricesForLaunchingGuestVM() {
Iterable<ProductItem> ramItems = Iterables.filter(cloudServerProductPackage.getItems(),
Predicates.and(categoryCode("ram"), capacity(2.0f)));
Map<Float, ProductItem> ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity());
ProductItemPrice ramPrice = ProductItems.price().apply(ramToProductItem.get(2.0f));
Iterable<ProductItem> cpuItems = Iterables.filter(cloudServerProductPackage.getItems(), Predicates.and(units("PRIVATE_CORE"), capacity(2.0f)));
Map<Float, ProductItem> coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity());
ProductItemPrice cpuPrice = ProductItems.price().apply(coresToProductItem.get(2.0f));
Iterable<ProductItem> operatingSystems = Iterables.filter(cloudServerProductPackage.getItems(), categoryCode("os"));
Map<String, ProductItem> osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description());
ProductItemPrice osPrice = ProductItems.price().apply(osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)"));
Set<ProductItemPrice> prices = Sets.<ProductItemPrice>newLinkedHashSet();
prices.addAll(SoftLayerConstants.DEFAULT_VIRTUAL_GUEST_PRICES);
prices.add(ramPrice);
prices.add(cpuPrice);
prices.add(osPrice);
VirtualGuest guest = VirtualGuest.builder().domain("jclouds.org")
.hostname("livetest")
.build();
String location = ""+Iterables.get(cloudServerProductPackage.getDatacenters(),0).getId();
ProductOrder order = ProductOrder.builder()
.packageId(cloudServerPackageId)
.location(location)
.quantity(1)
.useHourlyPricing(true)
.prices(prices)
.virtualGuest(guest)
.build();
//ProductOrderReceipt receipt = context.getApi().getVirtualGuestClient().orderVirtualGuest(order);
//TODO: There must be a more concise way of expressing this logic.
} }
private void checkProductItem(ProductItem item) { private void checkProductItem(ProductItem item) {

View File

@ -18,16 +18,25 @@
*/ */
package org.jclouds.softlayer.features; package org.jclouds.softlayer.features;
import static org.testng.Assert.assertEquals; import com.google.common.base.Predicates;
import static org.testng.Assert.assertTrue; import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import java.util.Set; import com.google.common.collect.Sets;
import org.jclouds.softlayer.compute.functions.ProductItems;
import org.jclouds.softlayer.domain.BillingItemVirtualGuest; import org.jclouds.softlayer.domain.*;
import org.jclouds.softlayer.domain.VirtualGuest; import org.jclouds.softlayer.reference.SoftLayerConstants;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import static org.jclouds.softlayer.predicates.ProductItemPredicates.*;
import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named;
import static org.jclouds.softlayer.reference.SoftLayerConstants.CLOUD_SERVER_PACKAGE_NAME;
import static org.testng.Assert.*;
/** /**
* Tests behavior of {@code VirtualGuestClient} * Tests behavior of {@code VirtualGuestClient}
* *
@ -35,6 +44,9 @@ import org.testng.annotations.Test;
*/ */
@Test(groups = "live") @Test(groups = "live")
public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest { public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
private static final String TEST_HOSTNAME_PREFIX = "livetest";
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
super.setupClient(); super.setupClient();
@ -55,6 +67,64 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
} }
} }
@Test
public void testCancelAndPlaceOrder() {
// TODO: Should also check if there are active transactions before trying to cancel.
// objectMask: virtualGuests.activeTransaction
for( VirtualGuest guest: client.listVirtualGuests()) {
if (guest.getHostname().startsWith(TEST_HOSTNAME_PREFIX)) {
BillingItemVirtualGuest billingItem = guest.getBillingItem();
if(billingItem!=null) {
client.cancelService(billingItem.getId());
}
}
}
int pkgId = Iterables.find(context.getApi().getAccountClient().getActivePackages(),named(CLOUD_SERVER_PACKAGE_NAME)).getId();
ProductPackage productPackage = context.getApi().getProductPackageClient().getProductPackage(pkgId);
Iterable<ProductItem> ramItems = Iterables.filter(productPackage.getItems(),
Predicates.and(categoryCode("ram"), capacity(2.0f)));
Map<Float, ProductItem> ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity());
ProductItemPrice ramPrice = ProductItems.price().apply(ramToProductItem.get(2.0f));
Iterable<ProductItem> cpuItems = Iterables.filter(productPackage.getItems(), Predicates.and(units("PRIVATE_CORE"), capacity(2.0f)));
Map<Float, ProductItem> coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity());
ProductItemPrice cpuPrice = ProductItems.price().apply(coresToProductItem.get(2.0f));
Iterable<ProductItem> operatingSystems = Iterables.filter(productPackage.getItems(), categoryCode("os"));
Map<String, ProductItem> osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description());
ProductItemPrice osPrice = ProductItems.price().apply(osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)"));
Set<ProductItemPrice> prices = Sets.<ProductItemPrice>newLinkedHashSet();
prices.addAll(SoftLayerConstants.DEFAULT_VIRTUAL_GUEST_PRICES);
prices.add(ramPrice);
prices.add(cpuPrice);
prices.add(osPrice);
VirtualGuest guest = VirtualGuest.builder().domain("jclouds.org")
.hostname(TEST_HOSTNAME_PREFIX+new Random().nextInt())
.build();
String location = ""+Iterables.get(productPackage.getDatacenters(),0).getId();
ProductOrder order = ProductOrder.builder()
.packageId(pkgId)
.location(location)
.quantity(1)
.useHourlyPricing(true)
.prices(prices)
.virtualGuest(guest)
.build();
ProductOrderReceipt receipt = context.getApi().getVirtualGuestClient().orderVirtualGuest(order);
assertNotNull(receipt);
}
private void checkVirtualGuest(VirtualGuest vg) { private void checkVirtualGuest(VirtualGuest vg) {
if (vg.getBillingItem()==null) return;//Quotes and shutting down guests if (vg.getBillingItem()==null) return;//Quotes and shutting down guests
checkBillingItem(vg.getBillingItem()); checkBillingItem(vg.getBillingItem());