JCLOUDS-610: Return the affected nodes from resumeNodesMatching, suspendNodesMatching and rebootNodesMatching

Methods have been refactored to match the functionality provided by destroyNodesMatching.
This commit is contained in:
Christopher Dancy 2014-06-22 11:18:42 -04:00 committed by Andrew Phillips
parent 8fa209b15e
commit 8598ee858a
3 changed files with 91 additions and 38 deletions

View File

@ -190,12 +190,14 @@ public interface ComputeService {
*
* affected nodes may not resume with the same IP address(es)
*
* @return list of nodes resumed
*
* @throws UnsupportedOperationException
* if the underlying provider doesn't support suspend/resume
* @throws NoSuchElementException
* if no nodes matched the predicate specified
*/
void resumeNodesMatching(Predicate<NodeMetadata> filter);
Set<? extends NodeMetadata> resumeNodesMatching(Predicate<NodeMetadata> filter);
/**
* suspend the node, given its id. This will result in
@ -218,12 +220,14 @@ public interface ComputeService {
*
* affected nodes may not resume with the same IP address(es)
*
* @return list of nodes suspended
*
* @throws UnsupportedOperationException
* if the underlying provider doesn't support suspend/resume
* @throws NoSuchElementException
* if no nodes matched the predicate specified
*/
void suspendNodesMatching(Predicate<NodeMetadata> filter);
Set<? extends NodeMetadata> suspendNodesMatching(Predicate<NodeMetadata> filter);
/**
* destroy the node, given its id. If it is the only node in a tag set, the dependent resources
@ -249,10 +253,12 @@ public interface ComputeService {
* nodes matching the filter are treated as a logical set. Using this command, you can save time
* by rebooting the nodes in parallel.
*
* @return list of nodes rebooted
*
* @throws NoSuchElementException
* if no nodes matched the predicate specified
*/
void rebootNodesMatching(Predicate<NodeMetadata> filter);
Set<? extends NodeMetadata> rebootNodesMatching(Predicate<NodeMetadata> filter);
/**
* Find a node by its id.

View File

@ -23,7 +23,6 @@ import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Sets.newLinkedHashSet;
import static com.google.common.util.concurrent.Futures.immediateFuture;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
@ -252,7 +251,7 @@ public class BaseComputeService implements ComputeService {
@Override
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> destroying nodes matching(%s)", filter);
Set<NodeMetadata> set = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
Set<NodeMetadata> destroyNodes = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
// TODO make an async interface instead of re-wrapping
@ -270,10 +269,10 @@ public class BaseComputeService implements ComputeService {
}
}, userExecutor, null, logger, "destroyNodesMatching(" + filter + ")"));
logger.debug("<< destroyed(%d)", set.size());
logger.debug("<< destroyed(%d)", destroyNodes.size());
cleanUpIncidentalResourcesOfDeadNodes(set);
return set;
cleanUpIncidentalResourcesOfDeadNodes(destroyNodes);
return destroyNodes;
}
/**
@ -428,19 +427,29 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc}
*/
@Override
public void rebootNodesMatching(Predicate<NodeMetadata> filter) {
public Set<? extends NodeMetadata> rebootNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> rebooting nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, ListenableFuture<? extends Void>>() {
// TODO use native async
Set<NodeMetadata> rebootNodes = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
// TODO make an async interface instead of re-wrapping
@Override
public ListenableFuture<Void> apply(NodeMetadata from) {
rebootNode(from.getId());
return immediateFuture(null);
public ListenableFuture<NodeMetadata> apply(final NodeMetadata from) {
return userExecutor.submit(new Callable<NodeMetadata>() {
public NodeMetadata call() throws Exception {
rebootNode(from.getId());
return from;
}
public String toString() {
return "rebootNode(" + from.getId() + ")";
}
});
}
}, userExecutor, null, logger, "rebootNodesMatching(" + filter + ")");
logger.debug("<< rebooted");
}, userExecutor, null, logger, "rebootNodesMatching(" + filter + ")"));
logger.debug("<< rebooted(%d)", rebootNodes.size());
return rebootNodes;
}
/**
@ -459,19 +468,29 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc}
*/
@Override
public void resumeNodesMatching(Predicate<NodeMetadata> filter) {
public Set<? extends NodeMetadata> resumeNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> resuming nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, ListenableFuture<? extends Void>>() {
// TODO use native async
Set<NodeMetadata> resumeNodes = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
// TODO make an async interface instead of re-wrapping
@Override
public ListenableFuture<Void> apply(NodeMetadata from) {
resumeNode(from.getId());
return immediateFuture(null);
public ListenableFuture<NodeMetadata> apply(final NodeMetadata from) {
return userExecutor.submit(new Callable<NodeMetadata>() {
public NodeMetadata call() throws Exception {
resumeNode(from.getId());
return from;
}
public String toString() {
return "resumeNode(" + from.getId() + ")";
}
});
}
}, userExecutor, null, logger, "resumeNodesMatching(" + filter + ")");
logger.debug("<< resumed");
}, userExecutor, null, logger, "resumeNodesMatching(" + filter + ")"));
logger.debug("<< resumed(%d)", resumeNodes.size());
return resumeNodes;
}
/**
@ -490,19 +509,29 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc}
*/
@Override
public void suspendNodesMatching(Predicate<NodeMetadata> filter) {
public Set<? extends NodeMetadata> suspendNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> suspending nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, ListenableFuture<? extends Void>>() {
// TODO use native async
Set<NodeMetadata> suspendNodes = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
// TODO make an async interface instead of re-wrapping
@Override
public ListenableFuture<Void> apply(NodeMetadata from) {
suspendNode(from.getId());
return immediateFuture(null);
public ListenableFuture<NodeMetadata> apply(final NodeMetadata from) {
return userExecutor.submit(new Callable<NodeMetadata>() {
public NodeMetadata call() throws Exception {
suspendNode(from.getId());
return from;
}
public String toString() {
return "suspendNode(" + from.getId() + ")";
}
});
}
}, userExecutor, null, logger, "suspendNodesMatching(" + filter + ")");
logger.debug("<< suspended");
}, userExecutor, null, logger, "suspendNodesMatching(" + filter + ")"));
logger.debug("<< suspended(%d)", suspendNodes.size());
return suspendNodes;
}
/**

View File

@ -549,14 +549,26 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
@Test(enabled = true, dependsOnMethods = "testGet")
public void testReboot() throws Exception {
client.rebootNodesMatching(inGroup(group));// TODO test
Set<? extends NodeMetadata> rebootNodes = client.rebootNodesMatching(inGroup(group));
for (ComputeMetadata node : rebootNodes) {
assertNotNull(node);
assert node.getProviderId() != null : node;
assert node.getLocation() != null : node;
}
// validation
testGet();
}
@Test(enabled = true, dependsOnMethods = "testReboot")
public void testSuspendResume() throws Exception {
client.suspendNodesMatching(inGroup(group));
Set<? extends NodeMetadata> suspendedNodes = client.suspendNodesMatching(inGroup(group));
for (ComputeMetadata node : suspendedNodes) {
assertNotNull(node);
assert node.getProviderId() != null : node;
assert node.getLocation() != null : node;
}
Set<? extends NodeMetadata> stoppedNodes = refreshNodes();
@ -572,7 +584,13 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
}) : stoppedNodes;
client.resumeNodesMatching(inGroup(group));
Set<? extends NodeMetadata> resumedNodes = client.resumeNodesMatching(inGroup(group));
for (ComputeMetadata node : resumedNodes) {
assertNotNull(node);
assert node.getProviderId() != null : node;
assert node.getLocation() != null : node;
}
testGet();
}