You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whirr.apache.org by as...@apache.org on 2011/08/18 05:51:07 UTC

svn commit: r1159016 - in /incubator/whirr/trunk: CHANGES.txt core/src/main/java/org/apache/whirr/actions/ConfigureClusterAction.java pom.xml

Author: asavu
Date: Thu Aug 18 03:51:07 2011
New Revision: 1159016

URL: http://svn.apache.org/viewvc?rev=1159016&view=rev
Log:
WHIRR-361. Emergency upgrade to jclouds 1.1.1 and improved configure phase logging (Adrian Cole via asavu)

Modified:
    incubator/whirr/trunk/CHANGES.txt
    incubator/whirr/trunk/core/src/main/java/org/apache/whirr/actions/ConfigureClusterAction.java
    incubator/whirr/trunk/pom.xml

Modified: incubator/whirr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/CHANGES.txt?rev=1159016&r1=1159015&r2=1159016&view=diff
==============================================================================
--- incubator/whirr/trunk/CHANGES.txt (original)
+++ incubator/whirr/trunk/CHANGES.txt Thu Aug 18 03:51:07 2011
@@ -81,6 +81,9 @@ Trunk (unreleased changes)
 
     WHIRR-361. Add Guava as an explicit dependency (Adrian Cole via asavu)
 
+    WHIRR-361. Emergency upgrade to jclouds 1.1.1 and improved configure phase 
+    logging (Adrian Cole via asavu)
+
 Release 0.5.0 - 2011-05-16
 
   INCOMPATIBLE CHANGES

Modified: incubator/whirr/trunk/core/src/main/java/org/apache/whirr/actions/ConfigureClusterAction.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/main/java/org/apache/whirr/actions/ConfigureClusterAction.java?rev=1159016&r1=1159015&r2=1159016&view=diff
==============================================================================
--- incubator/whirr/trunk/core/src/main/java/org/apache/whirr/actions/ConfigureClusterAction.java (original)
+++ incubator/whirr/trunk/core/src/main/java/org/apache/whirr/actions/ConfigureClusterAction.java Thu Aug 18 03:51:07 2011
@@ -18,8 +18,12 @@
 
 package org.apache.whirr.actions;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 
 import java.io.IOException;
@@ -40,6 +44,7 @@ import org.jclouds.compute.ComputeServic
 import org.jclouds.compute.RunScriptOnNodesException;
 import org.jclouds.compute.domain.NodeMetadata;
 import org.jclouds.compute.options.RunScriptOptions;
+import org.jclouds.compute.predicates.NodePredicates;
 import org.jclouds.domain.Credentials;
 import org.jclouds.scriptbuilder.domain.OsFamily;
 import org.slf4j.Logger;
@@ -71,20 +76,39 @@ public class ConfigureClusterAction exte
     for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
       ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
       Cluster cluster = entry.getValue().getCluster();
+
       StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
+
       ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
       ComputeService computeService = computeServiceContext.getComputeService();
+
       Credentials credentials = new Credentials(
           clusterSpec.getClusterUser(),
           clusterSpec.getPrivateKey());
+
       try {
-        LOG.info("Running configuration script");
+        Map<String, ? extends NodeMetadata> nodesInCluster = getNodesForInstanceIdsInCluster(cluster, computeService);
+        
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("Nodes in cluster: {}", nodesInCluster.values());
+        }
+        
+        Map<String, ? extends NodeMetadata> nodesToApply = Maps.uniqueIndex(
+            Iterables.filter(nodesInCluster.values(),
+                toNodeMetadataPredicate(clusterSpec, cluster, entry.getKey().getRoles())),
+            getNodeId
+        );
+
+        LOG.info("Running configuration script on nodes: {}", nodesToApply.keySet());
         if (LOG.isDebugEnabled())
-          LOG.debug("Running script:\n{}", statementBuilder.render(OsFamily.UNIX));
+          LOG.debug("script:\n{}", statementBuilder.render(OsFamily.UNIX));
+        
         computeService.runScriptOnNodesMatching(
-            toNodeMetadataPredicate(clusterSpec, cluster, entry.getKey().getRoles()),
+            withIds(nodesToApply.keySet()),
             statementBuilder,
-            RunScriptOptions.Builder.overrideCredentialsWith(credentials));
+            RunScriptOptions.Builder.overrideCredentialsWith(credentials)
+        );
+        
         LOG.info("Configuration script run completed");
       } catch (RunScriptOnNodesException e) {
         // TODO: retry
@@ -92,6 +116,43 @@ public class ConfigureClusterAction exte
       }
     }
   }
+
+  private Map<String, ? extends NodeMetadata> getNodesForInstanceIdsInCluster(Cluster cluster,
+        ComputeService computeService) {
+    Iterable<String> ids = Iterables.transform(cluster.getInstances(), new Function<Instance, String>() {
+
+      @Override
+      public String apply(Instance arg0) {
+        return arg0.getId();
+      }
+
+    });
+    
+    Set<? extends NodeMetadata> nodes = computeService.listNodesDetailsMatching(
+        NodePredicates.withIds(Iterables.toArray(ids, String.class)));
+    
+    return Maps.uniqueIndex(nodes, getNodeId);
+  }
+
+  public static Predicate<NodeMetadata> withIds(Iterable<String> ids) {
+    checkNotNull(ids, "ids must be defined");
+    final Set<String> search = ImmutableSet.copyOf(ids);
+    return new Predicate<NodeMetadata>() {
+      @Override
+      public boolean apply(NodeMetadata nodeMetadata) {
+        return search.contains(nodeMetadata.getId());
+      }
+    };
+  }
+  
+  private static Function<NodeMetadata, String> getNodeId = new Function<NodeMetadata, String>() {
+
+    @Override
+    public String apply(NodeMetadata arg0) {
+      return arg0.getId();
+    }
+     
+  };
   
   private Predicate<NodeMetadata> toNodeMetadataPredicate(final ClusterSpec clusterSpec, final Cluster cluster, final Set<String> roles) {
     final Map<String, Instance> nodeIdToInstanceMap = Maps.newHashMap();
@@ -101,10 +162,6 @@ public class ConfigureClusterAction exte
     return new Predicate<NodeMetadata>() {
       @Override
       public boolean apply(NodeMetadata nodeMetadata) {
-        // Check it's the correct cluster
-        if (!clusterSpec.getClusterName().equals(nodeMetadata.getGroup())) {
-          return false;
-        }
         Instance instance = nodeIdToInstanceMap.get(nodeMetadata.getId());
         if (instance == null) {
           LOG.debug("No instance for {} found in map", nodeMetadata);

Modified: incubator/whirr/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/pom.xml?rev=1159016&r1=1159015&r2=1159016&view=diff
==============================================================================
--- incubator/whirr/trunk/pom.xml (original)
+++ incubator/whirr/trunk/pom.xml Thu Aug 18 03:51:07 2011
@@ -51,7 +51,7 @@
   </modules>
 
   <properties>
-    <jclouds.version>1.1.0</jclouds.version>
+    <jclouds.version>1.1.1</jclouds.version>
   </properties>
 
   <dependencyManagement>