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
|
||||
* @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> {
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
*/
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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 + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,7 +26,11 @@ 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.
|
||||
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue