mirror of https://github.com/apache/jclouds.git
glesys fixes
This commit is contained in:
parent
3e5e09f406
commit
1beabce378
|
@ -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<Server
|
|||
private final GleSYSClient client;
|
||||
private final GleSYSAsyncClient aclient;
|
||||
private final ExecutorService userThreads;
|
||||
private final Timeouts timeouts;
|
||||
private final Supplier<Set<? extends Location>> locations;
|
||||
private final Provider<String> 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<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.timeouts = checkNotNull(timeouts, "timeouts");
|
||||
this.locations = checkNotNull(locations, "locations");
|
||||
this.passwordProvider = checkNotNull(passwordProvider, "passwordProvider");
|
||||
}
|
||||
|
@ -128,7 +133,7 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
|
|||
logger.debug(">> 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<ServerDetails>(result, result.getId() + "", LoginCredentials.builder()
|
||||
.password(password).build());
|
||||
|
@ -220,7 +225,19 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
|
|||
|
||||
@Override
|
||||
public void destroyNode(String id) {
|
||||
client.getServerClient().destroyServer(id, DestroyServerOptions.Builder.discardIp());
|
||||
new RetryablePredicate<String>(new Predicate<String>() {
|
||||
|
||||
@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
|
||||
|
|
|
@ -67,6 +67,7 @@ public class ServerDetailsToNodeMetadata implements Function<ServerDetails, Node
|
|||
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.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<ServerDetails, Node
|
|||
.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);
|
||||
builder.state(from.getState() != null ? serverStateToNodeState.get(from.getState()) : NodeState.PENDING);
|
||||
Iterable<String> addresses = Iterables.filter(Iterables.transform(from.getIps(), new Function<Ip, String>() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,7 +34,7 @@ public class Server implements Comparable<Server> {
|
|||
|
||||
public static enum State {
|
||||
|
||||
RUNNING, STOPPED, UNRECOGNIZED;
|
||||
RUNNING, LOCKED, STOPPED, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()));
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue