GleSYS provider: standardizing on memorySizeMB, diskSizeGB and transferGB

This commit is contained in:
Adam Lowe 2012-01-31 16:15:07 +00:00
parent 78c7b91c8a
commit 8c7ef457c6
4 changed files with 59 additions and 61 deletions

View File

@ -42,9 +42,9 @@ public class ServerDetails extends Server {
private String description; private String description;
private String templateName; private String templateName;
private int cpuCores; private int cpuCores;
private int memorySize; private int memorySizeMB;
private int diskSize; private int diskSizeGB;
private int transfer; private int transferGB;
private Cost cost; private Cost cost;
private List<Ip> ips; private List<Ip> ips;
@ -63,18 +63,18 @@ public class ServerDetails extends Server {
return this; return this;
} }
public Builder memorySize(int memorySize) { public Builder memorySizeMB(int memorySizeMB) {
this.memorySize = memorySize; this.memorySizeMB = memorySizeMB;
return this; return this;
} }
public Builder diskSize(int diskSize) { public Builder diskSizeGB(int diskSizeGB) {
this.diskSize = diskSize; this.diskSizeGB = diskSizeGB;
return this; return this;
} }
public Builder transfer(int transfer) { public Builder transferGB(int transferGB) {
this.transfer = transfer; this.transferGB = transferGB;
return this; return this;
} }
@ -93,12 +93,12 @@ public class ServerDetails extends Server {
} }
public ServerDetails build() { public ServerDetails build() {
return new ServerDetails(id, hostname, datacenter, platform, templateName, description, cpuCores, memorySize, diskSize, transfer, cost, ips); return new ServerDetails(id, hostname, datacenter, platform, templateName, description, cpuCores, memorySizeMB, diskSizeGB, transferGB, cost, ips);
} }
public Builder fromServerDetails(ServerDetails in) { public Builder fromServerDetails(ServerDetails in) {
return fromServer(in).templateName(in.getTemplateName()).memorySize(in.getMemorySizeMB()).diskSize(in.getDiskSizeGB()).cpuCores(in.getCpuCores()).cost(in.getCost()) return fromServer(in).templateName(in.getTemplateName()).memorySizeMB(in.getMemorySizeMB()).diskSizeGB(in.getDiskSizeGB()).cpuCores(in.getCpuCores()).cost(in.getCost())
.description(in.getDescription()).ips(in.getIps()); .transferGB(in.getTransferGB()).description(in.getDescription()).ips(in.getIps());
} }
@Override @Override
@ -133,23 +133,24 @@ public class ServerDetails extends Server {
@SerializedName("cpucores") @SerializedName("cpucores")
private final int cpuCores; private final int cpuCores;
@SerializedName("memorysize") @SerializedName("memorysize")
private final int memorySize; private final int memorySizeMB;
@SerializedName("disksize") @SerializedName("disksize")
private final int diskSize; private final int diskSizeGB;
private final int transfer; @SerializedName("transfer")
private final int transferGB;
private final Cost cost; private final Cost cost;
@SerializedName("iplist") @SerializedName("iplist")
private final List<Ip> ips; private final List<Ip> ips;
public ServerDetails(String id, String hostname, String datacenter, String platform, String templateName, public ServerDetails(String id, String hostname, String datacenter, String platform, String templateName,
String description, int cpuCores, int memorySize, int diskSize, int transfer, Cost cost, List<Ip> ips) { String description, int cpuCores, int memorySizeMB, int diskSizeGB, int transferGB, Cost cost, List<Ip> ips) {
super(id, hostname, datacenter, platform); super(id, hostname, datacenter, platform);
this.templateName = checkNotNull(templateName, "template"); this.templateName = checkNotNull(templateName, "template");
this.description = description; this.description = description;
this.cpuCores = cpuCores; this.cpuCores = cpuCores;
this.memorySize = memorySize; this.memorySizeMB = memorySizeMB;
this.diskSize = diskSize; this.diskSizeGB = diskSizeGB;
this.transfer = transfer; this.transferGB = transferGB;
this.cost = checkNotNull(cost, "cost"); this.cost = checkNotNull(cost, "cost");
this.ips = ips == null ? ImmutableList.<Ip>of() : ips; this.ips = ips == null ? ImmutableList.<Ip>of() : ips;
} }
@ -172,21 +173,21 @@ public class ServerDetails extends Server {
* @return the disk of the server in GB * @return the disk of the server in GB
*/ */
public int getDiskSizeGB() { public int getDiskSizeGB() {
return diskSize; return diskSizeGB;
} }
/** /**
* @return the memory of the server in MB * @return the memory of the server in MB
*/ */
public int getMemorySizeMB() { public int getMemorySizeMB() {
return memorySize; return memorySizeMB;
} }
/** /**
* @return the transfer of the server * @return the transfer of the server
*/ */
public int getTransferGB() { public int getTransferGB() {
return transfer; return transferGB;
} }
/** /**
@ -213,8 +214,8 @@ public class ServerDetails extends Server {
@Override @Override
public String toString() { public String toString() {
return String.format( return String.format(
"[id=%s, hostname=%s, datacenter=%s, platform=%s, templateName=%s, description=%s, cpuCores=%d, memorySize=%d, diskSize=%d, transfer=%d, cost=%s, ips=%s]", id, "[id=%s, hostname=%s, datacenter=%s, platform=%s, templateName=%s, description=%s, cpuCores=%d, memorySizeMB=%d, diskSizeGB=%d, transferGB=%d, cost=%s, ips=%s]", id,
hostname, datacenter, platform, templateName, description, cpuCores, memorySize, diskSize, transfer, cost, ips); hostname, datacenter, platform, templateName, description, cpuCores, memorySizeMB, diskSizeGB, transferGB, cost, ips);
} }
} }

View File

@ -24,31 +24,31 @@ package org.jclouds.glesys.options;
public class CloneServerOptions extends EditServerOptions { public class CloneServerOptions extends EditServerOptions {
public static class Builder { public static class Builder {
/** /**
* @see org.jclouds.glesys.options.CloneServerOptions#disksize * @see org.jclouds.glesys.options.CloneServerOptions#diskSizeGB
*/ */
public static CloneServerOptions disksize(int disksize) { public static CloneServerOptions diskSizeGB(int diskSizeGB) {
return CloneServerOptions.class.cast(new CloneServerOptions().disksize(disksize)); return CloneServerOptions.class.cast(new CloneServerOptions().diskSizeGB(diskSizeGB));
} }
/** /**
* @see org.jclouds.glesys.options.CloneServerOptions#memorysize * @see org.jclouds.glesys.options.CloneServerOptions#memorySizeMB
*/ */
public static CloneServerOptions memorysize(int memorysize) { public static CloneServerOptions memorySizeMB(int memorySizeMB) {
return CloneServerOptions.class.cast(new CloneServerOptions().memorysize(memorysize)); return CloneServerOptions.class.cast(new CloneServerOptions().memorySizeMB(memorySizeMB));
} }
/** /**
* @see org.jclouds.glesys.options.CloneServerOptions#cpucores * @see org.jclouds.glesys.options.CloneServerOptions#cpuCores
*/ */
public static CloneServerOptions cpucores(int cpucores) { public static CloneServerOptions cpucores(int cpucores) {
return CloneServerOptions.class.cast(new CloneServerOptions().cpucores(cpucores)); return CloneServerOptions.class.cast(new CloneServerOptions().cpuCores(cpucores));
} }
/** /**
* @see org.jclouds.glesys.options.CloneServerOptions#cpucores * @see org.jclouds.glesys.options.CloneServerOptions#transferGB
*/ */
public static CloneServerOptions transfer(int transfer) { public static CloneServerOptions transferGB(int transferGB) {
return CloneServerOptions.class.cast(new CloneServerOptions().transfer(transfer)); return CloneServerOptions.class.cast(new CloneServerOptions().transferGB(transferGB));
} }
/** /**

View File

@ -28,35 +28,32 @@ public class EditServerOptions extends BaseHttpRequestOptions {
public static class Builder { public static class Builder {
/** /**
* @see org.jclouds.glesys.options.EditServerOptions#disksize * @see org.jclouds.glesys.options.EditServerOptions#diskSizeGB
*/ */
public static EditServerOptions disksize(int disksize) { public static EditServerOptions disksizeGB(int disksizeGB) {
EditServerOptions options = new EditServerOptions(); return new EditServerOptions().diskSizeGB(disksizeGB);
return options.disksize(disksize);
} }
/** /**
* @see org.jclouds.glesys.options.EditServerOptions#memorysize * @see org.jclouds.glesys.options.EditServerOptions#memorySizeMB
*/ */
public static EditServerOptions memorysize(int memorysize) { public static EditServerOptions memorysizeMB(int memorysizeMB) {
EditServerOptions options = new EditServerOptions(); return new EditServerOptions().memorySizeMB(memorysizeMB);
return options.memorysize(memorysize);
} }
/** /**
* @see org.jclouds.glesys.options.EditServerOptions#cpucores * @see org.jclouds.glesys.options.EditServerOptions#cpuCores
*/ */
public static EditServerOptions cpucores(int cpucores) { public static EditServerOptions cpucores(int cpucores) {
EditServerOptions options = new EditServerOptions(); EditServerOptions options = new EditServerOptions();
return options.cpucores(cpucores); return options.cpuCores(cpucores);
} }
/** /**
* @see org.jclouds.glesys.options.EditServerOptions#cpucores * @see org.jclouds.glesys.options.EditServerOptions#transferGB
*/ */
public static EditServerOptions transfer(int transfer) { public static EditServerOptions transferGB(int transferGB) {
EditServerOptions options = new EditServerOptions(); return new EditServerOptions().transferGB(transferGB);
return options.transfer(transfer);
} }
/** /**
@ -77,26 +74,26 @@ public class EditServerOptions extends BaseHttpRequestOptions {
} }
/** Configure the size of the disk, in GB, of the server */ /** Configure the size of the disk, in GB, of the server */
public EditServerOptions disksize(int disksize) { public EditServerOptions diskSizeGB(int diskSizeGB) {
formParameters.put("disksize", Integer.toString(disksize)); formParameters.put("disksize", Integer.toString(diskSizeGB));
return this; return this;
} }
/** Configure the amount of RAM, in MB, allocated to the server */ /** Configure the amount of RAM, in MB, allocated to the server */
public EditServerOptions memorysize(int memorysize) { public EditServerOptions memorySizeMB(int memorySizeMB) {
formParameters.put("memorysize", Integer.toString(memorysize)); formParameters.put("memorysize", Integer.toString(memorySizeMB));
return this; return this;
} }
/** Configure the number of CPU cores allocated to the server */ /** Configure the number of CPU cores allocated to the server */
public EditServerOptions cpucores(int cpucores) { public EditServerOptions cpuCores(int cpucores) {
formParameters.put("cpucores", Integer.toString(cpucores)); formParameters.put("cpucores", Integer.toString(cpucores));
return this; return this;
} }
/** Configure the transfer setting for the server */ /** Configure the transfer setting for the server */
public EditServerOptions transfer(int transfer) { public EditServerOptions transferGB(int transferGB) {
formParameters.put("cpucores", Integer.toString(transfer)); formParameters.put("transfer", Integer.toString(transferGB));
return this; return this;
} }

View File

@ -156,8 +156,8 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
private ServerDetails expectedServerDetails() { private ServerDetails expectedServerDetails() {
Ip ip = Ip.builder().version4().ip("31.192.226.45").cost(2.0).build(); 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(); Cost cost = Cost.builder().amount(6.38).currency("EUR").timePeriod("month").build();
return ServerDetails.builder().id("vz1375882").transfer(50).hostname("jclouds-unit").cpuCores(1).memorySize(128) return ServerDetails.builder().id("vz1375882").transferGB(50).hostname("jclouds-unit").cpuCores(1).memorySizeMB(128)
.diskSize(5).description("unit test server").datacenter("Falkenberg").platform("OpenVZ") .diskSizeGB(5).description("unit test server").datacenter("Falkenberg").platform("OpenVZ")
.templateName("Debian 6.0 64-bit").cost(cost).ips(ip).build(); .templateName("Debian 6.0 64-bit").cost(cost).ips(ip).build();
} }
@ -197,7 +197,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
Cost cost = Cost.builder().amount(6.38).currency("EUR").timePeriod("month").build(); Cost cost = Cost.builder().amount(6.38).currency("EUR").timePeriod("month").build();
ServerDetails expected = ServerDetails.builder().id("vz1541880").hostname("mammamia").datacenter("Falkenberg").platform("OpenVZ") ServerDetails expected = ServerDetails.builder().id("vz1541880").hostname("mammamia").datacenter("Falkenberg").platform("OpenVZ")
.templateName("Ubuntu 11.04 64-bit").description("description").cpuCores(1).memorySize(128).diskSize(5).transfer(50).cost(cost).build(); .templateName("Ubuntu 11.04 64-bit").description("description").cpuCores(1).memorySizeMB(128).diskSizeGB(5).transferGB(50).cost(cost).build();
assertEquals( assertEquals(
client.createServerWithHostnameAndRootPassword( client.createServerWithHostnameAndRootPassword(
@ -267,7 +267,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
HttpResponse.builder().statusCode(200).build()).getServerClient(); HttpResponse.builder().statusCode(200).build()).getServerClient();
EditServerOptions options = EditServerOptions options =
EditServerOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test"); EditServerOptions.Builder.description("Description-of-server").diskSizeGB(1).memorySizeMB(512).cpuCores(1).hostname("jclouds-test");
client.editServer("server111", options); client.editServer("server111", options);
} }
@ -302,7 +302,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
.put("memorysize", "512") .put("memorysize", "512")
.put("cpucores", "1").build())).build(), .put("cpucores", "1").build())).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerClient(); HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerClient();
CloneServerOptions options = (CloneServerOptions) CloneServerOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1); CloneServerOptions options = (CloneServerOptions) CloneServerOptions.Builder.description("Description-of-server").diskSizeGB(1).memorySizeMB(512).cpuCores(1);
assertEquals(client.cloneServer("server111", "hostname1", options), expectedServerDetails()); assertEquals(client.cloneServer("server111", "hostname1", options), expectedServerDetails());
} }