You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vg...@apache.org on 2011/11/03 19:44:32 UTC

svn commit: r1197265 - in /incubator/ambari/trunk: CHANGES.txt controller/src/main/java/org/apache/ambari/controller/Clusters.java controller/src/main/java/org/apache/ambari/controller/Controller.java

Author: vgogate
Date: Thu Nov  3 18:44:32 2011
New Revision: 1197265

URL: http://svn.apache.org/viewvc?rev=1197265&view=rev
Log:
AMBARI-125

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1197265&r1=1197264&r2=1197265&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Nov  3 18:44:32 2011
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-125. Recover the the state of existing clusters after controller restart (vgogate)
+
   AMBARI-124. Add Zookeeper Data store and persist the cluster definitions across controller restart (vgogate)
 
   AMBARI-116. Change the name group to provider in hadoop-security-0.xml stack definition (vgogate)

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java?rev=1197265&r1=1197264&r2=1197265&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java Thu Nov  3 18:44:32 2011
@@ -424,18 +424,24 @@ public class Clusters {
         }
         
         /*
+         * TODO: Derive the role to nodes map based on nodes attributes
+         * then populate the node to roles association.
+         */
+        if (cdef.getRoleToNodes() == null) {
+            List<RoleToNodes> role2NodesList = generateRoleToNodesListBasedOnNodeAttributes (cdef);
+            cdef.setRoleToNodesMap(role2NodesList);
+        }
+        
+        /*
          * If dry run then update roles to nodes map, if not specified explicitly
          * and return
          */
         if (dry_run) {
-            List<RoleToNodes> role2NodesList = generateRoleToNodesListBasedOnNodeAttributes (cdef);
-            cdef.setRoleToNodesMap(role2NodesList);
             return cdef;
         }
         
         /*
          * Persist the new cluster and add entry to cache
-         * TODO: Persist reserved nodes against the cluster & service/role? 
          * 
          */
         Cluster cls = this.addClusterEntry(cdef, clsState);
@@ -449,19 +455,9 @@ public class Clusters {
         }
         
         /*
-         * Update the Node to Roles association, if specified
-         * If role is not explicitly associated w/ any node, then assign it w/ default role
-         * If RoleToNodes list is not specified then derive it based on the node attributes  
+         * Update the Node to Roles association
          */
         if (!cdef.getGoalState().equals(ClusterDefinition.GOAL_STATE_ATTIC)) {
-            if (cdef.getRoleToNodes() == null) {
-                /*
-                 * TODO: Derive the role to nodes map based on nodes attributes
-                 * then populate the node to roles association.
-                 */
-                List<RoleToNodes> role2NodesList = generateRoleToNodesListBasedOnNodeAttributes (cdef);
-                cdef.setRoleToNodesMap(role2NodesList);
-            }
             updateNodeToRolesAssociation(cdef.getNodes(), cdef.getRoleToNodes());
         }
         
@@ -557,7 +553,7 @@ public class Clusters {
     /*
      * Update the nodes associated with cluster
      */
-    private synchronized void updateClusterNodesReservation (String clusterName, ClusterDefinition clsDef) throws Exception {
+    public synchronized void updateClusterNodesReservation (String clusterName, ClusterDefinition clsDef) throws Exception {
                 
         ConcurrentHashMap<String, Node> all_nodes = Nodes.getInstance().getNodes();
         List<String> cluster_node_range = new ArrayList<String>();
@@ -650,7 +646,15 @@ public class Clusters {
         }
     }
     
-    private synchronized void updateNodeToRolesAssociation (String clusterNodes, List<RoleToNodes> roleToNodesList) throws Exception {
+    /**
+     * Update Node to Roles association.  
+     * If role is not explicitly associated w/ any node, then assign it w/ default role
+     * 
+     * @param clusterNodes
+     * @param roleToNodesList
+     * @throws Exception
+     */
+    public synchronized void updateNodeToRolesAssociation (String clusterNodes, List<RoleToNodes> roleToNodesList) throws Exception {
         /*
          * Associate roles list with node
          */

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java?rev=1197265&r1=1197264&r2=1197265&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java Thu Nov  3 18:44:32 2011
@@ -18,9 +18,13 @@
 
 package org.apache.ambari.controller;
 
+import java.util.List;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.ambari.common.rest.entities.ClusterDefinition;
+import org.apache.ambari.common.rest.entities.RoleToNodes;
 import org.apache.ambari.common.util.DaemonWatcher;
 import org.apache.ambari.common.util.ExceptionUtil;
 
@@ -107,6 +111,36 @@ public class Controller {
 
       root.addHandler(security);
       server.setStopAtShutdown(true);
+      
+      /*
+       *  Recover controller state before opening up the server to clients
+       */
+      Clusters clusterCtx = Clusters.getInstance();
+      Stacks stacksCtx = Stacks.getInstance();
+      Nodes nodesCtx = Nodes.getInstance();
+      
+      for (Cluster cls : clusterCtx.getClustersList("ALL")) {
+          ClusterDefinition cdef = cls.getClusterDefinition(-1);
+          /*
+           * Update cluster nodes reservation. 
+           */
+          if (cdef.getNodes() != null 
+              && !cdef.getGoalState().equals(ClusterDefinition.GOAL_STATE_ATTIC)) {
+              clusterCtx.updateClusterNodesReservation (cls.getName(), cdef);
+          }
+          
+          /*
+           * Update the Node to Roles association
+           *
+           */
+          if (!cdef.getGoalState().equals(ClusterDefinition.GOAL_STATE_ATTIC)) {
+              clusterCtx.updateNodeToRolesAssociation(cdef.getNodes(), cdef.getRoleToNodes());
+          }
+      }
+      
+      /*
+       * Start the server after controller state is recovered.
+       */
       server.start();
     } catch (Exception e) {
       LOG.error(ExceptionUtil.getStackTrace(e));