From 4a08bb630335f1e582df10d848983445758c15f1 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Wed, 14 Dec 2011 22:27:24 +0000 Subject: [PATCH] Continued work on server api - createServer and friends. Adjusted hashCode and equals methods to guava shorthand. --- .../glesys/config/GleSYSParserModule.java | 2 + .../org/jclouds/glesys/domain/Bandwidth.java | 24 +- .../java/org/jclouds/glesys/domain/Cost.java | 21 ++ .../java/org/jclouds/glesys/domain/Cpu.java | 39 +++- .../java/org/jclouds/glesys/domain/Disk.java | 24 +- .../org/jclouds/glesys/domain/Memory.java | 23 +- .../org/jclouds/glesys/domain/Server.java | 59 ++--- .../glesys/domain/ServerAllowedArguments.java | 210 ++++++++++++++++++ .../jclouds/glesys/domain/ServerConsole.java | 61 +++++ .../jclouds/glesys/domain/ServerCreated.java | 99 +++++++++ .../glesys/domain/ServerCreatedIp.java | 109 +++++++++ .../jclouds/glesys/domain/ServerDetails.java | 40 +++- .../jclouds/glesys/domain/ServerLimit.java | 113 ++++++++++ .../jclouds/glesys/domain/ServerStatus.java | 27 ++- .../jclouds/glesys/domain/ServerUptime.java | 17 ++ .../org/jclouds/glesys/domain/Template.java | 122 ++++++++++ .../glesys/features/ServerAsyncClient.java | 141 ++++++++++-- .../jclouds/glesys/features/ServerClient.java | 126 +++++++++-- .../internal/CustomDeserializers.java | 18 +- .../glesys/features/ServerClientLiveTest.java | 54 ++++- .../ParseServerAllowedArgumentsTest.java | 82 +++++++ .../glesys/parse/ParseServerCreatedTest.java | 60 +++++ .../parse/ParseServerTemplatesTest.java | 88 ++++++++ .../resources/server_allowed_arguments.json | 1 + .../src/test/resources/server_created.json | 1 + .../src/test/resources/server_templates.json | 1 + 26 files changed, 1464 insertions(+), 98 deletions(-) create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerAllowedArguments.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerConsole.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreatedIp.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerLimit.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Template.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerCreatedTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerTemplatesTest.java create mode 100644 sandbox-providers/glesys/src/test/resources/server_allowed_arguments.json create mode 100644 sandbox-providers/glesys/src/test/resources/server_created.json create mode 100644 sandbox-providers/glesys/src/test/resources/server_templates.json diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSParserModule.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSParserModule.java index 6aea74a0c1..318d5d55d6 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSParserModule.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSParserModule.java @@ -21,6 +21,7 @@ package org.jclouds.glesys.config; import com.google.common.collect.ImmutableMap; import com.google.inject.AbstractModule; import com.google.inject.Provides; +import org.jclouds.glesys.domain.ServerAllowedArguments; import org.jclouds.glesys.domain.ServerState; import org.jclouds.glesys.domain.ServerUptime; import org.jclouds.glesys.functions.internal.CustomDeserializers; @@ -30,6 +31,7 @@ import org.jclouds.json.config.GsonModule.DateAdapter; import javax.inject.Singleton; import java.lang.reflect.Type; import java.util.Map; +import java.util.Set; /** * @author Adrian Cole 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..60b68336d1 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerAllowedArguments.java @@ -0,0 +1,210 @@ +/** + * 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.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; + +/** + * 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; + } + + public List getDiskSizes() { + return diskSizes; + } + + public List getMemorySizes() { + return memorySizes; + } + + public List getCpuCores() { + return cpuCores; + } + + public List getTemplates() { + return templates; + } + + public List getTransfers() { + return transfers; + } + + 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..66357399d6 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerConsole.java @@ -0,0 +1,61 @@ +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 { + + 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; + } + + public String getHost() { + return host; + } + + public int getPort() { + return port; + } + + 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..2da6c4235f --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreatedIp.java @@ -0,0 +1,109 @@ +/** + * 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 ip. + */ +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; + } + + public int getVersion() { + return version; + } + + public String getIp() { + return ip; + } + + 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/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/ServerUptime.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java index d2ce545597..8f5273a836 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; @@ -81,8 +82,24 @@ public class ServerUptime { return time; } + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + return object instanceof ServerUptime + && time == ((ServerUptime) object).time; + } + + @Override + public int hashCode() { + return 37 * (int) 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/domain/Template.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Template.java new file mode 100644 index 0000000000..a7b9d60fbd --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Template.java @@ -0,0 +1,122 @@ +package org.jclouds.glesys.domain; + +import com.google.common.base.Objects; +import com.google.gson.annotations.SerializedName; + +/** + * @author Adam Lowe + * @see + */ +public class Template { + + + 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 Template build() { + return new Template(name, minDiskSize, minMemSize, os, platform); + } + + public Builder fromTemplate(Template 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 Template(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; + } + + public int getMinDiskSize() { + return minDiskSize; + } + + public int getMinMemSize() { + return minMemSize; + } + + public String getOs() { + return os; + } + + public String getPlatform() { + return platform; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof Template) { + final Template other = (Template) 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/features/ServerAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java index cca69a4262..8cbb286da2 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,17 @@ 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 * @see ServerClient * @see - * @author Adrian Cole */ @RequestFilters(BasicAuthentication.class) public interface ServerAsyncClient { @@ -69,9 +62,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 +72,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..f25a9b6bf8 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,43 @@ */ package org.jclouds.glesys.features; -import java.util.Set; -import java.util.concurrent.TimeUnit; - +import com.google.common.util.concurrent.ListenableFuture; import org.jclouds.concurrent.Timeout; -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.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; /** * Provides synchronous access to Server. *

- * + * + * @author Adrian Cole * @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 +63,98 @@ 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); + + // TODO should these be squished into single sets? + Map> getTemplates(); + 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..adab8f0a77 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; @@ -46,6 +45,55 @@ 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"); + + + client.destroyServer("xm3054942", 0); + } + + @Test + public void testListTemplates() throws Exception { + Map> templates = client.getTemplates(); + + assertTrue(templates.containsKey("OpenVZ")); + assertTrue(templates.containsKey("Xen")); + + for(Template template : templates.get("OpenVZ")) { + checkTemplate(template, "OpenVZ"); + } + + for(Template template : templates.get("Xen")) { + checkTemplate(template, "Xen"); + } + } + + private void checkTemplate(Template 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..7552a7eadb --- /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