mirror of https://github.com/apache/jclouds.git
Improving Server and Archive services, also adjusting equals to match Glesys api spec
This commit is contained in:
parent
92d9ee3ff1
commit
79674bd89b
|
@ -9,7 +9,7 @@ import com.google.gson.annotations.SerializedName;
|
||||||
* @author Adam Lowe
|
* @author Adam Lowe
|
||||||
* @see <a href= "https://customer.glesys.com/api.php?a=doc#archive_details" />
|
* @see <a href= "https://customer.glesys.com/api.php?a=doc#archive_details" />
|
||||||
*/
|
*/
|
||||||
public class Archive {
|
public class Archive implements Comparable<Archive> {
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,12 @@ public class Archive {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(username, totalSize, freeSize, locked);
|
return Objects.hashCode(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Archive other) {
|
||||||
|
return username.compareTo(other.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,15 +95,8 @@ public class Archive {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof Archive) {
|
return obj instanceof Archive
|
||||||
Archive other = (Archive) obj;
|
&& Objects.equal(username, ((Archive) obj).username);
|
||||||
return Objects.equal(username, other.username)
|
|
||||||
&& Objects.equal(totalSize, other.totalSize)
|
|
||||||
&& Objects.equal(freeSize, other.freeSize)
|
|
||||||
&& Objects.equal(locked, other.locked);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,12 +61,8 @@ public class ArchiveAllowedArguments {
|
||||||
if (this == object) {
|
if (this == object) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (object instanceof ArchiveAllowedArguments) {
|
return object instanceof ArchiveAllowedArguments
|
||||||
ArchiveAllowedArguments other = (ArchiveAllowedArguments) object;
|
&& Objects.equal(archiveSizes, ((ArchiveAllowedArguments) object).archiveSizes);
|
||||||
return Objects.equal(archiveSizes, other.archiveSizes);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,7 +29,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @see <a href= "https://customer.glesys.com/api.php?a=doc#server_list" />
|
* @see <a href= "https://customer.glesys.com/api.php?a=doc#server_list" />
|
||||||
*/
|
*/
|
||||||
public class Server {
|
public class Server implements Comparable<Server> {
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
@ -110,17 +110,18 @@ public class Server {
|
||||||
return datacenter;
|
return datacenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Server other) {
|
||||||
|
return id.compareTo(other.getId());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if (this == object) {
|
if (this == object) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (object instanceof Server) {
|
if (object instanceof Server) {
|
||||||
final Server other = (Server) object;
|
return Objects.equal(id, ((Server) object).id);
|
||||||
return Objects.equal(datacenter, other.datacenter)
|
|
||||||
&& Objects.equal(hostname, other.hostname)
|
|
||||||
&& Objects.equal(id, other.id)
|
|
||||||
&& Objects.equal(platform, other.platform);
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +129,7 @@ public class Server {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(datacenter, hostname, id, platform);
|
return Objects.hashCode(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -82,8 +82,7 @@ public class ServerConsole {
|
||||||
if (object instanceof ServerConsole) {
|
if (object instanceof ServerConsole) {
|
||||||
final ServerConsole other = (ServerConsole) object;
|
final ServerConsole other = (ServerConsole) object;
|
||||||
return Objects.equal(host, other.host)
|
return Objects.equal(host, other.host)
|
||||||
&& Objects.equal(port, other.port)
|
&& Objects.equal(port, other.port);
|
||||||
&& Objects.equal(password, other.password);
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +90,7 @@ public class ServerConsole {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(host, port, password);
|
return Objects.hashCode(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -82,18 +82,13 @@ public class ServerCreated {
|
||||||
if (this == object) {
|
if (this == object) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (object instanceof ServerCreated) {
|
return object instanceof ServerCreated
|
||||||
final ServerCreated other = (ServerCreated) object;
|
&& Objects.equal(id, ((ServerCreated) object).id);
|
||||||
return Objects.equal(id, other.id)
|
|
||||||
&& Objects.equal(ips, other.ips);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(id, ips);
|
return Objects.hashCode(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -161,27 +161,4 @@ public class ServerDetails extends Server {
|
||||||
hostname, datacenter, platform, description, cpuCores, memory, disk, cost);
|
hostname, datacenter, platform, description, cpuCores, memory, disk, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return super.hashCode() + Objects.hashCode(description, cpuCores, disk, memory, cost);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object object) {
|
|
||||||
if (this == object) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (object instanceof ServerDetails) {
|
|
||||||
final ServerDetails other = (ServerDetails) object;
|
|
||||||
return super.equals(other)
|
|
||||||
&& Objects.equal(description, other.description)
|
|
||||||
&& Objects.equal(cpuCores, other.cpuCores)
|
|
||||||
&& Objects.equal(disk, other.disk)
|
|
||||||
&& Objects.equal(memory, other.memory)
|
|
||||||
&& Objects.equal(cost, other.cost);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,9 +115,6 @@ public class ServerTemplate {
|
||||||
if (object instanceof ServerTemplate) {
|
if (object instanceof ServerTemplate) {
|
||||||
final ServerTemplate other = (ServerTemplate) object;
|
final ServerTemplate other = (ServerTemplate) object;
|
||||||
return Objects.equal(name, other.name)
|
return Objects.equal(name, other.name)
|
||||||
&& Objects.equal(minDiskSize, other.minDiskSize)
|
|
||||||
&& Objects.equal(minMemSize, other.minMemSize)
|
|
||||||
&& Objects.equal(os, other.os)
|
|
||||||
&& Objects.equal(platform, other.platform);
|
&& Objects.equal(platform, other.platform);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -126,7 +123,7 @@ public class ServerTemplate {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(name, minDiskSize, minMemSize, os, platform);
|
return Objects.hashCode(name, platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -47,7 +47,7 @@ public interface ArchiveAsyncClient {
|
||||||
/**
|
/**
|
||||||
* @see ArchiveClient#listArchives
|
* @see ArchiveClient#listArchives
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/archive/list/format/json")
|
@Path("/archive/list/format/json")
|
||||||
@SelectJson("archives")
|
@SelectJson("archives")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ -57,7 +57,7 @@ public interface ArchiveAsyncClient {
|
||||||
/**
|
/**
|
||||||
* @see ArchiveClient#archiveDetails
|
* @see ArchiveClient#archiveDetails
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/archive/details/format/json")
|
@Path("/archive/details/format/json")
|
||||||
@SelectJson("details")
|
@SelectJson("details")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
|
|
@ -46,7 +46,7 @@ public interface ServerAsyncClient {
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#listServers
|
* @see ServerClient#listServers
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/server/list/format/json")
|
@Path("/server/list/format/json")
|
||||||
@SelectJson("servers")
|
@SelectJson("servers")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ -56,43 +56,43 @@ public interface ServerAsyncClient {
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#getServerDetails
|
* @see ServerClient#getServerDetails
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/server/details/serverid/{id}/format/json")
|
@Path("/server/details/format/json")
|
||||||
@SelectJson("server")
|
@SelectJson("server")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<ServerDetails> getServerDetails(@PathParam("id") String id);
|
ListenableFuture<ServerDetails> getServerDetails(@FormParam("serverid") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#getServerStatus
|
* @see ServerClient#getServerStatus
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/server/status/serverid/{id}/format/json")
|
@Path("/server/status/format/json")
|
||||||
@SelectJson("server")
|
@SelectJson("server")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<ServerStatus> getServerStatus(@PathParam("id") String id);
|
ListenableFuture<ServerStatus> getServerStatus(@FormParam("serverid") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#getServerLimits
|
* @see ServerClient#getServerLimits
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/server/limits/serverid/{id}/format/json")
|
@Path("/server/limits/format/json")
|
||||||
@SelectJson("limits")
|
@SelectJson("limits")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<SortedMap<String, ServerLimit>> getServerLimits(@PathParam("id") String id);
|
ListenableFuture<SortedMap<String, ServerLimit>> getServerLimits(@FormParam("serverid") String id);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#getServerConsole
|
* @see ServerClient#getServerConsole
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/server/console/serverid/{id}/format/json")
|
@Path("/server/console/format/json")
|
||||||
@SelectJson("server")
|
@SelectJson("server")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<ServerConsole> getServerConsole(@PathParam("id") String id);
|
ListenableFuture<ServerConsole> getServerConsole(@FormParam("serverid") String id);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,30 +116,30 @@ public interface ServerAsyncClient {
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#stopServer
|
* @see ServerClient#stopServer
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/server/resetlimit/serverid/{id}/type/{type}/format/json")
|
@Path("/server/resetlimit/serverid/{id}/type/{type}/format/json")
|
||||||
ListenableFuture<Void> resetServerLimit(@PathParam("id") String id, @PathParam("type") String type);
|
ListenableFuture<Void> resetServerLimit(@FormParam("id") String id, @FormParam("type") String type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#rebootServer
|
* @see ServerClient#rebootServer
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/server/reboot/serverid/{id}/format/json")
|
@Path("/server/reboot/format/json")
|
||||||
ListenableFuture<Void> rebootServer(@PathParam("id") String id);
|
ListenableFuture<Void> rebootServer(@FormParam("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#startServer
|
* @see ServerClient#startServer
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/server/start/serverid/{id}/format/json")
|
@Path("/server/start/format/json")
|
||||||
ListenableFuture<Void> startServer(@PathParam("id") String id);
|
ListenableFuture<Void> startServer(@FormParam("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#stopServer
|
* @see ServerClient#stopServer
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
@Path("/server/stop/serverid/{id}/format/json")
|
@Path("/server/stop/format/json")
|
||||||
ListenableFuture<Void> stopServer(@PathParam("id") String id);
|
ListenableFuture<Void> stopServer(@FormParam("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#createServer
|
* @see ServerClient#createServer
|
||||||
|
|
|
@ -56,11 +56,13 @@ public class ArchiveClientLiveTest extends BaseGleSYSClientLiveTest {
|
||||||
}, 30, 1, TimeUnit.SECONDS);
|
}, 30, 1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterGroups(alwaysRun = true, groups={"live"})
|
@AfterGroups(groups={"live"})
|
||||||
public void teardownClient() {
|
public void tearDown() {
|
||||||
int before = client.listArchives().size();
|
int before = client.listArchives().size();
|
||||||
client.deleteArchive(archiveUser);
|
client.deleteArchive(archiveUser);
|
||||||
assertTrue(archiveCounter.apply(before - 1));
|
assertTrue(archiveCounter.apply(before - 1));
|
||||||
|
|
||||||
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArchiveClient client;
|
private ArchiveClient client;
|
||||||
|
|
|
@ -18,57 +18,108 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.glesys.features;
|
package org.jclouds.glesys.features;
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.google.inject.TypeLiteral;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||||
|
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.TypeLiteral;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests annotation parsing of {@code ServerAsyncClient}
|
* Tests annotation parsing of {@code ServerAsyncClient}
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
* @author Adam Lowe
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "ServerAsyncClientTest")
|
@Test(groups = "unit", testName = "ServerAsyncClientTest")
|
||||||
public class ServerAsyncClientTest extends BaseGleSYSAsyncClientTest<ServerAsyncClient> {
|
public class ServerAsyncClientTest extends BaseGleSYSAsyncClientTest<ServerAsyncClient> {
|
||||||
|
|
||||||
public void testListServers() throws SecurityException, NoSuchMethodException, IOException {
|
public void testListServers() throws Exception {
|
||||||
Method method = ServerAsyncClient.class.getMethod("listServers");
|
testVoidArgsMethod("listServers", "list", "POST", ReturnEmptySetOnNotFoundOr404.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetAllowedArguments() throws Exception {
|
||||||
|
testVoidArgsMethod("getServerAllowedArguments", "allowedarguments", "GET", MapHttp4xxCodesToExceptions.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetTemplates() throws Exception {
|
||||||
|
testVoidArgsMethod("getTemplates", "templates", "GET", MapHttp4xxCodesToExceptions.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetServer() throws Exception {
|
||||||
|
testServerMethod("getServerDetails", "details");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetgetServerStatus() throws Exception {
|
||||||
|
testServerMethod("getServerStatus", "status");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetServerLimits() throws Exception {
|
||||||
|
testServerMethod("getServerLimits", "limits");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetServerConsole() throws Exception {
|
||||||
|
testServerMethod("getServerConsole", "console");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStartServer() throws Exception {
|
||||||
|
testServerMethodVoidReturn("startServer", "start");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStopServer() throws Exception {
|
||||||
|
testServerMethodVoidReturn("stopServer", "stop");
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
HttpRequest httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET https://api.glesys.com/server/list/format/json HTTP/1.1");
|
assertRequestLineEquals(httpRequest, httpMethod + " https://api.glesys.com/server/" + remoteCall + "/format/json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, exceptionParser);
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetServer() throws SecurityException, NoSuchMethodException, IOException {
|
protected void testServerMethod(String localMethod, String remoteMethod) throws Exception {
|
||||||
Method method = ServerAsyncClient.class.getMethod("getServerDetails", String.class);
|
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");
|
HttpRequest httpRequest = processor.createRequest(method, "abcd");
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"GET https://api.glesys.com/server/details/serverid/abcd/format/json HTTP/1.1");
|
"POST https://api.glesys.com/server/" + remoteMethod + "/format/json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
|
||||||
|
|
||||||
|
if (acceptHeader) {
|
||||||
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertPayloadEquals(httpRequest, serverIdField + "=abcd", "application/x-www-form-urlencoded", false);
|
||||||
|
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,11 +20,14 @@ package org.jclouds.glesys.features;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import org.jclouds.glesys.domain.*;
|
import org.jclouds.glesys.domain.*;
|
||||||
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.testng.Assert.*;
|
import static org.testng.Assert.*;
|
||||||
|
|
||||||
|
@ -39,7 +42,29 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
|
||||||
@BeforeGroups(groups = {"live"})
|
@BeforeGroups(groups = {"live"})
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
|
|
||||||
client = context.getApi().getServerClient();
|
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);
|
||||||
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ServerStatePredicate implements Predicate<ServerClient> {
|
public static class ServerStatePredicate implements Predicate<ServerClient> {
|
||||||
|
@ -56,6 +81,21 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerClient client;
|
private ServerClient client;
|
||||||
|
private ServerCreated testServer;
|
||||||
|
private RetryablePredicate<Integer> 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, null, null);
|
||||||
|
|
||||||
|
assertNotNull(testServer.getId());
|
||||||
|
assertNotNull(testServer.getHostname());
|
||||||
|
assertFalse(testServer.getIps().isEmpty());
|
||||||
|
|
||||||
|
assertTrue(runningServerCounter.apply(before + 1));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllowedArguments() throws Exception {
|
public void testAllowedArguments() throws Exception {
|
||||||
|
@ -106,11 +146,12 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
|
||||||
assert t.getMinMemSize() > 0 : t;
|
assert t.getMinMemSize() > 0 : t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(dependsOnMethods = "testCreateServer")
|
||||||
public void testListServers() throws Exception {
|
public void testListServers() throws Exception {
|
||||||
Set<Server> response = client.listServers();
|
Set<Server> response = client.listServers();
|
||||||
assert null != response;
|
assertNotNull(response);
|
||||||
assertTrue(response.size() >= 0);
|
assertTrue(response.size() > 0);
|
||||||
|
|
||||||
for (Server server : response) {
|
for (Server server : response) {
|
||||||
ServerDetails newDetails = client.getServerDetails(server.getId());
|
ServerDetails newDetails = client.getServerDetails(server.getId());
|
||||||
assertEquals(newDetails.getId(), server.getId());
|
assertEquals(newDetails.getId(), server.getId());
|
||||||
|
@ -118,9 +159,39 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
|
||||||
assertEquals(newDetails.getPlatform(), server.getPlatform());
|
assertEquals(newDetails.getPlatform(), server.getPlatform());
|
||||||
assertEquals(newDetails.getDatacenter(), server.getDatacenter());
|
assertEquals(newDetails.getDatacenter(), server.getDatacenter());
|
||||||
checkServer(newDetails);
|
checkServer(newDetails);
|
||||||
ServerStatus newStatus = client.getServerStatus(server.getId());
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testCreateServer")
|
||||||
|
public void testServerDetails() throws Exception {
|
||||||
|
ServerStatus newStatus = client.getServerStatus(testServer.getId());
|
||||||
checkStatus(newStatus);
|
checkStatus(newStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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()) {
|
||||||
|
assertNotNull(entry.getKey());
|
||||||
|
assertNotNull(entry.getValue());
|
||||||
|
ServerLimit limit = entry.getValue();
|
||||||
|
assertTrue(limit.getBarrier() >= 0);
|
||||||
|
assertTrue(limit.getFailCount() == 0);
|
||||||
|
assertTrue(limit.getHeld() >= 0);
|
||||||
|
assertTrue(limit.getLimit() > 0);
|
||||||
|
assertTrue(limit.getMaxHeld() >= 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO in progress
|
||||||
|
@Test(enabled=false, dependsOnMethods = "testCreateServer")
|
||||||
|
public void testServerConsole() throws Exception {
|
||||||
|
ServerConsole console = client.getServerConsole(testServer.getId());
|
||||||
|
assertNotNull(console);
|
||||||
|
assertNotNull(console.getHost());
|
||||||
|
assertTrue(console.getPort() > 0 && console.getPort() < 65537);
|
||||||
|
assertNotNull(console.getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkServer(ServerDetails server) {
|
private void checkServer(ServerDetails server) {
|
||||||
|
@ -143,7 +214,9 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
|
||||||
assertNotNull(status.getCpu());
|
assertNotNull(status.getCpu());
|
||||||
assert status.getCpu().getSystem() >= 0.0 : status;
|
assert status.getCpu().getSystem() >= 0.0 : status;
|
||||||
assert status.getCpu().getUser() >= 0.0 : status;
|
assert status.getCpu().getUser() >= 0.0 : status;
|
||||||
|
if (status.getCpu().getNice() != null) {
|
||||||
assert status.getCpu().getNice() >= 0.0 : status;
|
assert status.getCpu().getNice() >= 0.0 : status;
|
||||||
|
}
|
||||||
assert status.getCpu().getIdle() >= 0.0 : status;
|
assert status.getCpu().getIdle() >= 0.0 : status;
|
||||||
assertNotNull(status.getCpu().getUnit());
|
assertNotNull(status.getCpu().getUnit());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue