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/09/27 09:36:42 UTC

svn commit: r1176247 - in /incubator/ambari/trunk: client/src/main/java/org/apache/ambari/common/rest/entities/ controller/src/main/java/org/apache/ambari/controller/ controller/src/main/java/org/apache/ambari/controller/rest/resources/

Author: vgogate
Date: Tue Sep 27 07:36:41 2011
New Revision: 1176247

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

Modified:
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.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/NodeState.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/HeartbeatHandler.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClusterResource.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClustersResource.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/StacksResource.java

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java?rev=1176247&r1=1176246&r2=1176247&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java Tue Sep 27 07:36:41 2011
@@ -44,121 +44,121 @@ import javax.xml.bind.annotation.XmlType
 @XmlRootElement(name = "ClusterDefinition")
 public class ClusterDefinition {
         
-        public static final String GOAL_STATE_ACTIVE = "ACTIVE";
-        public static final String GOAL_STATE_INACTIVE = "INACTIVE";
-        public static final String GOAL_STATE_ATTIC = "ATTIC";
+    public static final String GOAL_STATE_ACTIVE = "ACTIVE";
+    public static final String GOAL_STATE_INACTIVE = "INACTIVE";
+    public static final String GOAL_STATE_ATTIC = "ATTIC";
    
-        @XmlElement(name = "Name", required = true)
-    protected String name;
+    @XmlElement(name = "Name", required = true)
+    protected String name = null;
     @XmlElement(name = "Description", required = true)
-    protected String description;
-        @XmlElement(name = "BlueprintName", required = true)
-    protected String blueprintName;
-        @XmlElement(name = "GoalState", required = true)
-        protected String goalState;
-        @XmlElement(name = "ActiveServices", required = true)
-        protected List<String> activeServices;
-        @XmlElement(name = "NodeRangeExpressions", required = true)
-        protected List<String> nodeRangeExpressions;
-        @XmlElement(name = "RoleToNodesMap", required = true)
-        protected RoleToNodesMap roleToNodesMap;
-        
-        
-        /**
-         * @return the name
-         */
-        public String getName() {
-                return name;
-        }
-
-        /**
-         * @param name the name to set
-         */
-        public void setName(String name) {
-                this.name = name;
-        }
-
-        /**
-         * @return the description
-         */
-        public String getDescription() {
-                return description;
-        }
-
-        /**
-         * @param description the description to set
-         */
-        public void setDescription(String description) {
-                this.description = description;
-        }
-
-        /**
-         * @return the blueprintName
-         */
-        public String getBlueprintName() {
-                return blueprintName;
-        }
-
-        /**
-         * @param blueprintName the blueprintName to set
-         */
-        public void setBlueprintName(String blueprintName) {
-                this.blueprintName = blueprintName;
-        }
-
-        /**
-         * @return the goalState
-         */
-        public String getGoalState() {
-                return goalState;
-        }
-
-        /**
-         * @param goalState the goalState to set
-         */
-        public void setGoalState(String goalState) {
-                this.goalState = goalState;
-        }
-
-        /**
-         * @return the activeServices
-         */
-        public List<String> getActiveServices() {
-                return activeServices;
-        }
-
-        /**
-         * @param activeServices the active3Services to set
-         */
-        public void setActiveServices(List<String> activeServices) {
-                this.activeServices = activeServices;
-        }
-
-        /**
-         * @return the nodeRangeExpressions
-         */
-        public List<String> getNodeRangeExpressions() {
-                return nodeRangeExpressions;
-        }
-
-        /**
-         * @param nodeRangeExpressions the nodeRangeExpressions to set
-         */
-        public void setNodeRangeExpressions(List<String> nodeRangeExpressions) {
-                this.nodeRangeExpressions = nodeRangeExpressions;
-        }
-
-        /**
-         * @return the roleToNodesMap
-         */
-        public RoleToNodesMap getRoleToNodesMap() {
-                return roleToNodesMap;
-        }
-
-        /**
-         * @param roleToNodesMap the roleToNodesMap to set
-         */
-        public void setRoleToNodesMap(RoleToNodesMap roleToNodesMap) {
-                this.roleToNodesMap = roleToNodesMap;
-        }
+    protected String description = null;
+    @XmlElement(name = "BlueprintName", required = true)
+    protected String blueprintName = null;
+    @XmlElement(name = "GoalState", required = true)
+    protected String goalState = null;
+    @XmlElement(name = "ActiveServices", required = true)
+    protected List<String> activeServices = null;
+    @XmlElement(name = "NodeRangeExpressions", required = true)
+    protected List<String> nodeRangeExpressions = null;
+    @XmlElement(name = "RoleToNodesMap", required = true)
+    protected RoleToNodesMap roleToNodesMap = null;
+    
+    
+    /**
+     * @return the name
+     */
+    public String getName() {
+            return name;
+    }
+
+    /**
+     * @param name the name to set
+     */
+    public void setName(String name) {
+            this.name = name;
+    }
+
+    /**
+     * @return the description
+     */
+    public String getDescription() {
+            return description;
+    }
+
+    /**
+     * @param description the description to set
+     */
+    public void setDescription(String description) {
+            this.description = description;
+    }
+
+    /**
+     * @return the blueprintName
+     */
+    public String getBlueprintName() {
+            return blueprintName;
+    }
+
+    /**
+     * @param blueprintName the blueprintName to set
+     */
+    public void setBlueprintName(String blueprintName) {
+            this.blueprintName = blueprintName;
+    }
+
+    /**
+     * @return the goalState
+     */
+    public String getGoalState() {
+            return goalState;
+    }
+
+    /**
+     * @param goalState the goalState to set
+     */
+    public void setGoalState(String goalState) {
+            this.goalState = goalState;
+    }
+
+    /**
+     * @return the activeServices
+     */
+    public List<String> getActiveServices() {
+            return activeServices;
+    }
+
+    /**
+     * @param activeServices the active3Services to set
+     */
+    public void setActiveServices(List<String> activeServices) {
+            this.activeServices = activeServices;
+    }
+
+    /**
+     * @return the nodeRangeExpressions
+     */
+    public List<String> getNodeRangeExpressions() {
+            return nodeRangeExpressions;
+    }
+
+    /**
+     * @param nodeRangeExpressions the nodeRangeExpressions to set
+     */
+    public void setNodeRangeExpressions(List<String> nodeRangeExpressions) {
+            this.nodeRangeExpressions = nodeRangeExpressions;
+    }
+
+    /**
+     * @return the roleToNodesMap
+     */
+    public RoleToNodesMap getRoleToNodesMap() {
+            return roleToNodesMap;
+    }
+
+    /**
+     * @param roleToNodesMap the roleToNodesMap to set
+     */
+    public void setRoleToNodesMap(RoleToNodesMap roleToNodesMap) {
+            this.roleToNodesMap = roleToNodesMap;
+    }
 }

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=1176247&r1=1176246&r2=1176247&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 Tue Sep 27 07:36:41 2011
@@ -48,68 +48,69 @@ public class Node {
     @XmlElement(name = "NodeState", required = true)
     protected NodeState nodeState;
    
-        public Node () {}
+    public Node () {}
 
-	public Node (String name) {
-		this.name = name;
-	}
+    public Node (String name) {
+      this.name = name;
+    }
 	
-	/*
-	 * 
-	 */
-	public void releaseNodeFromCluster() {
-		this.nodeState.setClusterName(null);
-		this.getNodeState().setNodeServers(null);
-		/*
-		 * TODO: AllocatedToClsuter flag will be reset part of heart beat processing when node completes cleanup.
-		 */
-	}
+    /*
+     * 
+     */
+    public void releaseNodeFromCluster() {
+      this.nodeState.setClusterName(null);
+      this.getNodeState().setNodeServers(null);
+      this.getNodeState().setNodeRoleNames(null);
+      /*
+       * TODO: AllocatedToClsuter flag will be reset part of heart beat processing when node completes cleanup.
+       */
+    }
 	
-	/*
-	 * Reserving node for cluster is done by associating cluster name w/ node
-	 */
-	public void reserveNodeForCluster (String clusterName, Boolean agentInstalled) {
-		this.getNodeState().setClusterName(clusterName);
-		this.getNodeState().setAgentInstalled(agentInstalled);
-		this.getNodeState().setAllocatedToCluster(true);
-	}
+  	/*
+  	 * Reserving node for cluster is done by associating cluster name w/ node
+  	 */
+  	public void reserveNodeForCluster (String clusterName, Boolean agentInstalled) {
+  		this.getNodeState().setClusterName(clusterName);
+  		this.getNodeState().setAgentInstalled(agentInstalled);
+  		this.getNodeState().setAllocatedToCluster(true);
+  	}
         
     /**
-         * @return the name
-         */
-        public String getName() {
-                return name;
-        }
-        /**
-         * @param name the name to set
-         */
-        public void setName(String name) {
-                this.name = name;
-        }
-        
-        /**
-         * @return the nodeMetrics
-         */
-        public NodeAttributes getNodeAttributes() {
-                return nodeAttributes;
-        }
-        /**
-         * @param nodeMetrics the nodeMetrics to set
-         */
-        public void setNodeAttributes(NodeAttributes nodeAttributes) {
-                this.nodeAttributes = nodeAttributes;
-        }
-        /**
-         * @return the nodeState
-         */
-        public NodeState getNodeState() {
-                return nodeState;
-        }
-        
-        /**
-         * @param nodeState the nodeState to set
-         */
-        public void setNodeState(NodeState nodeState) {
-                this.nodeState = nodeState;
-        }
+     * @return the name
+     */
+    public String getName() {
+            return name;
+    }
+    /**
+     * @param name the name to set
+     */
+    public void setName(String name) {
+            this.name = name;
+    }
+    
+    /**
+     * @return the nodeMetrics
+     */
+    public NodeAttributes getNodeAttributes() {
+            return nodeAttributes;
+    }
+    /**
+     * @param nodeMetrics the nodeMetrics to set
+     */
+    public void setNodeAttributes(NodeAttributes nodeAttributes) {
+            this.nodeAttributes = nodeAttributes;
+    }
+    /**
+     * @return the nodeState
+     */
+    public NodeState getNodeState() {
+            return nodeState;
+    }
+    
+    /**
+     * @param nodeState the nodeState to set
+     */
+    public void setNodeState(NodeState nodeState) {
+            this.nodeState = nodeState;
+    }
 }

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/NodeState.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/NodeState.java?rev=1176247&r1=1176246&r2=1176247&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/NodeState.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/NodeState.java Tue Sep 27 07:36:41 2011
@@ -33,7 +33,8 @@ import javax.xml.datatype.XMLGregorianCa
     "clusterName",
     "AllocatedToCluster",
     "agentInstalled",
-        "nodeServers"
+    "nodeRoleNames",
+    "nodeServers"
 })
 public class NodeState {
 
@@ -45,85 +46,105 @@ public class NodeState {
      * Associating the cluster name would reserve the node for a given cluster
      * 
      */
-        @XmlElement(name = "ClusterName", required = true)
+    @XmlElement(name = "ClusterName", required = true)
     protected String clusterName;
 
-        @XmlElement(name = "AgentInstalled", required = true)
+    @XmlElement(name = "AgentInstalled", required = true)
     protected Boolean agentInstalled = true;
 
-        @XmlElement(name = "AllocatedToCluster", required = true)
+    @XmlElement(name = "AllocatedToCluster", required = true)
     protected Boolean allocatedToCluster = false;
         
-        @XmlElement(name = "NodeServers", required = true)
+    /*
+     * null indicates no roles associated with this node.
+     */
+    @XmlElement(name = "NodeRoleNames", required = true)
+    protected List<String> nodeRoleNames = null;
+        
+    @XmlElement(name = "NodeServers", required = true)
     protected List<NodeServer> nodeServers = new ArrayList<NodeServer>();
 
-        /**
-         * @return the allocatedToCluster
-         */
-        public Boolean getAllocatedToCluster() {
-                return allocatedToCluster;
-        }
-
-        /**
-         * @param allocatedToCluster the allocatedToCluster to set
-         */
-        public void setAllocatedToCluster(Boolean allocatedToCluster) {
-                this.allocatedToCluster = allocatedToCluster;
-        }
-        
-        /**
-         * @return the agentInstalled
-         */
-        public Boolean getAgentInstalled() {
-                return agentInstalled;
-        }
-
-        /**
-         * @param agentInstalled the agentInstalled to set
-         */
-        public void setAgentInstalled(Boolean agentInstalled) {
-                this.agentInstalled = agentInstalled;
-        }
-        
-        /**
-         * @return the clusterName
-         */
-        public String getClusterName() {
-                return clusterName;
-        }
-
-        /**
-         * @param clusterName the clusterName to set
-         */
-        public void setClusterName(String clusterName) {
-                this.clusterName = clusterName;
-        }
-        
-        /**
-         * @return the lastHeartbeatTime
-         */
-        public XMLGregorianCalendar getLastHeartbeatTime() {
-                return lastHeartbeatTime;
-        }
-
-        /**
-         * @param lastHeartbeatTime the lastHeartbeatTime to set
-         */
-        public void setLastHeartbeatTime(XMLGregorianCalendar lastHeartbeatTime) {
-                this.lastHeartbeatTime = lastHeartbeatTime;
-        }
-
-        /**
-         * @return the nodeServers
-         */
-        public List<NodeServer> getNodeServers() {
-                return nodeServers;
-        }
-
-        /**
-         * @param nodeServers the nodeServers to set
-         */
-        public void setNodeServers(List<NodeServer> nodeServers) {
-                this.nodeServers = nodeServers;
-        }
+    /**
+     * @return the nodeRoleNames
+     */
+    public List<String> getNodeRoleNames() {
+      return nodeRoleNames;
+    }
+
+    /**
+     * @param nodeRoleNames the nodeRoleNames to set
+     */
+    public void setNodeRoleNames(List<String> nodeRoleNames) {
+      this.nodeRoleNames = nodeRoleNames;
+    }
+
+    /**
+     * @return the allocatedToCluster
+     */
+    public Boolean getAllocatedToCluster() {
+            return allocatedToCluster;
+    }
+
+    /**
+     * @param allocatedToCluster the allocatedToCluster to set
+     */
+    public void setAllocatedToCluster(Boolean allocatedToCluster) {
+            this.allocatedToCluster = allocatedToCluster;
+    }
+    
+    /**
+     * @return the agentInstalled
+     */
+    public Boolean getAgentInstalled() {
+            return agentInstalled;
+    }
+
+    /**
+     * @param agentInstalled the agentInstalled to set
+     */
+    public void setAgentInstalled(Boolean agentInstalled) {
+            this.agentInstalled = agentInstalled;
+    }
+    
+    /**
+     * @return the clusterName
+     */
+    public String getClusterName() {
+            return clusterName;
+    }
+
+    /**
+     * @param clusterName the clusterName to set
+     */
+    public void setClusterName(String clusterName) {
+            this.clusterName = clusterName;
+    }
+    
+    /**
+     * @return the lastHeartbeatTime
+     */
+    public XMLGregorianCalendar getLastHeartbeatTime() {
+            return lastHeartbeatTime;
+    }
+
+    /**
+     * @param lastHeartbeatTime the lastHeartbeatTime to set
+     */
+    public void setLastHeartbeatTime(XMLGregorianCalendar lastHeartbeatTime) {
+            this.lastHeartbeatTime = lastHeartbeatTime;
+    }
+
+    /**
+     * @return the nodeServers
+     */
+    public List<NodeServer> getNodeServers() {
+            return nodeServers;
+    }
+
+    /**
+     * @param nodeServers the nodeServers to set
+     */
+    public void setNodeServers(List<NodeServer> nodeServers) {
+            this.nodeServers = nodeServers;
+    }
 }

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=1176247&r1=1176246&r2=1176247&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 Tue Sep 27 07:36:41 2011
@@ -36,26 +36,22 @@ import org.apache.ambari.common.rest.ent
 
 public class Clusters {
 
-        /*
-         * Operational clusters include both active and inactive clusters
-         */
-    protected ConcurrentHashMap<String, ClusterDefinition> operational_clusters = new ConcurrentHashMap<String, ClusterDefinition>();
+    /*
+     * Operational clusters include both active and inactive clusters
+     */
+    protected ConcurrentHashMap<String, Cluster> operational_clusters = new ConcurrentHashMap<String, Cluster>();
     
-    /* 
-     * Attic clusters are just definitions left around. When cluster is retired i.e. all its nodes 
-     * are released then the cluster entry is transferred to attic and deleted from active 
-     * clusters list.
-     * Cluster in attic list should be submitted as new cluster, if needs to be reactivated. 
+    /*
+     * Operational clusters name to ID map
      */
-    protected ConcurrentHashMap<String, ClusterDefinition> attic_clusters = new ConcurrentHashMap<String, ClusterDefinition>();
+    protected ConcurrentHashMap<String, String> operational_clusters_id_to_name = new ConcurrentHashMap<String, String>();
     
     /*
-     * Hashmap of cluster name to NodeToRolesMap
-     * For every cluster it keeps the association of each cluster node to its list of associated roles based on
-     * cluster definition. If roleToNodesExpressions are explicitly specified in the cluster definitions then
-     * it is considered else it is derived based on node attributes.
+     * List of clusters to be deleted when they get into ATTIC state 
+     * When cluster state is switched to ATTIC, if it is present in the tobe_deleted_list, 
+     * it should be deleted from the persistence list and inmemory list. 
      */
-    protected ConcurrentHashMap<String, ConcurrentHashMap<String, List<String>>> cluster_to_node_to_roles_map = new ConcurrentHashMap<String, ConcurrentHashMap<String, List<String>>>();
+    ConcurrentHashMap<String, String> tobe_deleted_clusters = new ConcurrentHashMap<String, String>();
     
     private static Clusters ClustersTypeRef=null;
         
@@ -139,7 +135,7 @@ public class Clusters {
 				updateNodeToRolesAssociation(c, c.getRoleToNodesMap());
 			} else {
 				/*
-				 * Derive the role to nodes map based on nodes attributes
+				 * TODO: Derive the role to nodes map based on nodes attributes
 				 * then populate the node to roles association.
 				 */
 			}
@@ -149,8 +145,9 @@ public class Clusters {
     		 * 		 Persist reserved nodes against the cluster & service/role
     		 */
     			
-    		// Add the cluster to list, when definition is persisted
-    		operational_clusters.put(c.getName(), c);
+    		// Add the cluster to the list, when definition is persisted
+    		this.operational_clusters.put(c.getName(), cls);
+    		this.operational_clusters_id_to_name.put(cls.getID(), c.getName());
     	}
     	return c;
     } 
@@ -250,265 +247,183 @@ public class Clusters {
 		}
 		
 		/*
-		 * Generate node to roles hash map. 
+		 * Add list of roles to Node
 		 * If node is not explicitly associated with any role then assign it w/ default role
+		 * TODO: 
 		 */
-		ConcurrentHashMap<String, List<String>> nodeToRolesHashMap = new ConcurrentHashMap<String, List<String>>();
 		for (RoleToNodesMapEntry e : roleToNodesMap.getRoleToNodesMapEntry()) {
 			List<String> hosts = getHostnamesFromRangeExpressions(e.getNodeRangeExpressions());
 			for (String host : hosts) {
-				if (!nodeToRolesHashMap.containsKey(host)) {
-					List<String> x = new ArrayList<String>();
-					x.add(e.getRoleName());
-					nodeToRolesHashMap.put(host, x);
-				} else {
-					nodeToRolesHashMap.get(host).add(e.getRoleName());
-				}
+			  if (Nodes.getInstance().getNodes().get(host).getNodeState().getNodeRoleNames() == null) {
+			    Nodes.getInstance().getNodes().get(host).getNodeState().setNodeRoleNames((new ArrayList<String>()));
+			  } 
+			  Nodes.getInstance().getNodes().get(host).getNodeState().getNodeRoleNames().add(e.getRoleName());
 			}
 		}
-				
+		
+		
 		/*
-		 * Get the list of specified global node list for the cluster 
+		 * Get the list of specified global node list for the cluster and any nodes not explicitly specified in the
+		 * role to nodes map, assign them with default role defined in cluster blueprint
 		 */
 		List<String> specified_node_range = new ArrayList<String>();
     	specified_node_range.addAll(getHostnamesFromRangeExpressions(c.getNodeRangeExpressions()));
     	for (String host : specified_node_range) {
-    		if (!nodeToRolesHashMap.containsKey(host)) {
-    			List<String> x = new ArrayList<String>();
-				x.add(getDefaultRoleName());
-				nodeToRolesHashMap.put(host, x);
-    		} else {
-    			nodeToRolesHashMap.get(host).add(getDefaultRoleName());
-    		}
+    	  if (Nodes.getInstance().getNodes().get(host).getNodeState().getNodeRoleNames() == null) {
+          Nodes.getInstance().getNodes().get(host).getNodeState().setNodeRoleNames((new ArrayList<String>()));
+          String clusterName = Nodes.getInstance().getNodes().get(host).getNodeState().getClusterName();
+          Nodes.getInstance().getNodes().get(host).getNodeState().getNodeRoleNames().add(getDefaultRoleName(clusterName));
+        } 
+        
     	}
-    	
-    	/*
-    	 * Add the nodeToRolesHashMap to gobal clsuter_to_node_to_roles map
-    	 */
-    	cluster_to_node_to_roles_map.put(c.getName(), nodeToRolesHashMap);
 	}
 
     /* 
-     * Update cluster 
+     * Update cluster definition
+     * Always latest version is kept in memory
     */
     public void updateCluster(String clusterName, ClusterDefinition c) throws Exception {
+        
         /*
-         * Update the cluster definition. 
-         * Always latest version of cluster definition is kept in memory 
-         * Revisions for cluster definition is mainly need for agents to know
-         * that something is changed in cluster definition?
-         * TODO: 
-         *              Make update atomic? i.e. persist the new revision first and then update the 
-         *              definition in memory? make sure get cluster does not get partial definition.. 
+         * Validate cluster definition
          */
-        int i;
-        ClusterDefinition cls = null;
-        for (i=0; i<operational_clusters.size(); i++) {
-                if (operational_clusters.get(i).equals(clusterName)) {
-                        cls = operational_clusters.get(i);
-                        break;
-                }
+        if (c.getName() == null || c.getName().equals("") || !c.getName().equals(clusterName)) {
+            Exception e = new Exception("Cluster name in resource URI ["+clusterName+"] does not match with one specified in update request element");
+            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
         }
         
-        // Throw exception if cluster is not found
-        if (i == operational_clusters.size()) {
-                throw new Exception("Specified cluster ["+clusterName+"] does not exists");
+        /*
+         * Check if cluster already exists
+         */
+        if (!this.operational_clusters.containsKey(clusterName)) {
+            Exception e = new Exception("Cluster ["+clusterName+"] does not exits");
+            throw new WebApplicationException(e, Response.Status.NOT_FOUND);
         }
         
-        synchronized (cls) {
-                if (c.getDescription() != null) cls.setDescription(c.getDescription());
-                // Update the last update time
-                //cls.setLastUpdateTime(new Date());
-                //cls.setRevision(cls.getRevision()+1);
-                /*
-                 * TODO: Persist the latest cluster definition under new revision
-                */
+        Cluster cls = this.operational_clusters.get(clusterName);
+        synchronized (cls.getClusterDefinition()) {
+            if (c.getBlueprintName() != null) cls.getClusterDefinition().setBlueprintName(c.getBlueprintName());
+            if (c.getDescription() != null) cls.getClusterDefinition().setDescription(c.getDescription());
+            if (c.getGoalState() != null) cls.getClusterDefinition().setGoalState(c.getGoalState());
+            if (c.getActiveServices() != null) cls.getClusterDefinition().setActiveServices(c.getActiveServices());
+            if (c.getNodeRangeExpressions() != null) {
+                cls.getClusterDefinition().setNodeRangeExpressions(c.getNodeRangeExpressions());
+                updateClusterNodesReservation (cls, c.getNodeRangeExpressions());
+            }
+            if (c.getRoleToNodesMap() != null) {
+                cls.getClusterDefinition().setRoleToNodesMap(c.getRoleToNodesMap());
+                updateNodeToRolesAssociation(cls.getClusterDefinition(), c.getRoleToNodesMap());
+            }  
+            
+            /*
+             *  Update the last update time & revision
+             */
+            cls.getClusterState().setLastUpdateTime(new Date());
+            cls.setRevision(cls.getRevision()+1);
+            
+            /*
+             * TODO: Persist the latest cluster definition under new revision
+             */
         }
         return;
     }
     
     /*
-     * Update role to Nodes Map
-    
-    private void updateClusterRoleToNodesMap (RoleToNodesMapType s, RoleToNodesMapType t) throws Exception {
-        for (RoleToNodesMapEntryType se : s.getRoleToNodesMapEntry()) {
-                for (RoleToNodesMapEntryType te : t.getRoleToNodesMapEntry()) {
-                        if (se.getServiceName().equals(te.getServiceName()) && se.getRoleName().equals(te.getRoleName())) {
-                                te.setNodeRangeExpression(se.getNodeRangeExpression());
-                        } else {
-                                t.getRoleToNodesMapEntry().add(se);
-                        }
-                }
-        }
-    } */
-    
-    /*
-     * Delete ClusterType from the list
-     * Delete operation will only remove the entry from the controller 
-     * Cluster must be in ATTIC state to be deleted from controller
-     
-    public void deleteCluster(ClusterType c) throws Exception { 
+     * Delete Cluster 
+     * Delete operation will bring the clsuter to ATTIC state and then remove the
+     * cluster definition from the controller 
+     * When cluster state transitions to ATTIC, it should check if the cluster definition is 
+     * part of tobe_deleted_clusters map and then deleted the definition.
+     */
+    public void deleteCluster(String clusterName) throws Exception { 
         synchronized (operational_clusters) {
-                for (int i=0;i<operational_clusters.size();i++) {
-                        if (operational_clusters.get(i).getName().equals(c.getName())) {
-                                synchronized (operational_clusters.get(i)) {
-                                        if (operational_clusters.get(i).getCurrentState().equals(ClusterState.CLUSTER_STATE_ATTIC)) {
-                                                // TODO: remove the persistent entry from data store
-                                                
-                                                 // Remove the entry from the in-memory clsuter list
-                                                 
-                                                operational_clusters.remove(i);
-                                        } else {
-                                                throw new Exception ("Cluster ["+operational_clusters.get(i).getName()+"] not in ATTIC state");
-                                        }
-                                }
-                        }
+            for (Cluster cls : operational_clusters.values()) {
+                if (cls.getClusterDefinition().getName().equals(clusterName)) {
+                    synchronized (cls) {
+                        cls.getClusterDefinition().setGoalState(ClusterState.CLUSTER_STATE_ATTIC);
+                        this.tobe_deleted_clusters.put(clusterName, null);                    
+                    }
                 } 
+            }
         }
-        return;
-    } */  
-    
-    
-    /*
-     * Get Cluster definition snapshot (whenever it is to be serialized over wire)
-     * TODO: CHECK_IT
+    }   
      
-    public ClusterType getClusterSnapshot(String clusterName) throws Exception {
-        for (ClusterType cls : operational_clusters) {
-                ClusterType cls1 = null;
-                        if (cls.getName().equals(clusterName)) {
-                                synchronized (cls) {
-                                        //cls1 = cls.clone();
-                                }
-                        }
-                        return cls1;
-                }
-        throw new Exception ("Cluster:["+clusterName+"] does not exists");
-    } */
-    
     /* 
-     * Get the cluster definition 
-    */
-    public ClusterDefinition getCluster(String clusterName) {
-        /*for (ClusterDefinition cls : operational_clusters) {
-                        if (cls.getName().equals(clusterName)) {
-                                return cls;
-                        }
-                }*/return null;
+     * Get the cluster by name
+     */
+    public Cluster getClusterByName(String clusterName) {
+        return this.operational_clusters.get(clusterName);
     }
     
-    /*
-     * Get the list of deployed clusters
-     * TODO: return the synchronized snapshot of the deployed cluster list
+    /* 
+     * Get the cluster by ID
      */
-    public List<ClusterDefinition> getDeployedClusterList(String type) {
-        List<ClusterDefinition> list = new ArrayList<ClusterDefinition>();
-        if (type.equals("ALL")) {
-                //list.addAll(this.operational_clusters);
-                return list;
+    public Cluster getClusterByID(String clusterID) {
+        String clusterName = this.operational_clusters_id_to_name.get(clusterID);
+        if (clusterName != null) {
+            return this.getClusterByName(clusterName);
         } else {
-                //for (ClusterDefinition cls : operational_clusters) {
-                        //if (cls.gcurrentState.equals(type)) {
-                        //      list.add(cls);
-                        //}
-                //}
+            return null;
         }
-        return list;
-    } 
+    }
     
-    /*
-     * Get the list of retired cluster definitions
-     * TODO: return synchronized snapshot of the retired cluster list
+    /* 
+     * Get the cluster definition by name
      */
-    public List<ClusterDefinition> getRetiredClusterList() {
-        List<ClusterDefinition> list = new ArrayList<ClusterDefinition>();
-        //list.addAll(this.attic_clusters);
-        return list;
+    public ClusterDefinition getClusterDefinition(String clusterName) throws WebApplicationException  {
+        if (!this.operational_clusters.containsKey(clusterName)) {
+            Exception e = new Exception("Cluster ["+clusterName+"] does not exits");
+            throw new WebApplicationException(e, Response.Status.NOT_FOUND);
+        }
+        return this.operational_clusters.get(clusterName).getClusterDefinition();
     }
     
-    /*
-     * Get the list of clusters
-     * TODO: Get the synchronized snapshot of each cluster definition? 
-     
-    public List<ClusterType> getClusterList(String type) {
-        List<ClusterType> list = new ArrayList<ClusterType>();
-        if (type.equals("ALL")) {
-                list.addAll(getRetiredClusterList());
-                list.addAll(getDeployedClusterList("ALL"));
-        } else if (type.equals("ATTIC")) {
-                list.addAll(getRetiredClusterList());
-        } else {
-                for (ClusterType cls : operational_clusters ) {
-                        if (cls.currentState.equals(type)) {
-                                list.add(cls);
-                        }
-                }
+    
+    /* 
+     * Get the cluster state
+    */
+    public ClusterState getClusterState(String clusterName) throws WebApplicationException {
+        if (!this.operational_clusters.containsKey(clusterName)) {
+            Exception e = new Exception("Cluster ["+clusterName+"] does not exits");
+            throw new WebApplicationException(e, Response.Status.NOT_FOUND);
         }
-        return list;
-    } */
+        return this.operational_clusters.get(clusterName).getClusterState();
+    }
+    
     
     /*
-     * Change the cluster goal state
-     * TODO: Change the argument goalState from string to enum
-     * TODO: Use state machine to trigger the state change events  
-     */
-    public void changeClusterGoalState (String clusterName, String goalState, Date requestTime) throws Exception {
-        int i;
-        ClusterDefinition cls = null;
-        for (i=0; i<operational_clusters.size(); i++) {
-                if (operational_clusters.get(i).equals(clusterName)) {
-                        cls = operational_clusters.get(i);
-                        break;
-                }
-        }
-        
-        // Throw exception if cluster is not found
-        if (i == operational_clusters.size()) {
-                throw new Exception("Specified cluster ["+clusterName+"] does not exists");
-        }
-        
-        synchronized (cls) {
-                // Set the goal state
-                //cls.setLastRequestedGoalState(goalState);
-                        //cls.setTimeOflastRequestedGoalState(requestTime);
-                
-                /*
-                 * TODO: Persist the latest cluster definition under new revision
-                */
+     * Get Cluster definition list
+     */
+    public List<ClusterDefinition> getClusterDefinitionsList(String state) {
+      List<ClusterDefinition> list = new ArrayList<ClusterDefinition>();
+      for (Cluster cls : this.operational_clusters.values()) {
+        if (state.equals("ALL")) {
+          list.add(cls.getClusterDefinition());
+        } else {
+          if (cls.getClusterState().getRepresentativeState().equals(state)) {
+            list.add(cls.getClusterDefinition());
+          }
         }
-        
-        /*
-         * send state change event to cluster state machine 
-         */
-        //changeClusterState(this.getName());
+      }
+      return list;
     }
     
     /*
-     * Cluster state change event Handler
-     * 
-         * TODO: 
-         *               -- Make sure cluster definition is complete else throw exception 
-         *                      -- Check all ClusterType fields have valid values
-         *                      -- Check if roles have required number of nodes associated with it.
-         *               -- Add the nodes to NodesType list w/ name, cluster name, deployment state etc.
-         *               -- Trigger agent installation on the nodes, if not already done 
-         * 
-         *               -- Once agent is installed it should register itself w/ controller, get the 
-         *                      associated latest cluster definition and deploy the stack. If goal state is active
-         *                      it should get the associated services up. Once sync-ed, it should
-         *                      update its state w/ controller through heartbeat.
-         * 
-         *      -- Once required number of service nodes are up cluster state should be changed accordingly
-        */
-    public void stateChangeEventHandler (String currentState, String goalState) {
-        synchronized(this) {
-                /*
-                 * ATTIC to ACTIVE or INACTIVE
-                 */
-                        if (currentState.equals(ClusterState.CLUSTER_STATE_ATTIC) && goalState.equals(ClusterState.CLUSTER_STATE_ACTIVE)) {
-                                
-                        }
+     * Get the list of clusters
+     * TODO: Get the synchronized snapshot of each cluster definition? 
+     */
+    public List<Cluster> getClustersList(String state) {
+        List<Cluster> list = new ArrayList<Cluster>();
+        if (state.equals("ALL")) {
+          list.addAll(this.operational_clusters.values());
+        } else {
+          for (Cluster cls : this.operational_clusters.values()) {
+            if (cls.getClusterState().getRepresentativeState().equals(state)) {
+              list.add(cls);
+            }
+          }
         }
+        return list;
     }
     
     /* 
@@ -518,35 +433,33 @@ public class Clusters {
 	/*
 	 * Get the list of role names associated with node
 	 */
-	public List<String> getAssociatedRoleNames(Node n) {
-		String clusterName = n.getNodeState().getClusterName();
-		if (clusterName != null) {
-			return Clusters.getInstance().cluster_to_node_to_roles_map.get(n.getNodeState().getClusterName()).get(n.getName());
-		} else {
-			return null;
-		}
+	public List<String> getAssociatedRoleNames(String hostname) {
+	  return Nodes.getInstance().getNodes().get(hostname).getNodeState().getNodeRoleNames();
 	}
 	
 	/*
 	 *  Return the default role name to be associated with specified cluster node that 
 	 *  has no specific role to nodes association specified in the cluster definition
+	 *  Throw exception if node is not associated to with any cluster
 	 */
-	public String getDefaultRoleName() {
+	public String getDefaultRoleName(String clusterName) throws Exception {
+	    Cluster c = Clusters.getInstance().getClusterByName(clusterName);
+	    // TODO: find the default role from the clsuter blueprint 
 		return "slaves";
 	}
 	
 	/*
-     * TODO: Implement proper range expression
-     */
-    public List<String> getHostnamesFromRangeExpressions (List<String> nodeRangeExpressions) throws Exception {
-  
-    	List<String> list = new ArrayList<String>();
-    	for (String nodeRangeExpression : nodeRangeExpressions) {
-	    	StringTokenizer st = new StringTokenizer(nodeRangeExpression);
-	    	while (st.hasMoreTokens()) {
-	    		list.add(st.nextToken());
-	    	}
+   * TODO: Implement proper range expression
+   * TODO: Remove any duplicate nodes from the derived list
+   */
+  public List<String> getHostnamesFromRangeExpressions (List<String> nodeRangeExpressions) throws Exception {
+  	List<String> list = new ArrayList<String>();
+  	for (String nodeRangeExpression : nodeRangeExpressions) {
+    	StringTokenizer st = new StringTokenizer(nodeRangeExpression);
+    	while (st.hasMoreTokens()) {
+    		list.add(st.nextToken());
     	}
-    	return list;
-    }
+  	}
+  	return list;
+  }
 }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java?rev=1176247&r1=1176246&r2=1176247&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java Tue Sep 27 07:36:41 2011
@@ -79,7 +79,7 @@ public class HeartbeatHandler {
     heartbeatQueue.add(heartbeat);
     
     //get the current response for the node/role
-    List<String> roles = Clusters.getInstance().getAssociatedRoleNames(node);
+    List<String> roles = Clusters.getInstance().getAssociatedRoleNames(heartbeat.getHostname());
     
     if (roles != null && roles.size() != 0) {
       

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=1176247&r1=1176246&r2=1176247&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 Tue Sep 27 07:36:41 2011
@@ -33,6 +33,7 @@ import javax.ws.rs.QueryParam;
 
 
 import org.apache.ambari.common.rest.entities.Cluster;
+import org.apache.ambari.common.rest.entities.ClusterDefinition;
 import org.apache.ambari.common.rest.entities.Node;
 import org.apache.ambari.common.rest.entities.ClusterState;
 import org.apache.ambari.controller.Clusters;
@@ -43,60 +44,57 @@ import org.apache.ambari.controller.Clus
 @Path(value = "/clusters/{clusterName}")
 public class ClusterResource {
         
-        /** Get the definition of specified Hadoop cluster.
-         * 
-         *  <p>
-         *  REST:<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/{clusterName}<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : GET <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  <p> 
-         *  
-         *  @param      clusterName             Name of the cluster; Each cluster is identified w/ unique name
-         *  @return                                     Returns the Cluster definition
-         *  @throws     Exception               Throws exception (TBD)
-         */
-        @GET
-        @Produces({"application/json", "application/xml"})
-        public Cluster getCluster(@PathParam("clusterName") String clusterName) throws Exception {
-                //return Clusters.getInstance().getCluster(clusterName);
-                return null;
-        }
+    /** Get the definition of specified Hadoop cluster.
+     * 
+     *  <p>
+     *  REST:<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/{clusterName}<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : GET <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  <p> 
+     *  
+     *  @param      clusterName             Name of the cluster; Each cluster is identified w/ unique name
+     *  @return                             Returns the Cluster definition
+     *  @throws     Exception               Throws exception (TBD)
+     */
+    @GET
+    @Produces({"application/json", "application/xml"})
+    public ClusterDefinition getClusterDefinition(@PathParam("clusterName") String clusterName) throws Exception {
+        return Clusters.getInstance().getClusterDefinition(clusterName);
+    }
     
     /** Update cluster definition.
      *  <p>
      *  Update cluster definition allows updating any sub-elements of cluster definition. Only sub-elements to be 
      *  updated can be specified with new values while others can be "null".
      *  <p>
-         *  REST:<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/{clusterName}<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : PUT <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  <p> 
+     *  REST:<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/{clusterName}<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : PUT <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  <p> 
      * 
      * @param   clusterName             Name of the cluster; Each cluster is identified w/ unique name
      * @param   cluster                 Cluster definition with specific sub-elements to be updated
-     * @return                                  Returns updated cluster definition
+     * @return                          Returns updated cluster definition
      * @throws  Exception               throws Exception (TBD)
      */ 
     @PUT
-        @Consumes({"application/json", "application/xml"})
-        public Cluster updateClusterDefinition(@PathParam("clusterName") String clusterName, Cluster cluster) throws Exception {
-        //      if (cluster.getName() == null || cluster.getName().equals("") || !cluster.getName().equals(clusterName)) {
-        //              throw new Exception("Cluster name in URI ["+clusterName+"] does not match with one specified in update request elelemt");
-      //                }
-        //Clusters.getInstance().updateCluster(clusterName, cluster);
-        return null;
+    @Consumes({"application/json", "application/xml"})
+    public ClusterDefinition updateClusterDefinition(@PathParam("clusterName") String clusterName, ClusterDefinition cluster) throws Exception {
+        
+    //Clusters.getInstance().updateCluster(clusterName, cluster);
+    return null;
     }
      
     /** Delete the the cluster.
@@ -105,25 +103,25 @@ public class ClusterResource {
      *  the controller repository. In "ATTIC" state all the cluster services would be stopped and nodes are 
      *  released. All the data on the cluster will be lost.
      *  <p>
-         *  REST:<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/{clusterName}/action/terminate<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : DELETE <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  <p> 
-         *  
+     *  REST:<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/{clusterName}/action/terminate<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : DELETE <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  <p> 
+     *  
      *  @param  clusterName             Name of the cluster; Each cluster is identified w/ unique name
      *  @throws Exception               throws Exception (TBD)
      */
     @DELETE
-        @Consumes({"application/json", "application/xml"})
-        public void deleteCluster( @PathParam("clusterName") String clusterName) throws Exception {
-                //Clusters.getInstance().changeClusterGoalState (clusterName, Clusters.GOAL_STATE_ATTIC, new Date());
-        }
+    @Consumes({"application/json", "application/xml"})
+    public void deleteCluster( @PathParam("clusterName") String clusterName) throws Exception {
+        Clusters.getInstance().deleteCluster(clusterName);
+    }
     
     /** Get the cluster state.
      *  <p>
@@ -134,17 +132,17 @@ public class ClusterResource {
      *          "ATTIC"         : Only cluster definition is available. No nodes are reserved for the cluster in this state.  <br>
      *  
      *  <p>
-         *  REST:<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/{clusterName}/clusterstate<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : GET <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  <p> 
-         *  
+     *  REST:<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/{clusterName}/clusterstate<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : GET <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  <p> 
+     *  
      *  @param  clusterName             Name of the cluster; Each cluster is identified w/ unique name
      *  @return                                 Returns cluster state object.
      *  @throws Exception               throws Exception (TBD)  

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClustersResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClustersResource.java?rev=1176247&r1=1176246&r2=1176247&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClustersResource.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClustersResource.java Tue Sep 27 07:36:41 2011
@@ -45,13 +45,13 @@ public class ClustersResource {
         ClusterDefinition cluster123 = new ClusterDefinition();
         ClusterDefinition cluster124 = new ClusterDefinition();
         cluster123.setName("blue.dev.Cluster123");
-       //cluster123.setBlueprintURI("http://localhost:123/blueprint");
-       // cluster123.setDescription("test cluster");
-       // cluster124.setName("blue.research.Cluster124");
-       //cluster124.setBlueprintURI("http://localhost:124/blueprint");
-       // cluster124.setDescription("production cluster");
-       // Clusters.getInstance().addCluster(cluster123, Clusters.GOAL_STATE_ATTIC);
-       // Clusters.getInstance().addCluster(cluster124, Clusters.GOAL_STATE_ATTIC);
+        //cluster123.setBlueprintURI("http://localhost:123/blueprint");
+        // cluster123.setDescription("test cluster");
+        // cluster124.setName("blue.research.Cluster124");
+        //cluster124.setBlueprintURI("http://localhost:124/blueprint");
+        // cluster124.setDescription("production cluster");
+        // Clusters.getInstance().addCluster(cluster123, Clusters.GOAL_STATE_ATTIC);
+        // Clusters.getInstance().addCluster(cluster124, Clusters.GOAL_STATE_ATTIC);
     }  
     
     /** Get the list of clusters.
@@ -63,79 +63,65 @@ public class ClustersResource {
      *  &nbsp;&nbsp;&nbsp;&nbsp;"ATTIC"         : All the retired i.e. ATTIC state clusters
      *  
      *  <p>
-         *  REST:<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : GET <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  <p> 
-         *  
+     *  REST:<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : GET <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  <p> 
+     *  
      *  @param  state                   The state of the cluster
      *  @param  search                  Optional search expression to return list of matching clusters
-     *  @return                                 Returns the list of clusters based on specified state and optional search criteria.
+     *  @return                         Returns the list of clusters based on specified state and optional search criteria.
      *  @throws Exception               throws Exception (TBD)
      */
     @GET
     @Produces({"application/json", "application/xml"})
     public List<ClusterDefinition> getClusterList (
-                                                 @DefaultValue("ALL") @QueryParam("state") String state,
+                                 @DefaultValue("ALL") @QueryParam("state") String state,
                                  @DefaultValue("") @QueryParam("search") String search) throws Exception {
         List<ClusterDefinition> searchResults = null;
-        if (!search.equals("")) {
-                /*
-                 * TODO: Implement search 
-                searchResults = new ArrayList<Cluster>();
-                for (Cluster cls : Clusters.getInstance().getClusterList(state)) {
-                        if (cls.getName().matches("^.*"+search+".*$")) {
-                                searchResults.add(cls);
-                        }
-                }
-                */
-        } else {
-                //searchResults = Clusters.getInstance().getClusterList(state);
-        }
+        searchResults = Clusters.getInstance().getClusterDefinitionsList(state);
     
         if (searchResults.isEmpty()) {
                 throw new WebApplicationException(Response.Status.NOT_FOUND);
-        }
-        
+        }   
         return searchResults;
     }
     
     /** Add new cluster definition.
-         *  <p>
-         *  Cluster goal state can be either "ACTIVE" or "INACTIVE". In the "INACTIVE" state, nodes specified in the 
-         *  cluster definition will be reserved for the cluster. Although the actual deployment and starting of services 
-         *  would begin when cluster definition is updated to be "ACTIVE"
+     *  <p>
+     *  Cluster goal state can be either "ACTIVE" or "INACTIVE". In the "INACTIVE" state, nodes specified in the 
+     *  cluster definition will be reserved for the cluster. Although the actual deployment and starting of services 
+     *  would begin when cluster definition is updated to be "ACTIVE"
      *  <p>   
      *  For cluster to be in active state cluster definition needs to be complete & valid 
      *  e.g. number of nodes associated are sufficient for each role, specified blueprint for cluster configuration
      *  should exist etc. 
      *  
      *  <p>
-         *  REST:<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : POST <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  <p> 
+     *  REST:<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /clusters/<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : POST <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  <p> 
      *  
      *   @param         cluster                 Definition of the cluster to be created 
-     *   @return                                        Returns the cluster definition 
+     *   @return                                Returns the cluster definition 
      *   @throws        Exception               Throws exception (TBD)
      */
     @POST
-        @Consumes({"application/json", "application/xml"})
-        public ClusterDefinition addCluster(ClusterDefinition cluster) throws Exception {
-                Clusters.getInstance().addCluster(cluster);
-                return null;
-        }
+    @Consumes({"application/json", "application/xml"})
+    public ClusterDefinition addCluster(ClusterDefinition cluster) throws Exception {
+        return Clusters.getInstance().addCluster(cluster);
+    }
 }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/StacksResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/StacksResource.java?rev=1176247&r1=1176246&r2=1176247&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/StacksResource.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/StacksResource.java Tue Sep 27 07:36:41 2011
@@ -55,16 +55,16 @@ public class StacksResource {
     /** Import a new Hadoop Stack description
      * 
      *  <p>
-         *  REST:<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /stacks/<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : POST <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  <p> 
+     *  REST:<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /stacks/<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : POST <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  <p> 
      * 
      * @param   url Location of the new stack definition
      * @throws  Exception               throws Exception
@@ -78,19 +78,19 @@ public class StacksResource {
     /** Get the list of stacks installed with Ambari controller.
      * 
      *  <p>
-         *  REST:<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /stacks/{stackName}<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : POST <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  <p> 
+     *  REST:<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /stacks/{stackName}<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : POST <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  <p> 
      * 
      * @param searchToken       Optionally specify the search token to return the stacks where stack name includes the search token 
-     * @return                          Returns list of stack definitions
+     * @return                  Returns list of stack definitions
      * @throws Exception        throws Exception
      */
     /*@GET
@@ -114,19 +114,19 @@ public class StacksResource {
     /** Get the default blueprint for a particular stack
      * 
      *  <p>
-         *  REST:<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /stacks/{stackName}<br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : GET <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
-         *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
-         *  <p> 
+     *  REST:<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;URL Path                                    : /stacks/{stackName}<br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Method                                 : GET <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Request Header                         : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;HTTP Response Header                        : <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-type        = application/json <br>
+     *  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accept              = application/json <br>
+     *  <p> 
      * 
-     * @param stackName  The name of the stack to get the default blueprint
-     * @return  The default blueprint for that stack
+     * @param stackName         The name of the stack to get the default blueprint
+     * @return                  The default blueprint for that stack
      * @throws Exception        throws Exception
      */
     @GET