* 'master' of https://github.com/jsonking/jclouds:
  Issue 158 Return Datacenter (location) information with ProductPackage
  Issue 158: Removed unused method from ProductPackage
  Issue 158: Updated links to softlayer documentation as URLs have changed
This commit is contained in:
Adrian Cole 2011-09-11 00:40:14 +02:00
commit db07d212dc
13 changed files with 60 additions and 35 deletions

View File

@ -29,7 +29,7 @@ import org.jclouds.softlayer.features.VirtualGuestAsyncClient;
* <p/>
*
* @see SoftLayerClient
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
public interface SoftLayerAsyncClient {

View File

@ -32,7 +32,7 @@ import org.jclouds.softlayer.features.VirtualGuestClient;
* <p/>
*
* @see SoftLayerAsyncClient
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)

View File

@ -21,7 +21,7 @@ package org.jclouds.softlayer.domain;
/**
*
* @author Adrian Cole
* @see <a href= "http://sldn.softlayer.com/wiki/index.php/SoftLayer_Location_Datacenter_%28type%29"
* @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;
@ -65,23 +66,26 @@ public class ProductPackage implements Comparable<ProductPackage> {
return this;
}
public Builder productItem(ProductItem items) {
this.items.add(checkNotNull(items, "items"));
return this;
}
public Builder items(Iterable<ProductItem> items) {
this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items"));
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());
}
}
@ -89,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
@ -133,7 +139,7 @@ public class ProductPackage implements Comparable<ProductPackage> {
}
/**
*
*
* @return A collection of valid items available for purchase in this
* package.
*/
@ -141,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);
}
@ -169,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

@ -34,7 +34,7 @@ import com.google.gson.annotations.SerializedName;
*
* @author Adrian Cole
* @see <a href=
* "http://sldn.softlayer.com/wiki/index.php/SoftLayer_Virtual_Guest_%28type%29#Local_Properties"
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest#Local_Properties"
* />
*/
public class VirtualGuest implements Comparable<VirtualGuest> {

View File

@ -41,7 +41,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* <p/>
*
* @see DatacenterClient
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@RequestFilters(BasicAuthentication.class)

View File

@ -29,7 +29,7 @@ import org.jclouds.softlayer.domain.Datacenter;
* <p/>
*
* @see DatacenterAsyncClient
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS)

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,20 +26,24 @@ 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/wiki/index.php/REST" />
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@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

@ -28,7 +28,7 @@ import org.jclouds.softlayer.domain.ProductPackage;
* <p/>
*
* @see ProductPackageAsyncClient
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)

View File

@ -42,7 +42,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* <p/>
*
* @see VirtualGuestClient
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@RequestFilters(BasicAuthentication.class)

View File

@ -29,7 +29,7 @@ import org.jclouds.softlayer.domain.VirtualGuest;
* <p/>
*
* @see VirtualGuestAsyncClient
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS)

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;
}
}