You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by an...@apache.org on 2014/06/24 22:59:01 UTC
git commit: JCLOUDS-610: Return the affected nodes from
resumeNodesMatching, suspendNodesMatching and rebootNodesMatching
Repository: jclouds
Updated Branches:
refs/heads/master 8fa209b15 -> 8598ee858
JCLOUDS-610: Return the affected nodes from resumeNodesMatching, suspendNodesMatching and rebootNodesMatching
Methods have been refactored to match the functionality provided by destroyNodesMatching.
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/8598ee85
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/8598ee85
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/8598ee85
Branch: refs/heads/master
Commit: 8598ee858adf05246124a7a7db0de26e191c3fb1
Parents: 8fa209b
Author: Christopher Dancy <da...@pega.com>
Authored: Sun Jun 22 11:18:42 2014 -0400
Committer: Andrew Phillips <an...@apache.org>
Committed: Tue Jun 24 22:58:34 2014 +0200
----------------------------------------------------------------------
.../org/jclouds/compute/ComputeService.java | 12 ++-
.../compute/internal/BaseComputeService.java | 93 +++++++++++++-------
.../internal/BaseComputeServiceLiveTest.java | 24 ++++-
3 files changed, 91 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/8598ee85/compute/src/main/java/org/jclouds/compute/ComputeService.java
----------------------------------------------------------------------
diff --git a/compute/src/main/java/org/jclouds/compute/ComputeService.java b/compute/src/main/java/org/jclouds/compute/ComputeService.java
index cb9e37a..9a1c06a 100644
--- a/compute/src/main/java/org/jclouds/compute/ComputeService.java
+++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java
@@ -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.
http://git-wip-us.apache.org/repos/asf/jclouds/blob/8598ee85/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java
----------------------------------------------------------------------
diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java
index 1efb6bd..0f620c3 100644
--- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java
+++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java
@@ -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;
}
/**
http://git-wip-us.apache.org/repos/asf/jclouds/blob/8598ee85/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java
----------------------------------------------------------------------
diff --git a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java
index 856fde0..f4111db 100644
--- a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java
+++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java
@@ -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();
}