whirr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject svn commit: r1195841 - in /whirr/trunk: CHANGES.txt core/src/main/java/org/apache/whirr/compute/StartupProcess.java
Date Tue, 01 Nov 2011 06:31:00 GMT
Author: asavu
Date: Tue Nov  1 06:31:00 2011
New Revision: 1195841

URL: http://svn.apache.org/viewvc?rev=1195841&view=rev
Log:
WHIRR-423. Refactor StartupProcess.cleanupFailedNodes (Adrian Cole via asavu)

Modified:
    whirr/trunk/CHANGES.txt
    whirr/trunk/core/src/main/java/org/apache/whirr/compute/StartupProcess.java

Modified: whirr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/whirr/trunk/CHANGES.txt?rev=1195841&r1=1195840&r2=1195841&view=diff
==============================================================================
--- whirr/trunk/CHANGES.txt (original)
+++ whirr/trunk/CHANGES.txt Tue Nov  1 06:31:00 2011
@@ -54,6 +54,8 @@ Trunk (unreleased changes)
 
     WHIRR-418. Add ssh debug logs to tests (Adrian Cole via asavu)
 
+    WHIRR-423. Refactor StartupProcess.cleanupFailedNodes (Adrian Cole via asavu)
+
   BUG FIXES
 
     WHIRR-377. Fix broken CLI logging config. (asavu via tomwhite)

Modified: whirr/trunk/core/src/main/java/org/apache/whirr/compute/StartupProcess.java
URL: http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/compute/StartupProcess.java?rev=1195841&r1=1195840&r2=1195841&view=diff
==============================================================================
--- whirr/trunk/core/src/main/java/org/apache/whirr/compute/StartupProcess.java (original)
+++ whirr/trunk/core/src/main/java/org/apache/whirr/compute/StartupProcess.java Tue Nov  1
06:31:00 2011
@@ -18,6 +18,7 @@
 
 package org.apache.whirr.compute;
 
+import com.google.common.base.Predicates;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import org.jclouds.compute.ComputeService;
@@ -28,8 +29,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
@@ -143,31 +144,19 @@ public class StartupProcess implements C
 
   void cleanupFailedNodes() throws InterruptedException {
     if (lostNodes.size() > 0) {
-      // parallel destroy of failed nodes
-      Set<Future<NodeMetadata>> deletingNodeFutures = Sets.newLinkedHashSet();
-      Iterator<?> it = lostNodes.keySet().iterator();
-      while (it.hasNext()) {
-        final NodeMetadata badNode = (NodeMetadata) it.next();
-        deletingNodeFutures.add(executorService.submit(
-            new Callable<NodeMetadata>() {
-              public NodeMetadata call() throws Exception {
-                final String nodeId = badNode.getId();
-                LOG.info("Deleting failed node node {}", nodeId);
-                computeService.destroyNode(nodeId);
-                LOG.info("Node deleted: {}", nodeId);
-                return badNode;
-              }
-            }
-          ));
+      Set<String> lostIds = Sets.newLinkedHashSet();
+      for (Entry<NodeMetadata, Throwable> lostNode : lostNodes.entrySet()) {
+        LOG.debug("Will destroy failed node {}", lostNode.getKey(), lostNode.getValue());
+        lostIds.add(lostNode.getKey().getId());
       }
-      Iterator<Future<NodeMetadata>> results = deletingNodeFutures.iterator();
-      while (results.hasNext()) {
-        try {
-          results.next().get();
-        } catch (ExecutionException e) {
-          LOG.warn("Error while destroying failed node:", e);
-        }
+      LOG.info("Destroying failed nodes {}", lostIds);
+      Set<? extends NodeMetadata> destroyedNodes = computeService.destroyNodesMatching(
+        Predicates.in(lostNodes.keySet()));
+      lostIds.clear();
+      for (NodeMetadata destroyed : destroyedNodes) {
+        lostIds.add(destroyed.getId());
       }
+      LOG.info("Destroyed failed nodes {}", lostIds);
     }
   }
 }



Mime
View raw message