incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgog...@apache.org
Subject svn commit: r1177932 - in /incubator/ambari/trunk: ./ controller/src/main/java/org/apache/ambari/controller/ controller/src/main/java/org/apache/ambari/controller/rest/resources/
Date Sat, 01 Oct 2011 06:37:41 GMT
Author: vgogate
Date: Sat Oct  1 06:37:41 2011
New Revision: 1177932

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

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.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/Stacks.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintResource.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintsResource.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/NodesResource.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1177932&r1=1177931&r2=1177932&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Sat Oct  1 06:37:41 2011
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-29. Implement Node Resource API
+
   AMBARI-24. Fix the versions in the pom.xml. (omalley)
 
   AMBARI-22. Implement Blueprint Resource API (vgogate)

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=1177932&r1=1177931&r2=1177932&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
Sat Oct  1 06:37:41 2011
@@ -152,11 +152,18 @@ public class Blueprints {
      */
     public void addBlueprint(Blueprint bp) throws Exception {
         
+        /* 
+         * Validate the name is not a reserved keyword and it does not exists already
+         * TODO: Check the specified parent blueprint already exits? may be not! 
+         */
+        if (bp.getName().equals("default")) {
+            String msg = "Blueprint can not have name default, a reserved keyword for default
blueprints associated w/ Hadoop stack";
+            throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.NOT_ACCEPTABLE)).get());
+        }
         if (blueprints.containsKey(bp.getName())) {
             if (blueprints.get(bp.getName()).containsKey(new Integer(bp.getRevision())))
{
-                Exception e = new Exception(
-                      "Specified blueprint [Name:"+bp.getName()+", Revision: ["+bp.getRevision()+"]
is already imported");
-                throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+                String msg = "Specified blueprint [Name:"+bp.getName()+", Revision: ["+bp.getRevision()+"]
already imported";
+                throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
             } else {
                 blueprints.get(bp.getName()).put(new Integer(bp.getRevision()), bp);
             }
@@ -184,11 +191,16 @@ public class Blueprints {
      * TODO: Check if blueprint is associated with any stack... 
      */
     public void deleteBlueprint(String blueprintName, int revision) throws Exception {
-        Blueprint bp = this.blueprints.get(blueprintName).get(new Integer(revision));
         
+        /*
+         * Check if the specified blueprint revision is used in any cluster definition
+         * except in ATTIC clusters.
+         */
+        Blueprint bp = this.blueprints.get(blueprintName).get(new Integer(revision));
         for (Cluster c : Clusters.getInstance().operational_clusters.values()) {
             String bpName = c.getClusterDefinition().getBlueprintName();
             String bpRevision = c.getClusterDefinition().getBlueprintRevision();
+            
             // TODO: May be don't consider ATTIC clusters
             if (c.getClusterState().getState().equals(ClusterState.ATTIC)) {
                 continue;

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=1177932&r1=1177931&r2=1177932&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
Sat Oct  1 06:37:41 2011
@@ -74,7 +74,7 @@ public class Nodes {
     }
        
     public ConcurrentHashMap<String, Node> getNodes () {
-            return nodes;
+        return nodes;
     }
     
     public List<Node> getClusterNodes (String clusterName, String roleName, boolean
alive) throws Exception {
@@ -95,8 +95,7 @@ public class Nodes {
                 if (!n.getNodeState().getNodeRoleNames().contains(roleName)) { continue;
}
             }
             
-            // TODO: If heartbeat is null? It is set to epoch during node initialization.
-            
+            // Heart beat is set to epoch during node initialization.
             GregorianCalendar cal = new GregorianCalendar(); 
             cal.setTime(new Date());
             XMLGregorianCalendar curTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
@@ -113,6 +112,58 @@ public class Nodes {
     }
     
     /*
+     * Get Nodes 
+     */
+    public List<Node> getNodesByState (boolean allocated, boolean alive) throws Exception
{
+        List<Node> list = new ArrayList<Node>();
+        GregorianCalendar cal = new GregorianCalendar(); 
+        cal.setTime(new Date());
+        XMLGregorianCalendar curTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
+        for (Node n : this.nodes.values()) {
+            if (allocated && alive) {
+                if (n.getNodeState().getAllocatedToCluster() && 
+                    getTimeDiffInMillis(curTime, n.getNodeState().getLastHeartbeatTime())
< NODE_NOT_RESPONDING_DURATION) {
+                    list.add(n);
+                }
+            }
+            if (allocated && !alive) {
+                if (n.getNodeState().getAllocatedToCluster() && 
+                    getTimeDiffInMillis(curTime, n.getNodeState().getLastHeartbeatTime())
>= NODE_NOT_RESPONDING_DURATION) {
+                    list.add(n);
+                }
+            }
+            if (!allocated && alive) {
+                if (!n.getNodeState().getAllocatedToCluster() && 
+                    getTimeDiffInMillis(curTime, n.getNodeState().getLastHeartbeatTime())
< NODE_NOT_RESPONDING_DURATION) {
+                    list.add(n);
+                }
+            }
+            if (!allocated && !alive) {
+                if (!n.getNodeState().getAllocatedToCluster() && 
+                    getTimeDiffInMillis(curTime, n.getNodeState().getLastHeartbeatTime())
>= NODE_NOT_RESPONDING_DURATION) {
+                    list.add(n);
+                }
+            }
+        }
+        
+        if (list.isEmpty()) {
+            throw new WebApplicationException(Response.Status.NO_CONTENT);
+        }   
+        return list;
+    }
+    
+    /*
+     * Get the node
+     */
+    public Node getNode (String name) throws Exception {
+        if (this.nodes.get(name) == null) {
+            String msg = "Node ["+name+"] does not exists";
+            throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.NOT_FOUND)).get());
+        }
+        return this.nodes.get(name);
+    }
+    
+    /*
      * Get time difference
      */
     public long getTimeDiffInMillis (XMLGregorianCalendar t2, XMLGregorianCalendar t1) throws
Exception {

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Stacks.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Stacks.java?rev=1177932&r1=1177931&r2=1177932&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Stacks.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Stacks.java
Sat Oct  1 06:37:41 2011
@@ -39,6 +39,11 @@ import javax.xml.bind.annotation.XmlRoot
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.ambari.common.rest.entities.Blueprint;
+import org.apache.ambari.common.rest.entities.Component;
+import org.apache.ambari.common.rest.entities.ConfigPropertiesCategory;
+import org.apache.ambari.common.rest.entities.Configuration;
+import org.apache.ambari.common.rest.entities.PackageRepository;
+import org.apache.ambari.common.rest.entities.Role;
 import org.apache.ambari.common.rest.entities.Stack;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jettison.json.JSONArray;
@@ -73,13 +78,66 @@ public class Stacks {
         y.put(x.getStackRevision(), x);
         this.stacks.put(x.getName(), y);
         
+        /*
+         * Create default blueprint
+         */
         Blueprint bp = new Blueprint();
         bp.setName("default");
         bp.setStackName(x.getName());
         bp.setParentName("default");
         bp.setRevision(new Integer(x.getStackRevision()).toString());
         bp.setParentRevision(new Integer(x.getStackRevision()).toString());
+       
+ 
+        Component hdfsC = new Component(); hdfsC.setName("hdfs");
+        hdfsC.getProperty().add(Blueprints.getInstance().getProperty ("dfs.name.dir", "${HADOOP_NN_DIR}"));
+        hdfsC.getProperty().add(Blueprints.getInstance().getProperty ("dfs.data.dir", "${HADOOP_DATA_DIR}"));
+        Component mapredC = new Component(); mapredC.setName("hdfs");
+        mapredC.getProperty().add(Blueprints.getInstance().getProperty ("mapred.system.dir",
"/mapred/mapredsystem"));
+        mapredC.getProperty().add(Blueprints.getInstance().getProperty ("mapred.local.dir",
"${HADOOP_MAPRED_DIR}"));
+        List<Component> compList = new ArrayList();
+        compList.add(mapredC);
+        compList.add(hdfsC);
+        bp.setComponents(compList);
+        
+        List<PackageRepository> prList = new ArrayList<PackageRepository>();
+        PackageRepository pr = new PackageRepository();
+        pr.setLocationURL("http://localhost/~vgogate/ambari");
+        pr.setType("RPM");  
+        bp.setPackageRepositories(prList);
+        
+        Configuration bpDefaultCfg = new Configuration();
+        ConfigPropertiesCategory hdfs_site = new ConfigPropertiesCategory();
+        hdfs_site.setName("hdfs-site");
+        ConfigPropertiesCategory mapred_site = new ConfigPropertiesCategory();
+        mapred_site.setName("mapred-site");  
+        hdfs_site.getProperty().add(Blueprints.getInstance().getProperty ("dfs.name.dir",
"/tmp/namenode"));
+        hdfs_site.getProperty().add(Blueprints.getInstance().getProperty ("dfs.data.dir",
"/tmp/datanode"));
+        mapred_site.getProperty().add(Blueprints.getInstance().getProperty ("mapred.system.dir",
"/mapred/mapredsystem"));
+        mapred_site.getProperty().add(Blueprints.getInstance().getProperty ("mapred.local.dir",
"/tmp/mapred")); 
+        bpDefaultCfg.getCategory().add(mapred_site);
+        bpDefaultCfg.getCategory().add(hdfs_site);
+        
+        bp.setConfiguration(bpDefaultCfg);
+        
+        List<Role> roleList = new ArrayList<Role>();
+        Role hdfs_nn_role = new Role();
+        hdfs_nn_role.setName("hdfs-NN");
+        hdfs_nn_role.setConfiguration(bpDefaultCfg);
         
+        Role mapred_jt_role = new Role();
+        mapred_jt_role.setName("mapred-JT");
+        mapred_jt_role.setConfiguration(bpDefaultCfg);
+        
+        Role slaves_role = new Role();
+        slaves_role.setName("slaves");
+        slaves_role.setConfiguration(bpDefaultCfg);
+        
+        bp.setRoles(roleList);
+        
+        /*
+         * Add default blueprint to default blueprints list assciated with the stack
+         */
         this.default_blueprints.put(x.getName()+":"+x.getStackRevision(), bp);
     }
     
@@ -157,6 +215,12 @@ public class Stacks {
             ObjectMapper m = new ObjectMapper();
             InputStream is = blueprintUrl.openStream();
             blueprint = m.readValue(is, Blueprint.class);
+            /*
+             * Validate default blueprint
+             */
+            validateDefaultBlueprint(blueprint, stack);
+        } catch (WebApplicationException we) {
+            throw we;
         } catch (Exception e) {
             this.stacks.get(stack.getName()).remove(stack.getStackRevision());
             if (this.stacks.get(stack.getName()).keySet().isEmpty()) {
@@ -167,6 +231,29 @@ public class Stacks {
         return blueprint;
     }
    
+    /*
+     * Validate the default blueprint before importing into stack.
+     */
+    public void validateDefaultBlueprint(Blueprint blueprint, Stack stack) throws WebApplicationException
{
+        if (!blueprint.getName().equals("default")) {
+            String msg = "Default blueprint associated with stack must be named <default>";
+            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
+        }
+        if (!blueprint.getName().equals(blueprint.getParentName()) ||
+            !blueprint.getParentRevision().equals(blueprint.getParentRevision())) {
+            String msg = "Parent name & version of default blueprint associated with
stack must be same as default blueprint";
+            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
+        }
+        /*
+         * Check if stack name and revision matches with blueprint stackname and blueprint
revision
+         */
+        if (!blueprint.getStackName().equals(stack.getName()) ||
+            !blueprint.getRevision().equals(stack.getStackRevision())) {
+            String msg = "Default blueprint's stanck name and revision does not match with
it's associated stack";
+            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
+        }
+    }
+    
     /* 
      * Delete stack 
     */

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=1177932&r1=1177931&r2=1177932&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
Sat Oct  1 06:37:41 2011
@@ -84,8 +84,7 @@ public class BlueprintResource {
     @DELETE
     @Consumes({"application/json", "application/xml"})
     public void deleteBlueprint(@PathParam("blueprintName") String blueprintName,
-                                @DefaultValue("") @QueryParam("revision") String revision
) throws Exception {
-        
+                                @DefaultValue("") @QueryParam("revision") String revision
) throws Exception {     
         try {
             if (revision == null || revision.equals("")) {
                 String msg = "Revision number not specified";

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintsResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintsResource.java?rev=1177932&r1=1177931&r2=1177932&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintsResource.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintsResource.java
Sat Oct  1 06:37:41 2011
@@ -56,8 +56,14 @@ public class BlueprintsResource {
      */
     @POST
     @Consumes ({"application/json"})
-    public void createBlueprint(Blueprint blueprint) throws Exception {
-        Blueprints.getInstance().addBlueprint(blueprint);
+    public void createBlueprint(Blueprint blueprint) throws Exception {   
+        try {
+            Blueprints.getInstance().addBlueprint(blueprint);
+        }catch (WebApplicationException we) {
+            throw we;
+        }catch (Exception e) {
+            throw new WebApplicationException((new ExceptionResponse(e)).get());
+        } 
     }
 
     /** 

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=1177932&r1=1177931&r2=1177932&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
Sat Oct  1 06:37:41 2011
@@ -41,10 +41,6 @@ import javax.ws.rs.core.Response;
  */
 @Path(value = "/clusters")
 public class ClustersResource {
-        
-    public ClustersResource() throws Exception {        
-        
-    }  
     
     /** 
      * Get the list of clusters.

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/NodesResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/NodesResource.java?rev=1177932&r1=1177931&r2=1177932&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/NodesResource.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/NodesResource.java
Sat Oct  1 06:37:41 2011
@@ -25,8 +25,12 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
 
 import org.apache.ambari.common.rest.entities.Node;
+import org.apache.ambari.controller.Clusters;
+import org.apache.ambari.controller.ExceptionResponse;
+import org.apache.ambari.controller.Nodes;
 
 import com.sun.jersey.spi.resource.Singleton;
 
@@ -45,14 +49,18 @@ public class NodesResource {
      *  @return                                 List of nodes
      *  @throws Exception               throws Exception
      */
-    @Path(value = "/nodes")
     @GET
     @Produces({"application/json", "application/xml"})
-    public List<Node> getNodes (@DefaultValue("false") @QueryParam("allocated") Boolean
allocated,
-                                                        @DefaultValue("false") @QueryParam("alive")
Boolean alive) throws Exception {
-        //return NodesType.getInstance().getNodes (clusterName, roleName, allocated, alive);
-        return null;
-        }
+    public List<Node> getNodes (@DefaultValue("true") @QueryParam("allocated") boolean
allocated,
+                                @DefaultValue("true") @QueryParam("alive") boolean alive)
throws Exception {
+        try {
+            return Nodes.getInstance().getNodesByState(allocated, alive);
+        }catch (WebApplicationException we) {
+            throw we;
+        }catch (Exception e) {
+            throw new WebApplicationException((new ExceptionResponse(e)).get());
+        } 
+    }
 
     /*
      * Get specified Node information
@@ -68,6 +76,12 @@ public class NodesResource {
     @GET
     @Produces({"application/json", "application/xml"})
     public Node getNode (@PathParam("hostname") String hostname) throws Exception {
-        return null;
+        try {
+            return Nodes.getInstance().getNode(hostname);
+        }catch (WebApplicationException we) {
+            throw we;
+        }catch (Exception e) {
+            throw new WebApplicationException((new ExceptionResponse(e)).get());
+        } 
     }
 }



Mime
View raw message