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/23 09:30:46 UTC

svn commit: r1205325 - in /incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller: Cluster.java Clusters.java

Author: vgogate
Date: Wed Nov 23 08:30:46 2011
New Revision: 1205325

URL: http://svn.apache.org/viewvc?rev=1205325&view=rev
Log:
AMBARI-136: Create Puppet configruation for the new/updated cluster definition

Modified:
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java?rev=1205325&r1=1205324&r2=1205325&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java Wed Nov 23 08:30:46 2011
@@ -55,6 +55,11 @@ public class Cluster {
     private final Map<String, ComponentPlugin> plugins =
                   new HashMap<String, ComponentPlugin>();
     
+    /*
+     * Store cluster puppet configuration
+     */
+    private final Map<Integer, String> clusterConfigurationRevisionList = new HashMap<Integer, String>();
+    
     
     public Cluster (String clusterName) {
         this.clusterName = clusterName;
@@ -112,6 +117,16 @@ public class Cluster {
       // find the plugins for the current definition of the cluster
       loadPlugins(c);
     }
+    
+    /**
+     * @return Add puppet configuration
+     */
+    public synchronized void updatePuppetConfiguration(String puppetConfig) throws Exception {
+      //this.latestRevisionNumber = dataStore.storeClusterDefinition(c);
+      //this.clusterDefinitionRevisionsList.put(this.latestRevisionNumber, c);
+      //this.latestDefinition = c;
+    }
+
 
     /*
      * Load plugins for the current definition of the cluster

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=1205325&r1=1205324&r2=1205325&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 Wed Nov 23 08:30:46 2011
@@ -27,6 +27,10 @@ import java.util.concurrent.ConcurrentHa
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 
+import org.apache.ambari.common.rest.entities.Component;
+import org.apache.ambari.common.rest.entities.ConfigurationCategory;
+import org.apache.ambari.common.rest.entities.Property;
+import org.apache.ambari.common.rest.entities.Role;
 import org.apache.ambari.common.rest.entities.Stack;
 import org.apache.ambari.common.rest.entities.ClusterDefinition;
 import org.apache.ambari.common.rest.entities.ClusterInformation;
@@ -191,7 +195,7 @@ public class Clusters {
     }
     
     /*
-     * Add Cluster Entry
+     * Add Cluster Entry into data store and memory cache
      */
     public synchronized Cluster addClusterEntry (ClusterDefinition cdef, ClusterState cs) throws Exception {
         Cluster cls = new Cluster (cdef, cs);
@@ -250,15 +254,18 @@ public class Clusters {
         ClusterDefinition newcd = new ClusterDefinition ();
         newcd.setName(clusterName);
         boolean clsDefChanged = false;
+        boolean configChanged = false;
         if (c.getStackName() != null && !c.getStackName().equals(cls.getClusterDefinition(-1).getStackName())) {
             newcd.setStackName(c.getStackName());
             clsDefChanged = true;
+            configChanged = true;
         } else {
             newcd.setStackName(cls.getClusterDefinition(-1).getStackName());
         }
         if (c.getStackRevision() != null && !c.getStackRevision().equals(cls.getClusterDefinition(-1).getStackRevision())) {
             newcd.setStackRevision(c.getStackRevision());
             clsDefChanged = true;
+            configChanged = true;
         } else {
             newcd.setStackRevision(cls.getClusterDefinition(-1).getStackRevision());
         }
@@ -337,7 +344,8 @@ public class Clusters {
         }
         
         /*
-         *  Udate the new cluster definition
+         *  Update the new cluster definition and state
+         *  Generate the config script for puppet
          */
         ClusterState cs = cls.getClusterState();
         cs.setLastUpdateTime(Util.getXMLGregorianCalendar(new Date()));
@@ -345,6 +353,12 @@ public class Clusters {
         cls.updateClusterState(cs);
         
         /*
+        if (configChanged || updateNodeToRolesAssociation || updateNodesReservation) {
+            String puppetConfig = this.getPuppetConfigString (newcd);
+            cls.updatePuppetConfiguration(puppetConfig);
+        }*/
+        
+        /*
          * Update the nodes reservation and node to roles association 
          */
         if (updateNodesReservation) {
@@ -355,6 +369,10 @@ public class Clusters {
         }
         
         /*
+         * If configChanged or nodes changed then generate the 
+         */
+        
+        /*
          * Invoke state machine event
          */
         if(c.getGoalState().equals(ClusterState.CLUSTER_STATE_ACTIVE)) {
@@ -451,6 +469,10 @@ public class Clusters {
         Cluster cls = this.addClusterEntry(cdef, clsState);
         
         /*
+         * TODO: Create and update the puppet configuration
+         */
+        
+        /*
          * Update cluster nodes reservation. 
          */
         if (cdef.getNodes() != null 
@@ -899,4 +921,32 @@ public class Clusters {
           }
       }
   }
+  
+  private String getPuppetConfigString (ClusterDefinition c) throws Exception {
+      Stacks stacksCtx = Stacks.getInstance();
+      Stack stack = stacksCtx.getStack(c.getStackName(), Integer.parseInt(c.getStackRevision()));
+      String config = "";
+      for (Component comp : stack.getComponents()) {
+          for (Role role : comp.getRoles()) {
+              config = config + "\n"+"$"+comp.getName()+"_"+role.getName()+"_conf => { ";
+              for (ConfigurationCategory cat : role.getConfiguration().getCategory()) {
+                   config = config+"\""+cat.getName()+"\" => { ";
+                   for (Property p : cat.getProperty()) {
+                       config = config+p.getName()+" => "+p.getValue()+", ";
+                   }
+                   config = config +" }, \n";
+              }
+              config = config + "} \n";
+          }
+      }
+      
+      for (RoleToNodes roleToNodesEntry : c.getRoleToNodesMap()) {
+          config = config + "$"+roleToNodesEntry.getRoleName()+"_hosts = [";
+          for (String host : this.getHostnamesFromRangeExpressions(roleToNodesEntry.getNodes())) {
+              config = config + "\'"+host+"\',";
+          }
+          config = config + "] \n";
+      }
+      return config;
+  }
 }