diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index feef8869bd..d7065b96dc 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -42,11 +42,9 @@ import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.domain.Location; import org.jclouds.functions.IdentityFunction; -import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; -import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.inject.Provides; import com.google.inject.TypeLiteral; diff --git a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java index a9fa7e71b8..f39e820e43 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java @@ -130,6 +130,7 @@ public interface ComputeServiceAdapter { N getNode(String id); + //TODO consider making reboot/resume/suspend return the node they affected void destroyNode(String id); void rebootNode(String id); diff --git a/compute/src/main/java/org/jclouds/compute/predicates/AtomicNodeSuspended.java b/compute/src/main/java/org/jclouds/compute/predicates/AtomicNodeSuspended.java index 0eb86b13e4..3e94459195 100644 --- a/compute/src/main/java/org/jclouds/compute/predicates/AtomicNodeSuspended.java +++ b/compute/src/main/java/org/jclouds/compute/predicates/AtomicNodeSuspended.java @@ -23,6 +23,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; +import com.google.common.collect.ImmutableSet; import com.google.inject.Inject; /** @@ -36,6 +37,6 @@ public class AtomicNodeSuspended extends RefreshAndDoubleCheckOnFailUnlessStateI @Inject public AtomicNodeSuspended(GetNodeMetadataStrategy client) { - super(NodeState.SUSPENDED, client); + super(NodeState.SUSPENDED, ImmutableSet.of(NodeState.ERROR, NodeState.TERMINATED), client); } } diff --git a/compute/src/main/java/org/jclouds/compute/strategy/impl/AdaptingComputeServiceStrategies.java b/compute/src/main/java/org/jclouds/compute/strategy/impl/AdaptingComputeServiceStrategies.java index 5651be3689..0713c52abc 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/impl/AdaptingComputeServiceStrategies.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/impl/AdaptingComputeServiceStrategies.java @@ -116,31 +116,36 @@ public class AdaptingComputeServiceStrategies implements CreateNodeW return nodeMetadataAdapter.apply(node); } + //TODO: make reboot/resume/suspend return the node they affected @Override public NodeMetadata rebootNode(String id) { NodeMetadata node = getNode(checkNotNull(id, "id")); - if (node == null || node.getState() == NodeState.TERMINATED) - return node; + checkStateAvailable(node); client.rebootNode(id); - return node; + // invalidate state of node + return getNode(checkNotNull(id, "id")); + } + + private void checkStateAvailable(NodeMetadata node) { + checkState(node != null && node.getState() != NodeState.TERMINATED, "node %s terminated or unavailable!", node); } @Override public NodeMetadata resumeNode(String id) { NodeMetadata node = getNode(checkNotNull(id, "id")); - if (node == null || node.getState() == NodeState.TERMINATED || node.getState() == NodeState.RUNNING) - return node; + checkStateAvailable(node); client.resumeNode(id); - return node; + // invalidate state of node + return getNode(checkNotNull(id, "id")); } @Override public NodeMetadata suspendNode(String id) { NodeMetadata node = getNode(checkNotNull(id, "id")); - if (node == null || node.getState() == NodeState.TERMINATED || node.getState() == NodeState.SUSPENDED) - return node; + checkStateAvailable(node); client.suspendNode(id); - return node; + // invalidate state of node + return getNode(checkNotNull(id, "id")); } @Override