mirror of https://github.com/apache/jclouds.git
merged glesys changes
This commit is contained in:
parent
1b57270ad4
commit
2cad1dc7b6
|
@ -27,26 +27,12 @@
|
|||
<version>1.4.0-SNAPSHOT</version>
|
||||
<relativePath>../../project/pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>org.jclouds.provider</groupId>
|
||||
<groupId>org.jclouds.labs</groupId>
|
||||
<artifactId>glesys</artifactId>
|
||||
<name>jclouds GleSYS core</name>
|
||||
<description>jclouds components to access GleSYS</description>
|
||||
<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>
|
||||
<test.glesys.endpoint>https://api.glesys.com</test.glesys.endpoint>
|
||||
<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.authenticate-sudo></test.glesys.image.authenticate-sudo>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
|
@ -48,6 +48,8 @@ public class GleSYSPropertiesBuilder extends PropertiesBuilder {
|
|||
properties.setProperty(PROPERTY_ZONE + ".Falkenberg." + ISO3166_CODES, "SE-N");
|
||||
properties.setProperty(PROPERTY_ZONE + ".New York City." + ISO3166_CODES, "US-NY");
|
||||
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");
|
||||
return properties;
|
||||
}
|
|
@ -20,9 +20,12 @@ package org.jclouds.glesys.compute;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
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.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
@ -30,6 +33,7 @@ import javax.inject.Named;
|
|||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.collect.FindResourceInSet;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
|
@ -44,10 +48,12 @@ import org.jclouds.compute.predicates.ImagePredicates;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.glesys.GleSYSAsyncClient;
|
||||
import org.jclouds.glesys.GleSYSClient;
|
||||
import org.jclouds.glesys.compute.options.GleSYSTemplateOptions;
|
||||
import org.jclouds.glesys.domain.AllowedArgumentsForCreateServer;
|
||||
import org.jclouds.glesys.domain.OSTemplate;
|
||||
import org.jclouds.glesys.domain.Server;
|
||||
import org.jclouds.glesys.domain.ServerDetails;
|
||||
import org.jclouds.glesys.domain.ServerSpec;
|
||||
import org.jclouds.glesys.options.CreateServerOptions;
|
||||
|
@ -62,8 +68,8 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* defines the connection between the {@link GleSYSClient} implementation and the jclouds
|
||||
* {@link ComputeService}
|
||||
* defines the connection between the {@link GleSYSClient} implementation and
|
||||
* the jclouds {@link ComputeService}
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
|
@ -74,32 +80,37 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
|
|||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final GleSYSClient client;
|
||||
private final GleSYSAsyncClient aclient;
|
||||
private final ExecutorService userThreads;
|
||||
private final Supplier<Set<? extends Location>> locations;
|
||||
private final Provider<String> passwordProvider;
|
||||
|
||||
@Inject
|
||||
public GleSYSComputeServiceAdapter(GleSYSClient client, @Memoized Supplier<Set<? extends Location>> locations,
|
||||
@Named("PASSWORD") Provider<String> passwordProvider) {
|
||||
public GleSYSComputeServiceAdapter(GleSYSClient client, GleSYSAsyncClient aclient,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, @Named("PASSWORD") Provider<String> passwordProvider) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.aclient = checkNotNull(aclient, "aclient");
|
||||
this.userThreads = checkNotNull(userThreads, "userThreads");
|
||||
this.locations = checkNotNull(locations, "locations");
|
||||
this.passwordProvider = checkNotNull(passwordProvider, "passwordProvider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeAndInitialCredentials<ServerDetails> createNodeWithGroupEncodedIntoName(String group, String name,
|
||||
Template template) {
|
||||
Template template) {
|
||||
checkNotNull(template, "template was null");
|
||||
checkNotNull(template.getOptions(), "template options was null");
|
||||
checkArgument(template.getOptions().getClass().isAssignableFrom(GleSYSTemplateOptions.class),
|
||||
"options class %s should have been assignable from GleSYSTemplateOptions", template.getOptions()
|
||||
.getClass());
|
||||
"options class %s should have been assignable from GleSYSTemplateOptions", template.getOptions().getClass());
|
||||
|
||||
GleSYSTemplateOptions templateOptions = template.getOptions().as(GleSYSTemplateOptions.class);
|
||||
|
||||
CreateServerOptions createServerOptions = new CreateServerOptions();
|
||||
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();
|
||||
builder.datacenter(template.getLocation().getId());
|
||||
|
@ -111,15 +122,16 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
|
|||
builder.transferGB(50);// TODO: add to template options with default value
|
||||
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);
|
||||
ServerDetails result = client.getServerClient().createServerWithHostnameAndRootPassword(spec, name, password,
|
||||
createServerOptions);
|
||||
createServerOptions);
|
||||
logger.trace("<< ServerDetails(%s)", result.getId());
|
||||
|
||||
return new NodeAndInitialCredentials<ServerDetails>(result, result.getId() + "", LoginCredentials.builder()
|
||||
.password(password).build());
|
||||
.password(password).build());
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -145,7 +157,7 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
|
|||
Set<OSTemplate> images = listImages();
|
||||
|
||||
for (Entry<String, AllowedArgumentsForCreateServer> platformToArgs : client.getServerClient()
|
||||
.getAllowedArgumentsForCreateServerByPlatform().entrySet())
|
||||
.getAllowedArgumentsForCreateServerByPlatform().entrySet())
|
||||
for (String datacenter : platformToArgs.getValue().getDataCenters())
|
||||
for (int diskSizeGB : platformToArgs.getValue().getDiskSizesInGB())
|
||||
for (int cpuCores : platformToArgs.getValue().getCpuCoreOptions())
|
||||
|
@ -157,14 +169,15 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
|
|||
}
|
||||
ImmutableSet<String> templatesSupported = templatesSupportedBuilder.build();
|
||||
if (templatesSupported.size() > 0)
|
||||
hardwareToReturn.add(new HardwareBuilder().ids(
|
||||
String.format("datacenter(%s)platform(%s)cpuCores(%d)memorySizeMB(%d)diskSizeGB(%d)",
|
||||
datacenter, platformToArgs.getKey(), cpuCores, memorySizeMB, diskSizeGB)).ram(
|
||||
memorySizeMB).processors(ImmutableList.of(new Processor(cpuCores, 1.0))).volumes(
|
||||
ImmutableList.<Volume> of(new VolumeImpl((float) diskSizeGB, true, true))).hypervisor(
|
||||
platformToArgs.getKey()).location(
|
||||
Iterables.find(locationsSet, LocationPredicates.idEquals(datacenter))).supportsImage(
|
||||
ImagePredicates.idIn(templatesSupported)).build());
|
||||
hardwareToReturn.add(new HardwareBuilder()
|
||||
.ids(String.format(
|
||||
"datacenter(%s)platform(%s)cpuCores(%d)memorySizeMB(%d)diskSizeGB(%d)", datacenter,
|
||||
platformToArgs.getKey(), cpuCores, memorySizeMB, diskSizeGB)).ram(memorySizeMB)
|
||||
.processors(ImmutableList.of(new Processor(cpuCores, 1.0)))
|
||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) diskSizeGB, true, true)))
|
||||
.hypervisor(platformToArgs.getKey())
|
||||
.location(Iterables.find(locationsSet, LocationPredicates.idEquals(datacenter)))
|
||||
.supportsImage(ImagePredicates.idIn(templatesSupported)).build());
|
||||
}
|
||||
|
||||
return hardwareToReturn.build();
|
||||
|
@ -177,21 +190,27 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
|
|||
|
||||
@Override
|
||||
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
|
||||
public Set<String> listLocations() {
|
||||
return ImmutableSet.copyOf(Iterables.concat(Iterables.transform(client.getServerClient()
|
||||
.getAllowedArgumentsForCreateServerByPlatform().values(),
|
||||
new Function<AllowedArgumentsForCreateServer, Set<String>>() {
|
||||
.getAllowedArgumentsForCreateServerByPlatform().values(),
|
||||
new Function<AllowedArgumentsForCreateServer, Set<String>>() {
|
||||
|
||||
@Override
|
||||
public Set<String> apply(AllowedArgumentsForCreateServer arg0) {
|
||||
return arg0.getDataCenters();
|
||||
}
|
||||
@Override
|
||||
public Set<String> apply(AllowedArgumentsForCreateServer arg0) {
|
||||
return arg0.getDataCenters();
|
||||
}
|
||||
|
||||
})));
|
||||
})));
|
||||
}
|
||||
|
||||
@Override
|
|
@ -18,9 +18,8 @@
|
|||
*/
|
||||
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.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -64,7 +63,7 @@ public class GleSYSComputeServiceContextModule
|
|||
super(GleSYSClient.class, GleSYSAsyncClient.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
|
@ -95,16 +94,11 @@ public class GleSYSComputeServiceContextModule
|
|||
@Named("PASSWORD")
|
||||
@Singleton
|
||||
public static class PasswordProvider implements Provider<String> {
|
||||
private final SecureRandom random;
|
||||
|
||||
@Inject
|
||||
protected PasswordProvider() {
|
||||
this.random = new SecureRandom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return random.nextLong() + "";
|
||||
return UUID.randomUUID().toString().replace("-","");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -43,10 +43,8 @@ import org.jclouds.compute.domain.Volume;
|
|||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.glesys.GleSYSClient;
|
||||
import org.jclouds.glesys.domain.Ip;
|
||||
import org.jclouds.glesys.domain.ServerDetails;
|
||||
import org.jclouds.glesys.options.ServerStatusOptions;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
|
||||
|
||||
|
@ -68,12 +66,11 @@ public class ServerDetailsToNodeMetadata implements Function<ServerDetails, Node
|
|||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
public static final Map<ServerDetails.State, NodeState> serverStateToNodeState = ImmutableMap
|
||||
.<ServerDetails.State, NodeState> builder().put(ServerDetails.State.STOPPED, NodeState.SUSPENDED).put(
|
||||
ServerDetails.State.RUNNING, NodeState.RUNNING).put(ServerDetails.State.UNRECOGNIZED,
|
||||
NodeState.UNRECOGNIZED).build();
|
||||
.<ServerDetails.State, NodeState> builder().put(ServerDetails.State.STOPPED, NodeState.SUSPENDED)
|
||||
.put(ServerDetails.State.RUNNING, NodeState.RUNNING)
|
||||
.put(ServerDetails.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).build();
|
||||
|
||||
protected final Supplier<Set<? extends Image>> images;
|
||||
protected final GleSYSClient client;
|
||||
protected final FindLocationForServerDetails findLocationForServerDetails;
|
||||
|
||||
private static class FindImageForServer implements Predicate<Image> {
|
||||
|
@ -90,9 +87,8 @@ public class ServerDetailsToNodeMetadata implements Function<ServerDetails, Node
|
|||
}
|
||||
|
||||
@Inject
|
||||
ServerDetailsToNodeMetadata(GleSYSClient client, FindLocationForServerDetails findLocationForServerDetails,
|
||||
@Memoized Supplier<Set<? extends Image>> images) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
ServerDetailsToNodeMetadata(FindLocationForServerDetails findLocationForServerDetails,
|
||||
@Memoized Supplier<Set<? extends Image>> images) {
|
||||
this.findLocationForServerDetails = checkNotNull(findLocationForServerDetails, "findLocationForServerDetails");
|
||||
this.images = checkNotNull(images, "images");
|
||||
}
|
||||
|
@ -105,15 +101,14 @@ public class ServerDetailsToNodeMetadata implements Function<ServerDetails, Node
|
|||
builder.hostname(from.getHostname());
|
||||
Location location = findLocationForServerDetails.apply(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.operatingSystem(parseOperatingSystem(from));
|
||||
builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB()).processors(
|
||||
ImmutableList.of(new Processor(from.getCpuCores(), 1.0))).volumes(
|
||||
ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true))).hypervisor(
|
||||
from.getPlatform()).build());
|
||||
builder.state(serverStateToNodeState.get(client.getServerClient().getServerStatus(from.getId(),
|
||||
ServerStatusOptions.Builder.state()).getState()));
|
||||
builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB())
|
||||
.processors(ImmutableList.of(new Processor(from.getCpuCores(), 1.0)))
|
||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSizeGB(), true, true)))
|
||||
.hypervisor(from.getPlatform()).build());
|
||||
builder.state(from.getState() != null ? serverStateToNodeState.get(from.getState()) : NodeState.UNRECOGNIZED);
|
||||
Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() {
|
||||
|
||||
@Override
|
|
@ -38,6 +38,7 @@ public class ServerDetails extends Server {
|
|||
}
|
||||
|
||||
public static class Builder extends Server.Builder {
|
||||
private Server.State state;
|
||||
private String description;
|
||||
private String templateName;
|
||||
private int cpuCores;
|
||||
|
@ -47,6 +48,11 @@ public class ServerDetails extends Server {
|
|||
private Cost cost;
|
||||
private Set<Ip> ips = ImmutableSet.of();
|
||||
|
||||
public Builder state(Server.State state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
|
@ -92,11 +98,13 @@ public class ServerDetails extends Server {
|
|||
}
|
||||
|
||||
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) {
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -126,6 +134,7 @@ public class ServerDetails extends Server {
|
|||
}
|
||||
}
|
||||
|
||||
private final Server.State state;
|
||||
private final String description;
|
||||
@SerializedName("templatename")
|
||||
private final String templateName;
|
||||
|
@ -141,9 +150,11 @@ public class ServerDetails extends Server {
|
|||
@SerializedName("iplist")
|
||||
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, Set<Ip> ips) {
|
||||
public ServerDetails(String id, String hostname, String datacenter, String platform, Server.State state,
|
||||
String templateName, String description, int cpuCores, int memorySizeMB, int diskSizeGB, int transferGB,
|
||||
Cost cost, Set<Ip> ips) {
|
||||
super(id, hostname, datacenter, platform);
|
||||
this.state = state;
|
||||
this.templateName = checkNotNull(templateName, "template");
|
||||
this.description = description;
|
||||
this.cpuCores = cpuCores;
|
||||
|
@ -151,7 +162,14 @@ public class ServerDetails extends Server {
|
|||
this.diskSizeGB = diskSizeGB;
|
||||
this.transferGB = transferGB;
|
||||
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
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"[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,
|
||||
hostname, datacenter, platform, templateName, description, cpuCores, memorySizeMB, diskSizeGB, transferGB, cost, ips);
|
||||
return String
|
||||
.format(
|
||||
"[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);
|
||||
}
|
||||
|
||||
}
|
|
@ -186,7 +186,7 @@ public class ServerSpec {
|
|||
@Override
|
||||
public String toString() {
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -85,6 +85,7 @@ public interface ServerAsyncClient {
|
|||
@Path("/server/details/format/json")
|
||||
@SelectJson("server")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@FormParams(keys = "includestate", values = "true")
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<ServerDetails> getServerDetails(@FormParam("serverid") String id);
|
||||
|
|
@ -166,6 +166,7 @@ public interface ServerClient {
|
|||
* @param options
|
||||
* optional settings ex. description
|
||||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
ServerDetails createServerWithHostnameAndRootPassword(ServerSpec serverSpec, String hostname, String rootPassword,
|
||||
CreateServerOptions... options);
|
||||
|
||||
|
@ -189,6 +190,7 @@ public interface ServerClient {
|
|||
* @param options
|
||||
* the settings to change
|
||||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
ServerDetails cloneServer(String serverid, String hostname, CloneServerOptions... options);
|
||||
|
||||
/**
|
|
@ -56,15 +56,12 @@ public class GleSYSErrorHandler implements HttpErrorHandler {
|
|||
exception = new AuthorizationException(message, exception);
|
||||
break;
|
||||
case 400:
|
||||
if (command.getCurrentRequest().getEndpoint().getPath().indexOf("delete") != -1
|
||||
&& message.indexOf("Could not find") != -1) {
|
||||
if (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);
|
||||
}
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
break;
|
||||
}
|
||||
} finally {
|
|
@ -18,11 +18,14 @@
|
|||
*/
|
||||
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.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Predicates.instanceOf;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Multimaps.forMap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -32,8 +35,8 @@ import org.jclouds.io.payloads.UrlEncodedFormPayload;
|
|||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
|
||||
/**
|
||||
* @author Adam Lowe
|
||||
|
@ -51,7 +54,7 @@ public class CreateServerOptions implements MapBinder {
|
|||
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
|
||||
|
||||
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)));
|
||||
formParams.put("datacenter", serverSpec.getDatacenter());
|
||||
formParams.put("platform", serverSpec.getPlatform());
|
||||
|
@ -109,4 +112,25 @@ public class CreateServerOptions implements MapBinder {
|
|||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
|
@ -50,7 +50,6 @@ public class GleSYSErrorHandlerTest {
|
|||
public void test401MakesAuthorizationException() {
|
||||
assertCodeMakes("GET", URI.create("https://api.glesys.com/foo"), 401, "", "Unauthorized",
|
||||
AuthorizationException.class);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -60,7 +59,7 @@ public class GleSYSErrorHandlerTest {
|
|||
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\"}}}}",
|
||||
"{\"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);
|
||||
}
|
||||
|
|
@ -40,6 +40,8 @@ import com.google.inject.Module;
|
|||
public class GleSYSComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||
public GleSYSComputeServiceLiveTest() {
|
||||
provider = "glesys";
|
||||
// ensure hyphens work
|
||||
group = "gle-sys";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,8 +51,8 @@ public class GleSYSComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
|
||||
public void testAssignability() throws Exception {
|
||||
@SuppressWarnings("unused")
|
||||
RestContext<GleSYSClient, GleSYSAsyncClient> tmContext = new ComputeServiceContextFactory()
|
||||
.createContext(provider, identity, credential).getProviderSpecificContext();
|
||||
RestContext<GleSYSClient, GleSYSAsyncClient> tmContext = new ComputeServiceContextFactory().createContext(
|
||||
provider, identity, credential).getProviderSpecificContext();
|
||||
}
|
||||
|
||||
// GleSYS does not support metadata
|
|
@ -18,12 +18,13 @@
|
|||
*/
|
||||
package org.jclouds.glesys.features;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.log4j.helpers.ISO8601DateFormat;
|
||||
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.glesys.GleSYSClient;
|
||||
|
@ -32,18 +33,13 @@ import org.jclouds.glesys.domain.DomainRecord;
|
|||
import org.jclouds.glesys.options.AddDomainOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.BaseRestClientExpectTest;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code DomainAsyncClient}
|
|
@ -146,6 +146,7 @@ public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClien
|
|||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("includestate", "true")
|
||||
.put("serverid", "xm3276891").build())).build(),
|
||||
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("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("includestate", "true")
|
||||
.put("serverid", "xm3276891").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getServerClient();
|
||||
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.assertFalse;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.compute.BaseVersionedServiceLiveTest;
|
||||
|
@ -67,9 +68,8 @@ public class BaseGleSYSClientLiveTest extends BaseVersionedServiceLiveTest {
|
|||
public void setupClient() {
|
||||
setupCredentials();
|
||||
|
||||
computeContext = new ComputeServiceContextFactory(setupRestProperties()).
|
||||
createContext(provider, ImmutableSet.<Module> of(
|
||||
new Log4JLoggingModule(), new SshjSshClientModule()), setupProperties());
|
||||
computeContext = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()), setupProperties());
|
||||
context = computeContext.getProviderSpecificContext();
|
||||
}
|
||||
|
||||
|
@ -85,29 +85,29 @@ public class BaseGleSYSClientLiveTest extends BaseVersionedServiceLiveTest {
|
|||
final DomainClient client = context.getApi().getDomainClient();
|
||||
int before = client.listDomains().size();
|
||||
client.addDomain(domain);
|
||||
RetryablePredicate<Integer> result = new RetryablePredicate<Integer>(
|
||||
new Predicate<Integer>() {
|
||||
public boolean apply(Integer value) {
|
||||
return client.listDomains().size() == value;
|
||||
}
|
||||
}, 30, 1, TimeUnit.SECONDS);
|
||||
RetryablePredicate<Integer> result = new RetryablePredicate<Integer>(new Predicate<Integer>() {
|
||||
public boolean apply(Integer value) {
|
||||
return client.listDomains().size() == value;
|
||||
}
|
||||
}, 30, 1, TimeUnit.SECONDS);
|
||||
|
||||
assertTrue(result.apply(before + 1));
|
||||
}
|
||||
|
||||
|
||||
protected ServerStatusChecker createServer(String hostName) {
|
||||
ServerClient client = context.getApi().getServerClient();
|
||||
|
||||
ServerDetails testServer = client.createServerWithHostnameAndRootPassword(
|
||||
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());
|
||||
assertEquals(testServer.getHostname(), hostName);
|
||||
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));
|
||||
return runningServerCounter;
|
||||
|
@ -115,10 +115,13 @@ public class BaseGleSYSClientLiveTest extends BaseVersionedServiceLiveTest {
|
|||
|
||||
public static class ServerStatusChecker extends RetryablePredicate<Server.State> {
|
||||
private final String serverId;
|
||||
|
||||
public String getServerId() {
|
||||
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>() {
|
||||
|
||||
public boolean apply(Server.State value) {
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue