mirror of https://github.com/apache/jclouds.git
Issue 158 Return Datacenter (location) information with ProductPackage
This commit is contained in:
parent
bf36742639
commit
cd70eefc6d
|
@ -21,7 +21,7 @@ package org.jclouds.softlayer.domain;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @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> {
|
public class Datacenter implements Comparable<Datacenter> {
|
||||||
|
|
|
@ -18,19 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.domain;
|
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 java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SoftLayer_Product_Package data type contains information about packages
|
* The SoftLayer_Product_Package data type contains information about packages
|
||||||
* from which orders can be generated. Packages contain general information
|
* from which orders can be generated. Packages contain general information
|
||||||
* regarding what is in them, where they are currently sold, availability, and
|
* regarding what is in them, where they are currently sold, availability, and
|
||||||
* pricing.
|
* pricing.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @see <a href=
|
* @see <a href=
|
||||||
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Package"
|
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Package"
|
||||||
|
@ -49,6 +49,7 @@ public class ProductPackage implements Comparable<ProductPackage> {
|
||||||
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();
|
||||||
|
|
||||||
public Builder id(long id) {
|
public Builder id(long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -70,13 +71,21 @@ public class ProductPackage implements Comparable<ProductPackage> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder datacenters(Iterable<Datacenter> datacenters) {
|
||||||
|
this.datacenters = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ProductPackage build() {
|
public ProductPackage build() {
|
||||||
return new ProductPackage(id, name, description, items);
|
return new ProductPackage(id, name, description, items, datacenters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder fromProductPackage(ProductPackage in) {
|
public static Builder fromProductPackage(ProductPackage in) {
|
||||||
return ProductPackage.builder().id(in.getId()).name(in.getName()).description(in.getDescription())
|
return ProductPackage.builder().id(in.getId())
|
||||||
.items(in.getItems());
|
.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 name;
|
||||||
private String description;
|
private String description;
|
||||||
private Set<ProductItem> items = Sets.newLinkedHashSet();
|
private Set<ProductItem> items = Sets.newLinkedHashSet();
|
||||||
|
private Set<Datacenter> locations = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
// for deserializer
|
// for deserializer
|
||||||
ProductPackage() {
|
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.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items"));
|
this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items"));
|
||||||
|
this.locations = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,7 +139,7 @@ public class ProductPackage implements Comparable<ProductPackage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return A collection of valid items available for purchase in this
|
* @return A collection of valid items available for purchase in this
|
||||||
* package.
|
* package.
|
||||||
*/
|
*/
|
||||||
|
@ -136,6 +147,14 @@ public class ProductPackage implements Comparable<ProductPackage> {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return A collection of valid locations for this package.
|
||||||
|
*/
|
||||||
|
public Set<Datacenter> getDatacenters() {
|
||||||
|
return locations;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder toBuilder() {
|
public Builder toBuilder() {
|
||||||
return Builder.fromProductPackage(this);
|
return Builder.fromProductPackage(this);
|
||||||
}
|
}
|
||||||
|
@ -164,6 +183,6 @@ public class ProductPackage implements Comparable<ProductPackage> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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 + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.features;
|
package org.jclouds.softlayer.features;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
import org.jclouds.rest.annotations.ExceptionParser;
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
import org.jclouds.rest.annotations.QueryParams;
|
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.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
import org.jclouds.softlayer.domain.ProductPackage;
|
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.
|
* Provides asynchronous access to ProductPackage via their REST API.
|
||||||
* <p/>
|
* <p/>
|
||||||
*
|
*
|
||||||
* @see ProductPackageClient
|
* @see ProductPackageClient
|
||||||
* @see <a href="http://sldn.softlayer.com/article/REST" />
|
* @see <a href="http://sldn.softlayer.com/article/REST" />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -44,7 +43,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@RequestFilters(BasicAuthentication.class)
|
@RequestFilters(BasicAuthentication.class)
|
||||||
@Path("/v{jclouds.api-version}")
|
@Path("/v{jclouds.api-version}")
|
||||||
public interface ProductPackageAsyncClient {
|
public interface ProductPackageAsyncClient {
|
||||||
public static String PRODUCT_MASK = "items";
|
public static String PRODUCT_MASK = "items;locations";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ProductPackageClient#getProductPackage
|
* @see ProductPackageClient#getProductPackage
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class ProductPackageAsyncClientTest extends BaseSoftLayerAsyncClientTest<
|
||||||
|
|
||||||
assertRequestLineEquals(
|
assertRequestLineEquals(
|
||||||
httpRequest,
|
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");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.softlayer.features;
|
||||||
|
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.jclouds.softlayer.domain.Datacenter;
|
||||||
import org.jclouds.softlayer.domain.ProductItem;
|
import org.jclouds.softlayer.domain.ProductItem;
|
||||||
import org.jclouds.softlayer.domain.ProductItemPrice;
|
import org.jclouds.softlayer.domain.ProductItemPrice;
|
||||||
import org.jclouds.softlayer.domain.ProductPackage;
|
import org.jclouds.softlayer.domain.ProductPackage;
|
||||||
|
@ -57,6 +58,11 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||||
// assertEquals(item.getId(), newDetails.getId());
|
// assertEquals(item.getId(), newDetails.getId());
|
||||||
checkProductItem(item);
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue