mirror of https://github.com/apache/jclouds.git
Glesys api unit test and javadoc improvements
This commit is contained in:
parent
a1c4ec13ca
commit
7d5a791071
|
@ -20,13 +20,11 @@ package org.jclouds.glesys.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
|
@ -36,175 +34,198 @@ import com.google.gson.annotations.SerializedName;
|
|||
* @see <a href="https://customer.glesys.com/api.php?a=doc#server_allowedarguments" />
|
||||
*/
|
||||
public class ServerAllowedArguments {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private List<Integer> diskSizes;
|
||||
private List<Integer> memorySizes;
|
||||
private List<Integer> cpuCores;
|
||||
private List<String> templates;
|
||||
private List<Integer> transfers;
|
||||
private List<String> dataCenters;
|
||||
public static class Builder {
|
||||
private List<Integer> diskSizes;
|
||||
private List<Integer> memorySizes;
|
||||
private List<Integer> cpuCores;
|
||||
private List<String> templates;
|
||||
private List<Integer> transfers;
|
||||
private List<String> dataCenters;
|
||||
|
||||
public Builder diskSizes(Integer... sizes) {
|
||||
return diskSizes(Arrays.<Integer>asList(sizes));
|
||||
}
|
||||
public Builder diskSizes(Integer... sizes) {
|
||||
return diskSizes(Arrays.<Integer>asList(sizes));
|
||||
}
|
||||
|
||||
public Builder diskSizes(List<Integer> sizes) {
|
||||
this.diskSizes = sizes;
|
||||
return this;
|
||||
}
|
||||
public Builder diskSizes(List<Integer> sizes) {
|
||||
this.diskSizes = sizes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder memorySizes(Integer... sizes) {
|
||||
return memorySizes(Arrays.<Integer>asList(sizes));
|
||||
}
|
||||
public Builder memorySizes(Integer... sizes) {
|
||||
return memorySizes(Arrays.<Integer>asList(sizes));
|
||||
}
|
||||
|
||||
public Builder memorySizes(List<Integer> sizes) {
|
||||
this.memorySizes = sizes;
|
||||
return this;
|
||||
}
|
||||
public Builder memorySizes(List<Integer> sizes) {
|
||||
this.memorySizes = sizes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder cpuCores(Integer... cpuCores) {
|
||||
this.cpuCores = Arrays.<Integer>asList(cpuCores);
|
||||
return this;
|
||||
}
|
||||
public Builder cpuCores(Integer... cpuCores) {
|
||||
this.cpuCores = Arrays.<Integer>asList(cpuCores);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder cpuCores(List<Integer> cpuCores) {
|
||||
this.cpuCores = cpuCores;
|
||||
return this;
|
||||
}
|
||||
public Builder cpuCores(List<Integer> cpuCores) {
|
||||
this.cpuCores = cpuCores;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder templates(String... templates) {
|
||||
return templates(Arrays.<String>asList(templates));
|
||||
}
|
||||
public Builder templates(String... templates) {
|
||||
return templates(Arrays.<String>asList(templates));
|
||||
}
|
||||
|
||||
public Builder templates(List<String> templates) {
|
||||
this.templates = templates;
|
||||
return this;
|
||||
}
|
||||
public Builder templates(List<String> templates) {
|
||||
this.templates = templates;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder transfers(Integer... transfers) {
|
||||
return transfers(Arrays.<Integer>asList(transfers));
|
||||
}
|
||||
public Builder transfers(Integer... transfers) {
|
||||
return transfers(Arrays.<Integer>asList(transfers));
|
||||
}
|
||||
|
||||
public Builder transfers(List<Integer> transfers) {
|
||||
this.transfers = transfers;
|
||||
return this;
|
||||
}
|
||||
public Builder transfers(List<Integer> transfers) {
|
||||
this.transfers = transfers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dataCenters(String... dataCenters) {
|
||||
return dataCenters(Arrays.<String>asList(dataCenters));
|
||||
}
|
||||
public Builder dataCenters(String... dataCenters) {
|
||||
return dataCenters(Arrays.<String>asList(dataCenters));
|
||||
}
|
||||
|
||||
public Builder dataCenters(List<String> dataCenters) {
|
||||
this.dataCenters = dataCenters;
|
||||
return this;
|
||||
}
|
||||
public Builder dataCenters(List<String> dataCenters) {
|
||||
this.dataCenters = dataCenters;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerAllowedArguments build() {
|
||||
return new ServerAllowedArguments(diskSizes, memorySizes, cpuCores, templates, transfers, dataCenters);
|
||||
}
|
||||
public ServerAllowedArguments build() {
|
||||
return new ServerAllowedArguments(diskSizes, memorySizes, cpuCores, templates, transfers, dataCenters);
|
||||
}
|
||||
|
||||
public Builder fromAllowedArguments(ServerAllowedArguments in) {
|
||||
return diskSizes(in.getDiskSizes())
|
||||
.memorySizes(in.getMemorySizes())
|
||||
.cpuCores(in.getCpuCores())
|
||||
.templates(in.getTemplates())
|
||||
.transfers(in.getTransfers())
|
||||
.dataCenters(in.getDataCenters());
|
||||
}
|
||||
}
|
||||
public Builder fromAllowedArguments(ServerAllowedArguments in) {
|
||||
return diskSizes(in.getDiskSizes())
|
||||
.memorySizes(in.getMemorySizes())
|
||||
.cpuCores(in.getCpuCores())
|
||||
.templates(in.getTemplates())
|
||||
.transfers(in.getTransfers())
|
||||
.dataCenters(in.getDataCenters());
|
||||
}
|
||||
}
|
||||
|
||||
@SerializedName("disksize")
|
||||
private final List<Integer> diskSizes;
|
||||
@SerializedName("memorysize")
|
||||
private final List<Integer> memorySizes;
|
||||
@SerializedName("cpucores")
|
||||
private final List<Integer> cpuCores;
|
||||
@SerializedName("template")
|
||||
private final List<String> templates;
|
||||
@SerializedName("transfer")
|
||||
private final List<Integer> transfers;
|
||||
@SerializedName("datacenter")
|
||||
private final List<String> dataCenters;
|
||||
@SerializedName("disksize")
|
||||
private final List<Integer> diskSizes;
|
||||
@SerializedName("memorysize")
|
||||
private final List<Integer> memorySizes;
|
||||
@SerializedName("cpucores")
|
||||
private final List<Integer> cpuCores;
|
||||
@SerializedName("template")
|
||||
private final List<String> templates;
|
||||
@SerializedName("transfer")
|
||||
private final List<Integer> transfers;
|
||||
@SerializedName("datacenter")
|
||||
private final List<String> dataCenters;
|
||||
|
||||
public ServerAllowedArguments(List<Integer> diskSizes, List<Integer> memorySizes, List<Integer> cpuCores,
|
||||
List<String> templates, List<Integer> transfers, List<String> dataCenters) {
|
||||
checkNotNull(diskSizes, "diskSizes");
|
||||
checkNotNull(memorySizes, "memorySizes");
|
||||
checkNotNull(cpuCores, "cpuCores");
|
||||
checkNotNull(templates, "templates");
|
||||
checkNotNull(transfers, "transfers");
|
||||
checkNotNull(dataCenters, "dataCenters");
|
||||
public ServerAllowedArguments(List<Integer> diskSizes, List<Integer> memorySizes, List<Integer> cpuCores,
|
||||
List<String> templates, List<Integer> transfers, List<String> dataCenters) {
|
||||
checkNotNull(diskSizes, "diskSizes");
|
||||
checkNotNull(memorySizes, "memorySizes");
|
||||
checkNotNull(cpuCores, "cpuCores");
|
||||
checkNotNull(templates, "templates");
|
||||
checkNotNull(transfers, "transfers");
|
||||
checkNotNull(dataCenters, "dataCenters");
|
||||
|
||||
this.diskSizes = diskSizes;
|
||||
this.memorySizes = memorySizes;
|
||||
this.cpuCores = cpuCores;
|
||||
this.templates = templates;
|
||||
this.transfers = transfers;
|
||||
this.dataCenters = dataCenters;
|
||||
}
|
||||
this.diskSizes = diskSizes;
|
||||
this.memorySizes = memorySizes;
|
||||
this.cpuCores = cpuCores;
|
||||
this.templates = templates;
|
||||
this.transfers = transfers;
|
||||
this.dataCenters = dataCenters;
|
||||
}
|
||||
|
||||
public List<Integer> getDiskSizes() {
|
||||
return diskSizes;
|
||||
}
|
||||
/**
|
||||
* @return a list of disk sizes, in GB, that can be used for creating servers on this platform
|
||||
* @see org.jclouds.glesys.domain.ServerTemplate#getMinDiskSize()
|
||||
*/
|
||||
public List<Integer> getDiskSizes() {
|
||||
return diskSizes;
|
||||
}
|
||||
|
||||
public List<Integer> getMemorySizes() {
|
||||
return memorySizes;
|
||||
}
|
||||
/**
|
||||
* @return a list of memory sizes, in MB, that can be used for creating servers on this platform
|
||||
* @see org.jclouds.glesys.domain.ServerTemplate#getMinMemSize()
|
||||
*/
|
||||
public List<Integer> getMemorySizes() {
|
||||
return memorySizes;
|
||||
}
|
||||
|
||||
public List<Integer> getCpuCores() {
|
||||
return cpuCores;
|
||||
}
|
||||
/**
|
||||
* @return a list of which core counts can be used for creating servers on this platform
|
||||
*/
|
||||
public List<Integer> getCpuCores() {
|
||||
return cpuCores;
|
||||
}
|
||||
|
||||
public List<String> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
/**
|
||||
* @return a list of template names available for creating servers on this platform
|
||||
* @see org.jclouds.glesys.domain.ServerTemplate#getName()
|
||||
*/
|
||||
public List<String> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
|
||||
public List<Integer> getTransfers() {
|
||||
return transfers;
|
||||
}
|
||||
/**
|
||||
* @return the list of transfer settings available for creating servers on this platform
|
||||
*/
|
||||
public List<Integer> getTransfers() {
|
||||
return transfers;
|
||||
}
|
||||
|
||||
public List<String> getDataCenters() {
|
||||
return dataCenters;
|
||||
}
|
||||
/**
|
||||
* @return the list of datacenters available that support creating servers on this platform
|
||||
*/
|
||||
public List<String> getDataCenters() {
|
||||
return dataCenters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
if (object instanceof ServerAllowedArguments) {
|
||||
final ServerAllowedArguments other = (ServerAllowedArguments) object;
|
||||
return Objects.equal(diskSizes, other.diskSizes)
|
||||
&& Objects.equal(memorySizes, other.memorySizes)
|
||||
&& Objects.equal(cpuCores, other.cpuCores)
|
||||
&& Objects.equal(templates, other.templates)
|
||||
&& Objects.equal(transfers, other.transfers)
|
||||
&& Objects.equal(dataCenters, other.dataCenters);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
if (object instanceof ServerAllowedArguments) {
|
||||
final ServerAllowedArguments other = (ServerAllowedArguments) object;
|
||||
return Objects.equal(diskSizes, other.diskSizes)
|
||||
&& Objects.equal(memorySizes, other.memorySizes)
|
||||
&& Objects.equal(cpuCores, other.cpuCores)
|
||||
&& Objects.equal(templates, other.templates)
|
||||
&& Objects.equal(transfers, other.transfers)
|
||||
&& Objects.equal(dataCenters, other.dataCenters);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(diskSizes, memorySizes, cpuCores, templates, transfers, dataCenters);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(diskSizes, memorySizes, cpuCores, templates, transfers, dataCenters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
checkNotNull(diskSizes, "diskSizes");
|
||||
checkNotNull(memorySizes, "memorySizes");
|
||||
checkNotNull(cpuCores, "cpuCores");
|
||||
checkNotNull(templates, "templates");
|
||||
checkNotNull(transfers, "transfers");
|
||||
checkNotNull(dataCenters, "dataCenters");
|
||||
@Override
|
||||
public String toString() {
|
||||
checkNotNull(diskSizes, "diskSizes");
|
||||
checkNotNull(memorySizes, "memorySizes");
|
||||
checkNotNull(cpuCores, "cpuCores");
|
||||
checkNotNull(templates, "templates");
|
||||
checkNotNull(transfers, "transfers");
|
||||
checkNotNull(dataCenters, "dataCenters");
|
||||
|
||||
Joiner commaJoiner = Joiner.on(", ");
|
||||
return String.format("[disksize=[%s], memorysize=[%s], cpuCores=[%s], templates=[%s], transfers=[%s], datacenters=[%s]]", commaJoiner.join(diskSizes), commaJoiner.join(memorySizes), commaJoiner.join(cpuCores), commaJoiner.join(templates), commaJoiner.join(transfers), commaJoiner.join(dataCenters));
|
||||
}
|
||||
Joiner commaJoiner = Joiner.on(", ");
|
||||
return String.format("[disksize=[%s], memorysize=[%s], cpuCores=[%s], templates=[%s], transfers=[%s], datacenters=[%s]]",
|
||||
commaJoiner.join(diskSizes), commaJoiner.join(memorySizes), commaJoiner.join(cpuCores), commaJoiner.join(templates),
|
||||
commaJoiner.join(transfers), commaJoiner.join(dataCenters));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,12 +4,45 @@ import com.google.common.base.Objects;
|
|||
|
||||
/**
|
||||
* Connection information to connect to a server with VNC.
|
||||
*
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see <a href="https://customer.glesys.com/api.php?a=doc#server_console" />
|
||||
*/
|
||||
public class ServerConsole {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String host;
|
||||
private int port;
|
||||
private String password;
|
||||
|
||||
public Builder host(String host) {
|
||||
this.host = host;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder port(int port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder password(String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerConsole build() {
|
||||
return new ServerConsole(host, port, password);
|
||||
}
|
||||
|
||||
public Builder fromServerConsole(ServerConsole in) {
|
||||
return host(in.getHost()).port(in.getPort()).password(in.getPassword());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final String password;
|
||||
|
@ -20,19 +53,27 @@ public class ServerConsole {
|
|||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the host name to use to connect to the server
|
||||
*/
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the port to use to connect to the server
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the password to use to connect to the server
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
|
@ -52,7 +93,7 @@ public class ServerConsole {
|
|||
public int hashCode() {
|
||||
return Objects.hashCode(host, port, password);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[host=%s, port=%s, password=%s]", host, port, password);
|
||||
|
|
|
@ -22,7 +22,10 @@ package org.jclouds.glesys.domain;
|
|||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* Represents detailed information about an available IP ip.
|
||||
* Represents detailed information about an available ip address of a new server.
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see ServerCreated
|
||||
*/
|
||||
public class ServerCreatedIp {
|
||||
|
||||
|
@ -49,11 +52,11 @@ public class ServerCreatedIp {
|
|||
this.cost = cost;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ServerCreatedIp build() {
|
||||
return new ServerCreatedIp(ip, version, cost);
|
||||
}
|
||||
|
||||
|
||||
public Builder fromIpCreated(ServerCreatedIp from) {
|
||||
return ip(from.getIp()).version(from.getVersion()).cost(from.getCost());
|
||||
}
|
||||
|
@ -62,25 +65,34 @@ public class ServerCreatedIp {
|
|||
protected final String ip;
|
||||
protected final int version;
|
||||
protected final double cost;
|
||||
|
||||
|
||||
public ServerCreatedIp(String ip, int version, double cost) {
|
||||
this.ip = ip;
|
||||
this.version = version;
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the IP version, ex. 4
|
||||
*/
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ip address of the new server
|
||||
*/
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cost of the ip address allocated to the new server
|
||||
*/
|
||||
public double getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
|
@ -91,7 +103,7 @@ public class ServerCreatedIp {
|
|||
return Objects.equal(ip, other.ip)
|
||||
&& Objects.equal(version, other.version)
|
||||
&& Objects.equal(cost, other.cost);
|
||||
} else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +116,6 @@ public class ServerCreatedIp {
|
|||
@Override
|
||||
public String toString() {
|
||||
return String.format("[ip=%s, version=%d, cost=%f]",
|
||||
ip, version, cost);
|
||||
ip, version, cost);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import com.google.common.base.CaseFormat;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Valid states for a server hosted in a Glesys cloud
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see ServerStatus
|
||||
*/
|
||||
|
|
|
@ -4,11 +4,12 @@ import com.google.common.base.Objects;
|
|||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Operating system template
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see <a href= "https://customer.glesys.com/api.php?a=doc#server_status" />
|
||||
* @see <a href= "https://customer.glesys.com/api.php?a=doc#server_templates" />
|
||||
*/
|
||||
public class Template {
|
||||
|
||||
public class ServerTemplate {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
|
@ -45,12 +46,12 @@ public class Template {
|
|||
this.platform = platform;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Template build() {
|
||||
return new Template(name, minDiskSize, minMemSize, os, platform);
|
||||
|
||||
public ServerTemplate build() {
|
||||
return new ServerTemplate(name, minDiskSize, minMemSize, os, platform);
|
||||
}
|
||||
|
||||
public Builder fromTemplate(Template in) {
|
||||
|
||||
public Builder fromTemplate(ServerTemplate in) {
|
||||
return name(in.getName()).minDiskSize(in.getMinDiskSize()).minMemSize(in.getMinMemSize()).os(in.getOs()).platform(in.getPlatform());
|
||||
}
|
||||
|
||||
|
@ -64,7 +65,7 @@ public class Template {
|
|||
private final String os;
|
||||
private final String platform;
|
||||
|
||||
public Template(String name, int minDiskSize, int minMemSize, String os, String platform) {
|
||||
public ServerTemplate(String name, int minDiskSize, int minMemSize, String os, String platform) {
|
||||
this.name = name;
|
||||
this.minDiskSize = minDiskSize;
|
||||
this.minMemSize = minMemSize;
|
||||
|
@ -76,18 +77,32 @@ public class Template {
|
|||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the minimum allowed disk size in GB
|
||||
* @see org.jclouds.glesys.domain.ServerAllowedArguments#getDiskSizes()
|
||||
*/
|
||||
public int getMinDiskSize() {
|
||||
return minDiskSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the minimum allowed memory size in MB
|
||||
* @see org.jclouds.glesys.domain.ServerAllowedArguments#getMemorySizes()
|
||||
*/
|
||||
public int getMinMemSize() {
|
||||
return minMemSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the operating system type ex. "linux"
|
||||
*/
|
||||
public String getOs() {
|
||||
return os;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the platform this template is available in, ex. "Xen"
|
||||
*/
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
@ -97,8 +112,8 @@ public class Template {
|
|||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
if (object instanceof Template) {
|
||||
final Template other = (Template) object;
|
||||
if (object instanceof ServerTemplate) {
|
||||
final ServerTemplate other = (ServerTemplate) object;
|
||||
return Objects.equal(name, other.name)
|
||||
&& Objects.equal(minDiskSize, other.minDiskSize)
|
||||
&& Objects.equal(minMemSize, other.minMemSize)
|
||||
|
@ -108,12 +123,12 @@ public class Template {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(name, minDiskSize, minMemSize, os, platform);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[name=%s, min_disk_size=%d, min_mem_size=%d, os=%s, platform=%s]",
|
|
@ -28,13 +28,16 @@ import java.util.List;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Represents an 'uptime' duration of server in a Glesys cloud
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see ServerStatus
|
||||
*/
|
||||
public class ServerUptime {
|
||||
private final long time;
|
||||
private final String timeString;
|
||||
|
||||
public ServerUptime(long time) {
|
||||
private ServerUptime(long time) {
|
||||
this.time = time;
|
||||
long days = TimeUnit.SECONDS.toDays(time);
|
||||
long hours = TimeUnit.SECONDS.toHours(time - TimeUnit.DAYS.toSeconds(days));
|
||||
|
@ -65,14 +68,14 @@ public class ServerUptime {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param uptimeString a Glesys uptime string
|
||||
* @param uptimeString a Glesys uptime string, ex. "0 0 0 0 0 10 1 1"
|
||||
*/
|
||||
public static ServerUptime fromValue(String uptimeString) {
|
||||
return new ServerUptime(uptimeString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param time number of seconds
|
||||
* @param time number of seconds the server has been up
|
||||
*/
|
||||
public static ServerUptime fromValue(long time) {
|
||||
return new ServerUptime(time);
|
||||
|
@ -88,12 +91,12 @@ public class ServerUptime {
|
|||
return true;
|
||||
}
|
||||
return object instanceof ServerUptime
|
||||
&& time == ((ServerUptime) object).time;
|
||||
&& Objects.equal(time, ((ServerUptime) object).getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 37 * (int) time;
|
||||
return Objects.hashCode(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,5 +104,4 @@ public class ServerUptime {
|
|||
return timeString;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -36,6 +36,7 @@ import java.util.*;
|
|||
* <p/>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Adam Lowe
|
||||
* @see ServerClient
|
||||
* @see <a href="https://customer.glesys.com/api.php" />
|
||||
*/
|
||||
|
@ -110,7 +111,7 @@ public interface ServerAsyncClient {
|
|||
@Path("/server/templates/format/json")
|
||||
@SelectJson("templates")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Map<String, Set<Template>>> getTemplates();
|
||||
ListenableFuture<Map<String, Set<ServerTemplate>>> getTemplates();
|
||||
|
||||
/**
|
||||
* @see ServerClient#stopServer
|
||||
|
|
|
@ -18,17 +18,13 @@
|
|||
*/
|
||||
package org.jclouds.glesys.features;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.glesys.domain.*;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.PathParam;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
|
@ -36,6 +32,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* <p/>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Adam Lowe
|
||||
* @see ServerAsyncClient
|
||||
* @see <a href="https://customer.glesys.com/api.php" />
|
||||
*/
|
||||
|
@ -86,10 +83,20 @@ public interface ServerClient {
|
|||
*/
|
||||
ServerConsole getServerConsole(String id);
|
||||
|
||||
// TODO should these be squished into single sets?
|
||||
Map<String, Set<Template>> getTemplates();
|
||||
/**
|
||||
* Get information about the OS templates available
|
||||
*
|
||||
* @return a map of templates, keyed on platform
|
||||
*/
|
||||
Map<String, Set<ServerTemplate>> getTemplates();
|
||||
|
||||
/**
|
||||
* Get information about valid arguments to #createServer for each platform
|
||||
*
|
||||
* @return a map of argument lists, keyed on platform
|
||||
*/
|
||||
Map<String, ServerAllowedArguments> getAllowedArguments();
|
||||
|
||||
|
||||
/**
|
||||
* Reset the fail count for a server limit (for OpenVZ only).
|
||||
*
|
||||
|
@ -155,6 +162,5 @@ public interface ServerClient {
|
|||
*/
|
||||
void resetPassword(@FormParam("serverid") String id, @FormParam("newpassword") String password);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -44,47 +44,47 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
|
|||
}
|
||||
|
||||
private ServerClient client;
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateAndDestroyServer() throws Exception {
|
||||
// ServerCreated server = client.createServer("Falkenberg", "Xen", "jclouds-test-host", "Debian-6 x64", 10, 512, 1, "password", 500, null, null);
|
||||
// System.out.println(server);
|
||||
//
|
||||
// boolean ready= false;
|
||||
//
|
||||
// for (int i=0; !ready && i<60; i++) {
|
||||
// ServerStatus newStatus = client.getServerStatus(server.getId());
|
||||
// if (newStatus.getState() == ServerState.RUNNING) {
|
||||
// ready = true;
|
||||
// break;
|
||||
// }
|
||||
// System.out.println(newStatus);
|
||||
// Thread.sleep(100);
|
||||
// }
|
||||
//
|
||||
// assertTrue(ready, "Server was not reported as running after 1 minute");
|
||||
public void testAllowedArguments() throws Exception {
|
||||
Map<String,ServerAllowedArguments> templates = client.getAllowedArguments();
|
||||
|
||||
assertTrue(templates.containsKey("OpenVZ"));
|
||||
assertTrue(templates.containsKey("Xen"));
|
||||
|
||||
client.destroyServer("xm3054942", 0);
|
||||
checkAllowedArguments(templates.get("OpenVZ"));
|
||||
checkAllowedArguments(templates.get("Xen"));
|
||||
}
|
||||
|
||||
private void checkAllowedArguments(ServerAllowedArguments t) {
|
||||
assertNotNull(t);
|
||||
|
||||
assert t.getDataCenters().size() > 0 : t;
|
||||
assert t.getCpuCores().size() > 0 : t;
|
||||
assert t.getDiskSizes().size() > 0 : t;
|
||||
assert t.getMemorySizes().size() > 0 : t;
|
||||
assert t.getTemplates().size() > 0 : t;
|
||||
assert t.getTransfers().size() > 0 : t;
|
||||
assert t.getTransfers().size() > 0 : t;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListTemplates() throws Exception {
|
||||
Map<String,Set<Template>> templates = client.getTemplates();
|
||||
Map<String,Set<ServerTemplate>> templates = client.getTemplates();
|
||||
|
||||
assertTrue(templates.containsKey("OpenVZ"));
|
||||
assertTrue(templates.containsKey("Xen"));
|
||||
|
||||
for(Template template : templates.get("OpenVZ")) {
|
||||
for(ServerTemplate template : templates.get("OpenVZ")) {
|
||||
checkTemplate(template, "OpenVZ");
|
||||
}
|
||||
|
||||
for(Template template : templates.get("Xen")) {
|
||||
for(ServerTemplate template : templates.get("Xen")) {
|
||||
checkTemplate(template, "Xen");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkTemplate(Template t, String platform) {
|
||||
private void checkTemplate(ServerTemplate t, String platform) {
|
||||
assertNotNull(t);
|
||||
assertNotNull(t.getName());
|
||||
assertNotNull(t.getOs());
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.testng.annotations.Test;
|
|||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseServerTemplatesTest")
|
||||
public class ParseServerTemplatesTest extends BaseItemParserTest<Map<String, Set<Template>>> {
|
||||
public class ParseServerTemplatesTest extends BaseItemParserTest<Map<String, Set<ServerTemplate>>> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
|
@ -47,8 +47,8 @@ public class ParseServerTemplatesTest extends BaseItemParserTest<Map<String, Set
|
|||
@Override
|
||||
@SelectJson("templates")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Map<String, Set<Template>> expected() {
|
||||
Map<String, Set<Template>> result = new LinkedHashMap<String, Set<Template>>();
|
||||
public Map<String, Set<ServerTemplate>> expected() {
|
||||
Map<String, Set<ServerTemplate>> result = new LinkedHashMap<String, Set<ServerTemplate>>();
|
||||
|
||||
String[] vzNames = new String[]{
|
||||
"Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit",
|
||||
|
@ -65,17 +65,17 @@ public class ParseServerTemplatesTest extends BaseItemParserTest<Map<String, Set
|
|||
"Windows Server 2008 R2 x64 std", "Windows Server 2008 R2 x64 web", "Windows Server 2008 x64 web", "Windows Server 2008 x86 web"
|
||||
};
|
||||
|
||||
result.put("OpenVZ", new HashSet<Template>());
|
||||
result.put("OpenVZ", new HashSet<ServerTemplate>());
|
||||
for (String name : vzNames) {
|
||||
result.get("OpenVZ").add(new Template(name, 5, 128, "linux", "OpenVZ"));
|
||||
result.get("OpenVZ").add(new ServerTemplate(name, 5, 128, "linux", "OpenVZ"));
|
||||
}
|
||||
|
||||
result.put("Xen", new HashSet<Template>());
|
||||
result.put("Xen", new HashSet<ServerTemplate>());
|
||||
for (String name : xenLinuxNames) {
|
||||
result.get("Xen").add(new Template(name, 5, 512, name.startsWith("FreeBSD") ? "freebsd" : "linux", "Xen"));
|
||||
result.get("Xen").add(new ServerTemplate(name, 5, 512, name.startsWith("FreeBSD") ? "freebsd" : "linux", "Xen"));
|
||||
}
|
||||
for (String name : xenWindowsNames) {
|
||||
result.get("Xen").add(new Template(name, 20, 1024, "windows", "Xen"));
|
||||
result.get("Xen").add(new ServerTemplate(name, 20, 1024, "windows", "Xen"));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue