incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgog...@apache.org
Subject svn commit: r1181298 - in /incubator/ambari/trunk: ./ client/src/main/java/org/apache/ambari/client/ client/src/main/java/org/apache/ambari/common/rest/entities/ controller/src/main/java/org/apache/ambari/controller/ controller/src/main/java/org/apache...
Date Mon, 10 Oct 2011 23:39:55 GMT
Author: vgogate
Date: Mon Oct 10 23:39:55 2011
New Revision: 1181298

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

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/AmbariClient.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/Command.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Node.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodes.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Nodes.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClusterResource.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1181298&r1=1181297&r2=1181298&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Mon Oct 10 23:39:55 2011
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-55. release cluster nodes function (vgogate)
+
   AMBARI-53. Refactor the HeartBeat to have Agents' states separated by 
   component/role (ddas)
 

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/AmbariClient.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/AmbariClient.java?rev=1181298&r1=1181297&r2=1181298&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/AmbariClient.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/AmbariClient.java
Mon Oct 10 23:39:55 2011
@@ -69,7 +69,7 @@ public class AmbariClient {
         if (args.length < 2) {
            if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
                System.out.println("Usage: AmbariClient <CommandCateogry> <CommandName>
<CommandOptions>\n");
-               System.out.println("       To get the help on each command use -help  e.g.
\"AmbariClient cluster list -help\"\n");
+               System.out.println("To get the help on each command use -help  e.g. \"AmbariClient
cluster list -help\"\n");
                for (String category : c.commands.keySet()) {
                    System.out.println("CommandCategory : ["+ category+"] : Commands "+c.commands.get(category).keySet());
                }

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java?rev=1181298&r1=1181297&r2=1181298&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java
Mon Oct 10 23:39:55 2011
@@ -220,9 +220,12 @@ public class ClusterCreate extends Comma
     }
     
     private List<String> splitServices(String services) {
+      if (services == null) { return null; }
       String[] arr = services.split(",");
       List<String> result = new ArrayList<String>(arr.length);
-      Collections.addAll(result, arr);
+      for (String x: arr) {
+          result.add(x.trim());
+      }
       return result;
     }
 

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/Command.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/Command.java?rev=1181298&r1=1181297&r2=1181298&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/Command.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/Command.java Mon
Oct 10 23:39:55 2011
@@ -17,9 +17,88 @@
  */
 package org.apache.ambari.client;
 
+import java.util.Hashtable;
+
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+
 public abstract class Command {
     
     protected String baseURLString = "http://localhost:4080/rest";
     
+    //Hashtable<String, String> commandOptions = new Hashtable<String, String>();
+    
+    //Options options = null;
+    
+    public Command() {
+        
+        /* boolean, name, description, required, argname,    
+        Option wait = "boolean, false, wait, Optionally wait for cluster to reach desired
state";
+        String dry_run = "boolean, false dry_run, Dry run";
+        String help = "boolean, false, help, help";
+        String name = "false, true, name, cluster_name, true, Name of the cluster to be created";
+        
+        
+        
+        OptionBuilder.withArgName("cluster_name");
+        OptionBuilder.isRequired();
+        OptionBuilder.hasArg();
+        OptionBuilder.withDescription( "Name of the cluster to be created");
+        Option name = OptionBuilder.create( "name" );
+        
+        OptionBuilder.withArgName("blueprint_name");
+        OptionBuilder.isRequired();
+        OptionBuilder.hasArg();
+        OptionBuilder.withDescription( "Name of the cluster blueprint");
+        Option blueprint = OptionBuilder.create( "blueprint" );
+        
+        OptionBuilder.withArgName( "\"node_exp1; node_exp2; ...\"" );
+        OptionBuilder.isRequired();
+        OptionBuilder.hasArg();
+        OptionBuilder.withDescription(  "List of node range expressions separated by semicolon
(;) and contained in double quotes (\"\")" );
+        Option nodes = OptionBuilder.create( "nodes" );
+        
+        OptionBuilder.withArgName( "blueprint_revision" );
+        OptionBuilder.hasArg();
+        OptionBuilder.withDescription(  "Blueprint revision, if not specified latest revision
is used" );
+        Option blueprint_revision = OptionBuilder.create( "revision" );
+        
+        OptionBuilder.withArgName( "description" );
+        OptionBuilder.hasArg();
+        OptionBuilder.withDescription(  "Description to be associated with cluster" );
+        Option desc = OptionBuilder.create( "desc" );
+        
+        OptionBuilder.withArgName( "goalstate" );
+        OptionBuilder.hasArg();
+        OptionBuilder.withDescription(  "Desired goal state of the cluster" );
+        Option goalstate = OptionBuilder.create( "goalstate" );
+        
+        OptionBuilder.withArgName( "\"component-1; component-2; ...\"" );
+        OptionBuilder.hasArg();
+        OptionBuilder.withDescription(  "List of components to be active in the cluster.
Components are seperated by semicolon \";\"" );
+        Option services = OptionBuilder.create( "services" );
+        
+        OptionBuilder.withArgName( "rolename=\"node_exp1; node_exp2; ... \"" );
+        OptionBuilder.hasArgs(2);
+        OptionBuilder.withValueSeparator();
+        OptionBuilder.withDescription( "Provide node range expressions for a given rolename
separated by semicolon (;) and contained in double quotes (\"\")" );
+        Option role = OptionBuilder.create( "role" );
+    
+        this.options = new Options();
+        options.addOption( wait );   
+        options.addOption(dry_run);
+        options.addOption( name );
+        options.addOption( blueprint );   
+        options.addOption(blueprint_revision);
+        options.addOption( desc );
+        options.addOption( role );
+        options.addOption( goalstate );
+        options.addOption( nodes );
+        options.addOption( services );
+        options.addOption(help);
+        */
+    }
+    
     public abstract void run () throws Exception;
 }

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Node.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Node.java?rev=1181298&r1=1181297&r2=1181298&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Node.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Node.java
Mon Oct 10 23:39:55 2011
@@ -51,15 +51,16 @@ public class Node {
     }
 	
     /*
-     * 
+     * Marks the nodes associated w/ Cluster to be released
      */
     public void releaseNodeFromCluster() {
-        this.nodeState.setClusterID(null);
-        this.getNodeState().setNodeServers(null);
-        this.getNodeState().setNodeRoleNames(null);
         /*
-         * TODO: AllocatedToClsuter flag will be reset part of heart beat processing when
node completes cleanup.
+         * Cluster ID + NodeServers + NodeToRoleNames associated w/ cluster will be reset

+         * part of heartbeat when node stop services and does clean up.
          */
+        this.nodeState.setAllocatedToCluster(false);
+        this.getNodeState().setNodeServers(null);
+        this.getNodeState().setNodeRoleNames(null);
     }
 	
   	/*

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodes.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodes.java?rev=1181298&r1=1181297&r2=1181298&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodes.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodes.java
Mon Oct 10 23:39:55 2011
@@ -46,13 +46,13 @@ public class RoleToNodes {
                 this.roleName = roleName;
         }
         /**
-         * @return the nodeRangeExpressions
+         * @return the nodes
          */
-        public String getNodeRangeExpressions() {
+        public String getNodes() {
                 return nodes;
         }
         /**
-         * @param nodeRangeExpressions the nodeRangeExpressions to set
+         * @param nodes the nodeRangeExpressions to set
          */
         public void setNodes(String nodes) {
                 this.nodes = nodes;

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=1181298&r1=1181297&r2=1181298&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
Mon Oct 10 23:39:55 2011
@@ -97,16 +97,6 @@ public class Clusters {
         rnm.add(rnme);
         
         cluster123.setRoleToNodesMap(rnm);
-        /*
-        try {
-            ObjectMapper m = new ObjectMapper();
-            ByteArrayOutputStream x = new ByteArrayOutputStream();
-            m.writeValue(x, cluster123);
-            System.out.println ("CLUSTERDEF: <"+new String(x.toString()));
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        */
         
         /*
          * Cluster definition 
@@ -275,7 +265,7 @@ public class Clusters {
         if (clsDef.getRoleToNodes() != null) {
             List<String> nodes_specified_using_role_association = new ArrayList<String>();
             for (RoleToNodes e : clsDef.getRoleToNodes()) {
-                List<String> hosts = getHostnamesFromRangeExpressions(e.getNodeRangeExpressions());
+                List<String> hosts = getHostnamesFromRangeExpressions(e.getNodes());
                 nodes_specified_using_role_association.addAll(hosts);
                 // TODO: Remove any duplicate nodes from nodes_specified_using_role_association
             }
@@ -357,7 +347,7 @@ public class Clusters {
         /*
          * deallocate nodes from a given cluster
          * TODO: Node agent would asynchronously clean up the node and notify it through
heartbeat which 
-         * would set the allocatedtoCluster flag false
+         * would reset the clusterID associated with node
          */
         for (String node_name : nodes_to_deallocate) {
             if (all_nodes.containsKey(node_name)) {
@@ -368,11 +358,22 @@ public class Clusters {
         }
     }
 
-    private synchronized void updateNodeToRolesAssociation (String nodeRangeExpressions,
List<RoleToNodes> roleToNodesMap) throws Exception {
+    /*
+     * This function disassociate the node from the cluster. The clsuterID associated w/
+     * cluster will be reset by heart beat when node reports all clean.
+     */
+    public synchronized void releaseClusterNodes (String clusterID) throws Exception {
+        String clusterName = this.getClusterByID(clusterID).getLatestClusterDefinition().getName();
+        for (Node clusterNode : Nodes.getInstance().getClusterNodes (clusterName, "", ""))
{
+            clusterNode.releaseNodeFromCluster();     
+        }
+    }
+    
+    private synchronized void updateNodeToRolesAssociation (String clusterNodes, List<RoleToNodes>
roleToNodesList) throws Exception {
         /*
          * Associate roles list with node
          */
-        if (roleToNodesMap == null) {
+        if (roleToNodesList == null) {
             return;
         }
         
@@ -380,8 +381,8 @@ public class Clusters {
          * Add list of roles to Node
          * If node is not explicitly associated with any role then assign it w/ default role
          */
-        for (RoleToNodes e : roleToNodesMap) {
-            List<String> hosts = getHostnamesFromRangeExpressions(e.getNodeRangeExpressions());
+        for (RoleToNodes e : roleToNodesList) {
+            List<String> hosts = getHostnamesFromRangeExpressions(e.getNodes());
             for (String host : hosts) {
               if (Nodes.getInstance().getNodes().get(host).getNodeState().getNodeRoleNames()
== null) {
                 Nodes.getInstance().getNodes().get(host).getNodeState().setNodeRoleNames((new
ArrayList<String>()));
@@ -396,7 +397,7 @@ public class Clusters {
          * role to nodes map, assign them with default role 
          */
         List<String> specified_node_range = new ArrayList<String>();
-        specified_node_range.addAll(getHostnamesFromRangeExpressions(nodeRangeExpressions));
+        specified_node_range.addAll(getHostnamesFromRangeExpressions(clusterNodes));
         for (String host : specified_node_range) {
             if (Nodes.getInstance().getNodes().get(host).getNodeState().getNodeRoleNames()
== null) {
                 Nodes.getInstance().getNodes().get(host).getNodeState().setNodeRoleNames((new
ArrayList<String>()));

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Nodes.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Nodes.java?rev=1181298&r1=1181297&r2=1181298&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Nodes.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Nodes.java
Mon Oct 10 23:39:55 2011
@@ -77,7 +77,12 @@ public class Nodes {
         return nodes;
     }
     
-    public List<Node> getClusterNodes (String clusterName, String roleName, boolean
alive) throws Exception {
+    /*
+     * Return the list of nodes associated with cluster given the role name and alive state
+     * If rolename or alive state is not specified (i.e. "") then all the nodes associated
+     * with cluster are returned.
+     */
+    public List<Node> getClusterNodes (String clusterName, String roleName, String
alive) throws Exception {
         List<Node> list = new ArrayList<Node>();
         ClusterDefinition c = Clusters.getInstance().getClusterDefinition(clusterName);
         if (c.getNodes() == null) {
@@ -99,8 +104,8 @@ public class Nodes {
             GregorianCalendar cal = new GregorianCalendar(); 
             cal.setTime(new Date());
             XMLGregorianCalendar curTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
-            if ((alive && getTimeDiffInMillis(curTime, n.getNodeState().getLastHeartbeatTime())
< NODE_NOT_RESPONDING_DURATION)
-                || (!alive && getTimeDiffInMillis(curTime, n.getNodeState().getLastHeartbeatTime())
>= NODE_NOT_RESPONDING_DURATION)) {
+            if (alive.equals("") || (alive.equalsIgnoreCase("true") && getTimeDiffInMillis(curTime,
n.getNodeState().getLastHeartbeatTime()) < NODE_NOT_RESPONDING_DURATION)
+                || (alive.equals("false") && getTimeDiffInMillis(curTime, n.getNodeState().getLastHeartbeatTime())
>= NODE_NOT_RESPONDING_DURATION)) {
                 list.add(this.nodes.get(host));
             }
         }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClusterResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClusterResource.java?rev=1181298&r1=1181297&r2=1181298&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClusterResource.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClusterResource.java
Mon Oct 10 23:39:55 2011
@@ -167,8 +167,10 @@ public class ClusterResource {
      *                      unique name
      *  @param  roleName    Optionally specify the role name to get the nodes 
      *                      associated with the service role
-     *  @param  alive       Boolean value to specify, if nodes to be returned 
-     *                       are alive or dead or both (if alive is set to null) 
+     *  @param  alive       Boolean value (true/false) to specify, if nodes to be 
+     *                      returned are alive or dead. if this query parameter is 
+     *                      is not specified them all the nodes associated with cluster
+     *                      are returned) 
      *  @return             List of nodes
      *  @throws Exception   throws Exception
      */
@@ -177,7 +179,7 @@ public class ClusterResource {
     @Produces({"application/json", "application/xml"})
     public List<Node> getNodes (@PathParam("clusterName") String clusterName,
                                 @DefaultValue("") @QueryParam("role") String role,
-                                @DefaultValue("") @QueryParam("alive") boolean alive) throws
Exception {    
+                                @DefaultValue("") @QueryParam("alive") String alive) throws
Exception {    
         try {
             return Nodes.getInstance().getClusterNodes(clusterName, role, alive);
         }catch (WebApplicationException we) {



Mime
View raw message