Issue 158 Return Datacenter (location) information with ProductPackage

This commit is contained in:
Jason King 2011-09-09 10:54:49 +01:00
parent bf36742639
commit cd70eefc6d
5 changed files with 51 additions and 21 deletions

View File

@ -21,7 +21,7 @@ package org.jclouds.softlayer.domain;
/**
*
* @author Adrian Cole
* @see <a href= "http://sldn.softlayer.com/reference/services/SoftLayer_Location_Datacenter"
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Location_Datacenter"
* />
*/
public class Datacenter implements Comparable<Datacenter> {

View File

@ -18,19 +18,19 @@
*/
package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The SoftLayer_Product_Package data type contains information about packages
* from which orders can be generated. Packages contain general information
* regarding what is in them, where they are currently sold, availability, and
* pricing.
*
*
* @author Adrian Cole
* @see <a href=
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Package"
@ -49,6 +49,7 @@ public class ProductPackage implements Comparable<ProductPackage> {
private String name;
private String description;
private Set<ProductItem> items = Sets.newLinkedHashSet();
private Set<Datacenter> datacenters = Sets.newLinkedHashSet();
public Builder id(long id) {
this.id = id;
@ -70,13 +71,21 @@ public class ProductPackage implements Comparable<ProductPackage> {
return this;
}
public Builder datacenters(Iterable<Datacenter> datacenters) {
this.datacenters = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters"));
return this;
}
public ProductPackage build() {
return new ProductPackage(id, name, description, items);
return new ProductPackage(id, name, description, items, datacenters);
}
public static Builder fromProductPackage(ProductPackage in) {
return ProductPackage.builder().id(in.getId()).name(in.getName()).description(in.getDescription())
.items(in.getItems());
return ProductPackage.builder().id(in.getId())
.name(in.getName())
.description(in.getDescription())
.items(in.getItems())
.datacenters(in.getDatacenters());
}
}
@ -84,17 +93,19 @@ public class ProductPackage implements Comparable<ProductPackage> {
private String name;
private String description;
private Set<ProductItem> items = Sets.newLinkedHashSet();
private Set<Datacenter> locations = Sets.newLinkedHashSet();
// for deserializer
ProductPackage() {
}
public ProductPackage(long id, String name, String description, Iterable<ProductItem> items) {
public ProductPackage(long id, String name, String description, Iterable<ProductItem> items, Iterable<Datacenter> datacenters) {
this.id = id;
this.name = name;
this.description = description;
this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items"));
this.locations = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters"));
}
@Override
@ -128,7 +139,7 @@ public class ProductPackage implements Comparable<ProductPackage> {
}
/**
*
*
* @return A collection of valid items available for purchase in this
* package.
*/
@ -136,6 +147,14 @@ public class ProductPackage implements Comparable<ProductPackage> {
return items;
}
/**
*
* @return A collection of valid locations for this package.
*/
public Set<Datacenter> getDatacenters() {
return locations;
}
public Builder toBuilder() {
return Builder.fromProductPackage(this);
}
@ -164,6 +183,6 @@ public class ProductPackage implements Comparable<ProductPackage> {
@Override
public String toString() {
return "ProductPackage [id=" + id + ", name=" + name + ", description=" + description + ", items=" + items + "]";
return "ProductPackage [id=" + id + ", name=" + name + ", description=" + description + ", items=" + items + ", datacenters=" + locations + "]";
}
}

View File

@ -18,12 +18,7 @@
*/
package org.jclouds.softlayer.features;
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.ExceptionParser;
import org.jclouds.rest.annotations.QueryParams;
@ -31,12 +26,16 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.softlayer.domain.ProductPackage;
import com.google.common.util.concurrent.ListenableFuture;
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;
/**
* Provides asynchronous access to ProductPackage via their REST API.
* <p/>
*
*
* @see ProductPackageClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
@ -44,7 +43,7 @@ import com.google.common.util.concurrent.ListenableFuture;
@RequestFilters(BasicAuthentication.class)
@Path("/v{jclouds.api-version}")
public interface ProductPackageAsyncClient {
public static String PRODUCT_MASK = "items";
public static String PRODUCT_MASK = "items;locations";
/**
* @see ProductPackageClient#getProductPackage

View File

@ -43,7 +43,7 @@ public class ProductPackageAsyncClientTest extends BaseSoftLayerAsyncClientTest<
assertRequestLineEquals(
httpRequest,
"GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/1234.json?objectMask=items HTTP/1.1");
"GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/1234.json?objectMask=items%3Blocations HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);

View File

@ -20,6 +20,7 @@ package org.jclouds.softlayer.features;
import static org.testng.Assert.assertTrue;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.ProductItem;
import org.jclouds.softlayer.domain.ProductItemPrice;
import org.jclouds.softlayer.domain.ProductPackage;
@ -57,6 +58,11 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
// assertEquals(item.getId(), newDetails.getId());
checkProductItem(item);
}
assertTrue(response.getDatacenters().size() > 0);
for (Datacenter datacenter : response.getDatacenters()) {
checkDatacenter(datacenter);
}
}
}
@ -81,4 +87,10 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
assert price.getRecurringFee() != null || price.getHourlyRecurringFee() != null : price;
}
private void checkDatacenter(Datacenter datacenter) {
assert datacenter.getId() > 0 : datacenter;
assert datacenter.getName() != null : datacenter;
assert datacenter.getLongName() != null : datacenter;
}
}