incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgog...@apache.org
Subject svn commit: r1179860 - 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/
Date Thu, 06 Oct 2011 21:29:32 GMT
Author: vgogate
Date: Thu Oct  6 21:29:32 2011
New Revision: 1179860

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

Modified:
    incubator/ambari/trunk/CHANGES.txt
    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/Blueprints.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/BlueprintResource.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1179860&r1=1179859&r2=1179860&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Oct  6 21:29:32 2011
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-42. Return the latest blueprint revision if revision is not specified as query parameter.
+
   AMBARI-43. Change the API StateMachineInvoker.getStateMachineClusterInstance 
   to take blueprint related arguments. (ddas)
 

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=1179860&r1=1179859&r2=1179860&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
Thu Oct  6 21:29:32 2011
@@ -56,7 +56,7 @@ public class Node {
      * 
      */
     public void releaseNodeFromCluster() {
-        this.nodeState.setClusterName(null);
+        this.nodeState.setClusterID(null);
         this.getNodeState().setNodeServers(null);
         this.getNodeState().setNodeRoleNames(null);
         /*
@@ -67,8 +67,8 @@ public class Node {
   	/*
   	 * Reserving node for cluster is done by associating cluster name w/ node
   	 */
-  	public void reserveNodeForCluster (String clusterName, Boolean agentInstalled) {
-  		this.getNodeState().setClusterName(clusterName);
+  	public void reserveNodeForCluster (String clusterID, Boolean agentInstalled) {
+  		this.getNodeState().setClusterID(clusterID);
   		this.getNodeState().setAgentInstalled(agentInstalled);
   		this.getNodeState().setAllocatedToCluster(true);
   	}

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=1179860&r1=1179859&r2=1179860&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
Thu Oct  6 21:29:32 2011
@@ -51,8 +51,8 @@ public class NodeState {
      * Associating the cluster name would reserve the node for a given cluster
      * 
      */
-    @XmlElement(name = "ClusterName", required = true)
-    protected String clusterName;
+    @XmlElement(name = "ClusterID", required = true)
+    protected String clusterID;
 
     @XmlElement(name = "AgentInstalled", required = true)
     protected Boolean agentInstalled = true;
@@ -111,19 +111,6 @@ public class NodeState {
             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
@@ -165,4 +152,19 @@ public class NodeState {
     public void setNodeServers(List<NodeServer> nodeServers) {
             this.nodeServers = nodeServers;
     }
+    
+    /**
+     * @return the clusterID
+     */
+    public String getClusterID() {
+        return clusterID;
+    }
+
+    /**
+     * @param clusterID the clusterID to set
+     */
+    public void setClusterID(String clusterID) {
+        this.clusterID = clusterID;
+    }
+
 }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java?rev=1179860&r1=1179859&r2=1179860&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
Thu Oct  6 21:29:32 2011
@@ -26,6 +26,8 @@ import java.io.Reader;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -131,14 +133,26 @@ public class Blueprints {
     
     
     /*
-     * Get blueprint
+     * Get blueprint. If revision = -1 then return latest revision
      */
     public Blueprint getBlueprint(String blueprintName, int revision) throws Exception {
-        Blueprint bp = this.blueprints.get(blueprintName).get(revision);
-        
-        if (bp == null) {
-            Exception e = new Exception ("Stack ["+blueprintName+"] revision ["+revision+"]
does not exists");
-            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+        /*
+         * If revision is -1, then return the latest revision
+         */  
+        Blueprint bp = null;
+        if (revision == -1) {
+            this.blueprints.get(blueprintName).keySet();
+            Integer [] a = new Integer [] {};
+            Integer[] keys = this.blueprints.get(blueprintName).keySet().toArray(a);
+            Arrays.sort(keys);  
+            bp = this.blueprints.get(blueprintName).get(keys[keys.length-1]);
+        } else {
+            if (!this.blueprints.containsKey(blueprintName) || !this.blueprints.get(blueprintName).containsKey(revision))
{
+                
+                String msg = "Blueprint ["+blueprintName+"], revision ["+revision+"] does
not exists";
+                throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
+            }
+            bp = this.blueprints.get(blueprintName).get(revision);
         }
         return bp;  
     }

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=1179860&r1=1179859&r2=1179860&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
Thu Oct  6 21:29:32 2011
@@ -45,7 +45,7 @@ public class Clusters {
     protected ConcurrentHashMap<String, Cluster> operational_clusters = new ConcurrentHashMap<String,
Cluster>();
     
     /*
-     * Operational clusters name to ID map
+     * Operational clusters ID to name map
      */
     protected ConcurrentHashMap<String, String> operational_clusters_id_to_name = new
ConcurrentHashMap<String, String>();
     
@@ -281,7 +281,7 @@ public class Clusters {
      */
     private synchronized void updateClusterNodesReservation (Cluster cls, List<String>
nodeRangeExpressions) throws Exception {
     	
-    	String cname = cls.getClusterDefinition().getName();
+    	String clusterID = getClusterIDByName(cls.getClusterDefinition().getName());
     	
     	/*
     	 * Check if all the nodes explicitly specified in the RoleToNodesMap belong the cluster
node range specified 
@@ -310,7 +310,7 @@ public class Clusters {
 		 */	
     	List<String> nodes_currently_allocated_to_cluster = new ArrayList<String>();
     	for (Node n : Nodes.getInstance().getNodes().values()) {
-    		if (n.getNodeState().getClusterName().equals(cls.getClusterDefinition().getName()))
{
+    		if (n.getNodeState().getClusterID().equals(cls.getClusterDefinition().getName())) {
     			nodes_currently_allocated_to_cluster.add(n.getName());
     		}
     	}
@@ -326,7 +326,7 @@ public class Clusters {
     	List<String> preallocatedhosts = new ArrayList<String>();
     	for (String n : nodes_to_allocate) {
     		if (all_nodes.containsKey(n) && 
-    				(all_nodes.get(n).getNodeState().getClusterName() != null || 
+    				(all_nodes.get(n).getNodeState().getClusterID() != null || 
     				 all_nodes.get(n).getNodeState().getAllocatedToCluster()
     				)
     			) {
@@ -353,7 +353,7 @@ public class Clusters {
 			if (all_nodes.containsKey(node_name)) { 
 				// Set the cluster name in the node 
 				synchronized (all_nodes.get(node_name)) {
-					all_nodes.get(node_name).reserveNodeForCluster(cname, true);
+					all_nodes.get(node_name).reserveNodeForCluster(clusterID, true);
 				}	
 			} else {
 				Node node = new Node(node_name);
@@ -365,7 +365,7 @@ public class Clusters {
 				/*
 				 * TODO: Set agentInstalled = true, unless controller uses SSH to setup the agent
 				 */
-				node.reserveNodeForCluster(cname, true);
+				node.reserveNodeForCluster(clusterID, true);
 				Nodes.getInstance().getNodes().put(node_name, node);
 			}
 		}
@@ -416,8 +416,8 @@ public class Clusters {
     	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>()));
-    	        String clusterName = Nodes.getInstance().getNodes().get(host).getNodeState().getClusterName();
-    	        Nodes.getInstance().getNodes().get(host).getNodeState().getNodeRoleNames().add(getDefaultRoleName(clusterName));
+    	        String cid = Nodes.getInstance().getNodes().get(host).getNodeState().getClusterID();
+    	        Nodes.getInstance().getNodes().get(host).getNodeState().getNodeRoleNames().add(getDefaultRoleName(cid));
     	    } 
     	}
 	}
@@ -519,6 +519,16 @@ public class Clusters {
         }
     }
     
+    /*
+     * Get cluster ID given cluster Name
+     */
+    public String getClusterIDByName (String clusterName) {
+        if (this.operational_clusters.containsKey(clusterName)) {
+            return this.operational_clusters.get(clusterName).getID();
+        } else {
+            return null;
+        }
+    }
     /* 
      * Get the cluster definition by name
      */
@@ -594,8 +604,8 @@ public class Clusters {
 	 *  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(String clusterName) throws Exception {
-	    Cluster c = Clusters.getInstance().getClusterByName(clusterName);
+	public String getDefaultRoleName(String clusterID) throws Exception {
+	    Cluster c = Clusters.getInstance().getClusterByID(clusterID);
 	    // TODO: find the default role from the clsuter blueprint 
 		return "slaves-role";
 	}

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=1179860&r1=1179859&r2=1179860&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
Thu Oct  6 21:29:32 2011
@@ -80,7 +80,7 @@ public class HeartbeatHandler {
         DatatypeFactory.newInstance().newXMLGregorianCalendar(c));
     
     Cluster cluster = 
-        Clusters.getInstance().getClusterByID(state.getClusterName());
+        Clusters.getInstance().getClusterByID(state.getClusterID());
     ClusterContext clusterContext = new ClusterContextImpl(cluster, node);
     
     List<Action> allActions = new ArrayList<Action>();

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintResource.java?rev=1179860&r1=1179859&r2=1179860&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintResource.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintResource.java
Thu Oct  6 21:29:32 2011
@@ -50,19 +50,15 @@ public class BlueprintResource {
      * @response.representation.200.mediaType application/json
      *  
      * @param  blueprintName   Name of the blueprint
-     * @param  revision        The optional blueprint revision to get
+     * @param  revision        The optional blueprint revision, if not specified get the
latest revision
      * @return                 blueprint definition
      * @throws Exception       throws Exception (TBD)
      */
     @GET
     @Produces({"application/json", "application/xml"})
     public Blueprint getBlueprint(@PathParam("blueprintName") String blueprintName, 
-                                  @DefaultValue("") @QueryParam("revision") String revision)
throws Exception {     
+                                  @DefaultValue("-1") @QueryParam("revision") String revision)
throws Exception {     
         try {
-            if (revision == null || revision.equals("")) {
-                String msg = "Revision number not specified";
-                throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
-            }
             return Blueprints.getInstance().getBlueprint(blueprintName, Integer.parseInt(revision));
         }catch (WebApplicationException we) {
             throw we;



Mime
View raw message