state bug

This commit is contained in:
Adrian Cole 2012-03-12 19:45:35 -07:00
parent 8880efe6f6
commit f383d01e0d
4 changed files with 17 additions and 12 deletions

View File

@ -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;

View File

@ -130,6 +130,7 @@ public interface ComputeServiceAdapter<N, H, I, L> {
N getNode(String id);
//TODO consider making reboot/resume/suspend return the node they affected
void destroyNode(String id);
void rebootNode(String id);

View File

@ -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);
}
}

View File

@ -116,31 +116,36 @@ public class AdaptingComputeServiceStrategies<N, H, I, L> 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