merged glesys changes

This commit is contained in:
Adrian Cole 2012-02-13 21:44:42 +01:00
parent 1b57270ad4
commit 2cad1dc7b6
118 changed files with 167 additions and 123 deletions

View File

@ -27,26 +27,12 @@
<version>1.4.0-SNAPSHOT</version> <version>1.4.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath> <relativePath>../../project/pom.xml</relativePath>
</parent> </parent>
<groupId>org.jclouds.provider</groupId> <groupId>org.jclouds.labs</groupId>
<artifactId>glesys</artifactId> <artifactId>glesys</artifactId>
<name>jclouds GleSYS core</name> <name>jclouds GleSYS core</name>
<description>jclouds components to access GleSYS</description> <description>jclouds components to access GleSYS</description>
<packaging>bundle</packaging> <packaging>bundle</packaging>
<!-- bootstrapping: need to fetch the project POM -->
<repositories>
<repository>
<id>jclouds-sona-snapshots-nexus</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<properties> <properties>
<test.glesys.endpoint>https://api.glesys.com</test.glesys.endpoint> <test.glesys.endpoint>https://api.glesys.com</test.glesys.endpoint>
<test.glesys.api-version>1</test.glesys.api-version> <test.glesys.api-version>1</test.glesys.api-version>
@ -57,6 +43,7 @@
<test.glesys.image.login-user></test.glesys.image.login-user> <test.glesys.image.login-user></test.glesys.image.login-user>
<test.glesys.image.authenticate-sudo></test.glesys.image.authenticate-sudo> <test.glesys.image.authenticate-sudo></test.glesys.image.authenticate-sudo>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.jclouds</groupId> <groupId>org.jclouds</groupId>

View File

@ -48,6 +48,8 @@ public class GleSYSPropertiesBuilder extends PropertiesBuilder {
properties.setProperty(PROPERTY_ZONE + ".Falkenberg." + ISO3166_CODES, "SE-N"); properties.setProperty(PROPERTY_ZONE + ".Falkenberg." + ISO3166_CODES, "SE-N");
properties.setProperty(PROPERTY_ZONE + ".New York City." + ISO3166_CODES, "US-NY"); properties.setProperty(PROPERTY_ZONE + ".New York City." + ISO3166_CODES, "US-NY");
properties.setProperty(PROPERTY_ZONE + ".Stockholm." + ISO3166_CODES, "SE-AB"); properties.setProperty(PROPERTY_ZONE + ".Stockholm." + ISO3166_CODES, "SE-AB");
properties.setProperty("jclouds.ssh.max-retries", "5");
properties.setProperty("jclouds.ssh.retry-auth", "true");
properties.setProperty(PROPERTY_GLESYS_DEFAULT_DC, "Falkenberg"); properties.setProperty(PROPERTY_GLESYS_DEFAULT_DC, "Falkenberg");
return properties; return properties;
} }

View File

@ -20,9 +20,12 @@ package org.jclouds.glesys.compute;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -30,6 +33,7 @@ import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.collect.FindResourceInSet; import org.jclouds.collect.FindResourceInSet;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeService;
@ -44,10 +48,12 @@ import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.glesys.GleSYSAsyncClient;
import org.jclouds.glesys.GleSYSClient; import org.jclouds.glesys.GleSYSClient;
import org.jclouds.glesys.compute.options.GleSYSTemplateOptions; import org.jclouds.glesys.compute.options.GleSYSTemplateOptions;
import org.jclouds.glesys.domain.AllowedArgumentsForCreateServer; import org.jclouds.glesys.domain.AllowedArgumentsForCreateServer;
import org.jclouds.glesys.domain.OSTemplate; import org.jclouds.glesys.domain.OSTemplate;
import org.jclouds.glesys.domain.Server;
import org.jclouds.glesys.domain.ServerDetails; import org.jclouds.glesys.domain.ServerDetails;
import org.jclouds.glesys.domain.ServerSpec; import org.jclouds.glesys.domain.ServerSpec;
import org.jclouds.glesys.options.CreateServerOptions; import org.jclouds.glesys.options.CreateServerOptions;
@ -62,8 +68,8 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
* defines the connection between the {@link GleSYSClient} implementation and the jclouds * defines the connection between the {@link GleSYSClient} implementation and
* {@link ComputeService} * the jclouds {@link ComputeService}
* *
*/ */
@Singleton @Singleton
@ -74,13 +80,18 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final GleSYSClient client; private final GleSYSClient client;
private final GleSYSAsyncClient aclient;
private final ExecutorService userThreads;
private final Supplier<Set<? extends Location>> locations; private final Supplier<Set<? extends Location>> locations;
private final Provider<String> passwordProvider; private final Provider<String> passwordProvider;
@Inject @Inject
public GleSYSComputeServiceAdapter(GleSYSClient client, @Memoized Supplier<Set<? extends Location>> locations, public GleSYSComputeServiceAdapter(GleSYSClient client, GleSYSAsyncClient aclient,
@Named("PASSWORD") Provider<String> passwordProvider) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads,
@Memoized Supplier<Set<? extends Location>> locations, @Named("PASSWORD") Provider<String> passwordProvider) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.aclient = checkNotNull(aclient, "aclient");
this.userThreads = checkNotNull(userThreads, "userThreads");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
this.passwordProvider = checkNotNull(passwordProvider, "passwordProvider"); this.passwordProvider = checkNotNull(passwordProvider, "passwordProvider");
} }
@ -91,15 +102,15 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
checkNotNull(template, "template was null"); checkNotNull(template, "template was null");
checkNotNull(template.getOptions(), "template options was null"); checkNotNull(template.getOptions(), "template options was null");
checkArgument(template.getOptions().getClass().isAssignableFrom(GleSYSTemplateOptions.class), checkArgument(template.getOptions().getClass().isAssignableFrom(GleSYSTemplateOptions.class),
"options class %s should have been assignable from GleSYSTemplateOptions", template.getOptions() "options class %s should have been assignable from GleSYSTemplateOptions", template.getOptions().getClass());
.getClass());
GleSYSTemplateOptions templateOptions = template.getOptions().as(GleSYSTemplateOptions.class); GleSYSTemplateOptions templateOptions = template.getOptions().as(GleSYSTemplateOptions.class);
CreateServerOptions createServerOptions = new CreateServerOptions(); CreateServerOptions createServerOptions = new CreateServerOptions();
createServerOptions.ip(templateOptions.getIp()); createServerOptions.ip(templateOptions.getIp());
createServerOptions.description(name); // TODO: add to templateOptions and set if present createServerOptions.description(name); // TODO: add to templateOptions and
// set if present
ServerSpec.Builder builder = ServerSpec.builder(); ServerSpec.Builder builder = ServerSpec.builder();
builder.datacenter(template.getLocation().getId()); builder.datacenter(template.getLocation().getId());
@ -111,7 +122,8 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
builder.transferGB(50);// TODO: add to template options with default value builder.transferGB(50);// TODO: add to template options with default value
ServerSpec spec = builder.build(); ServerSpec spec = builder.build();
String password = passwordProvider.get(); // TODO: add to templateOptions and set if present String password = passwordProvider.get(); // TODO: add to templateOptions
// and set if present
logger.debug(">> creating new Server spec(%s) name(%s) options(%s)", spec, name, createServerOptions); logger.debug(">> creating new Server spec(%s) name(%s) options(%s)", spec, name, createServerOptions);
ServerDetails result = client.getServerClient().createServerWithHostnameAndRootPassword(spec, name, password, ServerDetails result = client.getServerClient().createServerWithHostnameAndRootPassword(spec, name, password,
@ -157,14 +169,15 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
} }
ImmutableSet<String> templatesSupported = templatesSupportedBuilder.build(); ImmutableSet<String> templatesSupported = templatesSupportedBuilder.build();
if (templatesSupported.size() > 0) if (templatesSupported.size() > 0)
hardwareToReturn.add(new HardwareBuilder().ids( hardwareToReturn.add(new HardwareBuilder()
String.format("datacenter(%s)platform(%s)cpuCores(%d)memorySizeMB(%d)diskSizeGB(%d)", .ids(String.format(
datacenter, platformToArgs.getKey(), cpuCores, memorySizeMB, diskSizeGB)).ram( "datacenter(%s)platform(%s)cpuCores(%d)memorySizeMB(%d)diskSizeGB(%d)", datacenter,
memorySizeMB).processors(ImmutableList.of(new Processor(cpuCores, 1.0))).volumes( platformToArgs.getKey(), cpuCores, memorySizeMB, diskSizeGB)).ram(memorySizeMB)
ImmutableList.<Volume> of(new VolumeImpl((float) diskSizeGB, true, true))).hypervisor( .processors(ImmutableList.of(new Processor(cpuCores, 1.0)))
platformToArgs.getKey()).location( .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) diskSizeGB, true, true)))
Iterables.find(locationsSet, LocationPredicates.idEquals(datacenter))).supportsImage( .hypervisor(platformToArgs.getKey())
ImagePredicates.idIn(templatesSupported)).build()); .location(Iterables.find(locationsSet, LocationPredicates.idEquals(datacenter)))
.supportsImage(ImagePredicates.idIn(templatesSupported)).build());
} }
return hardwareToReturn.build(); return hardwareToReturn.build();
@ -177,7 +190,13 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
@Override @Override
public Iterable<ServerDetails> listNodes() { public Iterable<ServerDetails> listNodes() {
return ImmutableSet.of(); return transformParallel(client.getServerClient().listServers(), new Function<Server, Future<ServerDetails>>() {
@Override
public Future<ServerDetails> apply(Server from) {
return aclient.getServerClient().getServerDetails(from.getId());
}
}, userThreads, null, logger, "server details");
} }
@Override @Override

View File

@ -18,9 +18,8 @@
*/ */
package org.jclouds.glesys.compute.config; package org.jclouds.glesys.compute.config;
import java.security.SecureRandom; import java.util.UUID;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -64,7 +63,7 @@ public class GleSYSComputeServiceContextModule
super(GleSYSClient.class, GleSYSAsyncClient.class); super(GleSYSClient.class, GleSYSAsyncClient.class);
} }
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
@Override @Override
protected void configure() { protected void configure() {
super.configure(); super.configure();
@ -95,16 +94,11 @@ public class GleSYSComputeServiceContextModule
@Named("PASSWORD") @Named("PASSWORD")
@Singleton @Singleton
public static class PasswordProvider implements Provider<String> { public static class PasswordProvider implements Provider<String> {
private final SecureRandom random;
@Inject
protected PasswordProvider() {
this.random = new SecureRandom();
}
@Override @Override
public String get() { public String get() {
return random.nextLong() + ""; return UUID.randomUUID().toString().replace("-","");
} }
} }
} }

View File

@ -43,10 +43,8 @@ import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.VolumeImpl; import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.glesys.GleSYSClient;
import org.jclouds.glesys.domain.Ip; import org.jclouds.glesys.domain.Ip;
import org.jclouds.glesys.domain.ServerDetails; import org.jclouds.glesys.domain.ServerDetails;
import org.jclouds.glesys.options.ServerStatusOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.util.InetAddresses2.IsPrivateIPAddress; import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
@ -68,12 +66,11 @@ public class ServerDetailsToNodeMetadata implements Function<ServerDetails, Node
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
public static final Map<ServerDetails.State, NodeState> serverStateToNodeState = ImmutableMap public static final Map<ServerDetails.State, NodeState> serverStateToNodeState = ImmutableMap
.<ServerDetails.State, NodeState> builder().put(ServerDetails.State.STOPPED, NodeState.SUSPENDED).put( .<ServerDetails.State, NodeState> builder().put(ServerDetails.State.STOPPED, NodeState.SUSPENDED)
ServerDetails.State.RUNNING, NodeState.RUNNING).put(ServerDetails.State.UNRECOGNIZED, .put(ServerDetails.State.RUNNING, NodeState.RUNNING)
NodeState.UNRECOGNIZED).build(); .put(ServerDetails.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).build();
protected final Supplier<Set<? extends Image>> images; protected final Supplier<Set<? extends Image>> images;
protected final GleSYSClient client;
protected final FindLocationForServerDetails findLocationForServerDetails; protected final FindLocationForServerDetails findLocationForServerDetails;
private static class FindImageForServer implements Predicate<Image> { private static class FindImageForServer implements Predicate<Image> {
@ -90,9 +87,8 @@ public class ServerDetailsToNodeMetadata implements Function<ServerDetails, Node
} }
@Inject @Inject
ServerDetailsToNodeMetadata(GleSYSClient client, FindLocationForServerDetails findLocationForServerDetails, ServerDetailsToNodeMetadata(FindLocationForServerDetails findLocationForServerDetails,
@Memoized Supplier<Set<? extends Image>> images) { @Memoized Supplier<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client");
this.findLocationForServerDetails = checkNotNull(findLocationForServerDetails, "findLocationForServerDetails"); this.findLocationForServerDetails = checkNotNull(findLocationForServerDetails, "findLocationForServerDetails");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
} }
@ -105,15 +101,14 @@ public class ServerDetailsToNodeMetadata implements Function<ServerDetails, Node
builder.hostname(from.getHostname()); builder.hostname(from.getHostname());
Location location = findLocationForServerDetails.apply(from); Location location = findLocationForServerDetails.apply(from);
assert (location != null) : String.format("no location matched ServerDetails %s", from); assert (location != null) : String.format("no location matched ServerDetails %s", from);
builder.group(parseGroupFromName(from.getHostname())); builder.group(parseGroupFromName(from.getDescription()));
builder.imageId(from.getTemplateName() + ""); builder.imageId(from.getTemplateName() + "");
builder.operatingSystem(parseOperatingSystem(from)); builder.operatingSystem(parseOperatingSystem(from));
builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB()).processors( builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB())
ImmutableList.of(new Processor(from.getCpuCores(), 1.0))).volumes( .processors(ImmutableList.of(new Processor(from.getCpuCores(), 1.0)))
ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true))).hypervisor( .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true)))
from.getPlatform()).build()); .hypervisor(from.getPlatform()).build());
builder.state(serverStateToNodeState.get(client.getServerClient().getServerStatus(from.getId(), builder.state(from.getState() != null ? serverStateToNodeState.get(from.getState()) : NodeState.UNRECOGNIZED);
ServerStatusOptions.Builder.state()).getState()));
Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() { Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() {
@Override @Override

View File

@ -38,6 +38,7 @@ public class ServerDetails extends Server {
} }
public static class Builder extends Server.Builder { public static class Builder extends Server.Builder {
private Server.State state;
private String description; private String description;
private String templateName; private String templateName;
private int cpuCores; private int cpuCores;
@ -47,6 +48,11 @@ public class ServerDetails extends Server {
private Cost cost; private Cost cost;
private Set<Ip> ips = ImmutableSet.of(); private Set<Ip> ips = ImmutableSet.of();
public Builder state(Server.State state) {
this.state = state;
return this;
}
public Builder description(String description) { public Builder description(String description) {
this.description = description; this.description = description;
return this; return this;
@ -92,11 +98,13 @@ public class ServerDetails extends Server {
} }
public ServerDetails build() { public ServerDetails build() {
return new ServerDetails(id, hostname, datacenter, platform, templateName, description, cpuCores, memorySizeMB, diskSizeGB, transferGB, cost, ips); return new ServerDetails(id, hostname, datacenter, platform, state, templateName, description, cpuCores,
memorySizeMB, diskSizeGB, transferGB, cost, ips);
} }
public Builder fromServerDetails(ServerDetails in) { public Builder fromServerDetails(ServerDetails in) {
return fromServer(in).templateName(in.getTemplateName()).memorySizeMB(in.getMemorySizeMB()).diskSizeGB(in.getDiskSizeGB()).cpuCores(in.getCpuCores()).cost(in.getCost()) return fromServer(in).templateName(in.getTemplateName()).state(in.getState()).memorySizeMB(in.getMemorySizeMB())
.diskSizeGB(in.getDiskSizeGB()).cpuCores(in.getCpuCores()).cost(in.getCost())
.transferGB(in.getTransferGB()).description(in.getDescription()).ips(in.getIps()); .transferGB(in.getTransferGB()).description(in.getDescription()).ips(in.getIps());
} }
@ -126,6 +134,7 @@ public class ServerDetails extends Server {
} }
} }
private final Server.State state;
private final String description; private final String description;
@SerializedName("templatename") @SerializedName("templatename")
private final String templateName; private final String templateName;
@ -141,9 +150,11 @@ public class ServerDetails extends Server {
@SerializedName("iplist") @SerializedName("iplist")
private final Set<Ip> ips; private final Set<Ip> ips;
public ServerDetails(String id, String hostname, String datacenter, String platform, String templateName, public ServerDetails(String id, String hostname, String datacenter, String platform, Server.State state,
String description, int cpuCores, int memorySizeMB, int diskSizeGB, int transferGB, Cost cost, Set<Ip> ips) { String templateName, String description, int cpuCores, int memorySizeMB, int diskSizeGB, int transferGB,
Cost cost, Set<Ip> ips) {
super(id, hostname, datacenter, platform); super(id, hostname, datacenter, platform);
this.state = state;
this.templateName = checkNotNull(templateName, "template"); this.templateName = checkNotNull(templateName, "template");
this.description = description; this.description = description;
this.cpuCores = cpuCores; this.cpuCores = cpuCores;
@ -151,7 +162,14 @@ public class ServerDetails extends Server {
this.diskSizeGB = diskSizeGB; this.diskSizeGB = diskSizeGB;
this.transferGB = transferGB; this.transferGB = transferGB;
this.cost = checkNotNull(cost, "cost"); this.cost = checkNotNull(cost, "cost");
this.ips = ImmutableSet.<Ip>copyOf(ips); this.ips = ImmutableSet.<Ip> copyOf(ips);
}
/**
* @return the state of the server (e.g. "running")
*/
public Server.State getState() {
return state;
} }
/** /**
@ -212,9 +230,11 @@ public class ServerDetails extends Server {
@Override @Override
public String toString() { public String toString() {
return String.format( return String
"[id=%s, hostname=%s, datacenter=%s, platform=%s, templateName=%s, description=%s, cpuCores=%d, memorySizeMB=%d, diskSizeGB=%d, transferGB=%d, cost=%s, ips=%s]", id, .format(
hostname, datacenter, platform, templateName, description, cpuCores, memorySizeMB, diskSizeGB, transferGB, cost, ips); "[id=%s, hostname=%s, datacenter=%s, platform=%s, templateName=%s, state=%s, description=%s, cpuCores=%d, memorySizeMB=%d, diskSizeGB=%d, transferGB=%d, cost=%s, ips=%s]",
id, hostname, datacenter, platform, templateName, state, description, cpuCores, memorySizeMB,
diskSizeGB, transferGB, cost, ips);
} }
} }

View File

@ -186,7 +186,7 @@ public class ServerSpec {
@Override @Override
public String toString() { public String toString() {
return toStringHelper("").add("platform", platform).add("datacenter", datacenter) return toStringHelper("").add("platform", platform).add("datacenter", datacenter)
.add("templateName", templateName).add("cpuCores", cpuCores).add("cpuCores", cpuCores) .add("templateName", templateName).add("cpuCores", cpuCores).add("memorySizeMB", memorySizeMB)
.add("diskSizeGB", diskSizeGB).add("transferGB", transferGB).toString(); .add("diskSizeGB", diskSizeGB).add("transferGB", transferGB).toString();
} }
} }

View File

@ -85,6 +85,7 @@ public interface ServerAsyncClient {
@Path("/server/details/format/json") @Path("/server/details/format/json")
@SelectJson("server") @SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@FormParams(keys = "includestate", values = "true")
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ServerDetails> getServerDetails(@FormParam("serverid") String id); ListenableFuture<ServerDetails> getServerDetails(@FormParam("serverid") String id);

View File

@ -166,6 +166,7 @@ public interface ServerClient {
* @param options * @param options
* optional settings ex. description * optional settings ex. description
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
ServerDetails createServerWithHostnameAndRootPassword(ServerSpec serverSpec, String hostname, String rootPassword, ServerDetails createServerWithHostnameAndRootPassword(ServerSpec serverSpec, String hostname, String rootPassword,
CreateServerOptions... options); CreateServerOptions... options);
@ -189,6 +190,7 @@ public interface ServerClient {
* @param options * @param options
* the settings to change * the settings to change
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
ServerDetails cloneServer(String serverid, String hostname, CloneServerOptions... options); ServerDetails cloneServer(String serverid, String hostname, CloneServerOptions... options);
/** /**

View File

@ -56,15 +56,12 @@ public class GleSYSErrorHandler implements HttpErrorHandler {
exception = new AuthorizationException(message, exception); exception = new AuthorizationException(message, exception);
break; break;
case 400: case 400:
if (command.getCurrentRequest().getEndpoint().getPath().indexOf("delete") != -1 if (message.indexOf("Could not find") != -1) {
&& message.indexOf("Could not find") != -1) {
exception = new ResourceNotFoundException(message, exception); exception = new ResourceNotFoundException(message, exception);
} }
break; break;
case 404: case 404:
if (command.getCurrentRequest().getEndpoint().getPath().indexOf("delete") == -1) {
exception = new ResourceNotFoundException(message, exception); exception = new ResourceNotFoundException(message, exception);
}
break; break;
} }
} finally { } finally {

View File

@ -18,11 +18,14 @@
*/ */
package org.jclouds.glesys.options; package org.jclouds.glesys.options;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.instanceOf; import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Multimaps.forMap;
import java.util.Map; import java.util.Map;
@ -32,8 +35,8 @@ import org.jclouds.io.payloads.UrlEncodedFormPayload;
import org.jclouds.rest.MapBinder; import org.jclouds.rest.MapBinder;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimaps;
/** /**
* @author Adam Lowe * @author Adam Lowe
@ -51,7 +54,7 @@ public class CreateServerOptions implements MapBinder {
checkState(gRequest.getArgs() != null, "args should be initialized at this point"); checkState(gRequest.getArgs() != null, "args should be initialized at this point");
ImmutableMultimap.Builder<String, String> formParams = ImmutableMultimap.<String, String> builder(); ImmutableMultimap.Builder<String, String> formParams = ImmutableMultimap.<String, String> builder();
formParams.putAll(Multimaps.forMap(postParams)); formParams.putAll(forMap(postParams));
ServerSpec serverSpec = ServerSpec.class.cast(find(gRequest.getArgs(), instanceOf(ServerSpec.class))); ServerSpec serverSpec = ServerSpec.class.cast(find(gRequest.getArgs(), instanceOf(ServerSpec.class)));
formParams.put("datacenter", serverSpec.getDatacenter()); formParams.put("datacenter", serverSpec.getDatacenter());
formParams.put("platform", serverSpec.getPlatform()); formParams.put("platform", serverSpec.getPlatform());
@ -109,4 +112,25 @@ public class CreateServerOptions implements MapBinder {
public <R extends HttpRequest> R bindToRequest(R request, Object input) { public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@Override
public int hashCode() {
return Objects.hashCode(ip, description);
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (!(obj instanceof CreateServerOptions))
return false;
CreateServerOptions that = CreateServerOptions.class.cast(obj);
return equal(this.ip, that.ip) && equal(this.description, that.description);
}
@Override
public String toString() {
return toStringHelper("").add("ip", ip).add("description", description).toString();
}
} }

View File

@ -50,7 +50,6 @@ public class GleSYSErrorHandlerTest {
public void test401MakesAuthorizationException() { public void test401MakesAuthorizationException() {
assertCodeMakes("GET", URI.create("https://api.glesys.com/foo"), 401, "", "Unauthorized", assertCodeMakes("GET", URI.create("https://api.glesys.com/foo"), 401, "", "Unauthorized",
AuthorizationException.class); AuthorizationException.class);
} }
@Test @Test
@ -60,7 +59,7 @@ public class GleSYSErrorHandlerTest {
URI.create("https://api.glesys.com/domain/delete/format/json"), URI.create("https://api.glesys.com/domain/delete/format/json"),
400, 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\"}}}}", "{\"response\":{\"status\":{\"code\":400,\"timestamp\":\"2012-02-10T12:07:56+01:00\",\"text\":\"Could not find server with this id on this account.\n\"},\"debug\":{\"input\":{\"domainname\":\"email-test.jclouds.org\"}}}}",
ResourceNotFoundException.class); ResourceNotFoundException.class);
} }

View File

@ -40,6 +40,8 @@ import com.google.inject.Module;
public class GleSYSComputeServiceLiveTest extends BaseComputeServiceLiveTest { public class GleSYSComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public GleSYSComputeServiceLiveTest() { public GleSYSComputeServiceLiveTest() {
provider = "glesys"; provider = "glesys";
// ensure hyphens work
group = "gle-sys";
} }
@Override @Override
@ -49,8 +51,8 @@ public class GleSYSComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public void testAssignability() throws Exception { public void testAssignability() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
RestContext<GleSYSClient, GleSYSAsyncClient> tmContext = new ComputeServiceContextFactory() RestContext<GleSYSClient, GleSYSAsyncClient> tmContext = new ComputeServiceContextFactory().createContext(
.createContext(provider, identity, credential).getProviderSpecificContext(); provider, identity, credential).getProviderSpecificContext();
} }
// GleSYS does not support metadata // GleSYS does not support metadata

View File

@ -18,12 +18,13 @@
*/ */
package org.jclouds.glesys.features; package org.jclouds.glesys.features;
import com.google.common.collect.ImmutableMultimap; import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
import com.google.common.collect.ImmutableSet; import static org.testng.Assert.assertEquals;
import com.google.common.collect.ImmutableSortedSet; import static org.testng.Assert.assertTrue;
import com.google.common.collect.Iterables;
import com.google.inject.Inject; import java.net.URI;
import org.apache.log4j.helpers.ISO8601DateFormat; import java.util.Set;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.glesys.GleSYSClient; import org.jclouds.glesys.GleSYSClient;
@ -32,18 +33,13 @@ import org.jclouds.glesys.domain.DomainRecord;
import org.jclouds.glesys.options.AddDomainOptions; import org.jclouds.glesys.options.AddDomainOptions;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.rest.BaseRestClientExpectTest;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.net.URI; import com.google.common.collect.ImmutableMultimap;
import java.text.SimpleDateFormat; import com.google.common.collect.ImmutableSortedSet;
import java.util.Set; import com.google.common.collect.Iterables;
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
/** /**
* Tests annotation parsing of {@code DomainAsyncClient} * Tests annotation parsing of {@code DomainAsyncClient}

View File

@ -146,6 +146,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
.put("Accept", "application/json") .put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder() .payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("includestate", "true")
.put("serverid", "xm3276891").build())).build(), .put("serverid", "xm3276891").build())).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerClient(); HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerClient();
@ -169,6 +170,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
.put("Accept", "application/json") .put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder() .payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("includestate", "true")
.put("serverid", "xm3276891").build())).build(), .put("serverid", "xm3276891").build())).build(),
HttpResponse.builder().statusCode(404).build()).getServerClient(); HttpResponse.builder().statusCode(404).build()).getServerClient();

View File

@ -23,6 +23,7 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.BaseVersionedServiceLiveTest;
@ -67,9 +68,8 @@ public class BaseGleSYSClientLiveTest extends BaseVersionedServiceLiveTest {
public void setupClient() { public void setupClient() {
setupCredentials(); setupCredentials();
computeContext = new ComputeServiceContextFactory(setupRestProperties()). computeContext = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
createContext(provider, ImmutableSet.<Module> of( ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()), setupProperties());
new Log4JLoggingModule(), new SshjSshClientModule()), setupProperties());
context = computeContext.getProviderSpecificContext(); context = computeContext.getProviderSpecificContext();
} }
@ -85,8 +85,7 @@ public class BaseGleSYSClientLiveTest extends BaseVersionedServiceLiveTest {
final DomainClient client = context.getApi().getDomainClient(); final DomainClient client = context.getApi().getDomainClient();
int before = client.listDomains().size(); int before = client.listDomains().size();
client.addDomain(domain); client.addDomain(domain);
RetryablePredicate<Integer> result = new RetryablePredicate<Integer>( RetryablePredicate<Integer> result = new RetryablePredicate<Integer>(new Predicate<Integer>() {
new Predicate<Integer>() {
public boolean apply(Integer value) { public boolean apply(Integer value) {
return client.listDomains().size() == value; return client.listDomains().size() == value;
} }
@ -95,19 +94,20 @@ public class BaseGleSYSClientLiveTest extends BaseVersionedServiceLiveTest {
assertTrue(result.apply(before + 1)); assertTrue(result.apply(before + 1));
} }
protected ServerStatusChecker createServer(String hostName) { protected ServerStatusChecker createServer(String hostName) {
ServerClient client = context.getApi().getServerClient(); ServerClient client = context.getApi().getServerClient();
ServerDetails testServer = client.createServerWithHostnameAndRootPassword( ServerDetails testServer = client.createServerWithHostnameAndRootPassword(
ServerSpec.builder().datacenter("Falkenberg").platform("OpenVZ").templateName("Ubuntu 10.04 LTS 32-bit") ServerSpec.builder().datacenter("Falkenberg").platform("OpenVZ").templateName("Ubuntu 10.04 LTS 32-bit")
.diskSizeGB(5).memorySizeMB(512).cpuCores(1).transferGB(50).build(), hostName, "password"); .diskSizeGB(5).memorySizeMB(512).cpuCores(1).transferGB(50).build(), hostName, UUID.randomUUID()
.toString().replace("-",""));
assertNotNull(testServer.getId()); assertNotNull(testServer.getId());
assertEquals(testServer.getHostname(), hostName); assertEquals(testServer.getHostname(), hostName);
assertFalse(testServer.getIps().isEmpty()); assertFalse(testServer.getIps().isEmpty());
ServerStatusChecker runningServerCounter = new ServerStatusChecker(client, testServer.getId(), 180, 10, TimeUnit.SECONDS); ServerStatusChecker runningServerCounter = new ServerStatusChecker(client, testServer.getId(), 180, 10,
TimeUnit.SECONDS);
assertTrue(runningServerCounter.apply(Server.State.RUNNING)); assertTrue(runningServerCounter.apply(Server.State.RUNNING));
return runningServerCounter; return runningServerCounter;
@ -115,10 +115,13 @@ public class BaseGleSYSClientLiveTest extends BaseVersionedServiceLiveTest {
public static class ServerStatusChecker extends RetryablePredicate<Server.State> { public static class ServerStatusChecker extends RetryablePredicate<Server.State> {
private final String serverId; private final String serverId;
public String getServerId() { public String getServerId() {
return serverId; return serverId;
} }
public ServerStatusChecker(final ServerClient client, final String serverId, long maxWait, long period, TimeUnit unit) {
public ServerStatusChecker(final ServerClient client, final String serverId, long maxWait, long period,
TimeUnit unit) {
super(new Predicate<Server.State>() { super(new Predicate<Server.State>() {
public boolean apply(Server.State value) { public boolean apply(Server.State value) {

Some files were not shown because too many files have changed in this diff Show More