diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java b/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java index c5854f0b21..3dad6cfb97 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java @@ -46,6 +46,7 @@ import org.jclouds.compute.domain.Volume; import org.jclouds.compute.domain.internal.VolumeImpl; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.domain.Location; import org.jclouds.domain.LoginCredentials; import org.jclouds.glesys.GleSYSAsyncClient; @@ -60,8 +61,10 @@ import org.jclouds.glesys.options.CreateServerOptions; import org.jclouds.glesys.options.DestroyServerOptions; import org.jclouds.location.predicates.LocationPredicates; import org.jclouds.logging.Logger; +import org.jclouds.predicates.RetryablePredicate; import com.google.common.base.Function; +import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -82,16 +85,18 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter> locations; private final Provider passwordProvider; @Inject public GleSYSComputeServiceAdapter(GleSYSClient client, GleSYSAsyncClient aclient, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads, Timeouts timeouts, @Memoized Supplier> locations, @Named("PASSWORD") Provider passwordProvider) { this.client = checkNotNull(client, "client"); this.aclient = checkNotNull(aclient, "aclient"); this.userThreads = checkNotNull(userThreads, "userThreads"); + this.timeouts = checkNotNull(timeouts, "timeouts"); this.locations = checkNotNull(locations, "locations"); this.passwordProvider = checkNotNull(passwordProvider, "passwordProvider"); } @@ -128,7 +133,7 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter> creating new Server spec(%s) name(%s) options(%s)", spec, name, createServerOptions); ServerDetails result = client.getServerClient().createServerWithHostnameAndRootPassword(spec, name, password, createServerOptions); - logger.trace("<< ServerDetails(%s)", result.getId()); + logger.trace("<< server(%s)", result.getId()); return new NodeAndInitialCredentials(result, result.getId() + "", LoginCredentials.builder() .password(password).build()); @@ -220,7 +225,19 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter(new Predicate() { + + @Override + public boolean apply(String arg0) { + try { + client.getServerClient().destroyServer(arg0, DestroyServerOptions.Builder.discardIp()); + return true; + } catch (IllegalStateException e) { + return false; + } + } + + }, timeouts.nodeTerminated).apply(id); } @Override diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java b/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java index 3adfb28966..1077796769 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java @@ -67,6 +67,7 @@ public class ServerDetailsToNodeMetadata implements Function serverStateToNodeState = ImmutableMap . builder().put(ServerDetails.State.STOPPED, NodeState.SUSPENDED) + .put(ServerDetails.State.LOCKED, NodeState.PENDING) .put(ServerDetails.State.RUNNING, NodeState.RUNNING) .put(ServerDetails.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).build(); @@ -108,7 +109,7 @@ public class ServerDetailsToNodeMetadata implements Function of(new VolumeImpl((float) from.getDiskSizeGB(), true, true))) .hypervisor(from.getPlatform()).build()); - builder.state(from.getState() != null ? serverStateToNodeState.get(from.getState()) : NodeState.UNRECOGNIZED); + builder.state(from.getState() != null ? serverStateToNodeState.get(from.getState()) : NodeState.PENDING); Iterable addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function() { @Override diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Server.java b/labs/glesys/src/main/java/org/jclouds/glesys/domain/Server.java index 2de593fb3f..d70db141eb 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Server.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/domain/Server.java @@ -34,7 +34,7 @@ public class Server implements Comparable { public static enum State { - RUNNING, STOPPED, UNRECOGNIZED; + RUNNING, LOCKED, STOPPED, UNRECOGNIZED; public String value() { return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java b/labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java index ccf7bad8b8..9f5a37c309 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java @@ -63,6 +63,11 @@ public class GleSYSErrorHandler implements HttpErrorHandler { case 404: exception = new ResourceNotFoundException(message, exception); break; + case 500: + if (message.indexOf("Locked") != -1) { + exception = new IllegalStateException(message, exception); + } + break; } } finally { if (response.getPayload() != null) diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java index 56283a4c66..2db8980551 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java @@ -51,6 +51,16 @@ public class GleSYSErrorHandlerTest { assertCodeMakes("GET", URI.create("https://api.glesys.com/foo"), 401, "", "Unauthorized", AuthorizationException.class); } + @Test + public void test500LockedMakesIllegalStateException() { + assertCodeMakes( + "POST", + URI.create("https://api.glesys.com/server/destroy/format/json"), + 500, + "", + "{\"response\":{\"status\":{\"code\":606,\"timestamp\":\"2012-02-14T15:48:39+01:00\",\"text\":\"Server Locked\"},\"debug\":{\"input\":{\"serverid\":\"xm3270596\",\"keepip\":\"0\"}}}}", + IllegalStateException.class); + } @Test public void test400MakesResourceNotFoundExceptionOnCouldNotFind() {