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/07/01 18:06:48 UTC

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

Repository: jclouds
Updated Branches:
  refs/heads/1.7.x 3fc2f8525 -> 7f2845349


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/7f284534
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/7f284534
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/7f284534

Branch: refs/heads/1.7.x
Commit: 7f2845349c6be034b396d0a9095b90b5092179f8
Parents: 3fc2f85
Author: Christopher Dancy <da...@pega.com>
Authored: Sun Jun 22 11:18:42 2014 -0400
Committer: Andrew Phillips <an...@apache.org>
Committed: Tue Jul 1 09:06:17 2014 -0700

----------------------------------------------------------------------
 .../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/7f284534/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 a7c2519..d79b0b3 100644
--- a/compute/src/main/java/org/jclouds/compute/ComputeService.java
+++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java
@@ -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.

http://git-wip-us.apache.org/repos/asf/jclouds/blob/7f284534/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 75ea787..9d7e775 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;
@@ -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;
    }
 
    /**

http://git-wip-us.apache.org/repos/asf/jclouds/blob/7f284534/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 a6f064b..1a44d4d 100644
--- a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java
+++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java
@@ -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();
    }