Merge pull request #317 from aplowe/master

GleSYS provider, adding template and IP details to ServerDetails bean
This commit is contained in:
Adrian Cole 2012-01-16 13:43:44 -08:00
commit d78741ab0d
10 changed files with 109 additions and 39 deletions

View File

@ -22,12 +22,13 @@ package org.jclouds.glesys.domain;
import com.google.common.base.Objects;
/**
* Represents detailed information about an available ip address of a new server.
* Represents an ip address used by a server.
*
* @author Adam Lowe
* @see ServerCreated
* @see ServerDetails
*/
public class ServerCreatedIp {
public class Ip {
public static Builder builder() {
return new Builder();
@ -61,11 +62,11 @@ public class ServerCreatedIp {
return this;
}
public ServerCreatedIp build() {
return new ServerCreatedIp(ip, version, cost);
public Ip build() {
return new Ip(ip, version, cost);
}
public Builder fromIpCreated(ServerCreatedIp from) {
public Builder fromIpCreated(Ip from) {
return ip(from.getIp()).version(from.getVersion()).cost(from.getCost());
}
}
@ -74,7 +75,7 @@ public class ServerCreatedIp {
protected final int version;
protected final double cost;
public ServerCreatedIp(String ip, int version, double cost) {
public Ip(String ip, int version, double cost) {
this.ip = ip;
this.version = version;
this.cost = cost;
@ -106,8 +107,8 @@ public class ServerCreatedIp {
if (this == object) {
return true;
}
if (object instanceof ServerCreatedIp) {
final ServerCreatedIp other = (ServerCreatedIp) object;
if (object instanceof Ip) {
final Ip other = (Ip) object;
return Objects.equal(ip, other.ip)
&& Objects.equal(version, other.version)
&& Objects.equal(cost, other.cost);

View File

@ -43,19 +43,19 @@ public class ServerCreated {
public static class Builder {
private String id;
private String hostname;
private List<ServerCreatedIp> ips;
private List<Ip> ips;
public Builder id(String id) {
this.id = id;
return this;
}
public Builder ips(List<ServerCreatedIp> ips) {
public Builder ips(List<Ip> ips) {
this.ips = ips;
return this;
}
public Builder ips(ServerCreatedIp... ips) {
public Builder ips(Ip... ips) {
return ips(Arrays.asList(ips));
}
@ -77,9 +77,9 @@ public class ServerCreated {
private final String id;
private final String hostname;
@SerializedName("iplist")
private final List<ServerCreatedIp> ips;
private final List<Ip> ips;
public ServerCreated(String id, @Nullable String hostname, List<ServerCreatedIp> ips) {
public ServerCreated(String id, @Nullable String hostname, List<Ip> ips) {
checkNotNull(id, "id");
this.id = id;
this.hostname = hostname;
@ -100,8 +100,8 @@ public class ServerCreated {
}
/** @return the IP addresses assigned to the server */
public List<ServerCreatedIp> getIps() {
return ips == null ? ImmutableList.<ServerCreatedIp>of() : ips;
public List<Ip> getIps() {
return ips == null ? ImmutableList.<Ip>of() : ips;
}
@Override

View File

@ -20,8 +20,12 @@ package org.jclouds.glesys.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.SerializedName;
import java.util.Arrays;
import java.util.List;
/**
* Detailed information about a server such as cpuCores, hardware configuration
* (cpu, memory and disk), ip adresses, cost, transfer, os and more.
@ -36,16 +40,24 @@ public class ServerDetails extends Server {
public static class Builder extends Server.Builder {
private String description;
private String template;
private int cpuCores;
private int memory;
private int disk;
private int transfer;
private Cost cost;
private List<Ip> ips;
public Builder description(String description) {
this.description = description;
return this;
}
public Builder template(String template) {
this.template = template;
return this;
}
public Builder cpuCores(int cpuCores) {
this.cpuCores = cpuCores;
return this;
@ -61,18 +73,32 @@ public class ServerDetails extends Server {
return this;
}
public Builder transfer(int transfer) {
this.transfer = transfer;
return this;
}
public Builder cost(Cost cost) {
this.cost = cost;
return this;
}
public Builder ips(Ip... ips) {
return ips(Arrays.asList(ips));
}
public Builder ips(List<Ip> ips) {
this.ips = ips;
return this;
}
public ServerDetails build() {
return new ServerDetails(id, hostname, datacenter, platform, description, cpuCores, memory, disk, cost);
return new ServerDetails(id, hostname, datacenter, platform, template, description, cpuCores, memory, disk, transfer, cost, ips);
}
public Builder fromServerDetails(ServerDetails in) {
return fromServer(in).memory(in.getMemory()).disk(in.getDisk()).cpuCores(in.getCpuCores()).cost(in.getCost())
.description(in.getDescription());
return fromServer(in).template(in.getTemplate()).memory(in.getMemory()).disk(in.getDisk()).cpuCores(in.getCpuCores()).cost(in.getCost())
.description(in.getDescription()).ips(in.getIps());
}
@Override
@ -102,20 +128,27 @@ public class ServerDetails extends Server {
}
private final String description;
private final String template;
@SerializedName("cpucores")
private final int cpuCores;
private final int memory;
private final int disk;
private final int transfer;
private final Cost cost;
@SerializedName("iplist")
private final List<Ip> ips;
public ServerDetails(String id, String hostname, String datacenter, String platform, String description,
int cpuCores, int memory, int disk, Cost cost) {
public ServerDetails(String id, String hostname, String datacenter, String platform, String template,
String description, int cpuCores, int memory, int disk, int transfer, Cost cost, List<Ip> ips) {
super(id, hostname, datacenter, platform);
this.template = checkNotNull(template, "template");
this.description = description;
this.cpuCores = cpuCores;
this.memory = memory;
this.disk = disk;
this.transfer = transfer;
this.cost = checkNotNull(cost, "cost");
this.ips = ips == null ? ImmutableList.<Ip>of() : ips;
}
/**
@ -146,6 +179,13 @@ public class ServerDetails extends Server {
return memory;
}
/**
* @return the transfer of the server
*/
public int getTransfer() {
return transfer;
}
/**
* @return details of the cost of the server
*/
@ -153,11 +193,25 @@ public class ServerDetails extends Server {
return cost;
}
/**
* @return the ip addresses assigned to the server
*/
public List<Ip> getIps() {
return ips;
}
/**
* @return the name of the template used to create the server
*/
public String getTemplate() {
return template;
}
@Override
public String toString() {
return String.format(
"[id=%s, hostname=%s, datacenter=%s, platform=%s, description=%s, cpuCores=%s, memory=%s, disk=%s, cost=%s]", id,
hostname, datacenter, platform, description, cpuCores, memory, disk, cost);
"[id=%s, hostname=%s, datacenter=%s, platform=%s, template=%s, description=%s, cpuCores=%d, memory=%d, disk=%d, transfer=%d, cost=%s, ips=%s]", id,
hostname, datacenter, platform, template, description, cpuCores, memory, disk, transfer, cost, ips);
}
}

View File

@ -49,8 +49,6 @@ public class DomainClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
}
public void testListDomainsWhenResponseIs2xx() throws Exception {
//DomainClient client = createMock("list", "POST", 200, "/domain_list.json");
DomainClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/list/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
@ -59,7 +57,7 @@ public class DomainClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
.build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/domain_list.json")).build()).getDomainClient();
Set<Domain> expected = ImmutableSet.<Domain>of(
Set<Domain> expected = ImmutableSet.of(
Domain.builder().domain("adamlowe.net").createTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-12-20 10:58:51")).build());
assertEquals(client.listDomains(), expected);

View File

@ -23,8 +23,8 @@ import com.google.common.collect.ImmutableSet;
import org.jclouds.glesys.GleSYSClient;
import org.jclouds.glesys.domain.Server;
import org.jclouds.glesys.domain.ServerCreated;
import org.jclouds.glesys.domain.ServerCreatedIp;
import org.jclouds.glesys.domain.ServerDetails;
import org.jclouds.glesys.domain.Ip;
import org.jclouds.glesys.options.*;
import org.jclouds.glesys.parse.*;
import org.jclouds.http.HttpRequest;
@ -128,7 +128,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
.put("template", "Ubuntu 32-bit")
.put("disksize", "5").build())).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient();
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build();
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(Ip.builder().ip("109.74.10.27").build()).build();
assertEquals(client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 32-bit", 5, 512, 1, "password", 50), expected);
}
@ -152,7 +152,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
.put("ip", "10.0.0.1").build())).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient();
ServerCreateOptions options = ServerCreateOptions.Builder.description("Description-of-server").ip("10.0.0.1");
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build();
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(Ip.builder().ip("109.74.10.27").build()).build();
assertEquals(client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 32-bit", 5, 512, 1, "password", 50, options), expected);
}
@ -203,7 +203,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
.put("serverid", "server111")
.put("hostname", "hostname1").build())).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient();
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build();
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(Ip.builder().ip("109.74.10.27").build()).build();
assertEquals(client.cloneServer("server111", "hostname1"), expected);
}
@ -224,7 +224,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
.put("cpucores", "1").build())).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient();
ServerCloneOptions options = (ServerCloneOptions) ServerCloneOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1);
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build();
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(Ip.builder().ip("109.74.10.27").build()).build();
assertEquals(client.cloneServer("server111", "hostname1", options), expected);
}

View File

@ -133,6 +133,19 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
@Test
public void testServerDetails() throws Exception {
ServerDetails details = client.getServerDetails(testServerId);
checkServer(details);
assertEquals("Ubuntu 10.04 LTS 32-bit", details.getTemplate());
assertEquals("Falkenberg", details.getDatacenter());
assertEquals("OpenVZ", details.getPlatform());
assertEquals(5, details.getDisk());
assertEquals(512, details.getMemory());
assertEquals(1, details.getCpuCores());
assertEquals(50, details.getTransfer());
}
@Test
public void testServerStatus() throws Exception {
ServerStatus newStatus = client.getServerStatus(testServerId);
checkStatus(newStatus);
}
@ -238,6 +251,10 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
assert server.getDisk() > 0 : server;
assert server.getMemory() > 0 : server;
assert server.getCost() != null;
assert server.getTransfer() > 0 : server;
assertNotNull(server.getTemplate());
assertNotNull(server.getIps());
}
private void checkStatus(ServerStatus status) {

View File

@ -23,7 +23,7 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.glesys.config.GleSYSParserModule;
import org.jclouds.glesys.domain.ServerCreated;
import org.jclouds.glesys.domain.ServerCreatedIp;
import org.jclouds.glesys.domain.Ip;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.SelectJson;
@ -47,7 +47,7 @@ public class ParseServerCreatedTest extends BaseItemParserTest<ServerCreated> {
@SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON)
public ServerCreated expected() {
return ServerCreated.builder().id("xm3630641").hostname("jclouds-test-host").ips(ServerCreatedIp.builder().ip("109.74.10.27").version4().cost(2.00).build()).build();
return ServerCreated.builder().id("xm3630641").hostname("jclouds-test-host").ips(Ip.builder().ip("109.74.10.27").version4().cost(2.00).build()).build();
}

View File

@ -23,9 +23,8 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.glesys.config.GleSYSParserModule;
import org.jclouds.glesys.domain.Cost;
import org.jclouds.glesys.domain.ServerCreated;
import org.jclouds.glesys.domain.ServerCreatedIp;
import org.jclouds.glesys.domain.ServerDetails;
import org.jclouds.glesys.domain.Ip;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.SelectJson;
@ -49,10 +48,11 @@ public class ParseServerDetailsTest extends BaseItemParserTest<ServerDetails> {
@SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON)
public ServerDetails expected() {
Ip ip = Ip.builder().version4().ip("31.192.226.45").cost(2.0).build();
Cost cost = Cost.builder().amount(6.38).currency("EUR").timePeriod("month").build();
return ServerDetails.builder().id("vz1908384").hostname("jclouds-unit").cpuCores(1).
memory(128).disk(5).
description("unit test server").datacenter("Falkenberg").platform("OpenVZ").cost(cost).build();
return ServerDetails.builder().id("vz1375882").transfer(50).hostname("jclouds-unit").cpuCores(1).memory(128).disk(5)
.description("unit test server").datacenter("Falkenberg").platform("OpenVZ").template("Debian 6.0 64-bit")
.cost(cost).ips(ip).build();
}
protected Injector injector() {

View File

@ -52,7 +52,7 @@ public class ParseServerDetailsWithoutIPsTest extends BaseItemParserTest<ServerD
public ServerDetails expected() {
Cost cost = Cost.builder().amount(6.38).currency("EUR").timePeriod("month").build();
return ServerDetails.builder().id("vz1541880").hostname("mammamia").datacenter("Falkenberg").platform("OpenVZ")
.description("description").cpuCores(1).memory(128).disk(5).cost(cost).build();
.template("Ubuntu 11.04 64-bit").description("description").cpuCores(1).memory(128).disk(5).transfer(50).cost(cost).build();
}
protected Injector injector() {

View File

@ -1 +1 @@
{"response":{"status":{"code":"200","text":"OK"},"server":{"serverid":"vz1908384","hostname":"jclouds-unit","description":"unit test server","cpucores":"1","memory":"128","disk":"5","transfer":"50","template":"Debian 6.0 64-bit","datacenter":"Falkenberg","managedhosting":"no","platform":"OpenVZ","cost":{"amount":6.38,"currency":"EUR","timeperiod":"month"},"iplist":[]},"debug":{"input":{"serverid":"vz1908384"}}}}
{"response":{"status":{"code":"200","text":"OK"},"server":{"serverid":"vz1375882","hostname":"jclouds-unit","description":"unit test server","cpucores":"1","memory":"128","disk":"5","transfer":"50","template":"Debian 6.0 64-bit","datacenter":"Falkenberg","managedhosting":"no","platform":"OpenVZ","cost":{"amount":6.38,"currency":"EUR","timeperiod":"month"},"iplist":[{"ip":"31.192.226.45","version":"4","cost":"2.00"}]},"debug":{"input":{"serverid":"vz1375882"}}}}