mirror of https://github.com/apache/jclouds.git
Merge branch 'master' of github.com:jclouds/jclouds
This commit is contained in:
commit
d2dd4066d1
|
@ -23,29 +23,43 @@ import java.util.Map;
|
|||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.elasticstack.domain.Model;
|
||||
import org.jclouds.elasticstack.domain.NIC;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class MapToNICs implements Function<Map<String, String>, List<NIC>> {
|
||||
|
||||
private String apiVersion;
|
||||
|
||||
@Inject
|
||||
public MapToNICs(@ApiVersion String apiVersion) {
|
||||
this.apiVersion = apiVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NIC> apply(Map<String, String> from) {
|
||||
ImmutableList.Builder<NIC> nics = ImmutableList.builder();
|
||||
NIC: for (int id : new int[] { 0, 1 }) {
|
||||
NIC:
|
||||
for (int id : new int[]{0, 1}) {
|
||||
String key = String.format("nic:%d", id);
|
||||
if (!from.containsKey(key + ":model"))
|
||||
break NIC;
|
||||
NIC.Builder nicBuilder = new NIC.Builder();
|
||||
nicBuilder.dhcp(from.get(key + ":dhcp"));
|
||||
|
||||
if (apiVersion.equals("2.0")) {
|
||||
nicBuilder.dhcp(from.get(key + ":dhcp:ip"));
|
||||
} else {
|
||||
nicBuilder.dhcp(from.get(key + ":dhcp"));
|
||||
}
|
||||
nicBuilder.model(Model.fromValue(from.get(key + ":model")));
|
||||
nicBuilder.vlan(from.get(key + ":vlan"));
|
||||
nicBuilder.mac(from.get(key + ":mac"));
|
||||
|
|
|
@ -36,20 +36,22 @@ import org.jclouds.elasticstack.domain.VNC;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class MapToServerInfo implements Function<Map<String, String>, ServerInfo> {
|
||||
private String apiVersion;
|
||||
private final Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices;
|
||||
private final Function<Map<String, String>, ServerMetrics> mapToMetrics;
|
||||
private final Function<Map<String, String>, List<NIC>> mapToNICs;
|
||||
|
||||
@Inject
|
||||
public MapToServerInfo(Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices,
|
||||
Function<Map<String, String>, ServerMetrics> mapToMetrics, Function<Map<String, String>, List<NIC>> mapToNICs) {
|
||||
Function<Map<String, String>, ServerMetrics> mapToMetrics, Function<Map<String, String>, List<NIC>> mapToNICs) {
|
||||
this.apiVersion = apiVersion;
|
||||
this.mapToDevices = mapToDevices;
|
||||
this.mapToMetrics = mapToMetrics;
|
||||
this.mapToNICs = mapToNICs;
|
||||
|
@ -66,19 +68,28 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
|
|||
builder.tags(Splitter.on(' ').split(from.get("tags")));
|
||||
if (from.containsKey("status"))
|
||||
builder.status(ServerStatus.fromValue(from.get("status")));
|
||||
if (from.containsKey("smp") && !"auto".equals(from.get("smp")))
|
||||
builder.smp(new Integer(from.get("smp")));
|
||||
|
||||
|
||||
if (from.containsKey("smp:cores")) {
|
||||
builder.smp(new Integer(from.get("smp:cores")));
|
||||
} else if (from.containsKey("smp") && !"auto".equals(from.get("smp"))) {
|
||||
builder.smp(new Integer(from.get("smp")));
|
||||
}
|
||||
|
||||
builder.cpu(Integer.parseInt(from.get("cpu")));
|
||||
builder.mem(Integer.parseInt(from.get("mem")));
|
||||
builder.user(from.get("user"));
|
||||
if (from.containsKey("started"))
|
||||
builder.started(new Date(new Long(from.get("started"))));
|
||||
builder.uuid(from.get("server"));
|
||||
builder.vnc(new VNC(from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls")
|
||||
&& Boolean.valueOf(from.get("vnc:tls"))));
|
||||
if (from.containsKey("boot"))
|
||||
builder.bootDeviceIds(Splitter.on(' ').split(from.get("boot")));
|
||||
|
||||
|
||||
builder.vnc(new VNC(from.get("vnc:ip") == null ? "auto" : from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls")
|
||||
&& Boolean.valueOf(from.get("vnc:tls"))));
|
||||
|
||||
|
||||
Map<String, String> metadata = Maps.newLinkedHashMap();
|
||||
for (Entry<String, String> entry : from.entrySet()) {
|
||||
if (entry.getKey().startsWith("user:"))
|
||||
|
|
|
@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elasticstack.domain.Device;
|
||||
|
@ -32,13 +33,22 @@ import org.jclouds.elasticstack.domain.Server;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ServerToMap implements Function<Server, Map<String, String>> {
|
||||
|
||||
@ApiVersion
|
||||
private final String apiVersion;
|
||||
|
||||
@Inject
|
||||
public ServerToMap(@ApiVersion String apiVersion) {
|
||||
this.apiVersion = apiVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> apply(Server from) {
|
||||
checkNotNull(from, "server");
|
||||
|
@ -68,7 +78,14 @@ public class ServerToMap implements Function<Server, Map<String, String>> {
|
|||
builder.put("nic:" + nicId + ":mac", nic.getMac());
|
||||
nicId++;
|
||||
}
|
||||
builder.put("vnc:ip", from.getVnc().getIp() == null ? "auto" : from.getVnc().getIp());
|
||||
|
||||
String vncIp = from.getVnc().getIp();
|
||||
if (apiVersion.equals("2.0")) {
|
||||
builder.put("vnc", "auto");
|
||||
} else {
|
||||
builder.put("vnc:ip", vncIp == null ? "auto" : vncIp);
|
||||
}
|
||||
|
||||
if (from.getVnc().getPassword() != null)
|
||||
builder.put("vnc:password", from.getVnc().getPassword());
|
||||
if (from.getVnc().isTls())
|
||||
|
|
|
@ -18,30 +18,26 @@
|
|||
*/
|
||||
package org.jclouds.elasticstack.binders;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.elasticstack.domain.IDEDevice;
|
||||
import org.jclouds.elasticstack.domain.Model;
|
||||
import org.jclouds.elasticstack.domain.NIC;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.VNC;
|
||||
import org.jclouds.elasticstack.functions.ServerToMap;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.elasticstack.domain.*;
|
||||
import org.jclouds.elasticstack.functions.ServerToMap;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -69,19 +65,20 @@ public class BindServerToPlainTextStringTest {
|
|||
.nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).
|
||||
|
||||
build())).vnc(new VNC(null, "XXXXXXXX", false)).build();
|
||||
private static final BindServerToPlainTextString FN = Guice.createInjector(new AbstractModule() {
|
||||
private Injector i = Guice.createInjector(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(ApiVersion.class).to("1.0");
|
||||
bind(new TypeLiteral<Function<Server, Map<String, String>>>() {
|
||||
}).to(ServerToMap.class);
|
||||
}
|
||||
|
||||
}).getInstance(BindServerToPlainTextString.class);
|
||||
});
|
||||
|
||||
public void testSimple() throws IOException {
|
||||
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
|
||||
FN.bindToRequest(request, SERVER);
|
||||
i.getInstance(BindServerToPlainTextString.class).bindToRequest(request, SERVER);
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
|
||||
assertEquals(request.getPayload().getRawContent(), CREATED_SERVER);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.jclouds.elasticstack.domain.ServerMetrics;
|
|||
import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -48,6 +49,7 @@ public class KeyValuesDelimitedByBlankLinesToServerInfoTest {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(ApiVersion.class).to("1.0");
|
||||
bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() {
|
||||
}).to(MapToNICs.class);
|
||||
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends Device>>>() {
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.jclouds.elasticstack.domain.ServerMetrics;
|
|||
import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -51,6 +52,7 @@ public class ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(ApiVersion.class).to("1.0");
|
||||
bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() {
|
||||
}).to(MapToNICs.class);
|
||||
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends Device>>>() {
|
||||
|
|
|
@ -42,7 +42,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
|
@ -102,7 +102,7 @@ public class MapToServerInfoTest {
|
|||
.build()).build();
|
||||
|
||||
private static final MapToServerInfo MAP_TO_DRIVE = new MapToServerInfo(new MapToDevices(new DeviceToId()),
|
||||
new MapToServerMetrics(new MapToDriveMetrics()), new MapToNICs());
|
||||
new MapToServerMetrics(new MapToDriveMetrics()), new MapToNICs("1.0"));
|
||||
|
||||
public void testEmptyMapReturnsNull() {
|
||||
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.<String, String> of()), null);
|
||||
|
@ -158,4 +158,14 @@ public class MapToServerInfoTest {
|
|||
assertEquals(MAP_TO_DRIVE.apply(input), NEW);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testNew2() throws IOException {
|
||||
|
||||
Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply(
|
||||
Strings2.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/new_server2.txt"))).get(0);
|
||||
|
||||
assertEquals(MAP_TO_DRIVE.apply(input), NEW);
|
||||
|
||||
}
|
||||
}
|
|
@ -31,15 +31,16 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class ServerToMapTest {
|
||||
|
||||
private static final ServerToMap SERVER_TO_MAP = new ServerToMap();
|
||||
private static final ServerToMap SERVER_TO_MAP = new ServerToMap("1.0");
|
||||
private static final ServerToMap SERVER_TO_MAP_V2 = new ServerToMap("2.0");
|
||||
|
||||
public void testBasics() {
|
||||
public void testBasics() {
|
||||
assertEquals(
|
||||
SERVER_TO_MAP.apply(new Server.Builder()
|
||||
.name("TestServer")
|
||||
|
@ -62,4 +63,27 @@ public class ServerToMapTest {
|
|||
"vnc:password", "XXXXXXXX")).build());
|
||||
}
|
||||
|
||||
public void testBasicsV2() {
|
||||
assertEquals(
|
||||
SERVER_TO_MAP_V2.apply(new Server.Builder()
|
||||
.name("TestServer")
|
||||
.cpu(2000)
|
||||
.mem(1024)
|
||||
.devices(
|
||||
ImmutableMap.of("ide:0:0",
|
||||
new IDEDevice.Builder(0, 0).uuid("08c92dd5-70a0-4f51-83d2-835919d254df").build()))
|
||||
.bootDeviceIds(ImmutableSet.of("ide:0:0")).nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).
|
||||
|
||||
build())).vnc(new VNC(null, "XXXXXXXX", false)).build()),
|
||||
ImmutableMap
|
||||
.builder()
|
||||
.putAll(ImmutableMap.of("name", "TestServer", "cpu", "2000", "smp", "auto", "mem", "1024"))
|
||||
.putAll(
|
||||
ImmutableMap.of("persistent", "false", "boot", "ide:0:0", "ide:0:0",
|
||||
"08c92dd5-70a0-4f51-83d2-835919d254df"))
|
||||
.putAll(
|
||||
ImmutableMap.of("ide:0:0:media", "disk", "nic:0:model", "e1000", "vnc", "auto",
|
||||
"vnc:password", "XXXXXXXX")).build());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
ide:0:0:write:requests 0
|
||||
boot ide:0:0
|
||||
vnc:password XXXXXXXX
|
||||
ide:0:0 403c9a86-0aab-4e47-aa95-e9768021c4c1
|
||||
ide:0:0:read:requests 0
|
||||
ide:0:0:read:bytes 0
|
||||
vnc auto
|
||||
vnc:ip 83.222.249.221
|
||||
tx:packets 0
|
||||
tx 0
|
||||
rx 0
|
||||
smp 1
|
||||
mem 512
|
||||
nic:0:model e1000
|
||||
status active
|
||||
started 1292695612
|
||||
rx:packets 0
|
||||
user 2f6244eb-50bc-4403-847e-f03cc3706a1f
|
||||
ide:0:0:media disk
|
||||
name adriancole.test
|
||||
persistent true
|
||||
nic:0:block tcp/43594 tcp/5902 udp/5060 tcp/5900 tcp/5901 tcp/21 tcp/22 tcp/23 tcp/25 tcp/110 tcp/143 tcp/43595
|
||||
server bd98615a-6f74-4d63-ad1e-b13338b9356a
|
||||
ide:0:0:write:bytes 0
|
||||
cpu 1000
|
|
@ -0,0 +1,41 @@
|
|||
ide:0:0:write:requests 3698
|
||||
boot ide:0:0
|
||||
vnc:password HfHzVmLT
|
||||
ide:0:0 4af85ed3-0caa-4736-8a26-a33d7de0a122
|
||||
ide:0:0:read:requests 11154
|
||||
ide:0:0:read:bytes 45686784
|
||||
vnc:ip 46.20.114.124
|
||||
tx:packets 31
|
||||
tx 2550
|
||||
rx 455530
|
||||
smp 1
|
||||
mem 1024
|
||||
nic:0:model e1000
|
||||
status active
|
||||
started 1291493868
|
||||
rx:packets 7583
|
||||
user 2f6244eb-50bc-4403-847e-f03cc3706a1f
|
||||
name jo
|
||||
persistent true
|
||||
nic:0:block tcp/43594 tcp/5902 udp/5060 tcp/5900 tcp/5901 tcp/21 tcp/22 tcp/23 tcp/25 tcp/110 tcp/143 tcp/43595
|
||||
server f8bee9cd-8e4b-4a05-8593-1314e3bfe49b
|
||||
nic:0:dhcp auto
|
||||
nic:0:dhcp:ip 46.20.114.124
|
||||
ide:0:0:write:bytes 15147008
|
||||
cpu 2000
|
||||
|
||||
status stopped
|
||||
name Demo
|
||||
mem 1024
|
||||
boot ide:0:0
|
||||
vnc:password HWbjvrg2
|
||||
persistent true
|
||||
server 0f962616-2071-4173-be79-7dd084271edf
|
||||
smp auto
|
||||
nic:0:dhcp auto
|
||||
user 2f6244eb-50bc-4403-847e-f03cc3706a1f
|
||||
nic:0:model e1000
|
||||
vnc:ip auto
|
||||
ide:0:0 853bb98a-4fff-4c2f-a265-97c363f19ea5
|
||||
cpu 2000
|
||||
ide:0:0:media cdrom
|
|
@ -37,7 +37,7 @@ public class ElasticHostsBlueSquareLondonPropertiesBuilder extends ElasticStackP
|
|||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_ISO3166_CODES, "GB-LND");
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://api.lon-b.elastichosts.com");
|
||||
properties.setProperty(PROPERTY_API_VERSION, "1.0");
|
||||
properties.setProperty(PROPERTY_API_VERSION, "2.0");
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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 + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -29,10 +29,10 @@ 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)
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface DatacenterClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -29,10 +29,10 @@ 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)
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface VirtualGuestClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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