mirror of https://github.com/apache/jclouds.git
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:
parent
3fc2f85254
commit
7f2845349c
|
@ -193,12 +193,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
|
||||
|
@ -221,12 +223,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
|
||||
|
@ -252,10 +256,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.
|
||||
|
|
|
@ -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;
|
||||
|
@ -256,7 +255,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
|
||||
|
@ -274,10 +273,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -432,19 +431,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -463,19 +472,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -494,19 +513,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -553,14 +553,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();
|
||||
|
||||
|
@ -576,7 +588,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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue