From bb5210eb6f067da04ec0aca6bc684ec8963765b3 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Wed, 21 Dec 2011 22:16:40 +0000 Subject: [PATCH] Improving Domain, Server and Archive services --- .../jclouds/glesys/domain/ServerCreated.java | 4 +- .../jclouds/glesys/domain/ServerState.java | 2 +- .../glesys/features/ArchiveAsyncClient.java | 1 + .../glesys/features/DomainAsyncClient.java | 24 ++-- .../jclouds/glesys/features/DomainClient.java | 10 +- .../glesys/features/ServerAsyncClient.java | 36 ++--- .../jclouds/glesys/features/ServerClient.java | 51 ++++--- .../glesys/options/ServerCloneOptions.java | 69 ++++++++++ .../glesys/options/ServerCreateOptions.java | 43 ++++++ .../glesys/options/ServerEditOptions.java | 91 +++++++++++++ .../glesys/options/ServerStatusOptions.java | 64 +++++++++ .../glesys/options/ServerStopOptions.java | 25 ++++ .../jclouds/glesys/GleSYSAsyncClientTest.java | 2 + .../features/ArchiveAsyncClientTest.java | 43 ++++++ .../features/BaseGleSYSAsyncClientTest.java | 92 ++++++++++++- .../features/DomainAsyncClientTest.java | 69 ++++++++++ .../features/ServerAsyncClientTest.java | 106 ++++++++------- .../glesys/features/ServerClientLiveTest.java | 126 ++++++++++++------ 18 files changed, 708 insertions(+), 150 deletions(-) create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCreateOptions.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerEditOptions.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStatusOptions.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStopOptions.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java 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 index 0400686531..3117f8f746 100644 --- 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 @@ -3,9 +3,11 @@ package org.jclouds.glesys.domain; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Arrays; +import java.util.Collections; import java.util.List; import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; import com.google.gson.annotations.SerializedName; import org.jclouds.javax.annotation.Nullable; @@ -74,7 +76,7 @@ public class ServerCreated { } public List getIps() { - return ips; + return ips == null ? ImmutableList.of() : ips; } @Override diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerState.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerState.java index b30a48d000..7ccdc1f521 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerState.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerState.java @@ -30,7 +30,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public enum ServerState { - RUNNING, UNRECOGNIZED; + RUNNING, STOPPED, UNRECOGNIZED; public String value() { return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java index c9255242c3..257672179f 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java @@ -99,6 +99,7 @@ public interface ArchiveAsyncClient { @Path("/archive/allowedarguments/format/json") @SelectJson("argumentslist") @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture getArchiveAllowedArguments(); } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncClient.java index 53686e6926..c0ba9e5e32 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncClient.java @@ -25,10 +25,15 @@ import org.jclouds.glesys.options.DomainOptions; import org.jclouds.glesys.options.DomainRecordAddOptions; import org.jclouds.glesys.options.DomainRecordModifyOptions; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; import javax.ws.rs.core.MediaType; import java.util.Set; @@ -50,6 +55,7 @@ public interface DomainAsyncClient { @Path("/domain/list/format/json") @SelectJson("domains") @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listDomains(); /** @@ -57,43 +63,37 @@ public interface DomainAsyncClient { */ @POST @Path("/domain/add/format/json") - @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture addDomain(@FormParam("name") String domain, DomainOptions... options); + ListenableFuture addDomain(@FormParam("name") String name, DomainOptions... options); /** * @see DomainClient#editDomain */ @POST - @Path("/domain/add/format/json") - @Consumes(MediaType.APPLICATION_JSON) + @Path("/domain/edit/format/json") ListenableFuture editDomain(@FormParam("domain") String domain, DomainOptions... options); @POST @Path("/domain/delete/format/json") - @Consumes(MediaType.APPLICATION_JSON) ListenableFuture deleteDomain(@FormParam("domain") String domain); - @GET - @Path("/domain/list_records/domain/{domain}/format/json") + @POST + @Path("/domain/list_records/format/json") @SelectJson("records") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture> listRecords(@PathParam("domain") String domain); + ListenableFuture> listRecords(@FormParam("domain") String domain); @POST @Path("/domain/add_record/format/json") - @Consumes(MediaType.APPLICATION_JSON) ListenableFuture addRecord(@FormParam("domain") String domain, @FormParam("host") String host, @FormParam("type") String type, @FormParam("data") String data, DomainRecordAddOptions... options); @POST @Path("/domain/update_record/format/json") - @Consumes(MediaType.APPLICATION_JSON) ListenableFuture editRecord(@FormParam("record_id") String record_id, DomainRecordModifyOptions... options); @POST @Path("/domain/delete_record/format/json") - @Consumes(MediaType.APPLICATION_JSON) ListenableFuture deleteRecord(@FormParam("record_id") String recordId); } \ No newline at end of file diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainClient.java index be57748930..80d0b3e90e 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainClient.java @@ -33,7 +33,7 @@ import java.util.concurrent.TimeUnit; *

* * @author Adam Lowe - * @see InvoiceAsyncClient + * @see DomainAsyncClient * @see */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) @@ -49,14 +49,16 @@ public interface DomainClient { /** * Add a domain to the Glesys dns-system * - * @param domain the name of the domain to add. + * @param domain the name of the domain to add. + * @param options optional parameters */ void addDomain(String domain, DomainOptions... options); /** * Add a domain to the Glesys dns-system * - * @param domain the name of the domain to add. + * @param domain the name of the domain to add. + * @param options optional parameters */ void editDomain(String domain, DomainOptions... options); @@ -77,7 +79,7 @@ public interface DomainClient { /** * Add a DNS Record * - * @param domain + * @param domain the domain to add the record to * @param host * @param type * @param data 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 cc7106c3ee..df12c4c4d0 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 @@ -20,6 +20,7 @@ package org.jclouds.glesys.features; import com.google.common.util.concurrent.ListenableFuture; import org.jclouds.glesys.domain.*; +import org.jclouds.glesys.options.*; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; @@ -71,7 +72,7 @@ public interface ServerAsyncClient { @SelectJson("server") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getServerStatus(@FormParam("serverid") String id); + ListenableFuture getServerStatus(@FormParam("serverid") String id, ServerStatusOptions... options); /** * @see ServerClient#getServerLimits @@ -117,29 +118,29 @@ public interface ServerAsyncClient { * @see ServerClient#stopServer */ @POST - @Path("/server/resetlimit/serverid/{id}/type/{type}/format/json") - ListenableFuture resetServerLimit(@FormParam("id") String id, @FormParam("type") String type); + @Path("/server/resetlimit/format/json") + ListenableFuture resetServerLimit(@FormParam("serverid") String id, @FormParam("type") String type); /** * @see ServerClient#rebootServer */ @POST @Path("/server/reboot/format/json") - ListenableFuture rebootServer(@FormParam("id") String id); + ListenableFuture rebootServer(@FormParam("serverid") String id); /** * @see ServerClient#startServer */ @POST @Path("/server/start/format/json") - ListenableFuture startServer(@FormParam("id") String id); + ListenableFuture startServer(@FormParam("serverid") String id); /** * @see ServerClient#stopServer */ @POST @Path("/server/stop/format/json") - ListenableFuture stopServer(@FormParam("id") String id); + ListenableFuture stopServer(@FormParam("serverid") String id, ServerStopOptions... options); /** * @see ServerClient#createServer @@ -157,25 +158,26 @@ public interface ServerAsyncClient { @FormParam("cpucores") int cpucores, @FormParam("rootpw") String rootpw, @FormParam("transfer") int transfer, - String description, - String ip); + ServerCreateOptions... options); /** - * @see ServerClient#createServer + * @see ServerClient#cloneServer */ @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); - + @FormParam("hostname") String hostname, + ServerCloneOptions... options); + + /** + * @see ServerClient#editServer + */ + @POST + @Path("/server/edit/format/json") + ListenableFuture editServer(@FormParam("serverid") String serverid, ServerEditOptions... options); + /** * @see ServerClient#destroyServer */ 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 05c4a3aa50..554af8d627 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 @@ -20,6 +20,7 @@ package org.jclouds.glesys.features; import org.jclouds.concurrent.Timeout; import org.jclouds.glesys.domain.*; +import org.jclouds.glesys.options.*; import org.jclouds.javax.annotation.Nullable; import javax.ws.rs.FormParam; @@ -60,10 +61,11 @@ 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 + * @param id id of the server + * @param options optional parameters * @return the status of the server or null if not found */ - ServerStatus getServerStatus(String id); + ServerStatus getServerStatus(String id, ServerStatusOptions... options); /** * Get detailed information about a server's limits (for OpenVZ only). @@ -123,28 +125,45 @@ public interface ServerClient { /** * Stop a server * - * @param id id of the server + * @param id id of the server + * @param options optional parameters */ - void stopServer(String id); + void stopServer(String id, ServerStopOptions... options); /** * 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 + * @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 options optional settings ex. description */ 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); + int cpucores, String rootpw, int transfer, ServerCreateOptions... options); + + /** + * Edit the configuration of a server + * + * @param serverid the serverId of the server to edit + * @param options the settings to change + */ + void editServer(String serverid, ServerEditOptions... options); + + /** + * Clone a server + * + * @param serverid the serverId of the server to clone + * @param hostname the new host name of the cloned server + * @param options the settings to change + */ + ServerCreated cloneServer(String serverid, String hostname, ServerCloneOptions... options); /** * Destroy a server diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java new file mode 100644 index 0000000000..25d877e465 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java @@ -0,0 +1,69 @@ +package org.jclouds.glesys.options; + +/** + * @author Adam Lowe + */ +public class ServerCloneOptions extends ServerEditOptions { + public static class Builder { + /** + * @see org.jclouds.glesys.options.ServerCloneOptions#disksize + */ + public static ServerCloneOptions disksize(int disksize) { + ServerCloneOptions options = new ServerCloneOptions(); + return ServerCloneOptions.class.cast(options.disksize(disksize)); + } + + /** + * @see org.jclouds.glesys.options.ServerCloneOptions#memorysize + */ + public static ServerCloneOptions memorysize(int memorysize) { + ServerCloneOptions options = new ServerCloneOptions(); + return ServerCloneOptions.class.cast(options.memorysize(memorysize)); + } + + /** + * @see org.jclouds.glesys.options.ServerCloneOptions#cpucores + */ + public static ServerCloneOptions cpucores(int cpucores) { + ServerCloneOptions options = new ServerCloneOptions(); + return ServerCloneOptions.class.cast(options.cpucores(cpucores)); + } + + /** + * @see org.jclouds.glesys.options.ServerCloneOptions#cpucores + */ + public static ServerCloneOptions transfer(int transfer) { + ServerCloneOptions options = new ServerCloneOptions(); + return ServerCloneOptions.class.cast(options.transfer(transfer)); + } + + /** + * @see org.jclouds.glesys.options.ServerCloneOptions#hostname + */ + public static ServerCloneOptions hostname(String hostname) { + ServerCloneOptions options = new ServerCloneOptions(); + return ServerCloneOptions.class.cast(options.hostname(hostname)); + } + + /** + * @see org.jclouds.glesys.options.ServerEditOptions#description + */ + public static ServerCloneOptions description(String description) { + ServerCloneOptions options = new ServerCloneOptions(); + return ServerCloneOptions.class.cast(options.description(description)); + } + + /** + * @see org.jclouds.glesys.options.ServerCloneOptions#dataCenter + */ + public static ServerCloneOptions dataCenter(String dataCenter) { + ServerCloneOptions options = new ServerCloneOptions(); + return options.dataCenter(dataCenter); + } + } + + public ServerCloneOptions dataCenter(String dataCenter) { + formParameters.put("datacenter", dataCenter); + return this; + } +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCreateOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCreateOptions.java new file mode 100644 index 0000000000..858f393c09 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCreateOptions.java @@ -0,0 +1,43 @@ +package org.jclouds.glesys.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * @author Adam Lowe + */ +public class ServerCreateOptions extends BaseHttpRequestOptions { + public static class Builder { + /** + * @see ServerCreateOptions#description + */ + public static ServerCreateOptions description(String primaryNameServer) { + ServerCreateOptions options = new ServerCreateOptions(); + return options.description(primaryNameServer); + } + + /** + * @see ServerCreateOptions#ip + */ + public static ServerCreateOptions ip(String ip) { + ServerCreateOptions options = new ServerCreateOptions(); + return options.ip(ip); + } + } + + /** + * @param description the description of the server + */ + public ServerCreateOptions description(String description) { + formParameters.put("description", description); + return this; + } + + /** + * @param ip the ip address to assign to the server + */ + public ServerCreateOptions ip(String ip) { + formParameters.put("ip", ip); + return this; + } + +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerEditOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerEditOptions.java new file mode 100644 index 0000000000..3518fbe8bf --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerEditOptions.java @@ -0,0 +1,91 @@ +package org.jclouds.glesys.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * + * @author Adam Lowe + */ +public class ServerEditOptions extends BaseHttpRequestOptions { + + public static class Builder { + /** + * @see org.jclouds.glesys.options.ServerEditOptions#disksize + */ + public static ServerEditOptions disksize(int disksize) { + ServerEditOptions options = new ServerEditOptions(); + return options.disksize(disksize); + } + + /** + * @see org.jclouds.glesys.options.ServerEditOptions#memorysize + */ + public static ServerEditOptions memorysize(int memorysize) { + ServerEditOptions options = new ServerEditOptions(); + return options.memorysize(memorysize); + } + + /** + * @see org.jclouds.glesys.options.ServerEditOptions#cpucores + */ + public static ServerEditOptions cpucores(int cpucores) { + ServerEditOptions options = new ServerEditOptions(); + return options.cpucores(cpucores); + } + + /** + * @see org.jclouds.glesys.options.ServerEditOptions#cpucores + */ + public static ServerEditOptions transfer(int transfer) { + ServerEditOptions options = new ServerEditOptions(); + return options.transfer(transfer); + } + + /** + * @see org.jclouds.glesys.options.ServerEditOptions#hostname + */ + public static ServerEditOptions hostname(String hostname) { + ServerEditOptions options = new ServerEditOptions(); + return options.hostname(hostname); + } + + /** + * @see org.jclouds.glesys.options.ServerEditOptions#description + */ + public static ServerEditOptions description(String description) { + ServerEditOptions options = new ServerEditOptions(); + return options.description(description); + } + } + + public ServerEditOptions disksize(int disksize) { + formParameters.put("disksize", Integer.toString(disksize)); + return this; + } + + public ServerEditOptions memorysize(int memorysize) { + formParameters.put("memorysize", Integer.toString(memorysize)); + return this; + } + + public ServerEditOptions cpucores(int cpucores) { + formParameters.put("cpucores", Integer.toString(cpucores)); + return this; + } + + public ServerEditOptions transfer(int transfer) { + formParameters.put("cpucores", Integer.toString(transfer)); + return this; + } + + public ServerEditOptions hostname(String hostname) { + formParameters.put("hostname", hostname); + return this; + } + + public ServerEditOptions description(String description) { + formParameters.put("description", description); + return this; + } + +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStatusOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStatusOptions.java new file mode 100644 index 0000000000..c923e04113 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStatusOptions.java @@ -0,0 +1,64 @@ +package org.jclouds.glesys.options; + +import com.google.common.collect.Iterables; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * @author Adam Lowe + */ +public class ServerStatusOptions extends BaseHttpRequestOptions { + + public enum StatusTypes { + state, cpu, memory, disk, bandwidth, uptime + } + + public static class Builder { + /** + * @see org.jclouds.glesys.options.ServerStatusOptions#statusType + */ + public static ServerStatusOptions state() { + ServerStatusOptions options = new ServerStatusOptions(); + return options.statusType(StatusTypes.state); + } + + /** + * @see org.jclouds.glesys.options.ServerStatusOptions#statusType + */ + public static ServerStatusOptions cpu() { + ServerStatusOptions options = new ServerStatusOptions(); + return options.statusType(StatusTypes.cpu); + } + + /** + * @see org.jclouds.glesys.options.ServerStatusOptions#statusType + */ + public static ServerStatusOptions memory() { + ServerStatusOptions options = new ServerStatusOptions(); + return options.statusType(StatusTypes.memory); + } + + /** + * @see org.jclouds.glesys.options.ServerStatusOptions#statusType + */ + public static ServerStatusOptions disk() { + ServerStatusOptions options = new ServerStatusOptions(); + return options.statusType(StatusTypes.disk); + } + + /** + * @see org.jclouds.glesys.options.ServerStatusOptions#statusType + */ + public static ServerStatusOptions bandwidth() { + ServerStatusOptions options = new ServerStatusOptions(); + return options.statusType(StatusTypes.bandwidth); + } + } + + /** + * Select the given type of information form the server + */ + public ServerStatusOptions statusType(StatusTypes type) { + formParameters.put("statustype", type.name()); + return this; + } +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStopOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStopOptions.java new file mode 100644 index 0000000000..b8c337c0eb --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStopOptions.java @@ -0,0 +1,25 @@ +package org.jclouds.glesys.options; + +/** + * @author Adam Lowe + */ +public class ServerStopOptions extends ServerEditOptions { + public static class Builder { + /** + * @see org.jclouds.glesys.options.ServerStopOptions#hard + */ + public static ServerStopOptions hard() { + ServerStopOptions options = new ServerStopOptions(); + return options.hard(); + } + } + + /** + * Hard stop - only supported on Xen platform + */ + public ServerStopOptions hard() { + formParameters.put("type", "hard"); + return this; + } + +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncClientTest.java index bfd3ebfec5..1b344d361b 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncClientTest.java @@ -46,12 +46,14 @@ public class GleSYSAsyncClientTest extends BaseGleSYSAsyncClientTest { + public ArchiveAsyncClientTest() { + asyncClientClass = ArchiveAsyncClient.class; + remoteServicePrefix = "archive"; + } + + private Map.Entry userName = newEntry("username", "x"); + + public void testListArchives() throws Exception { + testMethod("listArchives", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class); + } + + public void testArchiveDetails() throws Exception { + testMethod("archiveDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, userName); + } + + public void testCreateArchive() throws Exception { + testMethod("createArchive", "create", "POST", false, MapHttp4xxCodesToExceptions.class, userName, + newEntry("password", "somepass"), newEntry("size", 5)); + } + + public void testDeleteArchive() throws Exception { + testMethod("deleteArchive", "delete", "POST", false, MapHttp4xxCodesToExceptions.class, userName); + } + + public void testResizeArchive() throws Exception { + testMethod("resizeArchive", "resize", "POST", false, MapHttp4xxCodesToExceptions.class, userName, + newEntry("size", 5)); + } + + public void testChangeArchivePassword() throws Exception { + testMethod("changeArchivePassword", "changepassword", "POST", false, MapHttp4xxCodesToExceptions.class, userName, + newEntry("password", "newpass")); + } + + public void testGetArchiveAllowedArguments() throws Exception { + testMethod("getArchiveAllowedArguments", "allowedarguments", "GET", true, ReturnEmptySetOnNotFoundOr404.class); + } @Override protected TypeLiteral> createTypeLiteral() { diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java index f004cff33f..7e650b149d 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java @@ -18,22 +18,33 @@ */ package org.jclouds.glesys.features; -import static org.testng.Assert.assertEquals; - -import java.util.Properties; - +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Maps; +import org.jclouds.glesys.GleSYSAsyncClient; +import org.jclouds.glesys.GleSYSClient; import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.http.options.BaseHttpRequestOptions; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextSpec; -import org.jclouds.glesys.GleSYSAsyncClient; -import org.jclouds.glesys.GleSYSClient; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import static org.testng.Assert.*; /** * @author Adrian Cole */ public abstract class BaseGleSYSAsyncClientTest extends RestClientTest { + protected Class asyncClientClass; + protected String remoteServicePrefix; @Override protected void checkFilters(HttpRequest request) { @@ -47,4 +58,73 @@ public abstract class BaseGleSYSAsyncClientTest extends RestClientTest { return new RestContextFactory().createContextSpec("glesys", "username", "apiKey", props); } + protected Map.Entry newEntry(String key, Object value) { + return Maps.immutableEntry(key, value.toString()); + } + + /** + * Test that a method call is annotated correctly. + *

+ * TODO de-code ampersands and spaces in args properly + * + * @param localMethod the method to call in asyncClientClass + * @param remoteCall the name of the expected call on the remote server + * @param httpMethod "GET" or "POST" + * @param expectResponse if true check Accept header and response parsers + * @param exceptionParser the class of exception handler expected + * @param args either Map.Entry or BaseHttpRequestOptions that make up the arguments to the method + */ + protected void testMethod(String localMethod, String remoteCall, String httpMethod, boolean expectResponse, Class exceptionParser, Object... args) throws Exception { + List argStrings = new ArrayList(); + List argValues = new ArrayList(); + + for (Object arg : args) { + if (arg instanceof BaseHttpRequestOptions) { + for (Map.Entry httpEntry : ((BaseHttpRequestOptions) arg).buildFormParameters().entries()) { + argStrings.add(httpEntry.getKey() + "=" + httpEntry.getValue()); + } + argValues.add(arg); + } else { + Map.Entry entry = (Map.Entry) arg; + argStrings.add(entry.getKey() + "=" + entry.getValue()); + argValues.add(entry.getValue()); + } + } + + Method method = null; + for (Method m : asyncClientClass.getMethods()) { + if (m.getName().equals(localMethod)) { + assertNull(method, "More than one method called " + localMethod + " in class " + asyncClientClass); + method = m; + } + } + + assertNotNull(method, "Failed to locate method " + localMethod + " in class " + asyncClientClass); + + HttpRequest httpRequest = processor.createRequest(method, argValues.toArray()); + + assertRequestLineEquals(httpRequest, httpMethod + " https://api.glesys.com/" + remoteServicePrefix + "/" + remoteCall + "/format/json HTTP/1.1"); + + if (expectResponse) { + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + } + + if (argStrings.isEmpty()) { + assertPayloadEquals(httpRequest, null, null, false); + } else { + assertNotNull(httpRequest.getPayload()); + String payload = (String) httpRequest.getPayload().getRawContent(); + Iterable in = Splitter.on("&").split(payload); + assertContentHeadersEqual(httpRequest, "application/x-www-form-urlencoded", null, null, null, 0L + payload.length(), null); + assertEquals(ImmutableSortedSet.copyOf(in), ImmutableSortedSet.copyOf(argStrings)); + + } + + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, exceptionParser); + + checkFilters(httpRequest); + } + } diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java new file mode 100644 index 0000000000..fb76cf394e --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java @@ -0,0 +1,69 @@ +/** + * 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.features; + +import com.google.inject.TypeLiteral; +import org.jclouds.glesys.options.DomainOptions; +import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import java.util.Map; + +/** + * Tests annotation parsing of {@code ArchiveAsyncClient} + * + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "DomainAsyncClientTest") +public class DomainAsyncClientTest extends BaseGleSYSAsyncClientTest { + public DomainAsyncClientTest() { + asyncClientClass = DomainAsyncClient.class; + remoteServicePrefix = "domain"; + } + + private Map.Entry domainName = newEntry("domain", "cl666666someuser"); + + public void testListDomains() throws Exception { + testMethod("listDomains", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class); + } + + public void testAddDomain() throws Exception { + testMethod("addDomain", "add", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("name", "cl66666_x"), + DomainOptions.Builder.primaryNameServer("ns1.somewhere.x").expire("1").minimum("1").refresh("1"). + responsiblePerson("Tester").retry("1").ttl(1)); + testMethod("addDomain", "add", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("name", "cl66666_x")); + } + + public void testEditDomain() throws Exception { + testMethod("editDomain", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("domain", "x")); + } + + public void testDeleteDomain() throws Exception { + testMethod("deleteDomain", "delete", "POST", false, MapHttp4xxCodesToExceptions.class, domainName); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java index 30be6c1a2d..8a659e62a7 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java @@ -18,7 +18,9 @@ */ package org.jclouds.glesys.features; +import com.google.common.collect.Maps; import com.google.inject.TypeLiteral; +import org.jclouds.glesys.options.*; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; @@ -29,6 +31,7 @@ import org.testng.annotations.Test; import java.io.IOException; import java.lang.reflect.Method; +import java.util.Map; /** * Tests annotation parsing of {@code ServerAsyncClient} @@ -39,87 +42,82 @@ import java.lang.reflect.Method; @Test(groups = "unit", testName = "ServerAsyncClientTest") public class ServerAsyncClientTest extends BaseGleSYSAsyncClientTest { + public ServerAsyncClientTest() { + asyncClientClass = ServerAsyncClient.class; + remoteServicePrefix = "server"; + } + + private Map.Entry serverIdOnly = newEntry("serverid", "abcd"); + public void testListServers() throws Exception { - testVoidArgsMethod("listServers", "list", "POST", ReturnEmptySetOnNotFoundOr404.class); + testMethod("listServers", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class); } public void testGetAllowedArguments() throws Exception { - testVoidArgsMethod("getServerAllowedArguments", "allowedarguments", "GET", MapHttp4xxCodesToExceptions.class); + testMethod("getServerAllowedArguments", "allowedarguments", "GET", true, MapHttp4xxCodesToExceptions.class); } public void testGetTemplates() throws Exception { - testVoidArgsMethod("getTemplates", "templates", "GET", MapHttp4xxCodesToExceptions.class); + testMethod("getTemplates", "templates", "GET", true, MapHttp4xxCodesToExceptions.class); } public void testGetServer() throws Exception { - testServerMethod("getServerDetails", "details"); + testMethod("getServerDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly); + } + + @Test + public void testCreateServer() throws Exception { + testMethod("createServer", "create", "POST", true, MapHttp4xxCodesToExceptions.class, + newEntry("datacenter", "Falkenberg"), newEntry("platform", "OpenVZ"), + newEntry("hostname", "jclouds-test"), newEntry("template", "Ubuntu%2032-bit"), + newEntry("disksize", 5), newEntry("memorysize", 512), newEntry("cpucores", 1), + newEntry("rootpw", "password"), newEntry("transfer", 50)); + testMethod("createServer", "create", "POST", true, MapHttp4xxCodesToExceptions.class, + newEntry("datacenter", "Falkenberg"), newEntry("platform", "OpenVZ"), + newEntry("hostname", "jclouds-test"), newEntry("template", "Ubuntu%2032-bit"), + newEntry("disksize", 5), newEntry("memorysize", 512), newEntry("cpucores", 1), + newEntry("rootpw", "password"), newEntry("transfer", 50), + ServerCreateOptions.Builder.description("Description-of-server").ip("10.0.0.1")); } - public void testGetgetServerStatus() throws Exception { - testServerMethod("getServerStatus", "status"); + @Test + public void testEditServer() throws Exception { + testMethod("editServer", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly); + testMethod("editServer", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, + ServerEditOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test")); + } + + @Test + public void testCloneServer() throws Exception { + testMethod("cloneServer", "clone", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, newEntry("hostname", "somename")); + testMethod("cloneServer", "clone", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, newEntry("hostname", "somename"), + ServerCloneOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test")); + } + + public void testGetServerStatus() throws Exception { + testMethod("getServerStatus", "status", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly); + testMethod("getServerStatus", "status", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly, ServerStatusOptions.Builder.state()); } public void testGetServerLimits() throws Exception { - testServerMethod("getServerLimits", "limits"); + testMethod("getServerLimits", "limits", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly); } public void testGetServerConsole() throws Exception { - testServerMethod("getServerConsole", "console"); + testMethod("getServerConsole", "console", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly); } public void testStartServer() throws Exception { - testServerMethodVoidReturn("startServer", "start"); + testMethod("startServer", "start", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly); } public void testStopServer() throws Exception { - testServerMethodVoidReturn("stopServer", "stop"); + testMethod("stopServer", "stop", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly); + testMethod("stopServer", "stop", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerStopOptions.Builder.hard()); } public void testRebootServer() throws Exception { - testServerMethodVoidReturn("rebootServer", "reboot"); - } - - protected void testVoidArgsMethod(String localMethod, String remoteCall, String httpMethod, Class exceptionParser) throws Exception { - Method method = ServerAsyncClient.class.getMethod(localMethod); - HttpRequest httpRequest = processor.createRequest(method); - - assertRequestLineEquals(httpRequest, httpMethod + " https://api.glesys.com/server/" + remoteCall + "/format/json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, exceptionParser); - - checkFilters(httpRequest); - } - - protected void testServerMethod(String localMethod, String remoteMethod) throws Exception { - testServerMethod(localMethod, remoteMethod, "serverid", true); - } - - protected void testServerMethodVoidReturn(String localMethod, String remoteMethod) throws Exception { - testServerMethod(localMethod, remoteMethod, "id", false); - } - - protected void testServerMethod(String localMethod, String remoteMethod, String serverIdField, boolean acceptHeader) throws Exception { - Method method = ServerAsyncClient.class.getMethod(localMethod, String.class); - HttpRequest httpRequest = processor.createRequest(method, "abcd"); - - assertRequestLineEquals(httpRequest, - "POST https://api.glesys.com/server/" + remoteMethod + "/format/json HTTP/1.1"); - - if (acceptHeader) { - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - } - - assertPayloadEquals(httpRequest, serverIdField + "=abcd", "application/x-www-form-urlencoded", false); - - assertSaxResponseParserClassEquals(method, null); - - checkFilters(httpRequest); + testMethod("rebootServer", "reboot", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly); } @Override 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 1fe7e0d6b0..38e61c33a6 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 @@ -20,6 +20,8 @@ package org.jclouds.glesys.features; import com.google.common.base.Predicate; import org.jclouds.glesys.domain.*; +import org.jclouds.glesys.options.ServerCloneOptions; +import org.jclouds.glesys.options.ServerStatusOptions; import org.jclouds.predicates.RetryablePredicate; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; @@ -35,6 +37,7 @@ import static org.testng.Assert.*; * Tests behavior of {@code ServerClient} * * @author Adrian Cole + * @author Adam Lowe */ @Test(groups = "live", testName = "ServerClientLiveTest") public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { @@ -42,59 +45,35 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { @BeforeGroups(groups = {"live"}) public void setupClient() { super.setupClient(); - client = context.getApi().getServerClient(); - - runningServerCounter = new RetryablePredicate( - new Predicate() { - public boolean apply(Integer value){ - int count = 0; - for(Server server : client.listServers()) { - ServerStatus status = client.getServerStatus(server.getId()); - if (status.getState() == ServerState.RUNNING && - status.getUptime() > 0) { - count++; - } - } - return count == value; - } - }, 120, 5, TimeUnit.SECONDS); } - + @AfterGroups(groups = {"live"}) public void tearDown() { client.destroyServer(testServer.getId(), 0); + if (testServer2 != null) { + client.destroyServer(testServer2.getId(), 0); + } super.tearDown(); } - - public static class ServerStatePredicate implements Predicate { - private ServerState state; - private String serverId; - public ServerStatePredicate(ServerState state, String serverId) { - this.state = state; - this.serverId = serverId; - } - @Override - public boolean apply(ServerClient client) { - return client.getServerStatus(serverId) != null && client.getServerStatus(serverId).getState() == state; - } - } - + private ServerClient client; private ServerCreated testServer; - private RetryablePredicate runningServerCounter; - + private ServerCreated testServer2; + // note this is initialized by testCreateServer() + private RetryablePredicate runningServerCounter; + @Test public void testCreateServer() throws Exception { - int before = client.listServers().size(); + testServer = client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 10.04 LTS 32-bit", 5, 512, 1, "password", 50); - testServer = client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 10.04 LTS 32-bit", 5, 512, 1, "password", 50, null, null); - assertNotNull(testServer.getId()); - assertNotNull(testServer.getHostname()); + assertEquals(testServer.getHostname(), "jclouds-test"); assertFalse(testServer.getIps().isEmpty()); - assertTrue(runningServerCounter.apply(before + 1)); + runningServerCounter = new ServerStatusChecker(testServer.getId(), 120, 2, TimeUnit.SECONDS); + + assertTrue(runningServerCounter.apply(ServerState.RUNNING)); } @Test @@ -168,11 +147,31 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { checkStatus(newStatus); } + @Test(dependsOnMethods = "testCreateServer") + public void testRebootServer() throws Exception { + client.rebootServer(testServer.getId()); + + assertTrue(runningServerCounter.apply(ServerState.STOPPED)); + assertTrue(runningServerCounter.apply(ServerState.RUNNING)); + } + + @Test(dependsOnMethods = "testCreateServer") + public void testStopAndStartServer() throws Exception { + client.stopServer(testServer.getId()); + + assertTrue(runningServerCounter.apply(ServerState.STOPPED)); + + client.startServer(testServer.getId()); + + assertTrue(runningServerCounter.apply(ServerState.RUNNING)); + } + + @Test(dependsOnMethods = "testCreateServer") public void testServerLimits() throws Exception { Map limits = client.getServerLimits(testServer.getId()); assertNotNull(limits); - for(Map.Entry entry : limits.entrySet()) { + for (Map.Entry entry : limits.entrySet()) { assertNotNull(entry.getKey()); assertNotNull(entry.getValue()); ServerLimit limit = entry.getValue(); @@ -194,6 +193,42 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { assertNotNull(console.getPassword()); } + // takes a few minutes + @Test(enabled=false, dependsOnMethods = "testCreateServer") + public void testCloneServer() throws Exception { + testServer2 = client.cloneServer(testServer.getId(), "jclouds-test2", ServerCloneOptions.Builder.cpucores(1)); + + assertNotNull(testServer2.getId()); + assertEquals(testServer2.getHostname(), "jclouds-test2"); + assertTrue(testServer2.getIps().isEmpty()); + + RetryablePredicate cloneChecker = new ServerStatusChecker(testServer2.getId(), 300, 10, TimeUnit.SECONDS); + + assertTrue(cloneChecker.apply(ServerState.STOPPED)); + + client.startServer(testServer2.getId()); + + // TODO ServerStatus==STOPPED suggests the previous call to start should have worked + cloneChecker = new RetryablePredicate( + new Predicate() { + + public boolean apply(ServerState value) { + ServerStatus status = client.getServerStatus(testServer2.getId(), ServerStatusOptions.Builder.state()); + if (status.getState() == value) { + return true; + } + + client.startServer(testServer2.getId()); + return false; + } + + }, 300, 10, TimeUnit.SECONDS); + + assertTrue(cloneChecker.apply(ServerState.RUNNING) + + ); + } + private void checkServer(ServerDetails server) { // description can be null assert server.getCpuCores() > 0 : server; @@ -230,4 +265,17 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { assert status.getMemory().getUsage() >= 0 : status; assertNotNull(status.getMemory().getUnit()); } + + private class ServerStatusChecker extends RetryablePredicate { + public ServerStatusChecker(final String serverId, long maxWait, long period, TimeUnit unit) { + super(new Predicate() { + + public boolean apply(ServerState value) { + ServerStatus status = client.getServerStatus(serverId, ServerStatusOptions.Builder.state()); + return status.getState() == value; + } + + }, maxWait, period, unit); + } + } }