Merge pull request #248 from aplowe/master

Glesys Server wip: added most of the calls
This commit is contained in:
Adrian Cole 2011-12-15 11:40:12 -08:00
commit 5cd866d384
26 changed files with 1564 additions and 100 deletions

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.glesys.domain; package org.jclouds.glesys.domain;
import com.google.common.base.Objects;
/** /**
* Detailed information on Server bandwidth * Detailed information on Server bandwidth
* *
@ -89,9 +91,29 @@ public class Bandwidth {
return max; 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 @Override
public String toString() { 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);
} }
} }

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.glesys.domain; package org.jclouds.glesys.domain;
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -94,6 +95,26 @@ public class Cost {
return timePeriod; 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 @Override
public String toString() { public String toString() {
return String.format( return String.format(

View File

@ -18,6 +18,9 @@
*/ */
package org.jclouds.glesys.domain; package org.jclouds.glesys.domain;
import com.google.common.base.Objects;
import org.jclouds.javax.annotation.Nullable;
/** /**
* Detailed information on Server cpu usage * Detailed information on Server cpu usage
* *
@ -33,7 +36,7 @@ public class Cpu {
public static class Builder { public static class Builder {
private double system; private double system;
private double user; private double user;
private double nice; private Double nice;
private double idle; private double idle;
private String unit; private String unit;
@ -47,7 +50,7 @@ public class Cpu {
return this; return this;
} }
public Builder nice(double nice) { public Builder nice(Double nice) {
this.nice = nice; this.nice = nice;
return this; return this;
} }
@ -73,11 +76,11 @@ public class Cpu {
private final double system; private final double system;
private final double user; private final double user;
private final double nice; private final Double nice;
private final double idle; private final double idle;
private final String unit; 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.system = system;
this.user = user; this.user = user;
this.nice = nice; this.nice = nice;
@ -95,7 +98,7 @@ public class Cpu {
/** /**
* @return the user time in use in #unit * @return the user time in use in #unit
*/ */
public Double getUser() { public double getUser() {
return user; return user;
} }
@ -109,7 +112,7 @@ public class Cpu {
/** /**
* @return the idle time in #unit * @return the idle time in #unit
*/ */
public Double getIdle() { public double getIdle() {
return idle; return idle;
} }
@ -120,9 +123,31 @@ public class Cpu {
return unit; 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 @Override
public String toString() { 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); system, user, nice, idle, unit);
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.glesys.domain; package org.jclouds.glesys.domain;
import com.google.common.base.Objects;
/** /**
* Detailed information on Server disk usage * Detailed information on Server disk usage
* *
@ -89,9 +91,29 @@ public class Disk {
return unit; 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 @Override
public String toString() { 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);
} }
} }

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.glesys.domain; package org.jclouds.glesys.domain;
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
/** /**
@ -93,8 +94,28 @@ public class Memory {
return unit; 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 @Override
public String toString() { 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);
} }
} }

View File

@ -18,13 +18,14 @@
*/ */
package org.jclouds.glesys.domain; 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 com.google.gson.annotations.SerializedName;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Listing of a server. * Listing of a server.
* *
* @author Adrian Cole * @author Adrian Cole
* @see <a href= "https://customer.glesys.com/api.php?a=doc#server_list" /> * @see <a href= "https://customer.glesys.com/api.php?a=doc#server_list" />
*/ */
@ -110,46 +111,24 @@ public class Server {
} }
@Override @Override
public int hashCode() { public boolean equals(Object object) {
final int prime = 31; if (this == object) {
int result = 1; return true;
result = prime * result + ((datacenter == null) ? 0 : datacenter.hashCode()); }
result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); if (object instanceof Server) {
result = prime * result + ((id == null) ? 0 : id.hashCode()); final Server other = (Server) object;
result = prime * result + ((platform == null) ? 0 : platform.hashCode()); return Objects.equal(datacenter, other.datacenter)
return result; && Objects.equal(hostname, other.hostname)
&& Objects.equal(id, other.id)
&& Objects.equal(platform, other.platform);
} else {
return false;
}
} }
@Override @Override
public boolean equals(Object obj) { public int hashCode() {
if (this == obj) return Objects.hashCode(datacenter, hostname, id, platform);
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;
} }
@Override @Override

View File

@ -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 <a href="https://customer.glesys.com/api.php?a=doc#server_allowedarguments" />
*/
public class ServerAllowedArguments {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private List<Integer> diskSizes;
private List<Integer> memorySizes;
private List<Integer> cpuCores;
private List<String> templates;
private List<Integer> transfers;
private List<String> dataCenters;
public Builder diskSizes(Integer... sizes) {
return diskSizes(Arrays.<Integer>asList(sizes));
}
public Builder diskSizes(List<Integer> sizes) {
this.diskSizes = sizes;
return this;
}
public Builder memorySizes(Integer... sizes) {
return memorySizes(Arrays.<Integer>asList(sizes));
}
public Builder memorySizes(List<Integer> sizes) {
this.memorySizes = sizes;
return this;
}
public Builder cpuCores(Integer... cpuCores) {
this.cpuCores = Arrays.<Integer>asList(cpuCores);
return this;
}
public Builder cpuCores(List<Integer> cpuCores) {
this.cpuCores = cpuCores;
return this;
}
public Builder templates(String... templates) {
return templates(Arrays.<String>asList(templates));
}
public Builder templates(List<String> templates) {
this.templates = templates;
return this;
}
public Builder transfers(Integer... transfers) {
return transfers(Arrays.<Integer>asList(transfers));
}
public Builder transfers(List<Integer> transfers) {
this.transfers = transfers;
return this;
}
public Builder dataCenters(String... dataCenters) {
return dataCenters(Arrays.<String>asList(dataCenters));
}
public Builder dataCenters(List<String> 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<Integer> diskSizes;
@SerializedName("memorysize")
private final List<Integer> memorySizes;
@SerializedName("cpucores")
private final List<Integer> cpuCores;
@SerializedName("template")
private final List<String> templates;
@SerializedName("transfer")
private final List<Integer> transfers;
@SerializedName("datacenter")
private final List<String> dataCenters;
public ServerAllowedArguments(List<Integer> diskSizes, List<Integer> memorySizes, List<Integer> cpuCores,
List<String> templates, List<Integer> transfers, List<String> dataCenters) {
checkNotNull(diskSizes, "diskSizes");
checkNotNull(memorySizes, "memorySizes");
checkNotNull(cpuCores, "cpuCores");
checkNotNull(templates, "templates");
checkNotNull(transfers, "transfers");
checkNotNull(dataCenters, "dataCenters");
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<Integer> 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<Integer> getMemorySizes() {
return memorySizes;
}
/**
* @return a list of which core counts can be used for creating servers on this platform
*/
public List<Integer> 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<String> getTemplates() {
return templates;
}
/**
* @return the list of transfer settings available for creating servers on this platform
*/
public List<Integer> getTransfers() {
return transfers;
}
/**
* @return the list of datacenters available that support creating servers on this platform
*/
public List<String> getDataCenters() {
return dataCenters;
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof ServerAllowedArguments) {
final ServerAllowedArguments other = (ServerAllowedArguments) object;
return Objects.equal(diskSizes, other.diskSizes)
&& Objects.equal(memorySizes, other.memorySizes)
&& Objects.equal(cpuCores, other.cpuCores)
&& Objects.equal(templates, other.templates)
&& Objects.equal(transfers, other.transfers)
&& Objects.equal(dataCenters, other.dataCenters);
} else {
return false;
}
}
@Override
public 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));
}
}

View File

@ -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 <a href="https://customer.glesys.com/api.php?a=doc#server_console" />
*/
public class ServerConsole {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String host;
private int port;
private String password;
public Builder host(String host) {
this.host = host;
return this;
}
public Builder port(int port) {
this.port = port;
return this;
}
public Builder password(String password) {
this.password = password;
return this;
}
public ServerConsole build() {
return new ServerConsole(host, port, password);
}
public Builder fromServerConsole(ServerConsole in) {
return host(in.getHost()).port(in.getPort()).password(in.getPassword());
}
}
private final String host;
private final int port;
private final String password;
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);
}
}

View File

@ -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 <a href="https://customer.glesys.com/api.php?a=doc#server_console" />
*/
public class ServerCreated {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String id;
private String hostname;
private List<ServerCreatedIp> ips;
public Builder id(String id) {
this.id = id;
return this;
}
public Builder port(List<ServerCreatedIp> 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<ServerCreatedIp> ips;
public ServerCreated(String id, @Nullable String hostname, List<ServerCreatedIp> 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<ServerCreatedIp> 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);
}
}

View File

@ -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);
}
}

View File

@ -20,12 +20,13 @@ package org.jclouds.glesys.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
/** /**
* Detailed information about a server such as cpuCores, hardware configuration * Detailed information about a server such as cpuCores, hardware configuration
* (cpu, memory and disk), ip adresses, cost, transfer, os and more. * (cpu, memory and disk), ip adresses, cost, transfer, os and more.
* *
* @author Adrian Cole * @author Adrian Cole
* @see <a href= "https://customer.glesys.com/api.php?a=doc#server_details" /> * @see <a href= "https://customer.glesys.com/api.php?a=doc#server_details" />
*/ */
@ -65,7 +66,7 @@ public class ServerDetails extends Server {
this.cost = cost; this.cost = cost;
return this; return this;
} }
public ServerDetails build() { public ServerDetails build() {
return new ServerDetails(id, hostname, datacenter, platform, description, cpuCores, memory, disk, cost); 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)); return Builder.class.cast(super.fromServer(in));
} }
} }
private final String description; private final String description;
@SerializedName("cpucores") @SerializedName("cpucores")
private final int cpuCores; private final int cpuCores;
private final int memory; private final int memory;
private final int disk; private final int disk;
private final Cost cost; private final Cost cost;
public ServerDetails(String id, String hostname, String datacenter, String platform, String description, 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); super(id, hostname, datacenter, platform);
this.description = checkNotNull(description, "description"); this.description = checkNotNull(description, "description");
this.cpuCores = cpuCores; 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() { public Cost getCost() {
return cost; return cost;
} }
@Override @Override
@ -160,4 +161,27 @@ public class ServerDetails extends Server {
hostname, datacenter, platform, description, cpuCores, memory, disk, cost); 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;
}
}
} }

View File

@ -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 <a href= "https://customer.glesys.com/api.php?a=doc#server_limits" />
*/
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);
}
}

View File

@ -23,6 +23,8 @@ import com.google.common.base.CaseFormat;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Valid states for a server hosted in a Glesys cloud
*
* @author Adam Lowe * @author Adam Lowe
* @see ServerStatus * @see ServerStatus
*/ */

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.glesys.domain; 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. * 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(); 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 @Override
public String toString() { 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); state, cpu, memory, disk, bandwidth, uptime);
} }

View File

@ -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 <a href= "https://customer.glesys.com/api.php?a=doc#server_templates" />
*/
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);
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.glesys.domain; package org.jclouds.glesys.domain;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -27,13 +28,16 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* Represents an 'uptime' duration of server in a Glesys cloud
*
* @author Adam Lowe * @author Adam Lowe
* @see ServerStatus
*/ */
public class ServerUptime { public class ServerUptime {
private final long time; private final long time;
private final String timeString; private final String timeString;
public ServerUptime(long time) { private ServerUptime(long time) {
this.time = time; this.time = time;
long days = TimeUnit.SECONDS.toDays(time); long days = TimeUnit.SECONDS.toDays(time);
long hours = TimeUnit.SECONDS.toHours(time - TimeUnit.DAYS.toSeconds(days)); 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) { public static ServerUptime fromValue(String uptimeString) {
return new ServerUptime(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) { public static ServerUptime fromValue(long time) {
return new ServerUptime(time); return new ServerUptime(time);
@ -81,8 +85,23 @@ public class ServerUptime {
return time; 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 @Override
public String toString() { public String toString() {
return timeString; return timeString;
} }
} }

View File

@ -18,17 +18,8 @@
*/ */
package org.jclouds.glesys.features; package org.jclouds.glesys.features;
import java.util.Set; import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.glesys.domain.*;
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 org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters; 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.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; 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. * Provides asynchronous access to Server via their REST API.
* <p/> * <p/>
* *
* @author Adrian Cole
* @author Adam Lowe
* @see ServerClient * @see ServerClient
* @see <a href="https://customer.glesys.com/api.php" /> * @see <a href="https://customer.glesys.com/api.php" />
* @author Adrian Cole
*/ */
@RequestFilters(BasicAuthentication.class) @RequestFilters(BasicAuthentication.class)
public interface ServerAsyncClient { public interface ServerAsyncClient {
@ -69,9 +63,8 @@ public interface ServerAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ServerDetails> getServerDetails(@PathParam("id") String id); ListenableFuture<ServerDetails> getServerDetails(@PathParam("id") String id);
/** /**
* @see ServerClient#getServerDetails * @see ServerClient#getServerStatus
*/ */
@GET @GET
@Path("/server/status/serverid/{id}/format/json") @Path("/server/status/serverid/{id}/format/json")
@ -80,4 +73,121 @@ public interface ServerAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ServerStatus> getServerStatus(@PathParam("id") String id); ListenableFuture<ServerStatus> 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<SortedMap<String, ServerLimit>> 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<ServerConsole> getServerConsole(@PathParam("id") String id);
/**
* @see ServerClient#getAllowedArguments
*/
@GET
@Path("/server/allowedarguments/format/json")
@SelectJson("argumentslist")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Map<String, ServerAllowedArguments>> getAllowedArguments();
/**
* @see ServerClient#getTemplates
*/
@GET
@Path("/server/templates/format/json")
@SelectJson("templates")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Map<String, Set<ServerTemplate>>> getTemplates();
/**
* @see ServerClient#stopServer
*/
@GET
@Path("/server/resetlimit/serverid/{id}/type/{type}/format/json")
ListenableFuture<Void> resetServerLimit(@PathParam("id") String id, @PathParam("type") String type);
/**
* @see ServerClient#rebootServer
*/
@GET
@Path("/server/reboot/serverid/{id}/format/json")
ListenableFuture<Void> rebootServer(@PathParam("id") String id);
/**
* @see ServerClient#startServer
*/
@GET
@Path("/server/start/serverid/{id}/format/json")
ListenableFuture<Void> startServer(@PathParam("id") String id);
/**
* @see ServerClient#stopServer
*/
@GET
@Path("/server/stop/serverid/{id}/format/json")
ListenableFuture<Void> stopServer(@PathParam("id") String id);
/**
* @see ServerClient#createServer
*/
@POST
@Path("/server/create/format/json")
@SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<ServerCreated> 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<ServerCreated> 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<Void> destroyServer(@FormParam("serverid") String id, @FormParam("keepip") int keepIp);
/**
* @see ServerClient#resetPassword
*/
@POST
@Path("/server/destroy/format/json")
ListenableFuture<Void> resetPassword(@FormParam("serverid") String id, @FormParam("newpassword") String password);
} }

View File

@ -18,39 +18,40 @@
*/ */
package org.jclouds.glesys.features; 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.Set;
import java.util.concurrent.TimeUnit; 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. * Provides synchronous access to Server.
* <p/> * <p/>
* *
* @author Adrian Cole
* @author Adam Lowe
* @see ServerAsyncClient * @see ServerAsyncClient
* @see <a href="https://customer.glesys.com/api.php" /> * @see <a href="https://customer.glesys.com/api.php" />
* @author Adrian Cole
*/ */
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface ServerClient { public interface ServerClient {
/** /**
* Get a list of all servers on this account. * Get a list of all servers on this account.
* *
* @return an account's associated server objects. * @return an account's associated server objects.
*/ */
Set<Server> listServers(); Set<Server> listServers();
/** /**
* Get detailed information about a server such as hostname, hardware * 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. * more.
* *
* @param id * @param id id of the server
* id of the server
* @return server or null if not found * @return server or null if not found
*/ */
ServerDetails getServerDetails(String id); ServerDetails getServerDetails(String id);
@ -59,10 +60,107 @@ public interface ServerClient {
* Get detailed information about a server status including up-time and hardware usage * Get detailed information about a server status including up-time and hardware usage
* (cpu, disk, memory and bandwidth) * (cpu, disk, memory and bandwidth)
* *
* @param id * @param id id of the server
* id of the server * @return the status of the server or null if not found
* @return server or null if not found
*/ */
ServerStatus getServerStatus(String id); ServerStatus getServerStatus(String id);
/**
* Get detailed information about a server's limits (for OpenVZ only).
* <p/>
*
* @param id id of the server
* @return the requested information about the server or null if not found
*/
Map<String, ServerLimit> 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<String, Set<ServerTemplate>> getTemplates();
/**
* Get information about valid arguments to #createServer for each platform
*
* @return a map of argument lists, keyed on platform
*/
Map<String, ServerAllowedArguments> getAllowedArguments();
/**
* Reset the fail count for a server limit (for OpenVZ only).
*
* @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);
} }

View File

@ -3,14 +3,14 @@ package org.jclouds.glesys.functions.internal;
import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException; 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.ServerState;
import org.jclouds.glesys.domain.ServerStatus;
import org.jclouds.glesys.domain.ServerUptime; import org.jclouds.glesys.domain.ServerUptime;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;
/** /**
* @Author Adam Lowe * @Author Adam Lowe
@ -34,5 +34,17 @@ public class CustomDeserializers {
return ServerUptime.fromValue(toParse); return ServerUptime.fromValue(toParse);
} }
} }
public static class ServerAllowedArgumentsAdaptor implements JsonDeserializer<Set<ServerAllowedArguments>> {
@Override
public Set<ServerAllowedArguments> deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
Set<ServerAllowedArguments> result = new HashSet<ServerAllowedArguments>();
for(JsonElement e : jsonElement.getAsJsonObject().get("OpenVZ").getAsJsonArray()) {
result.add(jsonDeserializationContext.<ServerAllowedArguments>deserialize(e, ServerAllowedArguments.class));
}
return result;
}
}
} }

View File

@ -22,11 +22,10 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jclouds.glesys.domain.Server; import org.jclouds.glesys.domain.*;
import org.jclouds.glesys.domain.ServerDetails;
import org.jclouds.glesys.domain.ServerStatus;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -45,7 +44,56 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
} }
private ServerClient client; private ServerClient client;
@Test
public void testAllowedArguments() throws Exception {
Map<String,ServerAllowedArguments> 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<String,Set<ServerTemplate>> 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 @Test
public void testListServers() throws Exception { public void testListServers() throws Exception {
Set<Server> response = client.listServers(); Set<Server> response = client.listServers();

View File

@ -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<Map<String, ServerAllowedArguments>> {
@Override
public String resource() {
return "/server_allowed_arguments.json";
}
@Override
@SelectJson("argumentslist")
@Consumes(MediaType.APPLICATION_JSON)
public Map<String, ServerAllowedArguments> expected() {
Map<String, ServerAllowedArguments> result = new LinkedHashMap<String, ServerAllowedArguments>();
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());
}
}

View File

@ -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<ServerCreated> {
@Override
public String resource() {
return "/server_created.json";
}
@Override
@SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON)
public ServerCreated expected() {
List<ServerCreatedIp> ips = new ArrayList<ServerCreatedIp>();
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());
}
}

View File

@ -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<Map<String, Set<ServerTemplate>>> {
@Override
public String resource() {
return "/server_templates.json";
}
@Override
@SelectJson("templates")
@Consumes(MediaType.APPLICATION_JSON)
public Map<String, Set<ServerTemplate>> expected() {
Map<String, Set<ServerTemplate>> result = new LinkedHashMap<String, Set<ServerTemplate>>();
String[] vzNames = new String[]{
"Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit",
"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<ServerTemplate>());
for (String name : vzNames) {
result.get("OpenVZ").add(new ServerTemplate(name, 5, 128, "linux", "OpenVZ"));
}
result.put("Xen", new HashSet<ServerTemplate>());
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());
}
}

View File

@ -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":[]}}}

View File

@ -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":""}}}}

View File

@ -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":[]}}}