From f1d6ca2b7fbd9daafc40adfced20048495182386 Mon Sep 17 00:00:00 2001 From: Jason King Date: Wed, 21 Sep 2011 09:57:37 +0100 Subject: [PATCH 1/3] Issue 158: Added equals and hashcode to ProductItemPrice (test fails under maven) --- .../softlayer/domain/ProductItemPrice.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java index b23ea6c152..2fe6b2d5f3 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java @@ -140,4 +140,20 @@ public class ProductItemPrice implements Comparable { + hourlyRecurringFee + "]"; } + @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 + public int hashCode() { + return (int) (id ^ (id >>> 32)); + } } From b14ecb86d549f71ecf1e8b0e86ec635e250d7c66 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 22 Sep 2011 18:04:40 +0100 Subject: [PATCH 2/3] Issue 158: Fix live test: Singapore Datacenter's address does not have state present (id=224092) --- .../org/jclouds/softlayer/features/DatacenterClientLiveTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java index dd16682fc5..55362b2ef7 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java @@ -96,6 +96,5 @@ public class DatacenterClientLiveTest extends BaseSoftLayerClientLiveTest { private void checkAddress(Address address) { assert address.getId() >0 : address; assert address.getCountry() != null : address; - assert address.getState() != null : address; } } From 3bd0c20856c136ba80f02bb570c8465fef338025 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 22 Sep 2011 18:08:55 +0100 Subject: [PATCH 3/3] Issue 158: Can now place orders via VirtualGuestClient. Additional support classes present --- .../softlayer/binders/ProductOrderToJson.java | 130 +++++++++++ .../softlayer/domain/ProductOrder.java | 219 ++++++++++++++++++ .../softlayer/domain/ProductOrderReceipt.java | 104 +++++++++ .../softlayer/domain/VirtualGuest.java | 29 ++- .../features/VirtualGuestAsyncClient.java | 27 ++- .../features/VirtualGuestClient.java | 11 + .../reference/SoftLayerConstants.java | 24 +- .../ProductPackageClientLiveTest.java | 28 ++- .../features/VirtualGuestClientLiveTest.java | 5 +- 9 files changed, 546 insertions(+), 31 deletions(-) create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/binders/ProductOrderToJson.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrder.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrderReceipt.java diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/binders/ProductOrderToJson.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/binders/ProductOrderToJson.java new file mode 100644 index 0000000000..06a626c94c --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/binders/ProductOrderToJson.java @@ -0,0 +1,130 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.softlayer.binders; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.rest.Binder; +import org.jclouds.softlayer.domain.ProductItemPrice; +import org.jclouds.softlayer.domain.ProductOrder; +import org.jclouds.softlayer.domain.VirtualGuest; + +import javax.inject.Inject; +import java.util.Set; + +/** + * Converts a ProductOrder into a json string + * valid for placing an order via the softlayer api + * The String is set into the payload of the HttpRequest + * + * @author Jason King + */ +public class ProductOrderToJson implements Binder { + + private Json json; + + @Inject + public ProductOrderToJson(Json json) { + this.json = json; + } + + @Override + public R bindToRequest(R request, Object input) { + ProductOrder order = ProductOrder.class.cast(input); + request.setPayload(buildJson(order)); + return request; + } + + /** + * Builds a Json string suitable for sending to the softlayer api + * @param order + * @return + */ + String buildJson(ProductOrder order) { + + Iterable prices = Iterables.transform(order.getPrices(), + new Function() { + @Override + public Price apply(ProductItemPrice productItemPrice) { + return new Price(productItemPrice.getId()); + } + }); + + Iterable hosts = Iterables.transform(order.getVirtualGuests(), + new Function() { + @Override + public HostnameAndDomain apply(VirtualGuest virtualGuest) { + return new HostnameAndDomain(virtualGuest.getHostname(),virtualGuest.getDomain()); + } + }); + + OrderData data = new OrderData(order.getPackageId(),order.getLocation(), + Sets.newLinkedHashSet(prices),Sets.newLinkedHashSet(hosts), + order.getQuantity(),order.getUseHourlyPricing()); + + return json.toJson(ImmutableMap.of("parameters", ImmutableList.of(data))); + } + + private static class OrderData { + private String complexType = "SoftLayer_Container_Product_Order_Virtual_Guest"; + private long packageId = -1; + private String location; + private Set prices; + private Set virtualGuests; + private long quantity; + private boolean useHourlyPricing; + + public OrderData( long packageId, String location, + Set prices,Set virtualGuests, + long quantity, boolean useHourlyPricing ) { + this.packageId = packageId; + this.location = location; + this.prices = prices; + this.virtualGuests = virtualGuests; + this.quantity = quantity; + this.useHourlyPricing = useHourlyPricing; + + } + } + + private static class HostnameAndDomain { + private String hostname; + private String domain; + + public HostnameAndDomain(String hostname,String domain) { + this.hostname = hostname; + this.domain = domain; + } + + } + + private static class Price { + private long id; + + public Price(long id) { + this.id = id; + } + } + +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrder.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrder.java new file mode 100644 index 0000000000..beb04f5233 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrder.java @@ -0,0 +1,219 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.softlayer.domain; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Strings.emptyToNull; + +/** + * + * @author Jason King + * @see + */ +public class ProductOrder { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private long packageId = -1; + private Set prices = Sets.newLinkedHashSet(); + private Set virtualGuests = Sets.newLinkedHashSet(); + private String location; + private long quantity; + private boolean useHourlyPricing; + + public Builder packageId(long packageId) { + this.packageId = packageId; + return this; + } + + /** + * Adds a price to the order + * All that is required to send in is the price ID of each item desired to be ordered. + * @param prices + * The Prices of the item desired to be ordered + */ + public Builder price(ProductItemPrice prices) { + this.prices.add(checkNotNull(prices, "prices")); + return this; + } + + /** + * Adds multiple prices to the order, overwriting any existing ones + * All that is required to send in is the price ID of each item desired to be ordered. + * @param prices + * The Prices of the items desired to be ordered + */ + public Builder prices(Iterable prices) { + this.prices = ImmutableSet. 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 virtualGuests) { + this.virtualGuests = ImmutableSet. copyOf(checkNotNull(virtualGuests, "virtualGuests")); + return this; + } + + public Builder location(String location) { + this.location = location; + return this; + } + + public Builder quantity(long quantity) { + this.quantity = quantity; + return this; + } + + public Builder useHourlyPricing(Boolean useHourlyPricing) { + this.useHourlyPricing = useHourlyPricing; + return this; + } + + public ProductOrder build() { + return new ProductOrder(packageId, location,prices, virtualGuests, quantity, useHourlyPricing); + } + + public static Builder fromProductOrder(ProductOrder in) { + return ProductOrder.builder().packageId(in.getPackageId()) + .location(in.getLocation()) + .prices(in.getPrices()) + .virtualGuests(in.getVirtualGuests()) + .quantity(in.getQuantity()) + .useHourlyPricing(in.getUseHourlyPricing()); + } + } + + private long packageId = -1; + private String location; + private Set prices = Sets.newLinkedHashSet(); + private Set virtualGuests = Sets.newLinkedHashSet(); + private long quantity; + private boolean useHourlyPricing; + + // for deserializer + ProductOrder() { + + } + + public ProductOrder(long packageId, String location, Iterable prices, Iterable virtualGuest, long quantity, boolean useHourlyPricing) { + this.packageId = packageId; + this.location = checkNotNull(emptyToNull(location),"location cannot be null or empty:"+location); + this.prices = ImmutableSet. copyOf(checkNotNull(prices, "prices")); + this.virtualGuests = ImmutableSet. copyOf(checkNotNull(virtualGuest, "virtualGuest")); + this.quantity = quantity; + this.useHourlyPricing = useHourlyPricing; + } + + /** + * @return The package id of an order. This is required. + */ + public long getPackageId() { + return packageId; + } + + /** + * @return The region keyname or specific location keyname where the order should be provisioned. + */ + public String getLocation() { + return location; + } + + /** + * Gets the item prices in this order. + * All that is required to be present is the price ID + * @return the prices. + */ + public Set getPrices() { + return prices; + } + + /** + * Gets the virtual guests in this order. + * @return the the virtual guests. + */ + public Set getVirtualGuests() { + return virtualGuests; + } + + public long getQuantity() { + return quantity; + } + + public boolean getUseHourlyPricing() { + return useHourlyPricing; + } + + public Builder toBuilder() { + return Builder.fromProductOrder(this); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProductOrder that = (ProductOrder) o; + + if (packageId != that.packageId) return false; + if (quantity != that.quantity) return false; + if (useHourlyPricing != that.useHourlyPricing) return false; + if (location != null ? !location.equals(that.location) : that.location != null) + return false; + if (prices != null ? !prices.equals(that.prices) : that.prices != null) + return false; + if (virtualGuests != null ? !virtualGuests.equals(that.virtualGuests) : that.virtualGuests != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = (int) (packageId ^ (packageId >>> 32)); + result = 31 * result + (location != null ? location.hashCode() : 0); + result = 31 * result + (prices != null ? prices.hashCode() : 0); + result = 31 * result + (virtualGuests != null ? virtualGuests.hashCode() : 0); + result = 31 * result + (int) (quantity ^ (quantity >>> 32)); + result = 31 * result + (useHourlyPricing ? 1 : 0); + return result; + } + + + public String toString() { + return "[packageId=" + packageId + ", location=" + location + ", prices=" + prices + + ", virtualGuests=" + virtualGuests +", quantity=" + quantity + ", useHourlyPricing=" + useHourlyPricing + "]"; + } +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrderReceipt.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrderReceipt.java new file mode 100644 index 0000000000..ba6e691d20 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrderReceipt.java @@ -0,0 +1,104 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.softlayer.domain; + +/** + * + * @author Jason King + * @see + */ +public class ProductOrderReceipt implements Comparable { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private long orderId = -1; + + public Builder orderId(long orderId) { + this.orderId = orderId; + return this; + } + + public ProductOrderReceipt build() { + return new ProductOrderReceipt(orderId); + } + + public static Builder fromAddress(ProductOrderReceipt in) { + return ProductOrderReceipt.builder().orderId(in.getOrderId()); + } + } + + private long orderId = -1; + + // for deserializer + ProductOrderReceipt() { + + } + + public ProductOrderReceipt(long orderId) { + this.orderId = orderId; + } + + @Override + public int compareTo(ProductOrderReceipt arg0) { + return new Long(orderId).compareTo(arg0.getOrderId()); + } + + /** + * @return unique identifier for the order. + */ + public long getOrderId() { + return orderId; + } + + public Builder toBuilder() { + return Builder.fromAddress(this); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (orderId ^ (orderId >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ProductOrderReceipt other = (ProductOrderReceipt) obj; + if (orderId != other.orderId) + return false; + return true; + } + + @Override + public String toString() { + return "[orderId=" + orderId + "]"; + } + + +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuest.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuest.java index 8691fde2a3..d8ba66a12f 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuest.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuest.java @@ -43,7 +43,31 @@ public class VirtualGuest implements Comparable { } public static class Builder { + private String domain; + private String hostname; + + public Builder domain(String domain) { + this.domain = domain; + return this; + } + + public Builder hostname(String hostname) { + this.hostname = hostname; + return this; + } + + public VirtualGuest build() { + return new VirtualGuest(-1, null, true, domain,null,hostname, + -1,null,-1, null,-1,null,null,null, + true,-1,-1,null,null,null,null); + } + + public static Builder fromVirtualGuest(VirtualGuest in) { + return VirtualGuest.builder() + .domain(in.getDomain()) + .hostname(in.getHostname()); + } } public static enum State { @@ -389,7 +413,10 @@ public class VirtualGuest implements Comparable { return false; } else if (!uuid.equals(other.uuid)) return false; - if (!billingItem.equals(other.billingItem)) + if (billingItem == null) { + if (other.billingItem != null) + return false; + } else if (!billingItem.equals(other.billingItem)) return false; return true; } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java index 1a4bdad2ec..b70b464ea5 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java @@ -18,24 +18,23 @@ */ package org.jclouds.softlayer.features; -import java.util.Set; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.MediaType; - +import com.google.common.util.concurrent.ListenableFuture; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.softlayer.binders.ProductOrderToJson; +import org.jclouds.softlayer.domain.ProductOrder; +import org.jclouds.softlayer.domain.ProductOrderReceipt; import org.jclouds.softlayer.domain.VirtualGuest; -import com.google.common.util.concurrent.ListenableFuture; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.Set; /** * Provides asynchronous access to VirtualGuest via their REST API. @@ -123,4 +122,14 @@ public interface VirtualGuestAsyncClient { @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnVoidOnNotFoundOr404.class) ListenableFuture cancelService(@PathParam("id") long id); + + /** + * @see org.jclouds.softlayer.features.VirtualGuestClient#orderVirtualGuest + */ + @POST + @Path("/SoftLayer_Product_Order/placeOrder.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture orderVirtualGuest(@BinderParam(ProductOrderToJson.class)ProductOrder order); + } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java index a7a14f9757..74d9172a75 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java @@ -22,6 +22,8 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.softlayer.domain.ProductOrder; +import org.jclouds.softlayer.domain.ProductOrderReceipt; import org.jclouds.softlayer.domain.VirtualGuest; /** @@ -98,4 +100,13 @@ public interface VirtualGuestClient { * @return true or false */ boolean cancelService(long id); + + /** + * Use this method for placing server orders and additional services orders. + * @param order + * Details required to order. + * @return A receipt for the order + * @see + */ + ProductOrderReceipt orderVirtualGuest(ProductOrder order); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java index ec97fa6a09..200e4357c3 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java @@ -19,7 +19,7 @@ package org.jclouds.softlayer.reference; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; +import org.jclouds.softlayer.domain.ProductItemPrice; import java.util.Set; @@ -34,16 +34,16 @@ public interface SoftLayerConstants { */ public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME = "jclouds.softlayer.virtualguest.package-name"; - public static final Set DEFAULT_VIRTUAL_GUEST_PRICES = ImmutableSet.builder() - .add(1639L) // 100 GB (SAN) - .add(21L) // 1 IP Address - .add(55L) // Host Ping - .add(58L) // Automated Notification - .add(1800L) // 0 GB Bandwidth - .add(57L) // Email and Ticket - .add(274L) // 1000 Mbps Public & Private Networks - .add(905L) // Reboot / Remote Console - .add(418L) // Nessus Vulnerability Assessment & Reporting - .add(420L) // Unlimited SSL VPN Users & 1 PPTP VPN User per account + public static final Set DEFAULT_VIRTUAL_GUEST_PRICES = ImmutableSet.builder() + .add(ProductItemPrice.builder().id(1639L).build()) // 100 GB (SAN) + .add(ProductItemPrice.builder().id(21L).build()) // 1 IP Address + .add(ProductItemPrice.builder().id(55L).build()) // Host Ping + .add(ProductItemPrice.builder().id(58L).build()) // Automated Notification + .add(ProductItemPrice.builder().id(1800L).build()) // 0 GB Bandwidth + .add(ProductItemPrice.builder().id(57L).build()) // Email and Ticket + .add(ProductItemPrice.builder().id(274L).build()) // 1000 Mbps Public & Private Networks + .add(ProductItemPrice.builder().id(905L).build()) // Reboot / Remote Console + .add(ProductItemPrice.builder().id(418L).build()) // Nessus Vulnerability Assessment & Reporting + .add(ProductItemPrice.builder().id(420L).build()) // Unlimited SSL VPN Users & 1 PPTP VPN User per account .build(); } diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java index cd86987191..9a7a2b73c5 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java @@ -147,11 +147,11 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest { @Test public void testPricesForLaunchingGuestVM() { Iterable ramItems = Iterables.filter(cloudServerProductPackage.getItems(), - Predicates.and(categoryCode("ram"), capacity(1.0f))); + Predicates.and(categoryCode("ram"), capacity(2.0f))); Map ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity()); - ProductItemPrice ramPrice = ProductItems.price().apply(ramToProductItem.get(1.0f)); + ProductItemPrice ramPrice = ProductItems.price().apply(ramToProductItem.get(2.0f)); Iterable cpuItems = Iterables.filter(cloudServerProductPackage.getItems(), Predicates.and(units("PRIVATE_CORE"), capacity(2.0f))); Map coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity()); @@ -162,13 +162,27 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest { Map osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description()); ProductItemPrice osPrice = ProductItems.price().apply(osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)")); - Set prices = Sets.newLinkedHashSet(); + Set prices = Sets.newLinkedHashSet(); prices.addAll(SoftLayerConstants.DEFAULT_VIRTUAL_GUEST_PRICES); - prices.add(ramPrice.getId()); - prices.add(cpuPrice.getId()); - prices.add(osPrice.getId()); + prices.add(ramPrice); + prices.add(cpuPrice); + prices.add(osPrice); - //This should be everything needed to launch Ubuntu Hardy Heron with 1GB Ram and 2 CPU Cores + 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. } diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java index bc1fc21f79..f3789a2d17 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java @@ -56,6 +56,9 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest { } private void checkVirtualGuest(VirtualGuest vg) { + if (vg.getBillingItem()==null) return;//Quotes and shutting down guests + checkBillingItem(vg.getBillingItem()); + assert vg.getAccountId() > 0 : vg; assert vg.getCreateDate() != null : vg; assert vg.getDomain() != null : vg; @@ -72,8 +75,6 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest { assert vg.getUuid() != null : vg; assert vg.getPrimaryBackendIpAddress() != null : vg; assert vg.getPrimaryIpAddress() != null : vg; - - checkBillingItem(vg.getBillingItem()); } private void checkBillingItem(BillingItemVirtualGuest billingItem) {