mirror of https://github.com/apache/jclouds.git
Merge branch 'master' of github.com:jclouds/jclouds
* 'master' of github.com:jclouds/jclouds: Issue 158: Removed location override Mark a live test as not enabled (needs investigation), change comment line Issue 158: Fixing unit/live tests Better error message - print node details Issue 158: Updated comment Issue 158: Get prices via orderTemplateCall. Use this to build hardware/image/os
This commit is contained in:
commit
b2e1da711a
|
@ -718,7 +718,7 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
long time = currentTimeMillis();
|
long time = currentTimeMillis();
|
||||||
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
|
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
|
||||||
NodeMetadata node = getOnlyElement(nodes);
|
NodeMetadata node = getOnlyElement(nodes);
|
||||||
assert node.getState() != NodeState.RUNNING;
|
assert node.getState() != NodeState.RUNNING : node;
|
||||||
long duration = (currentTimeMillis() - time) / 1000;
|
long duration = (currentTimeMillis() - time) / 1000;
|
||||||
assert duration < nonBlockDurationSeconds : format("duration(%d) longer than expected(%d) seconds! ",
|
assert duration < nonBlockDurationSeconds : format("duration(%d) longer than expected(%d) seconds! ",
|
||||||
duration, nonBlockDurationSeconds);
|
duration, nonBlockDurationSeconds);
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class ProductItemToImage implements Function<ProductItem, Image> {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return new ImageBuilder()
|
return new ImageBuilder()
|
||||||
.id(imageId().apply(productItem))
|
.ids(imageId().apply(productItem))
|
||||||
.description(productItem.getDescription())
|
.description(productItem.getDescription())
|
||||||
.operatingSystem(os)
|
.operatingSystem(os)
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -21,9 +21,11 @@ package org.jclouds.softlayer.compute.functions;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import org.jclouds.softlayer.domain.ProductItem;
|
import org.jclouds.softlayer.domain.ProductItem;
|
||||||
|
import org.jclouds.softlayer.domain.ProductItemCategory;
|
||||||
import org.jclouds.softlayer.domain.ProductItemPrice;
|
import org.jclouds.softlayer.domain.ProductItemPrice;
|
||||||
|
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class ProductItems {
|
public class ProductItems {
|
||||||
|
|
||||||
|
@ -65,4 +67,25 @@ public class ProductItems {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function to get the ProductItem for the ProductItemPrice.
|
||||||
|
* Copies the category information from the price to the item if necessary
|
||||||
|
* The ProductItemPrices must have ProductItems.
|
||||||
|
*/
|
||||||
|
public static Function<ProductItemPrice,ProductItem> item() {
|
||||||
|
return new Function<ProductItemPrice,ProductItem>() {
|
||||||
|
@Override
|
||||||
|
public ProductItem apply(ProductItemPrice productItemPrice) {
|
||||||
|
Set<ProductItemCategory> categories = productItemPrice.getCategories();
|
||||||
|
ProductItem item = productItemPrice.getItem();
|
||||||
|
ProductItem.Builder builder = ProductItem.Builder.fromProductItem(productItemPrice.getItem());
|
||||||
|
if( item.getCategories().size()==0 && categories.size() != 0) {
|
||||||
|
builder.categories(categories);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class ProductItemsToHardware implements Function<Set<ProductItem>, Hardwa
|
||||||
final float volumeSize = ProductItems.capacity().apply(volumeItem);
|
final float volumeSize = ProductItems.capacity().apply(volumeItem);
|
||||||
|
|
||||||
return new HardwareBuilder()
|
return new HardwareBuilder()
|
||||||
.id(hardwareId)
|
.ids(hardwareId)
|
||||||
.processors(ImmutableList.of(new Processor(cores, CORE_SPEED)))
|
.processors(ImmutableList.of(new Processor(cores, CORE_SPEED)))
|
||||||
.ram(ram)
|
.ram(ram)
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(volumeSize, true, false)))
|
.volumes(ImmutableList.<Volume> of(new VolumeImpl(volumeSize, true, false)))
|
||||||
|
|
|
@ -28,18 +28,25 @@ import java.util.Set;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import org.jclouds.collect.FindResourceInSet;
|
import org.jclouds.collect.FindResourceInSet;
|
||||||
import org.jclouds.collect.Memoized;
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.*;
|
import org.jclouds.compute.domain.*;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.http.HttpResponseException;
|
||||||
|
import org.jclouds.softlayer.SoftLayerClient;
|
||||||
import org.jclouds.softlayer.domain.Datacenter;
|
import org.jclouds.softlayer.domain.Datacenter;
|
||||||
|
import org.jclouds.softlayer.domain.ProductItem;
|
||||||
|
import org.jclouds.softlayer.domain.ProductOrder;
|
||||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import org.jclouds.softlayer.predicates.ProductItemPredicates;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -54,12 +61,19 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
|
||||||
|
|
||||||
private final Map<String, Credentials> credentialStore;
|
private final Map<String, Credentials> credentialStore;
|
||||||
private final FindLocationForVirtualGuest findLocationForVirtualGuest;
|
private final FindLocationForVirtualGuest findLocationForVirtualGuest;
|
||||||
|
private final GetHardwareForVirtualGuest getHardwareForVirtualGuest;
|
||||||
|
private final GetImageForVirtualGuest getImageForVirtualGuest;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
VirtualGuestToNodeMetadata(Map<String, Credentials> credentialStore,
|
VirtualGuestToNodeMetadata(Map<String, Credentials> credentialStore,
|
||||||
FindLocationForVirtualGuest findLocationForVirtualGuest) {
|
FindLocationForVirtualGuest findLocationForVirtualGuest,
|
||||||
|
GetHardwareForVirtualGuest getHardwareForVirtualGuest,
|
||||||
|
GetImageForVirtualGuest getImageForVirtualGuest
|
||||||
|
) {
|
||||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||||
this.findLocationForVirtualGuest = checkNotNull(findLocationForVirtualGuest, "findLocationForVirtualGuest");
|
this.findLocationForVirtualGuest = checkNotNull(findLocationForVirtualGuest, "findLocationForVirtualGuest");
|
||||||
|
this.getHardwareForVirtualGuest = checkNotNull(getHardwareForVirtualGuest, "getHardwareForVirtualGuest");
|
||||||
|
this.getImageForVirtualGuest = checkNotNull(getImageForVirtualGuest, "getImageForVirtualGuest");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -68,14 +82,19 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
|
||||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||||
builder.ids(from.getId() + "");
|
builder.ids(from.getId() + "");
|
||||||
builder.name(from.getHostname());
|
builder.name(from.getHostname());
|
||||||
|
builder.hostname(from.getHostname());
|
||||||
builder.location(findLocationForVirtualGuest.apply(from));
|
builder.location(findLocationForVirtualGuest.apply(from));
|
||||||
builder.group(parseGroupFromName(from.getHostname()));
|
builder.group(parseGroupFromName(from.getHostname()));
|
||||||
// TODO determine image id (product price)from virtual guest
|
|
||||||
// builder.imageId(from.imageId + "");
|
|
||||||
// TODO make operating system from virtual guest
|
|
||||||
// builder.operatingSystem(OperatingSystem.builder()...);
|
|
||||||
|
|
||||||
builder.hardware(getHardware(from));
|
Image image = getImageForVirtualGuest.getImage(from);
|
||||||
|
if (image!=null) {
|
||||||
|
builder.imageId(image.getId());
|
||||||
|
builder.operatingSystem(image.getOperatingSystem());
|
||||||
|
}
|
||||||
|
|
||||||
|
Hardware hardware = getHardwareForVirtualGuest.getHardware(from);
|
||||||
|
if (hardware!=null) builder.hardware(hardware);
|
||||||
|
|
||||||
builder.state(serverStateToNodeState.get(from.getPowerState().getKeyName()));
|
builder.state(serverStateToNodeState.get(from.getPowerState().getKeyName()));
|
||||||
|
|
||||||
// These are null for 'bad' guest orders in the HALTED state.
|
// These are null for 'bad' guest orders in the HALTED state.
|
||||||
|
@ -105,19 +124,53 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Hardware getHardware(VirtualGuest from) {
|
@Singleton
|
||||||
HardwareBuilder builder = new HardwareBuilder().id("TODO");
|
public static class GetHardwareForVirtualGuest {
|
||||||
|
|
||||||
final double cpus = from.getMaxCpu();
|
private SoftLayerClient client;
|
||||||
if (cpus>0) {
|
|
||||||
builder.processor(new Processor(cpus, CORE_SPEED));
|
@Inject
|
||||||
|
public GetHardwareForVirtualGuest(SoftLayerClient client) {
|
||||||
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int maxMemory = from.getMaxMemory();
|
public Hardware getHardware(VirtualGuest guest) {
|
||||||
if (maxMemory>0) {
|
// 'bad' orders have no start cpu's and cause the order lookup to fail.
|
||||||
builder.ram(maxMemory);
|
if (guest.getStartCpus()<1) return null;
|
||||||
|
try {
|
||||||
|
ProductOrder order = client.getVirtualGuestClient().getOrderTemplate(guest.getId());
|
||||||
|
Iterable<ProductItem> items = Iterables.transform(order.getPrices(),ProductItems.item());
|
||||||
|
return new ProductItemsToHardware().apply(Sets.newLinkedHashSet(items));
|
||||||
|
} catch (HttpResponseException e) {
|
||||||
|
//Shouldn't happen any more - was blowing up in Singapore
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
@Singleton
|
||||||
|
public static class GetImageForVirtualGuest {
|
||||||
|
|
||||||
|
private SoftLayerClient client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public GetImageForVirtualGuest(SoftLayerClient client) {
|
||||||
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Image getImage(VirtualGuest guest) {
|
||||||
|
// 'bad' orders have no start cpu's and cause the order lookup to fail.
|
||||||
|
if (guest.getStartCpus()<1) return null;
|
||||||
|
try {
|
||||||
|
ProductOrder order = client.getVirtualGuestClient().getOrderTemplate(guest.getId());
|
||||||
|
Iterable<ProductItem> items = Iterables.transform(order.getPrices(),ProductItems.item());
|
||||||
|
ProductItem os = Iterables.find(items, ProductItemPredicates.categoryCode("os"));
|
||||||
|
return new ProductItemToImage().apply(os);
|
||||||
|
} catch (HttpResponseException e) {
|
||||||
|
//Shouldn't happen any more - was blowing up in Singapore
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,14 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.domain;
|
package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 price. You can find out what
|
||||||
|
@ -44,6 +50,8 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
|
||||||
private long itemId = -1;
|
private long itemId = -1;
|
||||||
private Float recurringFee;
|
private Float recurringFee;
|
||||||
private Float hourlyRecurringFee;
|
private Float hourlyRecurringFee;
|
||||||
|
private ProductItem item;
|
||||||
|
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
public Builder id(int id) {
|
public Builder id(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -65,8 +73,23 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder item(ProductItem item) {
|
||||||
|
this.item = item;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder category(ProductItemCategory categories) {
|
||||||
|
this.categories.add(checkNotNull(categories, "categories"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder categories(Iterable<ProductItemCategory> categories) {
|
||||||
|
this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ProductItemPrice build() {
|
public ProductItemPrice build() {
|
||||||
return new ProductItemPrice(id, itemId, recurringFee, hourlyRecurringFee);
|
return new ProductItemPrice(id, itemId, recurringFee, hourlyRecurringFee, item, categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromPrice(ProductItemPrice in) {
|
public static Builder fromPrice(ProductItemPrice in) {
|
||||||
|
@ -79,17 +102,21 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
|
||||||
private long itemId = -1;
|
private long itemId = -1;
|
||||||
private Float recurringFee;
|
private Float recurringFee;
|
||||||
private Float hourlyRecurringFee;
|
private Float hourlyRecurringFee;
|
||||||
|
private ProductItem item;
|
||||||
|
private Set<ProductItemCategory> categories = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
// for deserializer
|
// for deserializer
|
||||||
ProductItemPrice() {
|
ProductItemPrice() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductItemPrice(int id, long itemId, Float recurringFee, Float hourlyRecurringFee) {
|
public ProductItemPrice(int id, long itemId, Float recurringFee, Float hourlyRecurringFee, ProductItem item, Iterable<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.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -130,6 +157,21 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
|
||||||
return hourlyRecurringFee;
|
return hourlyRecurringFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return An item's associated item categories.
|
||||||
|
*/
|
||||||
|
public Set<ProductItemCategory> getCategories() {
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The product item a price is tied to.
|
||||||
|
*/
|
||||||
|
public ProductItem getItem() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder toBuilder() {
|
public Builder toBuilder() {
|
||||||
return Builder.fromPrice(this);
|
return Builder.fromPrice(this);
|
||||||
}
|
}
|
||||||
|
@ -137,7 +179,7 @@ public class ProductItemPrice implements Comparable<ProductItemPrice> {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[id=" + id + ", itemId=" + itemId + ", recurringFee=" + recurringFee + ", hourlyRecurringFee="
|
return "[id=" + id + ", itemId=" + itemId + ", recurringFee=" + recurringFee + ", hourlyRecurringFee="
|
||||||
+ hourlyRecurringFee + "]";
|
+ hourlyRecurringFee + ", item="+item+", categories="+categories+"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class ProductOrder {
|
||||||
|
|
||||||
public ProductOrder(int packageId, String location, Iterable<ProductItemPrice> prices, Iterable<VirtualGuest> virtualGuest, int 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 = location;
|
||||||
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
|
this.prices = ImmutableSet.<ProductItemPrice> copyOf(checkNotNull(prices, "prices"));
|
||||||
this.virtualGuests = ImmutableSet.<VirtualGuest> copyOf(checkNotNull(virtualGuest, "virtualGuest"));
|
this.virtualGuests = ImmutableSet.<VirtualGuest> copyOf(checkNotNull(virtualGuest, "virtualGuest"));
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
|
|
|
@ -133,4 +133,15 @@ public interface VirtualGuestAsyncClient {
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<ProductOrderReceipt> orderVirtualGuest(@BinderParam(ProductOrderToJson.class)ProductOrder order);
|
ListenableFuture<ProductOrderReceipt> orderVirtualGuest(@BinderParam(ProductOrderToJson.class)ProductOrder order);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws an Internal Server Error if called on bad orders (mapped to HttpResponseException)
|
||||||
|
* @see VirtualGuestClient#getOrderTemplate
|
||||||
|
* @throws org.jclouds.http.HttpResponseException if called with a 'bad' order.
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("SoftLayer_Virtual_Guest/{id}/getOrderTemplate/MONTHLY.json")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<ProductOrder> getOrderTemplate(@PathParam("id") long id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,14 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.features;
|
package org.jclouds.softlayer.features;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.softlayer.domain.ProductOrder;
|
import org.jclouds.softlayer.domain.ProductOrder;
|
||||||
import org.jclouds.softlayer.domain.ProductOrderReceipt;
|
import org.jclouds.softlayer.domain.ProductOrderReceipt;
|
||||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides synchronous access to VirtualGuest.
|
* Provides synchronous access to VirtualGuest.
|
||||||
* <p/>
|
* <p/>
|
||||||
|
@ -109,4 +109,16 @@ public interface VirtualGuestClient {
|
||||||
* @see <a href="http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder" />
|
* @see <a href="http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder" />
|
||||||
*/
|
*/
|
||||||
ProductOrderReceipt orderVirtualGuest(ProductOrder order);
|
ProductOrderReceipt orderVirtualGuest(ProductOrder order);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain an order container that is ready to be sent to the orderVirtualGuest method.
|
||||||
|
* This container will include all services that the selected computing instance has.
|
||||||
|
* If desired you may remove prices which were returned.
|
||||||
|
* @see <a href=" @see <a href="http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder" />
|
||||||
|
* @param id
|
||||||
|
* The id of the existing Virtual Guest
|
||||||
|
* @return
|
||||||
|
* The ProductOrder used to create the VirtualGust
|
||||||
|
*/
|
||||||
|
ProductOrder getOrderTemplate(long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,9 +69,7 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL
|
||||||
public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() {
|
public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() {
|
||||||
String group = "foo";
|
String group = "foo";
|
||||||
String name = "node"+new Random().nextInt();
|
String name = "node"+new Random().nextInt();
|
||||||
Template template = computeContext.getComputeService().templateBuilder()
|
Template template = computeContext.getComputeService().templateBuilder().build();
|
||||||
.locationId("3") // the default (singapore) doesn't work.
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// test passing custom options
|
// test passing custom options
|
||||||
template.getOptions().as(SoftLayerTemplateOptions.class).domainName("me.org");
|
template.getOptions().as(SoftLayerTemplateOptions.class).domainName("me.org");
|
||||||
|
|
|
@ -43,6 +43,7 @@ import static org.testng.Assert.assertEquals;
|
||||||
public class SoftLayerComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
public class SoftLayerComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
public SoftLayerComputeServiceLiveTest() {
|
public SoftLayerComputeServiceLiveTest() {
|
||||||
provider = "softlayer";
|
provider = "softlayer";
|
||||||
|
group = "soft-layer";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,33 +58,7 @@ public class SoftLayerComputeServiceLiveTest extends BaseComputeServiceLiveTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String tag) throws IOException {
|
public void testOptionToNotBlock() {
|
||||||
super.checkNodes(nodes, tag);
|
// start call is blocking anyway.
|
||||||
for (NodeMetadata node : nodes) {
|
|
||||||
assertEquals(node.getLocation().getScope(), LocationScope.HOST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testReboot", expectedExceptions = UnsupportedOperationException.class)
|
|
||||||
public void testSuspendResume() throws Exception {
|
|
||||||
super.testSuspendResume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testSuspendResume")
|
|
||||||
@Override
|
|
||||||
public void testGetNodesWithDetails() throws Exception {
|
|
||||||
super.testGetNodesWithDetails();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testSuspendResume")
|
|
||||||
@Override
|
|
||||||
public void testListNodes() throws Exception {
|
|
||||||
super.testListNodes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails" })
|
|
||||||
@Override
|
|
||||||
public void testDestroyNodes() {
|
|
||||||
super.testDestroyNodes();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,15 +20,14 @@ package org.jclouds.softlayer.compute.functions;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import org.jclouds.softlayer.domain.ProductItem;
|
import org.jclouds.softlayer.domain.ProductItem;
|
||||||
|
import org.jclouds.softlayer.domain.ProductItemCategory;
|
||||||
import org.jclouds.softlayer.domain.ProductItemPrice;
|
import org.jclouds.softlayer.domain.ProductItemPrice;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import static org.jclouds.softlayer.compute.functions.ProductItems.capacity;
|
import static org.jclouds.softlayer.compute.functions.ProductItems.*;
|
||||||
import static org.jclouds.softlayer.compute.functions.ProductItems.description;
|
|
||||||
import static org.jclouds.softlayer.compute.functions.ProductItems.price;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
|
|
||||||
|
@ -40,12 +39,15 @@ import static org.testng.Assert.assertNull;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ProductItemsTest {
|
public class ProductItemsTest {
|
||||||
|
|
||||||
|
private ProductItemCategory category;
|
||||||
private ProductItemPrice price;
|
private ProductItemPrice price;
|
||||||
private ProductItem item;
|
private ProductItem item;
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
|
||||||
|
category = ProductItemCategory.builder().id(1).categoryCode("category").build();
|
||||||
|
|
||||||
price = ProductItemPrice.builder().id(1).build();
|
price = ProductItemPrice.builder().id(1).build();
|
||||||
|
|
||||||
item = ProductItem.builder().id(1)
|
item = ProductItem.builder().id(1)
|
||||||
|
@ -54,6 +56,7 @@ public class ProductItemsTest {
|
||||||
.price(price)
|
.price(price)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCapacity() {
|
public void testCapacity() {
|
||||||
assertEquals(capacity().apply(item), 2.0f);
|
assertEquals(capacity().apply(item), 2.0f);
|
||||||
|
@ -93,4 +96,48 @@ public class ProductItemsTest {
|
||||||
ProductItem noPriceItem = ProductItem.builder().id(1).build();
|
ProductItem noPriceItem = ProductItem.builder().id(1).build();
|
||||||
price().apply(noPriceItem);
|
price().apply(noPriceItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testItemCallGetsCategory() {
|
||||||
|
ProductItemPrice price = ProductItemPrice.builder().id(1)
|
||||||
|
.category(category)
|
||||||
|
.item(item)
|
||||||
|
.build();
|
||||||
|
ProductItem newItem = item().apply(price);
|
||||||
|
assertEquals(newItem.getCategories(), ImmutableSet.of(category));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testItemCallNoCategoryOnPrice() {
|
||||||
|
|
||||||
|
ProductItem item1 = ProductItem.Builder.fromProductItem(item)
|
||||||
|
.categories(ImmutableSet.of(category)).build();
|
||||||
|
|
||||||
|
ProductItemPrice price = ProductItemPrice.builder().id(1)
|
||||||
|
.item(item1)
|
||||||
|
.build();
|
||||||
|
ProductItem newItem = item().apply(price);
|
||||||
|
assertEquals(newItem.getCategories(), ImmutableSet.of(category));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testItemCallCategoryExists() {
|
||||||
|
|
||||||
|
ProductItemCategory category2 = ProductItemCategory.builder()
|
||||||
|
.id(12)
|
||||||
|
.categoryCode("new category")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ProductItem item1 = ProductItem.Builder.fromProductItem(item)
|
||||||
|
.categories(ImmutableSet.of(category2)).build();
|
||||||
|
|
||||||
|
ProductItemPrice price = ProductItemPrice.builder().id(1)
|
||||||
|
.category(category)
|
||||||
|
.item(item1)
|
||||||
|
.build();
|
||||||
|
ProductItem newItem = item().apply(price);
|
||||||
|
assertEquals(newItem.getCategories(), ImmutableSet.of(category2));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,14 +61,17 @@ public class VirtualGuestToNodeMetadataTest {
|
||||||
.<Location> of(expectedLocation));
|
.<Location> of(expectedLocation));
|
||||||
|
|
||||||
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
||||||
new FindLocationForVirtualGuest(locationSupplier));
|
new FindLocationForVirtualGuest(locationSupplier),new GetHardwareForVirtualGuestMock(),new GetImageForVirtualGuestMock());
|
||||||
|
|
||||||
NodeMetadata node = parser.apply(guest);
|
NodeMetadata node = parser.apply(guest);
|
||||||
|
|
||||||
assertEquals(node, new NodeMetadataBuilder().ids("416788").name("node1000360500").location(
|
assertEquals(node, new NodeMetadataBuilder().ids("416788")
|
||||||
expectedLocation).state(NodeState.PENDING).publicAddresses(ImmutableSet.of("173.192.29.186"))
|
.name("node1000360500").hostname("node1000360500")
|
||||||
.privateAddresses(ImmutableSet.of("10.37.102.194"))
|
.location(expectedLocation).state(NodeState.PENDING)
|
||||||
.hardware(new HardwareBuilder().id("TODO").processor(new Processor(1,2.0)).ram(1042).build())
|
.publicAddresses(ImmutableSet.of("173.192.29.186")).privateAddresses(ImmutableSet.of("10.37.102.194"))
|
||||||
|
.hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
|
||||||
|
.imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
|
||||||
|
.operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
// because it wasn't present in the credential store.
|
// because it wasn't present in the credential store.
|
||||||
|
@ -90,14 +93,16 @@ public class VirtualGuestToNodeMetadataTest {
|
||||||
.<Location> of());
|
.<Location> of());
|
||||||
|
|
||||||
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
||||||
new FindLocationForVirtualGuest(locationSupplier));
|
new FindLocationForVirtualGuest(locationSupplier),new GetHardwareForVirtualGuestMock(),new GetImageForVirtualGuestMock());
|
||||||
|
|
||||||
NodeMetadata node = parser.apply(guest);
|
NodeMetadata node = parser.apply(guest);
|
||||||
|
|
||||||
assertEquals(node, new NodeMetadataBuilder().ids("413348")
|
assertEquals(node, new NodeMetadataBuilder().ids("413348")
|
||||||
.name("foo-ef4").group("foo")
|
.name("foo-ef4").hostname("foo-ef4").group("foo")
|
||||||
.state(NodeState.PENDING)
|
.state(NodeState.PENDING)
|
||||||
.hardware(new HardwareBuilder().id("TODO").ram(256).build())
|
.hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
|
||||||
|
.imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
|
||||||
|
.operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
// because it wasn't present in the credential store.
|
// because it wasn't present in the credential store.
|
||||||
|
@ -120,14 +125,17 @@ public class VirtualGuestToNodeMetadataTest {
|
||||||
.<Location> of(expectedLocation));
|
.<Location> of(expectedLocation));
|
||||||
|
|
||||||
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
||||||
new FindLocationForVirtualGuest(locationSupplier));
|
new FindLocationForVirtualGuest(locationSupplier),new GetHardwareForVirtualGuestMock(),new GetImageForVirtualGuestMock());
|
||||||
|
|
||||||
NodeMetadata node = parser.apply(guest);
|
NodeMetadata node = parser.apply(guest);
|
||||||
|
|
||||||
assertEquals(node, new NodeMetadataBuilder().ids("416700").name("node1703810489").location(
|
assertEquals(node, new NodeMetadataBuilder().ids("416700")
|
||||||
expectedLocation).state(NodeState.PENDING).credentials(credentials)
|
.name("node1703810489").hostname("node1703810489")
|
||||||
|
.location(expectedLocation).state(NodeState.PENDING).credentials(credentials)
|
||||||
.publicAddresses(ImmutableSet.of("173.192.29.187")).privateAddresses(ImmutableSet.of("10.37.102.195"))
|
.publicAddresses(ImmutableSet.of("173.192.29.187")).privateAddresses(ImmutableSet.of("10.37.102.195"))
|
||||||
.hardware(new HardwareBuilder().id("TODO").processor(new Processor(1,2.0)).ram(1042).build())
|
.hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
|
||||||
|
.imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
|
||||||
|
.operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
// because it wasn't present in the credential store.
|
// because it wasn't present in the credential store.
|
||||||
|
@ -150,14 +158,17 @@ public class VirtualGuestToNodeMetadataTest {
|
||||||
.<Location> of(expectedLocation));
|
.<Location> of(expectedLocation));
|
||||||
|
|
||||||
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
||||||
new FindLocationForVirtualGuest(locationSupplier));
|
new FindLocationForVirtualGuest(locationSupplier),new GetHardwareForVirtualGuestMock(),new GetImageForVirtualGuestMock());
|
||||||
|
|
||||||
NodeMetadata node = parser.apply(guest);
|
NodeMetadata node = parser.apply(guest);
|
||||||
|
|
||||||
assertEquals(node, new NodeMetadataBuilder().ids("416700").name("node1703810489").location(
|
assertEquals(node, new NodeMetadataBuilder().ids("416700")
|
||||||
expectedLocation).state(NodeState.SUSPENDED).credentials(credentials)
|
.name("node1703810489").hostname("node1703810489")
|
||||||
|
.location(expectedLocation).state(NodeState.SUSPENDED).credentials(credentials)
|
||||||
.publicAddresses(ImmutableSet.of("173.192.29.187")).privateAddresses(ImmutableSet.of("10.37.102.195"))
|
.publicAddresses(ImmutableSet.of("173.192.29.187")).privateAddresses(ImmutableSet.of("10.37.102.195"))
|
||||||
.hardware(new HardwareBuilder().id("TODO").processor(new Processor(1,2.0)).ram(1042).build())
|
.hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
|
||||||
|
.imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
|
||||||
|
.operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
// because it wasn't present in the credential store.
|
// because it wasn't present in the credential store.
|
||||||
|
@ -180,17 +191,44 @@ public class VirtualGuestToNodeMetadataTest {
|
||||||
.<Location> of(expectedLocation));
|
.<Location> of(expectedLocation));
|
||||||
|
|
||||||
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
|
||||||
new FindLocationForVirtualGuest(locationSupplier));
|
new FindLocationForVirtualGuest(locationSupplier),new GetHardwareForVirtualGuestMock(),new GetImageForVirtualGuestMock());
|
||||||
|
|
||||||
NodeMetadata node = parser.apply(guest);
|
NodeMetadata node = parser.apply(guest);
|
||||||
|
|
||||||
assertEquals(node, new NodeMetadataBuilder().ids("416700").name("node1703810489").location(
|
assertEquals(node, new NodeMetadataBuilder().ids("416700")
|
||||||
expectedLocation).state(NodeState.RUNNING).credentials(credentials)
|
.name("node1703810489").hostname("node1703810489")
|
||||||
|
.location(expectedLocation).state(NodeState.RUNNING).credentials(credentials)
|
||||||
.publicAddresses(ImmutableSet.of("173.192.29.187")).privateAddresses(ImmutableSet.of("10.37.102.195"))
|
.publicAddresses(ImmutableSet.of("173.192.29.187")).privateAddresses(ImmutableSet.of("10.37.102.195"))
|
||||||
.hardware(new HardwareBuilder().id("TODO").processor(new Processor(1,2.0)).ram(1042).build())
|
.hardware(new GetHardwareForVirtualGuestMock().getHardware(guest))
|
||||||
|
.imageId(new GetImageForVirtualGuestMock().getImage(guest).getId())
|
||||||
|
.operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
// because it wasn't present in the credential store.
|
// because it wasn't present in the credential store.
|
||||||
assertEquals(node.getCredentials(), credentials);
|
assertEquals(node.getCredentials(), credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class GetHardwareForVirtualGuestMock extends VirtualGuestToNodeMetadata.GetHardwareForVirtualGuest {
|
||||||
|
public GetHardwareForVirtualGuestMock() {
|
||||||
|
super(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Hardware getHardware(VirtualGuest guest) {
|
||||||
|
return new HardwareBuilder().ids("mocked hardware").build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GetImageForVirtualGuestMock extends VirtualGuestToNodeMetadata.GetImageForVirtualGuest {
|
||||||
|
public GetImageForVirtualGuestMock() {
|
||||||
|
super(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(VirtualGuest guest) {
|
||||||
|
return new ImageBuilder().ids("123").description("mocked image")
|
||||||
|
.operatingSystem(OperatingSystem.builder().description("foo os").build())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,9 +66,11 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(enabled = false)
|
||||||
public void testCancelAndPlaceOrder() {
|
public void testCancelAndPlaceOrder() {
|
||||||
|
|
||||||
|
// This method was not working needs testing out.
|
||||||
|
|
||||||
// TODO: Should also check if there are active transactions before trying to cancel.
|
// TODO: Should also check if there are active transactions before trying to cancel.
|
||||||
// objectMask: virtualGuests.activeTransaction
|
// objectMask: virtualGuests.activeTransaction
|
||||||
for( VirtualGuest guest: client.listVirtualGuests()) {
|
for( VirtualGuest guest: client.listVirtualGuests()) {
|
||||||
|
@ -108,10 +110,8 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||||
.hostname(TEST_HOSTNAME_PREFIX+new Random().nextInt())
|
.hostname(TEST_HOSTNAME_PREFIX+new Random().nextInt())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String location = ""+Iterables.get(productPackage.getDatacenters(),0).getId();
|
|
||||||
ProductOrder order = ProductOrder.builder()
|
ProductOrder order = ProductOrder.builder()
|
||||||
.packageId(pkgId)
|
.packageId(pkgId)
|
||||||
.location(location)
|
|
||||||
.quantity(1)
|
.quantity(1)
|
||||||
.useHourlyPricing(true)
|
.useHourlyPricing(true)
|
||||||
.prices(prices)
|
.prices(prices)
|
||||||
|
@ -119,10 +119,15 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ProductOrderReceipt receipt = context.getApi().getVirtualGuestClient().orderVirtualGuest(order);
|
ProductOrderReceipt receipt = context.getApi().getVirtualGuestClient().orderVirtualGuest(order);
|
||||||
|
ProductOrder order2 = receipt.getOrderDetails();
|
||||||
|
VirtualGuest result = Iterables.get(order2.getVirtualGuests(), 0);
|
||||||
|
|
||||||
|
ProductOrder order3 = context.getApi().getVirtualGuestClient().getOrderTemplate(result.getId());
|
||||||
|
|
||||||
|
assertEquals(order.getPrices(),order3.getPrices());
|
||||||
assertNotNull(receipt);
|
assertNotNull(receipt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkVirtualGuest(VirtualGuest vg) {
|
private void checkVirtualGuest(VirtualGuest vg) {
|
||||||
if (vg.getBillingItemId()==-1) return;//Quotes and shutting down guests
|
if (vg.getBillingItemId()==-1) return;//Quotes and shutting down guests
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
/**
|
||||||
|
* 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.parse;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.json.BaseItemParserTest;
|
||||||
|
import org.jclouds.json.config.GsonModule;
|
||||||
|
import org.jclouds.softlayer.compute.functions.ProductItems;
|
||||||
|
import org.jclouds.softlayer.config.SoftLayerParserModule;
|
||||||
|
import org.jclouds.softlayer.domain.ProductItem;
|
||||||
|
import org.jclouds.softlayer.domain.ProductItemPrice;
|
||||||
|
import org.jclouds.softlayer.domain.ProductOrder;
|
||||||
|
import org.jclouds.softlayer.predicates.ProductItemPredicates;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "ParseProductOrderTest")
|
||||||
|
public class ParseProductOrderTest extends BaseItemParserTest<ProductOrder> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resource() {
|
||||||
|
return "/product_order_template.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public ProductOrder expected() {
|
||||||
|
|
||||||
|
Set<ProductItemPrice> prices = ImmutableSet.<ProductItemPrice>builder()
|
||||||
|
.add(ProductItemPrice.builder().id(1962).itemId(1045).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(1644).itemId(861).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(905).itemId(503).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(274).itemId(188).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(1800).itemId(439).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(21).itemId(15).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(1639).itemId(865).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(1693).itemId(884).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(55).itemId(49).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(57).itemId(51).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(58).itemId(52).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(420).itemId(309).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.add(ProductItemPrice.builder().id(418).itemId(307).recurringFee(0F).hourlyRecurringFee(0F).build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ProductOrder order = ProductOrder.builder()
|
||||||
|
.quantity(0)
|
||||||
|
.packageId(46)
|
||||||
|
.useHourlyPricing(true)
|
||||||
|
.prices(prices)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
ProductOrder expects = expected();
|
||||||
|
Function<HttpResponse, ProductOrder> parser = parser(injector());
|
||||||
|
ProductOrder response = parser.apply(new HttpResponse(200, "ok", payload()));
|
||||||
|
assertEquals(response,expects);
|
||||||
|
hasOs(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hasOs(ProductOrder order) {
|
||||||
|
Iterable<ProductItem> items = Iterables.transform(order.getPrices(), ProductItems.item());
|
||||||
|
ProductItem os = Iterables.find(ImmutableSet.copyOf(items), ProductItemPredicates.categoryCode("os"));
|
||||||
|
assertNotNull(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Injector injector() {
|
||||||
|
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||||
|
super.configure();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue