mirror of https://github.com/apache/jclouds.git
glesys api changes
This commit is contained in:
parent
241a33b5c8
commit
1c8bc98733
|
@ -105,6 +105,7 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
|
|||
builder.datacenter(template.getLocation().getId());
|
||||
builder.templateName(template.getImage().getId());
|
||||
builder.platform(template.getHardware().getHypervisor());
|
||||
builder.memorySizeMB(template.getHardware().getRam());
|
||||
builder.diskSizeGB(Math.round(template.getHardware().getVolumes().get(0).getSize()));
|
||||
builder.cpuCores((int) template.getHardware().getProcessors().get(0).getCores());
|
||||
builder.transferGB(50);// TODO: add to template options with default value
|
||||
|
|
|
@ -53,6 +53,7 @@ import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -113,14 +114,14 @@ public class ServerDetailsToNodeMetadata implements Function<ServerDetails, Node
|
|||
from.getPlatform()).build());
|
||||
builder.state(serverStateToNodeState.get(client.getServerClient().getServerStatus(from.getId(),
|
||||
ServerStatusOptions.Builder.state()).getState()));
|
||||
Iterable<String> addresses = Iterables.transform(from.getIps(), new Function<Ip, String>() {
|
||||
Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Ip arg0) {
|
||||
return arg0.getIp();
|
||||
return Strings.emptyToNull(arg0.getIp());
|
||||
}
|
||||
|
||||
});
|
||||
}), Predicates.notNull());
|
||||
builder.publicAddresses(Iterables.filter(addresses, Predicates.not(IsPrivateIPAddress.INSTANCE)));
|
||||
builder.privateAddresses(Iterables.filter(addresses, IsPrivateIPAddress.INSTANCE));
|
||||
return builder.build();
|
||||
|
|
|
@ -51,7 +51,7 @@ import com.google.common.net.InetAddresses;
|
|||
*/
|
||||
public class GleSYSTemplateOptions extends TemplateOptions implements Cloneable {
|
||||
|
||||
protected String ip;
|
||||
protected String ip = "any";
|
||||
|
||||
@Override
|
||||
public GleSYSTemplateOptions clone() {
|
||||
|
@ -76,7 +76,7 @@ public class GleSYSTemplateOptions extends TemplateOptions implements Cloneable
|
|||
*/
|
||||
public TemplateOptions ip(String ip) {
|
||||
if (ip != null)
|
||||
checkArgument(InetAddresses.isInetAddress(ip), "ip %s is not valid", ip);
|
||||
checkArgument("any".equals(ip) || InetAddresses.isInetAddress(ip), "ip %s is not valid", ip);
|
||||
this.ip = ip;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.jclouds.glesys.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Represents an ip address used by a server.
|
||||
|
@ -70,7 +71,8 @@ public class Ip {
|
|||
return ip(from.getIp()).version(from.getVersion()).cost(from.getCost());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SerializedName("ipaddress")
|
||||
protected final String ip;
|
||||
protected final int version;
|
||||
protected final double cost;
|
||||
|
|
|
@ -18,14 +18,13 @@
|
|||
*/
|
||||
package org.jclouds.glesys.domain;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Detailed information about a server such as cpuCores, hardware configuration
|
||||
* (cpu, memory and disk), ip adresses, cost, transfer, os and more.
|
||||
|
@ -46,7 +45,7 @@ public class ServerDetails extends Server {
|
|||
private int diskSizeGB;
|
||||
private int transferGB;
|
||||
private Cost cost;
|
||||
private List<Ip> ips;
|
||||
private Set<Ip> ips = ImmutableSet.of();
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
|
@ -84,11 +83,11 @@ public class ServerDetails extends Server {
|
|||
}
|
||||
|
||||
public Builder ips(Ip... ips) {
|
||||
return ips(Arrays.asList(ips));
|
||||
return ips(ImmutableSet.copyOf(ips));
|
||||
}
|
||||
|
||||
public Builder ips(List<Ip> ips) {
|
||||
this.ips = ips;
|
||||
public Builder ips(Iterable<Ip> ips) {
|
||||
this.ips = ImmutableSet.copyOf(ips);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -140,10 +139,10 @@ public class ServerDetails extends Server {
|
|||
private final int transferGB;
|
||||
private final Cost cost;
|
||||
@SerializedName("iplist")
|
||||
private final List<Ip> ips;
|
||||
private final Set<Ip> ips;
|
||||
|
||||
public ServerDetails(String id, String hostname, String datacenter, String platform, String templateName,
|
||||
String description, int cpuCores, int memorySizeMB, int diskSizeGB, int transferGB, Cost cost, List<Ip> ips) {
|
||||
String description, int cpuCores, int memorySizeMB, int diskSizeGB, int transferGB, Cost cost, Set<Ip> ips) {
|
||||
super(id, hostname, datacenter, platform);
|
||||
this.templateName = checkNotNull(templateName, "template");
|
||||
this.description = description;
|
||||
|
@ -152,7 +151,7 @@ public class ServerDetails extends Server {
|
|||
this.diskSizeGB = diskSizeGB;
|
||||
this.transferGB = transferGB;
|
||||
this.cost = checkNotNull(cost, "cost");
|
||||
this.ips = ips == null ? ImmutableList.<Ip>of() : ips;
|
||||
this.ips = ImmutableSet.<Ip>copyOf(ips);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,7 +199,7 @@ public class ServerDetails extends Server {
|
|||
/**
|
||||
* @return the ip addresses assigned to the server
|
||||
*/
|
||||
public List<Ip> getIps() {
|
||||
public Set<Ip> getIps() {
|
||||
return ips;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,24 +46,26 @@ public class GleSYSErrorHandler implements HttpErrorHandler {
|
|||
// it is important to always read fully and close streams
|
||||
String message = parseMessage(response);
|
||||
Exception exception = message != null ? new HttpResponseException(command, response, message)
|
||||
: new HttpResponseException(command, response);
|
||||
: new HttpResponseException(command, response);
|
||||
try {
|
||||
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
|
||||
response.getStatusLine());
|
||||
response.getStatusLine());
|
||||
switch (response.getStatusCode()) {
|
||||
case 401:
|
||||
case 403:
|
||||
exception = new AuthorizationException(message, exception);
|
||||
break;
|
||||
case 404:
|
||||
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
}
|
||||
break;
|
||||
case 500:
|
||||
if (message != null && message.indexOf("Unable to determine package for") != -1) {
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
}
|
||||
case 401:
|
||||
case 403:
|
||||
exception = new AuthorizationException(message, exception);
|
||||
break;
|
||||
case 400:
|
||||
if (command.getCurrentRequest().getEndpoint().getPath().indexOf("delete") != -1
|
||||
&& message.indexOf("Could not find") != -1) {
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
}
|
||||
break;
|
||||
case 404:
|
||||
if (command.getCurrentRequest().getEndpoint().getPath().indexOf("delete") == -1) {
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} finally {
|
||||
if (response.getPayload() != null)
|
||||
|
|
|
@ -18,22 +18,22 @@
|
|||
*/
|
||||
package org.jclouds.glesys;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.reportMatcher;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.easymock.IArgumentMatcher;
|
||||
import org.jclouds.glesys.handlers.GleSYSErrorHandler;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.glesys.handlers.GleSYSErrorHandler;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -46,21 +46,22 @@ import com.google.inject.Guice;
|
|||
@Test(groups = { "unit" })
|
||||
public class GleSYSErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
public void test500MakesResourceNotFoundExceptionOnUnableToDeterminePackage() {
|
||||
assertCodeMakes(
|
||||
"GET",
|
||||
URI.create("https://api.glesys.com/foo"),
|
||||
500,
|
||||
"",
|
||||
"{\"error\":\"Unable to determine package for 'node2102835255.me.org'.\"}",
|
||||
ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test401MakesAuthorizationException() {
|
||||
assertCodeMakes("GET", URI.create("https://api.glesys.com/foo"), 401, "", "Unauthorized",
|
||||
AuthorizationException.class);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test400MakesResourceNotFoundExceptionOnCouldNotFind() {
|
||||
assertCodeMakes(
|
||||
"POST",
|
||||
URI.create("https://api.glesys.com/domain/delete/format/json"),
|
||||
400,
|
||||
"",
|
||||
"{\"response\":{\"status\":{\"code\":400,\"timestamp\":\"2012-02-10T12:07:56+01:00\",\"text\":\"Could not find domain on this account.\n\"},\"debug\":{\"input\":{\"domainname\":\"email-test.jclouds.org\"}}}}",
|
||||
ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
* 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.compute.functions;
|
||||
|
||||
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.Volume;
|
||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
import org.jclouds.glesys.compute.internal.BaseGleSYSComputeServiceExpectTest;
|
||||
import org.jclouds.glesys.features.ServerClientExpectTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ServerDetailsToNodeMetadataTest")
|
||||
public class ServerDetailsToNodeMetadataTest extends BaseGleSYSComputeServiceExpectTest {
|
||||
|
||||
@Test
|
||||
public void testServerDetailsRequest() {
|
||||
|
||||
ServerDetailsToNodeMetadata toTest = injectorForKnownArgumentsAndConstantPassword(
|
||||
ImmutableMap
|
||||
.<HttpRequest, HttpResponse> builder()
|
||||
.put(HttpRequest
|
||||
.builder()
|
||||
.method("POST")
|
||||
.endpoint(URI.create("https://api.glesys.com/server/details/format/json"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(
|
||||
newUrlEncodedFormPayload(ImmutableMultimap.<String, String> builder()
|
||||
.put("serverid", "xm3276891").build())).build(),
|
||||
HttpResponse
|
||||
.builder()
|
||||
.statusCode(200)
|
||||
.payload(
|
||||
payloadFromString("{\"response\":{\"status\":{\"code\":200,\"timestamp\":\"2012-02-10T11:28:50+01:00\",\"text\":\"OK\"},\"server\":{\"state\":\"running\"},\"debug\":{\"input\":{\"serverid\":\"xm3276891\",\"statustype\":\"state\"}}}}"))
|
||||
.build())
|
||||
.put(HttpRequest
|
||||
.builder()
|
||||
.method("POST")
|
||||
.endpoint(URI.create("https://api.glesys.com/server/status/format/json"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(
|
||||
newUrlEncodedFormPayload(ImmutableMultimap.<String, String> builder()
|
||||
.put("serverid", "xm3276891").put("statustype", "state").build())).build(),
|
||||
HttpResponse.builder().statusCode(206).payload(payloadFromResource("/server_status.json"))
|
||||
.build()).build()
|
||||
|
||||
).getInstance(ServerDetailsToNodeMetadata.class);
|
||||
|
||||
assertEquals(
|
||||
toTest.apply(ServerClientExpectTest.expectedServerDetails()),
|
||||
new NodeMetadataBuilder()
|
||||
.ids("xm3276891")
|
||||
.name("glesys-s-6dd")
|
||||
.hostname("glesys-s-6dd")
|
||||
.group("glesys-s")
|
||||
.imageId("Ubuntu 11.04 x64")
|
||||
.operatingSystem(
|
||||
OperatingSystem.builder().name("Ubuntu 11.04 x64").family(OsFamily.UBUNTU).version("11.04")
|
||||
.is64Bit(true).description("Ubuntu 11.04 x64").build())
|
||||
.publicAddresses(ImmutableSet.of("109.74.10.45"))
|
||||
.hardware(
|
||||
new HardwareBuilder().ids("xm3276891").ram(512)
|
||||
.processors(ImmutableList.of(new Processor(1, 1.0)))
|
||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(5f, true, true))).hypervisor("Xen")
|
||||
.build()).state(NodeState.RUNNING).build());
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.glesys.compute.internal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
|
@ -31,6 +32,7 @@ import org.jclouds.logging.config.NullLoggingModule;
|
|||
import org.jclouds.rest.BaseRestClientExpectTest;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -51,8 +53,7 @@ public abstract class BaseGleSYSComputeServiceExpectTest extends BaseRestClientE
|
|||
@Override
|
||||
public ComputeService createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
|
||||
return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, identity, credential,
|
||||
ImmutableSet.<Module> of(new ExpectModule(fn), new NullLoggingModule(), module), props)
|
||||
.getComputeService();
|
||||
ImmutableSet.<Module> of(new ExpectModule(fn), new NullLoggingModule(), module), props).getComputeService();
|
||||
}
|
||||
|
||||
protected PasswordProvider passwordGenerator() {
|
||||
|
@ -65,28 +66,47 @@ public abstract class BaseGleSYSComputeServiceExpectTest extends BaseRestClientE
|
|||
}
|
||||
|
||||
protected Injector injectorForKnownArgumentsAndConstantPassword() {
|
||||
return computeContextForKnownArgumentsAndConstantPassword().utils().injector();
|
||||
return injectorForKnownArgumentsAndConstantPassword(ImmutableMap.<HttpRequest, HttpResponse> of());
|
||||
}
|
||||
|
||||
protected Injector injectorForKnownArgumentsAndConstantPassword(Map<HttpRequest, HttpResponse> requestsResponses) {
|
||||
return computeContextForKnownArgumentsAndConstantPassword(requestsResponses).utils().injector();
|
||||
}
|
||||
|
||||
protected ComputeServiceContext computeContextForKnownArgumentsAndConstantPassword(
|
||||
Map<HttpRequest, HttpResponse> requestsResponses) {
|
||||
return requestsSendResponses(
|
||||
ImmutableMap
|
||||
.<HttpRequest, HttpResponse> builder()
|
||||
.put(HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("https://api.glesys.com/server/templates/format/json"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_templates.json"))
|
||||
.build())
|
||||
.put(HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("https://api.glesys.com/server/allowedarguments/format/json"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(204)
|
||||
.payload(payloadFromResource("/server_allowed_arguments.json")).build())
|
||||
.putAll(requestsResponses).build(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(PasswordProvider.class).toInstance(passwordGenerator());
|
||||
}
|
||||
|
||||
}).getContext();
|
||||
}
|
||||
|
||||
protected ComputeServiceContext computeContextForKnownArgumentsAndConstantPassword() {
|
||||
return requestsSendResponses(
|
||||
HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.glesys.com/server/templates/format/json")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_templates.json")).build(),
|
||||
HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.glesys.com/server/allowedarguments/format/json")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(204).payload(payloadFromResource("/server_allowed_arguments.json"))
|
||||
.build(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(PasswordProvider.class).toInstance(passwordGenerator());
|
||||
}
|
||||
|
||||
}).getContext();
|
||||
return computeContextForKnownArgumentsAndConstantPassword(ImmutableMap.<HttpRequest, HttpResponse> of());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class GleSYSTemplateOptionsTest {
|
|||
@Test
|
||||
public void testDefaultip() {
|
||||
TemplateOptions options = new GleSYSTemplateOptions();
|
||||
assertEquals(options.as(GleSYSTemplateOptions.class).getIp(), null);
|
||||
assertEquals(options.as(GleSYSTemplateOptions.class).getIp(), "any");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.jclouds.glesys.domain.EmailOverview;
|
|||
import org.jclouds.glesys.domain.EmailOverviewDomain;
|
||||
import org.jclouds.glesys.internal.BaseGleSYSClientLiveTest;
|
||||
import org.jclouds.glesys.options.CreateAccountOptions;
|
||||
import org.jclouds.glesys.options.EditAccountOptions;
|
||||
import org.jclouds.glesys.options.DestroyServerOptions;
|
||||
import org.jclouds.glesys.options.EditAccountOptions;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
|
|
|
@ -146,19 +146,19 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server1ssg-1.1").build())).build(),
|
||||
.put("serverid", "xm3276891").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerClient();
|
||||
|
||||
ServerDetails actual = client.getServerDetails("server1ssg-1.1");
|
||||
ServerDetails actual = client.getServerDetails("xm3276891");
|
||||
assertEquals(actual.toString(), expectedServerDetails().toString());
|
||||
}
|
||||
|
||||
private ServerDetails expectedServerDetails() {
|
||||
Ip ip = Ip.builder().version4().ip("31.192.226.45").cost(2.0).build();
|
||||
Cost cost = Cost.builder().amount(6.38).currency("EUR").timePeriod("month").build();
|
||||
return ServerDetails.builder().id("vz1375882").transferGB(50).hostname("jclouds-unit").cpuCores(1).memorySizeMB(128)
|
||||
.diskSizeGB(5).description("unit test server").datacenter("Falkenberg").platform("OpenVZ")
|
||||
.templateName("Debian 6.0 64-bit").cost(cost).ips(ip).build();
|
||||
public static ServerDetails expectedServerDetails() {
|
||||
Ip ip = Ip.builder().version4().ip("109.74.10.45").cost(2.0).build();
|
||||
Cost cost = Cost.builder().amount(13.22).currency("EUR").timePeriod("month").build();
|
||||
return ServerDetails.builder().id("xm3276891").transferGB(50).hostname("glesys-s-6dd").cpuCores(1).memorySizeMB(512)
|
||||
.diskSizeGB(5).description("glesys-s-6dd").datacenter("Falkenberg").platform("Xen")
|
||||
.templateName("Ubuntu 11.04 x64").cost(cost).ips(ip).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -169,10 +169,10 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111").build())).build(),
|
||||
.put("serverid", "xm3276891").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getServerClient();
|
||||
|
||||
assertNull(client.getServerDetails("server111"));
|
||||
assertNull(client.getServerDetails("xm3276891"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -243,10 +243,10 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111").build())).build(),
|
||||
.put("serverid", "xm3276891").build())).build(),
|
||||
HttpResponse.builder().statusCode(206).build()).getServerClient();
|
||||
|
||||
client.editServer("server111");
|
||||
client.editServer("xm3276891");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -257,7 +257,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111")
|
||||
.put("serverid", "xm3276891")
|
||||
.put("description", "Description-of-server")
|
||||
.put("disksize", "1")
|
||||
.put("memorysize", "512")
|
||||
|
@ -269,7 +269,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
EditServerOptions options =
|
||||
EditServerOptions.Builder.description("Description-of-server").diskSizeGB(1).memorySizeMB(512).cpuCores(1).hostname("jclouds-test");
|
||||
|
||||
client.editServer("server111", options);
|
||||
client.editServer("xm3276891", options);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -280,11 +280,11 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111")
|
||||
.put("serverid", "xm3276891")
|
||||
.put("hostname", "hostname1").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerClient();
|
||||
|
||||
assertEquals(client.cloneServer("server111", "hostname1"), expectedServerDetails());
|
||||
assertEquals(client.cloneServer("xm3276891", "hostname1"), expectedServerDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -295,7 +295,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111")
|
||||
.put("serverid", "xm3276891")
|
||||
.put("hostname", "hostname1")
|
||||
.put("description", "Description-of-server")
|
||||
.put("disksize", "1")
|
||||
|
@ -304,7 +304,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerClient();
|
||||
CloneServerOptions options = (CloneServerOptions) CloneServerOptions.Builder.description("Description-of-server").diskSizeGB(1).memorySizeMB(512).cpuCores(1);
|
||||
|
||||
assertEquals(client.cloneServer("server111", "hostname1", options), expectedServerDetails());
|
||||
assertEquals(client.cloneServer("xm3276891", "hostname1", options), expectedServerDetails());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
|
@ -315,11 +315,11 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111")
|
||||
.put("serverid", "xm3276891")
|
||||
.put("hostname", "hostname1").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getServerClient();
|
||||
|
||||
client.cloneServer("server111", "hostname1");
|
||||
client.cloneServer("xm3276891", "hostname1");
|
||||
}
|
||||
|
||||
public void testGetServerStatusWhenResponseIs2xx() throws Exception {
|
||||
|
@ -329,11 +329,11 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111").build())).build(),
|
||||
.put("serverid", "xm3276891").build())).build(),
|
||||
HttpResponse.builder().statusCode(206).payload(payloadFromResource("/server_status.json")).build())
|
||||
.getServerClient();
|
||||
|
||||
assertEquals(client.getServerStatus("server111"), expectedServerStatus());
|
||||
assertEquals(client.getServerStatus("xm3276891"), expectedServerStatus());
|
||||
}
|
||||
|
||||
public void testGetServerStatusWithOptsWhenResponseIs2xx() throws Exception {
|
||||
|
@ -539,9 +539,9 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
|
||||
private ServerStatus expectedServerStatus() {
|
||||
ResourceUsage cpu = ResourceUsage.builder().unit("cores").max(1.0).usage(0.0).build();
|
||||
ResourceUsage disk = ResourceUsage.builder().unit("MB").usage(371.0).max(5120).build();
|
||||
ResourceUsage memory = ResourceUsage.builder().unit("MB").usage(3.0).max(128).build();
|
||||
ServerUptime uptime = ServerUptime.builder().current(23).unit("seconds").build();
|
||||
ResourceUsage disk = ResourceUsage.builder().unit("GB").usage(0.0).max(5).build();
|
||||
ResourceUsage memory = ResourceUsage.builder().unit("MB").usage(0.0).max(512).build();
|
||||
ServerUptime uptime = ServerUptime.builder().current(0).unit("seconds").build();
|
||||
return ServerStatus.builder().state(Server.State.RUNNING).uptime(uptime).
|
||||
cpu(cpu).disk(disk).memory(memory).build();
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"response":{"status":{"code":"200","text":"OK"},"server":{"serverid":"vz1375882","hostname":"jclouds-unit","description":"unit test server","cpucores":"1","memorysize":"128","disksize":"5","transfer":"50","templatename":"Debian 6.0 64-bit","datacenter":"Falkenberg","managedhosting":"no","platform":"OpenVZ","cost":{"amount":6.38,"currency":"EUR","timeperiod":"month"},"iplist":[{"ip":"31.192.226.45","version":"4","cost":"2.00"}]},"debug":{"input":{"serverid":"vz1375882"}}}}
|
||||
{"response":{"status":{"code":200,"timestamp":"2012-02-10T11:11:05+01:00","text":"OK"},"server":{"serverid":"xm3276891","hostname":"glesys-s-6dd","description":"glesys-s-6dd","cpucores":1,"memorysize":512,"disksize":5,"transfer":50,"templatename":"Ubuntu 11.04 x64","datacenter":"Falkenberg","managedhosting":"no","platform":"Xen","cost":{"amount":13.22,"currency":"EUR","timeperiod":"month"},"iplist":[{"ipaddress":"109.74.10.45","version":4,"cost":2,"currency":"EUR"}]},"debug":{"input":{"serverid":"xm3276891"}}}}
|
|
@ -1 +1 @@
|
|||
{"response":{"status":{"code":200,"text":"OK"},"server":{"state":"running","cpu":{"usage":0,"max":1,"unit":"cores"},"memory":{"usage":3,"max":128,"unit":"MB"},"disk":{"usage":371,"max":5120,"unit":"MB"},"transfer":{"usage":0,"max":50,"unit":"GB last 30 days"},"uptime":{"current":23,"unit":"seconds"}},"debug":{"input":{"serverid":"vz1952928"}}}}
|
||||
{"response":{"status":{"code":200,"timestamp":"2012-02-10T11:21:50+01:00","text":"OK"},"server":{"state":"running","cpu":{"usage":0,"max":1,"unit":"cores"},"memory":{"usage":null,"max":512,"unit":"MB"},"disk":{"usage":null,"max":5,"unit":"GB"},"transfer":{"usage":0,"max":50,"unit":"GB last 30 days"},"uptime":{"current":null,"unit":"seconds"}},"debug":{"input":{"serverid":"xm3276891"}}}}
|
Loading…
Reference in New Issue