diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Bandwidth.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Bandwidth.java index 4fd98fead9..31d9d1aa5e 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Bandwidth.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Bandwidth.java @@ -18,6 +18,8 @@ */ package org.jclouds.glesys.domain; +import com.google.common.base.Objects; + /** * Detailed information on Server bandwidth * @@ -89,9 +91,29 @@ public class Bandwidth { return max; } + @Override + public int hashCode() { + return Objects.hashCode(today, last30Days, max); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof Bandwidth) { + Bandwidth other = (Bandwidth) object; + return Objects.equal(today, other.today) + && Objects.equal(last30Days, other.last30Days) + && Objects.equal(max, other.max); + } else { + return false; + } + } + @Override public String toString() { - return String.format("Bandwidth[today=%d, last30Days=%d, max=%d]", today, last30Days, max); + return String.format("[today=%d, last30Days=%d, max=%d]", today, last30Days, max); } } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Cost.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Cost.java index df7f7bb895..08da121d17 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Cost.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Cost.java @@ -18,6 +18,7 @@ */ package org.jclouds.glesys.domain; +import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; import static com.google.common.base.Preconditions.checkNotNull; @@ -94,6 +95,26 @@ public class Cost { return timePeriod; } + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof Cost) { + Cost other = (Cost) object; + return Objects.equal(amount, other.amount) + && Objects.equal(currency, other.currency) + && Objects.equal(timePeriod, other.timePeriod); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(amount, currency, timePeriod); + } + @Override public String toString() { return String.format( diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Cpu.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Cpu.java index 3b5b5e7135..143df7ca1d 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Cpu.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Cpu.java @@ -18,6 +18,9 @@ */ package org.jclouds.glesys.domain; +import com.google.common.base.Objects; +import org.jclouds.javax.annotation.Nullable; + /** * Detailed information on Server cpu usage * @@ -33,7 +36,7 @@ public class Cpu { public static class Builder { private double system; private double user; - private double nice; + private Double nice; private double idle; private String unit; @@ -47,7 +50,7 @@ public class Cpu { return this; } - public Builder nice(double nice) { + public Builder nice(Double nice) { this.nice = nice; return this; } @@ -73,11 +76,11 @@ public class Cpu { private final double system; private final double user; - private final double nice; + private final Double nice; private final double idle; private final String unit; - public Cpu(double system, double user, double nice, double idle, String unit) { + public Cpu(double system, double user, @Nullable Double nice, double idle, String unit) { this.system = system; this.user = user; this.nice = nice; @@ -95,7 +98,7 @@ public class Cpu { /** * @return the user time in use in #unit */ - public Double getUser() { + public double getUser() { return user; } @@ -109,7 +112,7 @@ public class Cpu { /** * @return the idle time in #unit */ - public Double getIdle() { + public double getIdle() { return idle; } @@ -120,9 +123,31 @@ public class Cpu { return unit; } + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof Cpu) { + Cpu other = (Cpu) object; + return Objects.equal(system, other.system) + && Objects.equal(user, other.user) + && Objects.equal(nice, other.nice) + && Objects.equal(idle, other.idle) + && Objects.equal(unit, other.unit); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(system, user, nice, idle, unit); + } + @Override public String toString() { - return String.format("Cpu[system=%f, user=%f, nice=%f, idle=%f, unit=%s]", + return String.format("[system=%f, user=%f, nice=%f, idle=%f, unit=%s]", system, user, nice, idle, unit); } } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Disk.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Disk.java index ac27c71f6a..7748276876 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Disk.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Disk.java @@ -18,6 +18,8 @@ */ package org.jclouds.glesys.domain; +import com.google.common.base.Objects; + /** * Detailed information on Server disk usage * @@ -89,9 +91,29 @@ public class Disk { return unit; } + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof Disk) { + Disk other = (Disk) object; + return Objects.equal(used, other.used) + && Objects.equal(size, other.size) + && Objects.equal(unit, other.unit); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(used, size, unit); + } + @Override public String toString() { - return String.format("Disk[used=%d, size=%d, unit=%s]", used, size, unit); + return String.format("[used=%d, size=%d, unit=%s]", used, size, unit); } } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Memory.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Memory.java index b95b0361e7..a5e48c19a6 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Memory.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Memory.java @@ -18,6 +18,7 @@ */ package org.jclouds.glesys.domain; +import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; /** @@ -93,8 +94,28 @@ public class Memory { return unit; } + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof Memory) { + Memory other = (Memory) object; + return Objects.equal(usage, other.usage) + && Objects.equal(size, other.size) + && Objects.equal(unit, other.unit); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(usage, size, unit); + } + @Override public String toString() { - return String.format("Memory[usage=%d, size=%d, unit=%s]", usage, size, unit); + return String.format("[usage=%d, size=%d, unit=%s]", usage, size, unit); } } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Server.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Server.java index 554ceee2e6..055fee5906 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Server.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Server.java @@ -18,13 +18,14 @@ */ package org.jclouds.glesys.domain; -import static com.google.common.base.Preconditions.checkNotNull; - +import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Listing of a server. - * + * * @author Adrian Cole * @see */ @@ -110,46 +111,24 @@ public class Server { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((datacenter == null) ? 0 : datacenter.hashCode()); - result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((platform == null) ? 0 : platform.hashCode()); - return result; + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof Server) { + final Server other = (Server) object; + return Objects.equal(datacenter, other.datacenter) + && Objects.equal(hostname, other.hostname) + && Objects.equal(id, other.id) + && Objects.equal(platform, other.platform); + } else { + return false; + } } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Server other = (Server) obj; - if (datacenter == null) { - if (other.datacenter != null) - return false; - } else if (!datacenter.equals(other.datacenter)) - return false; - if (hostname == null) { - if (other.hostname != null) - return false; - } else if (!hostname.equals(other.hostname)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (platform == null) { - if (other.platform != null) - return false; - } else if (!platform.equals(other.platform)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(datacenter, hostname, id, platform); } @Override diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerAllowedArguments.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerAllowedArguments.java new file mode 100644 index 0000000000..ffe53dc50e --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerAllowedArguments.java @@ -0,0 +1,231 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; +import java.util.List; + +import com.google.common.base.Joiner; +import com.google.common.base.Objects; +import com.google.gson.annotations.SerializedName; + +/** + * Lists the allowed arguments for some of the functions in this module such as disksize, cpucores etc. + * + * @author Adam Lowe + * @see + */ +public class ServerAllowedArguments { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private List diskSizes; + private List memorySizes; + private List cpuCores; + private List templates; + private List transfers; + private List dataCenters; + + public Builder diskSizes(Integer... sizes) { + return diskSizes(Arrays.asList(sizes)); + } + + public Builder diskSizes(List sizes) { + this.diskSizes = sizes; + return this; + } + + public Builder memorySizes(Integer... sizes) { + return memorySizes(Arrays.asList(sizes)); + } + + public Builder memorySizes(List sizes) { + this.memorySizes = sizes; + return this; + } + + public Builder cpuCores(Integer... cpuCores) { + this.cpuCores = Arrays.asList(cpuCores); + return this; + } + + public Builder cpuCores(List cpuCores) { + this.cpuCores = cpuCores; + return this; + } + + public Builder templates(String... templates) { + return templates(Arrays.asList(templates)); + } + + public Builder templates(List templates) { + this.templates = templates; + return this; + } + + public Builder transfers(Integer... transfers) { + return transfers(Arrays.asList(transfers)); + } + + public Builder transfers(List transfers) { + this.transfers = transfers; + return this; + } + + public Builder dataCenters(String... dataCenters) { + return dataCenters(Arrays.asList(dataCenters)); + } + + public Builder dataCenters(List dataCenters) { + this.dataCenters = dataCenters; + return this; + } + + 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()); + } + } + + @SerializedName("disksize") + private final List diskSizes; + @SerializedName("memorysize") + private final List memorySizes; + @SerializedName("cpucores") + private final List cpuCores; + @SerializedName("template") + private final List templates; + @SerializedName("transfer") + private final List transfers; + @SerializedName("datacenter") + private final List dataCenters; + + public ServerAllowedArguments(List diskSizes, List memorySizes, List cpuCores, + List templates, List transfers, List 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; + } + + /** + * @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 getDiskSizes() { + return diskSizes; + } + + /** + * @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 getMemorySizes() { + return memorySizes; + } + + /** + * @return a list of which core counts can be used for creating servers on this platform + */ + public List getCpuCores() { + return cpuCores; + } + + /** + * @return a list of template names available for creating servers on this platform + * @see org.jclouds.glesys.domain.ServerTemplate#getName() + */ + public List getTemplates() { + return templates; + } + + /** + * @return the list of transfer settings available for creating servers on this platform + */ + public List getTransfers() { + return transfers; + } + + /** + * @return the list of datacenters available that support creating servers on this platform + */ + public List 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 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"); + + 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)); + } + +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerConsole.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerConsole.java new file mode 100644 index 0000000000..2337de5054 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerConsole.java @@ -0,0 +1,102 @@ +package org.jclouds.glesys.domain; + +import com.google.common.base.Objects; + +/** + * Connection information to connect to a server with VNC. + * + * @author Adam Lowe + * @see + */ +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; + + public ServerConsole(String host, int port, String password) { + this.host = host; + this.port = port; + 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) { + return true; + } + if (object instanceof ServerConsole) { + final ServerConsole other = (ServerConsole) object; + return Objects.equal(host, other.host) + && Objects.equal(port, other.port) + && Objects.equal(password, other.password); + } else { + return false; + } + } + + @Override + 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); + } + +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java new file mode 100644 index 0000000000..7c243ca49b --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java @@ -0,0 +1,99 @@ +package org.jclouds.glesys.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; + +import com.google.common.base.Objects; +import com.google.gson.annotations.SerializedName; +import org.jclouds.javax.annotation.Nullable; + +/** + * Connection information to connect to a server with VNC. + * + * @author Adam Lowe + * @see + */ +public class ServerCreated { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String id; + private String hostname; + private List ips; + + public Builder id(String id) { + this.id = id; + return this; + } + public Builder port(List ips) { + this.ips = ips; + return this; + } + + public Builder hostname(String hostname) { + this.hostname = hostname; + return this; + } + + public ServerCreated build() { + return new ServerCreated(id, hostname, ips); + } + + public Builder fromServerCreated(ServerCreated in) { + return id(in.getId()).hostname(in.getHostname()).port(in.getIps()); + } + } + + @SerializedName("serverid") + private final String id; + private final String hostname; + @SerializedName("iplist") + private final List ips; + + public ServerCreated(String id, @Nullable String hostname, List ips) { + checkNotNull(id, "id"); + this.id = id; + this.hostname = hostname; + this.ips = ips; + } + + public String getId() { + return id; + } + + public String getHostname() { + return hostname; + } + + public List getIps() { + return ips; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof ServerCreated) { + final ServerCreated other = (ServerCreated) object; + return Objects.equal(id, other.id) + && Objects.equal(ips, other.ips); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(id, ips); + } + + @Override + public String toString() { + return String.format("[id=%s, hostname=%s, ips=%s]", id, hostname, ips); + } + +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreatedIp.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreatedIp.java new file mode 100644 index 0000000000..f8c210185b --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreatedIp.java @@ -0,0 +1,121 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.glesys.domain; + +import com.google.common.base.Objects; + +/** + * Represents detailed information about an available ip address of a new server. + * + * @author Adam Lowe + * @see ServerCreated + */ +public class ServerCreatedIp { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + protected String ip; + protected int version; + protected double cost; + + public Builder version(int version) { + this.version = version; + return this; + } + + public Builder ip(String ip) { + this.ip = ip; + return this; + } + + public Builder cost(double cost) { + 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()); + } + } + + 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) { + return true; + } + if (object instanceof ServerCreatedIp) { + final ServerCreatedIp other = (ServerCreatedIp) object; + return Objects.equal(ip, other.ip) + && Objects.equal(version, other.version) + && Objects.equal(cost, other.cost); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(ip, version, cost); + } + + @Override + public String toString() { + return String.format("[ip=%s, version=%d, cost=%f]", + ip, version, cost); + } +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java index 022f44ebd5..258c1c93ba 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java @@ -20,12 +20,13 @@ package org.jclouds.glesys.domain; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; /** * Detailed information about a server such as cpuCores, hardware configuration * (cpu, memory and disk), ip adresses, cost, transfer, os and more. - * + * * @author Adrian Cole * @see */ @@ -65,7 +66,7 @@ public class ServerDetails extends Server { this.cost = cost; return this; } - + public ServerDetails build() { return new ServerDetails(id, hostname, datacenter, platform, description, cpuCores, memory, disk, cost); } @@ -100,16 +101,16 @@ public class ServerDetails extends Server { return Builder.class.cast(super.fromServer(in)); } } - + private final String description; @SerializedName("cpucores") private final int cpuCores; private final int memory; private final int disk; private final Cost cost; - + public ServerDetails(String id, String hostname, String datacenter, String platform, String description, - int cpuCores, int memory, int disk, Cost cost) { + int cpuCores, int memory, int disk, Cost cost) { super(id, hostname, datacenter, platform); this.description = checkNotNull(description, "description"); this.cpuCores = cpuCores; @@ -147,10 +148,10 @@ public class ServerDetails extends Server { } /** - * @return details of the cost of the server - */ + * @return details of the cost of the server + */ public Cost getCost() { - return cost; + return cost; } @Override @@ -160,4 +161,27 @@ public class ServerDetails extends Server { hostname, datacenter, platform, description, cpuCores, memory, disk, cost); } + @Override + public int hashCode() { + return super.hashCode() + Objects.hashCode(description, cpuCores, disk, memory, cost); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof ServerDetails) { + final ServerDetails other = (ServerDetails) object; + return super.equals(other) + && Objects.equal(description, other.description) + && Objects.equal(cpuCores, other.cpuCores) + && Objects.equal(disk, other.disk) + && Objects.equal(memory, other.memory) + && Objects.equal(cost, other.cost); + } else { + return false; + } + } + } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerLimit.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerLimit.java new file mode 100644 index 0000000000..b0faaa0e1f --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerLimit.java @@ -0,0 +1,113 @@ +package org.jclouds.glesys.domain; + +import com.google.common.base.Objects; + +/** + * Detailed information about an OpenVZ server's limits + * + * @author Adam Lowe + * @see + */ +public class ServerLimit { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private int held; + private int maxHeld; + private int barrier; + private int limit; + private int failCount; + + public Builder held(int held) { + this.held = held; + return this; + } + + public Builder maxHeld(int maxHeld) { + this.maxHeld = maxHeld; + return this; + } + + public Builder barrier(int barrier) { + this.barrier = barrier; + return this; + } + + public Builder limit(int limit) { + this.limit = limit; + return this; + } + + public Builder failCount(int failCount) { + this.failCount = failCount; + return this; + } + + public ServerLimit build() { + return new ServerLimit(held, maxHeld, barrier, limit, failCount); + } + } + + private final long held; + private final long maxHeld; + private final long barrier; + private final long limit; + private final long failCount; + + public ServerLimit(long held, long maxHeld, long barrier, long limit, long failCount) { + this.held = held; + this.maxHeld = maxHeld; + this.barrier = barrier; + this.limit = limit; + this.failCount = failCount; + } + + public long getHeld() { + return held; + } + + public long getMaxHeld() { + return maxHeld; + } + + public long getBarrier() { + return barrier; + } + + public long getLimit() { + return limit; + } + + public long getFailCount() { + return failCount; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof ServerLimit) { + final ServerLimit other = (ServerLimit) object; + return Objects.equal(held, other.held) + && Objects.equal(maxHeld, other.maxHeld) + && Objects.equal(barrier, other.barrier) + && Objects.equal(limit, other.limit) + && Objects.equal(failCount, other.failCount); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(held, maxHeld, barrier, limit, failCount); + } + + @Override + public String toString() { + return String.format("[held=%d, maxHeld=%d, barrier=%d, limit=%d, failCount=%d]", held, maxHeld, barrier, limit, failCount); + } +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerState.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerState.java index b5540f5312..b30a48d000 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerState.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerState.java @@ -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 */ diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java index f8159742bb..9e802c34d9 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java @@ -18,6 +18,8 @@ */ package org.jclouds.glesys.domain; +import com.google.common.base.Objects; + /** * Detailed information server status including hardware usage (cpu, memory and disk), bandwidth and up-time. * @@ -136,9 +138,32 @@ public class ServerStatus { return uptime.getTime(); } + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof ServerStatus) { + final ServerStatus other = (ServerStatus) object; + return Objects.equal(state, other.state) + && Objects.equal(cpu, other.cpu) + && Objects.equal(memory, other.memory) + && Objects.equal(disk, other.disk) + && Objects.equal(bandwidth, other.bandwidth) + && uptime == other.uptime; + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(state, cpu, memory, disk, bandwidth, uptime); + } + @Override public String toString() { - return String.format("Status[state=%s, cpu=%s, memory=%s, disk=%s, bandwidth=%s, uptime=%s]", + return String.format("[state=%s, cpu=%s, memory=%s, disk=%s, bandwidth=%s, uptime=%s]", state, cpu, memory, disk, bandwidth, uptime); } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerTemplate.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerTemplate.java new file mode 100644 index 0000000000..7d5ccf3dfc --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerTemplate.java @@ -0,0 +1,137 @@ +package org.jclouds.glesys.domain; + +import com.google.common.base.Objects; +import com.google.gson.annotations.SerializedName; + +/** + * Operating system template + * + * @author Adam Lowe + * @see + */ +public class ServerTemplate { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String name; + private int minDiskSize; + private int minMemSize; + private String os; + private String platform; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder minDiskSize(int minDiskSize) { + this.minDiskSize = minDiskSize; + return this; + } + + public Builder minMemSize(int minMemSize) { + this.minMemSize = minMemSize; + return this; + } + + public Builder os(String os) { + this.os = os; + return this; + } + + public Builder platform(String platform) { + this.platform = platform; + return this; + } + + public ServerTemplate build() { + return new ServerTemplate(name, minDiskSize, minMemSize, os, platform); + } + + public Builder fromTemplate(ServerTemplate in) { + return name(in.getName()).minDiskSize(in.getMinDiskSize()).minMemSize(in.getMinMemSize()).os(in.getOs()).platform(in.getPlatform()); + } + + } + + private final String name; + @SerializedName("min_disk_size") + private final int minDiskSize; + @SerializedName("min_mem_size") + private final int minMemSize; + private final String os; + private final String platform; + + public ServerTemplate(String name, int minDiskSize, int minMemSize, String os, String platform) { + this.name = name; + this.minDiskSize = minDiskSize; + this.minMemSize = minMemSize; + this.os = os; + this.platform = platform; + } + + public String getName() { + 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; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + 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) + && Objects.equal(os, other.os) + && Objects.equal(platform, other.platform); + } else { + 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]", + name, minDiskSize, minMemSize, os, platform); + } +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java index d2ce545597..24ab2a9792 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java @@ -19,6 +19,7 @@ package org.jclouds.glesys.domain; import com.google.common.base.Joiner; +import com.google.common.base.Objects; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; @@ -27,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)); @@ -64,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); @@ -81,8 +85,23 @@ public class ServerUptime { return time; } + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + return object instanceof ServerUptime + && Objects.equal(time, ((ServerUptime) object).getTime()); + } + + @Override + public int hashCode() { + return Objects.hashCode(time); + } + @Override public String toString() { return timeString; } + } \ No newline at end of file diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java index cca69a4262..30400e60f7 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java @@ -18,17 +18,8 @@ */ package org.jclouds.glesys.features; -import java.util.Set; - -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 org.jclouds.glesys.domain.Server; -import org.jclouds.glesys.domain.ServerDetails; -import org.jclouds.glesys.domain.ServerStatus; +import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.glesys.domain.*; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; @@ -36,15 +27,18 @@ import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import com.google.common.util.concurrent.ListenableFuture; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.*; /** * Provides asynchronous access to Server via their REST API. *

- * + * + * @author Adrian Cole + * @author Adam Lowe * @see ServerClient * @see - * @author Adrian Cole */ @RequestFilters(BasicAuthentication.class) public interface ServerAsyncClient { @@ -69,9 +63,8 @@ public interface ServerAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getServerDetails(@PathParam("id") String id); - /** - * @see ServerClient#getServerDetails + * @see ServerClient#getServerStatus */ @GET @Path("/server/status/serverid/{id}/format/json") @@ -80,4 +73,121 @@ public interface ServerAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getServerStatus(@PathParam("id") String id); + /** + * @see ServerClient#getServerLimits + */ + @GET + @Path("/server/limits/serverid/{id}/format/json") + @SelectJson("limits") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getServerLimits(@PathParam("id") String id); + + + /** + * @see ServerClient#getServerConsole + */ + @GET + @Path("/server/console/serverid/{id}/format/json") + @SelectJson("server") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getServerConsole(@PathParam("id") String id); + + + /** + * @see ServerClient#getAllowedArguments + */ + @GET + @Path("/server/allowedarguments/format/json") + @SelectJson("argumentslist") + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture> getAllowedArguments(); + + /** + * @see ServerClient#getTemplates + */ + @GET + @Path("/server/templates/format/json") + @SelectJson("templates") + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture>> getTemplates(); + + /** + * @see ServerClient#stopServer + */ + @GET + @Path("/server/resetlimit/serverid/{id}/type/{type}/format/json") + ListenableFuture resetServerLimit(@PathParam("id") String id, @PathParam("type") String type); + + /** + * @see ServerClient#rebootServer + */ + @GET + @Path("/server/reboot/serverid/{id}/format/json") + ListenableFuture rebootServer(@PathParam("id") String id); + + /** + * @see ServerClient#startServer + */ + @GET + @Path("/server/start/serverid/{id}/format/json") + ListenableFuture startServer(@PathParam("id") String id); + + /** + * @see ServerClient#stopServer + */ + @GET + @Path("/server/stop/serverid/{id}/format/json") + ListenableFuture stopServer(@PathParam("id") String id); + + /** + * @see ServerClient#createServer + */ + @POST + @Path("/server/create/format/json") + @SelectJson("server") + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture createServer(@FormParam("datacenter") String dataCenter, + @FormParam("platform") String platform, + @FormParam("hostname") String hostname, + @FormParam("template") String template, + @FormParam("disksize") int diskSize, + @FormParam("memorysize") int memorySize, + @FormParam("cpucores") int cpucores, + @FormParam("rootpw") String rootpw, + @FormParam("transfer") int transfer, + String description, + String ip); + + /** + * @see ServerClient#createServer + */ + @POST + @Path("/server/clone/format/json") + @SelectJson("server") + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture cloneServer(@FormParam("serverid") String serverid, + @FormParam("hostname") String hostname, + @FormParam("disksize") int diskSize, + @FormParam("memorysize") int memorySize, + @FormParam("cpucores") int cpucores, + @FormParam("transfer") int transfer, + @FormParam("description") String description, + @FormParam("datacenter") String dataCenter); + + /** + * @see ServerClient#destroyServer + */ + @POST + @Path("/server/destroy/format/json") + ListenableFuture destroyServer(@FormParam("serverid") String id, @FormParam("keepip") int keepIp); + + /** + * @see ServerClient#resetPassword + */ + @POST + @Path("/server/destroy/format/json") + ListenableFuture resetPassword(@FormParam("serverid") String id, @FormParam("newpassword") String password); + } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java index b5a8819cdf..8bbd00b669 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java @@ -18,39 +18,40 @@ */ package org.jclouds.glesys.features; +import org.jclouds.concurrent.Timeout; +import org.jclouds.glesys.domain.*; +import org.jclouds.javax.annotation.Nullable; + +import javax.ws.rs.FormParam; +import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.jclouds.concurrent.Timeout; -import org.jclouds.glesys.domain.Server; -import org.jclouds.glesys.domain.ServerDetails; -import org.jclouds.glesys.domain.ServerStatus; - /** * Provides synchronous access to Server. *

- * + * + * @author Adrian Cole + * @author Adam Lowe * @see ServerAsyncClient * @see - * @author Adrian Cole */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) public interface ServerClient { /** * Get a list of all servers on this account. - * + * * @return an account's associated server objects. */ Set listServers(); /** * Get detailed information about a server such as hostname, hardware - * configuration (cpu, memory and disk), ip adresses, cost, transfer, os and + * configuration (cpu, memory and disk), ip addresses, cost, transfer, os and * more. - * - * @param id - * id of the server + * + * @param id id of the server * @return server or null if not found */ ServerDetails getServerDetails(String id); @@ -59,10 +60,107 @@ public interface ServerClient { * Get detailed information about a server status including up-time and hardware usage * (cpu, disk, memory and bandwidth) * - * @param id - * id of the server - * @return server or null if not found + * @param id id of the server + * @return the status of the server or null if not found */ ServerStatus getServerStatus(String id); - + + /** + * Get detailed information about a server's limits (for OpenVZ only). + *

+ * + * @param id id of the server + * @return the requested information about the server or null if not found + */ + Map getServerLimits(String id); + + + /** + * Get information about how to connect to a server via VNC + * + * @param id id of the server + * @return the requested information about the server or null if not found + */ + ServerConsole getServerConsole(String id); + + /** + * Get information about the OS templates available + * + * @return a map of templates, keyed on platform + */ + Map> getTemplates(); + + /** + * Get information about valid arguments to #createServer for each platform + * + * @return a map of argument lists, keyed on platform + */ + Map getAllowedArguments(); + + /** + * Reset the fail count for a server limit (for OpenVZ only). + * + * @param id id of the server + * @param type the type of limit to reset + */ + + void resetServerLimit(String id, String type); + + /** + * Reboot a server + * + * @param id id of the server + */ + void rebootServer(String id); + + /** + * Start a server + * + * @param id id of the server + */ + void startServer(String id); + + /** + * Stop a server + * + * @param id id of the server + */ + void stopServer(String id); + + /** + * Create a new server + * + * @param datacenter the data center to create the new server in + * @param platform the platform to use (i.e. "Xen" or "OpenVZ") + * @param hostname the host name of the new server + * @param template the template to use to create the new server + * @param disksize the amount of disk space, in GB, to allocate + * @param memorysize the memory, in MB, to allocate + * @param cpucores the number of CPU cores to allocate + * @param rootpw the root password to use + * @param transfer the transfer size + * @param description a description of the server + * @param ip ip address to assign to the new server, required by Xen platform + */ + ServerCreated createServer(String datacenter, String platform, + String hostname, String template, int disksize, int memorysize, + int cpucores, String rootpw, int transfer, @Nullable String description, @Nullable String ip); + + /** + * Destroy a server + * + * @param id the id of the server + * @param keepIp if 1 the servers ip will be retained for use in your Glesys account + */ + void destroyServer(String id, int keepIp); + + /** + * Reset the root password of a server + * + * @param id the id of the server + * @param password the new password to use + */ + void resetPassword(@FormParam("serverid") String id, @FormParam("newpassword") String password); + + } \ No newline at end of file diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/CustomDeserializers.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/CustomDeserializers.java index 1bd792f543..85a158a6ab 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/CustomDeserializers.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/CustomDeserializers.java @@ -3,14 +3,14 @@ package org.jclouds.glesys.functions.internal; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; +import org.jclouds.glesys.domain.ServerAllowedArguments; import org.jclouds.glesys.domain.ServerState; -import org.jclouds.glesys.domain.ServerStatus; import org.jclouds.glesys.domain.ServerUptime; import java.lang.reflect.Type; +import java.util.HashSet; +import java.util.Set; /** * @Author Adam Lowe @@ -34,5 +34,17 @@ public class CustomDeserializers { return ServerUptime.fromValue(toParse); } } + + public static class ServerAllowedArgumentsAdaptor implements JsonDeserializer> { + + @Override + public Set deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + Set result = new HashSet(); + for(JsonElement e : jsonElement.getAsJsonObject().get("OpenVZ").getAsJsonArray()) { + result.add(jsonDeserializationContext.deserialize(e, ServerAllowedArguments.class)); + } + return result; + } + } } \ No newline at end of file diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java index 38ad734216..ce4329edae 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java @@ -22,11 +22,10 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import java.util.Map; import java.util.Set; -import org.jclouds.glesys.domain.Server; -import org.jclouds.glesys.domain.ServerDetails; -import org.jclouds.glesys.domain.ServerStatus; +import org.jclouds.glesys.domain.*; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -45,7 +44,56 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { } private ServerClient client; + + @Test + public void testAllowedArguments() throws Exception { + Map templates = client.getAllowedArguments(); + + assertTrue(templates.containsKey("OpenVZ")); + assertTrue(templates.containsKey("Xen")); + + 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> templates = client.getTemplates(); + + assertTrue(templates.containsKey("OpenVZ")); + assertTrue(templates.containsKey("Xen")); + + for(ServerTemplate template : templates.get("OpenVZ")) { + checkTemplate(template, "OpenVZ"); + } + + for(ServerTemplate template : templates.get("Xen")) { + checkTemplate(template, "Xen"); + } + } + + private void checkTemplate(ServerTemplate t, String platform) { + assertNotNull(t); + assertNotNull(t.getName()); + assertNotNull(t.getOs()); + + assertEquals(t.getPlatform(), platform); + assert t.getMinDiskSize() > 0 : t; + assert t.getMinMemSize() > 0 : t; + } + @Test public void testListServers() throws Exception { Set response = client.listServers(); diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java new file mode 100644 index 0000000000..cebde48f22 --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java @@ -0,0 +1,82 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.parse; + + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; +import java.util.*; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.glesys.config.GleSYSParserModule; +import org.jclouds.glesys.domain.ServerAllowedArguments; +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "ParseServerAllowedArgumentsTest") +public class ParseServerAllowedArgumentsTest extends BaseItemParserTest> { + + @Override + public String resource() { + return "/server_allowed_arguments.json"; + } + + @Override + @SelectJson("argumentslist") + @Consumes(MediaType.APPLICATION_JSON) + public Map expected() { + Map result = new LinkedHashMap(); + ServerAllowedArguments openvz = ServerAllowedArguments.builder() + .dataCenters("Amsterdam", "Falkenberg", "New York City", "Stockholm") + .memorySizes(128, 256, 512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288) + .diskSizes(5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 150) + .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) + .templates("Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit", "Debian 5.0 32-bit", + "Debian 5.0 64-bit", "Debian 6.0 32-bit", "Debian 6.0 64-bit", "Fedora Core 11", "Fedora Core 11 64-bit", + "Gentoo", "Gentoo 64-bit", "Scientific Linux 6", "Scientific Linux 6 64-bit", "Slackware 12", + "Ubuntu 10.04 LTS 32-bit", "Ubuntu 10.04 LTS 64-bit", "Ubuntu 11.04 64-bit") + .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) + .build(); + ServerAllowedArguments xen = ServerAllowedArguments.builder() + .memorySizes(512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 14336, 16384) + .diskSizes(5, 10, 20, 30, 40, 50, 80, 100, 120, 140, 150, 160, 160, 200, 250, 300) + .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) + .templates("CentOS 5.5 x64", "CentOS 5.5 x86", "Centos 6 x64", "Centos 6 x86", "Debian-6 x64", + "Debian 5.0.1 x64", "FreeBSD 8.2", "Gentoo 10.1 x64", "Ubuntu 8.04 x64", "Ubuntu 10.04 LTS 64-bit", + "Ubuntu 10.10 x64", "Ubuntu 11.04 x64", "Windows Server 2008 R2 x64 std", + "Windows Server 2008 R2 x64 web", "Windows Server 2008 x64 web", "Windows Server 2008 x86 web") + .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) + .dataCenters("Falkenberg") + .build(); + result.put("Xen", xen); + result.put("OpenVZ", openvz); + return result; + } + + + protected Injector injector() { + return Guice.createInjector(new GleSYSParserModule(), new GsonModule()); + } +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerCreatedTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerCreatedTest.java new file mode 100644 index 0000000000..7023f33694 --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerCreatedTest.java @@ -0,0 +1,60 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.parse; + + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; +import java.util.*; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.glesys.config.GleSYSParserModule; +import org.jclouds.glesys.domain.ServerCreatedIp; +import org.jclouds.glesys.domain.ServerCreated; +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "ParseServerCreatedTest") +public class ParseServerCreatedTest extends BaseItemParserTest { + + @Override + public String resource() { + return "/server_created.json"; + } + + @Override + @SelectJson("server") + @Consumes(MediaType.APPLICATION_JSON) + public ServerCreated expected() { + List ips = new ArrayList(); + ips.add(ServerCreatedIp.builder().ip("109.74.10.27").version(4).cost(2.00).build()); + return ServerCreated.builder().id("xm3630641").hostname("jclouds-test-host").port(ips).build(); + } + + + protected Injector injector() { + return Guice.createInjector(new GleSYSParserModule(), new GsonModule()); + } +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerTemplatesTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerTemplatesTest.java new file mode 100644 index 0000000000..e42f01bfc1 --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerTemplatesTest.java @@ -0,0 +1,88 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.parse; + + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import java.util.*; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.glesys.config.GleSYSParserModule; +import org.jclouds.glesys.domain.*; +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "ParseServerTemplatesTest") +public class ParseServerTemplatesTest extends BaseItemParserTest>> { + + @Override + public String resource() { + return "/server_templates.json"; + } + + @Override + @SelectJson("templates") + @Consumes(MediaType.APPLICATION_JSON) + public Map> expected() { + Map> result = new LinkedHashMap>(); + + String[] vzNames = new String[]{ + "Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit", + "Debian 5.0 32-bit", "Debian 5.0 64-bit", "Debian 6.0 32-bit", "Debian 6.0 64-bit", + "Fedora Core 11", "Fedora Core 11 64-bit", "Gentoo", "Gentoo 64-bit", + "Scientific Linux 6", "Scientific Linux 6 64-bit", "Slackware 12", + "Ubuntu 10.04 LTS 32-bit", "Ubuntu 10.04 LTS 64-bit", "Ubuntu 11.04 64-bit" + }; + String[] xenLinuxNames = new String[] { + "CentOS 5.5 x64", "CentOS 5.5 x86", "Centos 6 x64", "Centos 6 x86", "Debian-6 x64", "Debian 5.0.1 x64", + "FreeBSD 8.2", "Gentoo 10.1 x64", "Ubuntu 8.04 x64", "Ubuntu 10.04 LTS 64-bit", "Ubuntu 10.10 x64", "Ubuntu 11.04 x64", + }; + String[] xenWindowsNames = new String[] { + "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()); + for (String name : vzNames) { + result.get("OpenVZ").add(new ServerTemplate(name, 5, 128, "linux", "OpenVZ")); + } + + result.put("Xen", new HashSet()); + for (String name : xenLinuxNames) { + result.get("Xen").add(new ServerTemplate(name, 5, 512, name.startsWith("FreeBSD") ? "freebsd" : "linux", "Xen")); + } + for (String name : xenWindowsNames) { + result.get("Xen").add(new ServerTemplate(name, 20, 1024, "windows", "Xen")); + } + + return result; + } + + protected Injector injector() { + return Guice.createInjector(new GleSYSParserModule(), new GsonModule()); + } + +} diff --git a/sandbox-providers/glesys/src/test/resources/server_allowed_arguments.json b/sandbox-providers/glesys/src/test/resources/server_allowed_arguments.json new file mode 100644 index 0000000000..411e7e2bcb --- /dev/null +++ b/sandbox-providers/glesys/src/test/resources/server_allowed_arguments.json @@ -0,0 +1 @@ +{"response":{"status":{"code":"200","text":"OK"},"argumentslist":{"Xen":{"disksize":["5","10","20","30","40","50","80","100","120","140","150","160","160","200","250","300"],"memorysize":["512","768","1024","1536","2048","2560","3072","3584","4096","5120","6144","7168","8192","9216","10240","11264","12288","14336","16384"],"cpucores":["1","2","3","4","5","6","7","8"],"template":["CentOS 5.5 x64","CentOS 5.5 x86","Centos 6 x64","Centos 6 x86","Debian-6 x64","Debian 5.0.1 x64","FreeBSD 8.2","Gentoo 10.1 x64","Ubuntu 8.04 x64","Ubuntu 10.04 LTS 64-bit","Ubuntu 10.10 x64","Ubuntu 11.04 x64","Windows Server 2008 R2 x64 std","Windows Server 2008 R2 x64 web","Windows Server 2008 x64 web","Windows Server 2008 x86 web"],"transfer":["50","100","250","500","1000","2000","3000","4000","5000","6000","7000","8000","9000","10000"],"datacenter":["Falkenberg"]},"OpenVZ":{"disksize":["5","10","20","30","40","50","60","70","80","90","100","120","140","150"],"memorysize":["128","256","512","768","1024","1536","2048","2560","3072","3584","4096","5120","6144","7168","8192","9216","10240","11264","12288"],"cpucores":["1","2","3","4","5","6","7","8"],"template":["Centos 5","Centos 5 64-bit","Centos 6 32-bit","Centos 6 64-bit","Debian 5.0 32-bit","Debian 5.0 64-bit","Debian 6.0 32-bit","Debian 6.0 64-bit","Fedora Core 11","Fedora Core 11 64-bit","Gentoo","Gentoo 64-bit","Scientific Linux 6","Scientific Linux 6 64-bit","Slackware 12","Ubuntu 10.04 LTS 32-bit","Ubuntu 10.04 LTS 64-bit","Ubuntu 11.04 64-bit"],"transfer":["50","100","250","500","1000","2000","3000","4000","5000","6000","7000","8000","9000","10000"],"datacenter":["Amsterdam","Falkenberg","New York City","Stockholm"]}},"debug":{"input":[]}}} diff --git a/sandbox-providers/glesys/src/test/resources/server_created.json b/sandbox-providers/glesys/src/test/resources/server_created.json new file mode 100644 index 0000000000..417d5cee92 --- /dev/null +++ b/sandbox-providers/glesys/src/test/resources/server_created.json @@ -0,0 +1 @@ +{"response":{"status":{"code":"200","text":"OK"},"server":{"serverid":"xm3630641","hostname":"jclouds-test-host","iplist":[{"ip":"109.74.10.27","version":"4","cost":"2.00"}]},"debug":{"input":{"cpucores":"1","memorysize":"512","datacenter":"Falkenberg","transfer":"500","rootpw":"password","hostname":"jclouds-test-host","platform":"Xen","template":"Debian-6 x64","disksize":"10","description":""}}}} diff --git a/sandbox-providers/glesys/src/test/resources/server_templates.json b/sandbox-providers/glesys/src/test/resources/server_templates.json new file mode 100644 index 0000000000..96c8f7de7b --- /dev/null +++ b/sandbox-providers/glesys/src/test/resources/server_templates.json @@ -0,0 +1 @@ +{"response":{"status":{"code":"200","text":"OK"},"templates":{"OpenVZ":[{"name":"Centos 5","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Centos 5 64-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Centos 6 32-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Centos 6 64-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Debian 5.0 32-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Debian 5.0 64-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Debian 6.0 32-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Debian 6.0 64-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Fedora Core 11","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Fedora Core 11 64-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Gentoo","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Gentoo 64-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Scientific Linux 6","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Scientific Linux 6 64-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Slackware 12","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Ubuntu 10.04 LTS 32-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Ubuntu 10.04 LTS 64-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"},{"name":"Ubuntu 11.04 64-bit","min_disk_size":"5","min_mem_size":"128","os":"linux","platform":"OpenVZ"}],"Xen":[{"name":"CentOS 5.5 x64","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"CentOS 5.5 x86","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"Centos 6 x64","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"Centos 6 x86","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"Debian-6 x64","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"Debian 5.0.1 x64","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"FreeBSD 8.2","min_disk_size":"5","min_mem_size":"512","os":"freebsd","platform":"Xen"},{"name":"Gentoo 10.1 x64","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"Ubuntu 8.04 x64","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"Ubuntu 10.04 LTS 64-bit","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"Ubuntu 10.10 x64","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"Ubuntu 11.04 x64","min_disk_size":"5","min_mem_size":"512","os":"linux","platform":"Xen"},{"name":"Windows Server 2008 R2 x64 std","min_disk_size":"20","min_mem_size":"1024","os":"windows","platform":"Xen"},{"name":"Windows Server 2008 R2 x64 web","min_disk_size":"20","min_mem_size":"1024","os":"windows","platform":"Xen"},{"name":"Windows Server 2008 x64 web","min_disk_size":"20","min_mem_size":"1024","os":"windows","platform":"Xen"},{"name":"Windows Server 2008 x86 web","min_disk_size":"20","min_mem_size":"1024","os":"windows","platform":"Xen"}]},"debug":{"input":[]}}}