mirror of https://github.com/apache/jclouds.git
Improving Domain, Server and Archive services
This commit is contained in:
parent
79674bd89b
commit
bb5210eb6f
|
@ -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<ServerCreatedIp> getIps() {
|
||||
return ips;
|
||||
return ips == null ? ImmutableList.<ServerCreatedIp>of() : ips;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -99,6 +99,7 @@ public interface ArchiveAsyncClient {
|
|||
@Path("/archive/allowedarguments/format/json")
|
||||
@SelectJson("argumentslist")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<ArchiveAllowedArguments> getArchiveAllowedArguments();
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Set<Domain>> listDomains();
|
||||
|
||||
/**
|
||||
|
@ -57,43 +63,37 @@ public interface DomainAsyncClient {
|
|||
*/
|
||||
@POST
|
||||
@Path("/domain/add/format/json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Void> addDomain(@FormParam("name") String domain, DomainOptions... options);
|
||||
ListenableFuture<Void> 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<Void> editDomain(@FormParam("domain") String domain, DomainOptions... options);
|
||||
|
||||
@POST
|
||||
@Path("/domain/delete/format/json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Void> 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<Set<DomainRecord>> listRecords(@PathParam("domain") String domain);
|
||||
ListenableFuture<Set<DomainRecord>> listRecords(@FormParam("domain") String domain);
|
||||
|
||||
@POST
|
||||
@Path("/domain/add_record/format/json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Void> 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<Void> editRecord(@FormParam("record_id") String record_id, DomainRecordModifyOptions... options);
|
||||
|
||||
@POST
|
||||
@Path("/domain/delete_record/format/json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Void> deleteRecord(@FormParam("record_id") String recordId);
|
||||
|
||||
}
|
|
@ -33,7 +33,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* <p/>
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see InvoiceAsyncClient
|
||||
* @see DomainAsyncClient
|
||||
* @see <a href="https://customer.glesys.com/api.php" />
|
||||
*/
|
||||
@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
|
||||
|
|
|
@ -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<ServerStatus> getServerStatus(@FormParam("serverid") String id);
|
||||
ListenableFuture<ServerStatus> 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<Void> resetServerLimit(@FormParam("id") String id, @FormParam("type") String type);
|
||||
@Path("/server/resetlimit/format/json")
|
||||
ListenableFuture<Void> resetServerLimit(@FormParam("serverid") String id, @FormParam("type") String type);
|
||||
|
||||
/**
|
||||
* @see ServerClient#rebootServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/server/reboot/format/json")
|
||||
ListenableFuture<Void> rebootServer(@FormParam("id") String id);
|
||||
ListenableFuture<Void> rebootServer(@FormParam("serverid") String id);
|
||||
|
||||
/**
|
||||
* @see ServerClient#startServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/server/start/format/json")
|
||||
ListenableFuture<Void> startServer(@FormParam("id") String id);
|
||||
ListenableFuture<Void> startServer(@FormParam("serverid") String id);
|
||||
|
||||
/**
|
||||
* @see ServerClient#stopServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/server/stop/format/json")
|
||||
ListenableFuture<Void> stopServer(@FormParam("id") String id);
|
||||
ListenableFuture<Void> 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<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);
|
||||
|
||||
@FormParam("hostname") String hostname,
|
||||
ServerCloneOptions... options);
|
||||
|
||||
/**
|
||||
* @see ServerClient#editServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/server/edit/format/json")
|
||||
ListenableFuture<Void> editServer(@FormParam("serverid") String serverid, ServerEditOptions... options);
|
||||
|
||||
/**
|
||||
* @see ServerClient#destroyServer
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -46,12 +46,14 @@ public class GleSYSAsyncClientTest extends BaseGleSYSAsyncClientTest<GleSYSAsync
|
|||
assert syncClient.getServerClient() != null;
|
||||
assert syncClient.getIpClient() != null;
|
||||
assert syncClient.getArchiveClient() != null;
|
||||
assert syncClient.getDomainClient() != null;
|
||||
}
|
||||
|
||||
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
assert asyncClient.getServerClient() != null;
|
||||
assert asyncClient.getIpClient() != null;
|
||||
assert asyncClient.getArchiveClient() != null;
|
||||
assert asyncClient.getDomainClient() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,9 +19,15 @@
|
|||
package org.jclouds.glesys.features;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
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 javax.ws.rs.FormParam;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ArchiveAsyncClient}
|
||||
*
|
||||
|
@ -29,6 +35,43 @@ import org.testng.annotations.Test;
|
|||
*/
|
||||
@Test(groups = "unit", testName = "ArchiveAsyncClientTest")
|
||||
public class ArchiveAsyncClientTest extends BaseGleSYSAsyncClientTest<ArchiveAsyncClient> {
|
||||
public ArchiveAsyncClientTest() {
|
||||
asyncClientClass = ArchiveAsyncClient.class;
|
||||
remoteServicePrefix = "archive";
|
||||
}
|
||||
|
||||
private Map.Entry<String, String> 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<RestAnnotationProcessor<ArchiveAsyncClient>> createTypeLiteral() {
|
||||
|
|
|
@ -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<T> extends RestClientTest<T> {
|
||||
protected Class asyncClientClass;
|
||||
protected String remoteServicePrefix;
|
||||
|
||||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
|
@ -47,4 +58,73 @@ public abstract class BaseGleSYSAsyncClientTest<T> extends RestClientTest<T> {
|
|||
return new RestContextFactory().createContextSpec("glesys", "username", "apiKey", props);
|
||||
}
|
||||
|
||||
protected Map.Entry<String, String> newEntry(String key, Object value) {
|
||||
return Maps.immutableEntry(key, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a method call is annotated correctly.
|
||||
* <p/>
|
||||
* 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<String> argStrings = new ArrayList<String>();
|
||||
List<Object> argValues = new ArrayList<Object>();
|
||||
|
||||
for (Object arg : args) {
|
||||
if (arg instanceof BaseHttpRequestOptions) {
|
||||
for (Map.Entry<String, String> httpEntry : ((BaseHttpRequestOptions) arg).buildFormParameters().entries()) {
|
||||
argStrings.add(httpEntry.getKey() + "=" + httpEntry.getValue());
|
||||
}
|
||||
argValues.add(arg);
|
||||
} else {
|
||||
Map.Entry<String, String> entry = (Map.Entry<String, String>) 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<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<DomainAsyncClient> {
|
||||
public DomainAsyncClientTest() {
|
||||
asyncClientClass = DomainAsyncClient.class;
|
||||
remoteServicePrefix = "domain";
|
||||
}
|
||||
|
||||
private Map.Entry<String, String> 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<RestAnnotationProcessor<DomainAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<DomainAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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<ServerAsyncClient> {
|
||||
|
||||
public ServerAsyncClientTest() {
|
||||
asyncClientClass = ServerAsyncClient.class;
|
||||
remoteServicePrefix = "server";
|
||||
}
|
||||
|
||||
private Map.Entry<String, String> 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
|
||||
|
|
|
@ -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<Integer>(
|
||||
new Predicate<Integer>() {
|
||||
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<ServerClient> {
|
||||
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<Integer> runningServerCounter;
|
||||
|
||||
private ServerCreated testServer2;
|
||||
// note this is initialized by testCreateServer()
|
||||
private RetryablePredicate<ServerState> 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<String, ServerLimit> limits = client.getServerLimits(testServer.getId());
|
||||
assertNotNull(limits);
|
||||
for(Map.Entry<String,ServerLimit> entry : limits.entrySet()) {
|
||||
for (Map.Entry<String, ServerLimit> 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<ServerState> 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<ServerState>(
|
||||
new Predicate<ServerState>() {
|
||||
|
||||
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<ServerState> {
|
||||
public ServerStatusChecker(final String serverId, long maxWait, long period, TimeUnit unit) {
|
||||
super(new Predicate<ServerState>() {
|
||||
|
||||
public boolean apply(ServerState value) {
|
||||
ServerStatus status = client.getServerStatus(serverId, ServerStatusOptions.Builder.state());
|
||||
return status.getState() == value;
|
||||
}
|
||||
|
||||
}, maxWait, period, unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue