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/29 03:18:03 UTC

svn commit: r1177145 - 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: Thu Sep 29 01:18:02 2011
New Revision: 1177145

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

Added:
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/ExceptionResponse.java
Removed:
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Service.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Services.java
Modified:
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Cluster.java
    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/ClusterState.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ObjectFactory.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Role.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/Stacks.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/NodesResource.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/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Cluster.java?rev=1177145&r1=1177144&r2=1177145&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Cluster.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Cluster.java Thu Sep 29 01:18:02 2011
@@ -26,79 +26,62 @@ import javax.xml.bind.annotation.XmlRoot
 import javax.xml.bind.annotation.XmlType;
 
 
-
-/**
- * <p>Java class for ClusterType complex type.
- * 
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "Cluster", propOrder = {
-    "name",
-    "ID",
-    "revision",
-    "clusterDefinition",
-    "clusterState"
-})
-@XmlRootElement(name = "Cluster")
 public class Cluster {
         
     protected String ID;
     protected long revision;
-        
-        @XmlElement(name = "ClusterDefinition", required = true)
-        protected ClusterDefinition clusterDefinition;
-        @XmlElement(name = "ClusterState", required = true)
-        protected ClusterState clusterState;
-        
-        /**
-         * @return the revision
-         */
-        public long getRevision() {
-                return revision;
-        }
-        /**
-         * @param revision the revision to set
-         */
-        public void setRevision(long revision) {
-                this.revision = revision;
-        }
-        
-        /**
-         * @return the iD
-         */
-        public String getID() {
-                return ID;
-        }
-        /**
-         * @param iD the iD to set
-         */
-        public void setID(String iD) {
-                ID = iD;
-        }
-        
-        /**
-         * @return the clusterDefinition
-         */
-        public ClusterDefinition getClusterDefinition() {
-                return clusterDefinition;
-        }
-        /**
-         * @param clusterDefinition the clusterDefinition to set
-         */
-        public void setClusterDefinition(ClusterDefinition clusterDefinition) {
-                this.clusterDefinition = clusterDefinition;
-        }
-        /**
-         * @return the clusterState
-         */
-        public ClusterState getClusterState() {
-                return clusterState;
-        }
-        /**
-         * @param clusterState the clusterState to set
-         */
-        public void setClusterState(ClusterState clusterState) {
-                this.clusterState = clusterState;
-        }
+    protected ClusterDefinition clusterDefinition;
+    protected ClusterState clusterState;
+    
+    /**
+     * @return the revision
+     */
+    public long getRevision() {
+            return revision;
+    }
+    /**
+     * @param revision the revision to set
+     */
+    public void setRevision(long revision) {
+            this.revision = revision;
+    }
+    
+    /**
+     * @return the iD
+     */
+    public String getID() {
+            return ID;
+    }
+    /**
+     * @param iD the iD to set
+     */
+    public void setID(String iD) {
+            ID = iD;
+    }
+    
+    /**
+     * @return the clusterDefinition
+     */
+    public ClusterDefinition getClusterDefinition() {
+            return clusterDefinition;
+    }
+    /**
+     * @param clusterDefinition the clusterDefinition to set
+     */
+    public void setClusterDefinition(ClusterDefinition clusterDefinition) {
+            this.clusterDefinition = clusterDefinition;
+    }
+    /**
+     * @return the clusterState
+     */
+    public ClusterState getClusterState() {
+            return clusterState;
+    }
+    /**
+     * @param clusterState the clusterState to set
+     */
+    public void setClusterState(ClusterState clusterState) {
+            this.clusterState = clusterState;
+    }
         
 }

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=1177145&r1=1177144&r2=1177145&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 Thu Sep 29 01:18:02 2011
@@ -50,17 +50,17 @@ public class ClusterDefinition {
    
     @XmlElement(name = "Name", required = true)
     protected String name = null;
-    @XmlElement(name = "Description", required = true)
+    @XmlElement(name = "Description")
     protected String description = null;
-    @XmlElement(name = "BlueprintName", required = true)
+    @XmlElement(name = "BlueprintName")
     protected String blueprintName = null;
-    @XmlElement(name = "GoalState", required = true)
+    @XmlElement(name = "GoalState")
     protected String goalState = null;
-    @XmlElement(name = "ActiveServices", required = true)
+    @XmlElement(name = "ActiveServices")
     protected List<String> activeServices = null;
-    @XmlElement(name = "NodeRangeExpressions", required = true)
+    @XmlElement(name = "NodeRangeExpressions")
     protected List<String> nodeRangeExpressions = null;
-    @XmlElement(name = "RoleToNodesMap", required = true)
+    @XmlElement(name = "RoleToNodesMap")
     protected RoleToNodesMap roleToNodesMap = null;
     
     

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterState.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterState.java?rev=1177145&r1=1177144&r2=1177145&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterState.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterState.java Thu Sep 29 01:18:02 2011
@@ -37,7 +37,7 @@ import javax.xml.datatype.XMLGregorianCa
  */
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "ClusterType", propOrder = {
-    "RepresentativeState",
+    "state",
     "creationTime",
     "deployTime",
     "lastUpdateTime"
@@ -45,113 +45,127 @@ import javax.xml.datatype.XMLGregorianCa
 @XmlRootElement(name = "ClusterState")
 public class ClusterState {
         
-        /*
-         *  Cluster is deployed w/ Hadoop stack and required services are up
-         */
-        public static final String CLUSTER_STATE_ACTIVE = "ACTIVE";
-        /* 
-         * Cluster nodes are reserved but may not be deployed w/ stack. If deployed w/ stack
-         * then cluster services are down
-         */
-        public static final String CLUSTER_STATE_INACTIVE = "INACTIVE";
-        /*
-         * No nodes are reserved for the cluster
-         */
-        public static final String CLUSTER_STATE_ATTIC = "ATTIC";
-        
-        @XmlElement(name = "RepresentativeState", required = true)
-    protected String representativeState;
+    /*
+     *  Cluster is deployed w/ Hadoop stack and required services are up
+     */
+    public static final String CLUSTER_STATE_ACTIVE = "ACTIVE";
+    
+    /* 
+     * Cluster nodes are reserved but may not be deployed w/ stack. If deployed w/ stack
+     * then cluster services are down
+     */
+    public static final String CLUSTER_STATE_INACTIVE = "INACTIVE";
+    
+    /*
+     * No nodes are reserved for the cluster
+     */
+    public static final String CLUSTER_STATE_ATTIC = "ATTIC";
+    
+    @XmlElement(name = "State", required = true)
+    protected String state;
     @XmlElement(name = "CreationTime", required = true)
     @XmlSchemaType(name = "dateTime")
     protected XMLGregorianCalendar creationTime;
-        @XmlElement(name = "DeployTime", required = true)
+    @XmlElement(name = "DeployTime")
     @XmlSchemaType(name = "dateTime")
     protected XMLGregorianCalendar deployTime;
     @XmlElement(name = "LastUpdateTime", required = true)
     @XmlSchemaType(name = "dateTime")
     protected XMLGregorianCalendar lastUpdateTime;
 
-        /**
-         * @return the creationTime
-         */
-        public XMLGregorianCalendar getCreationTime() {
-                return creationTime;
-        }
-
-        /**
-         * @param creationTime the creationTime to set
-         */
-        public void setCreationTime(XMLGregorianCalendar creationTime) {
-                this.creationTime = creationTime;
-        }
-        
-        /**
-         * @param creationTime the creationTime to set
-         */
-        public void setCreationTime(Date creationTime) throws Exception {
-                GregorianCalendar cal = new GregorianCalendar();
-                cal.setTime(creationTime);
-                this.creationTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
-        }
-
-        /**
-         * @return the deployTime
-         */
-        public XMLGregorianCalendar getDeployTime() {
-                return deployTime;
-        }
-
-        /**
-         * @param deployTime the deployTime to set
-         */
-        public void setDeployTime(XMLGregorianCalendar deployTime) {
-                this.deployTime = deployTime;
-        }
-
-        /**
-         * @param creationTime the creationTime to set
-         */
-        public void setDeployTime(Date deployTime) throws Exception {
-                GregorianCalendar cal = new GregorianCalendar();
-                cal.setTime(deployTime);
-                this.deployTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
-        }
-        
-        /**
-         * @return the lastUpdateTime
-         */
-        public XMLGregorianCalendar getLastUpdateTime() {
-                return lastUpdateTime;
-        }
-
-        /**
-         * @param lastUpdateTime the lastUpdateTime to set
-         */
-        public void setLastUpdateTime(XMLGregorianCalendar lastUpdateTime) {
-                this.lastUpdateTime = lastUpdateTime;
-        }
-
-        /**
-         * @param creationTime the creationTime to set
-         */
-        public void setLastUpdateTime(Date lastUpdateTime) throws Exception {
-                GregorianCalendar cal = new GregorianCalendar();
-                cal.setTime(lastUpdateTime);
-                this.lastUpdateTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
-        }
-        
-        /**
-         * @return the representativeState
-         */
-        public String getRepresentativeState() {
-                return representativeState;
-        }
-
-        /**
-         * @param representativeState the representativeState to set
-         */
-        public void setRepresentativeState(String representativeState) {
-                this.representativeState = representativeState;
-        }
+    /**
+     * @return the creationTime
+     */
+    public XMLGregorianCalendar getCreationTime() {
+            return creationTime;
+    }
+
+    /**
+     * @param creationTime the creationTime to set
+     */
+    public void setCreationTime(XMLGregorianCalendar creationTime) {
+            this.creationTime = creationTime;
+    }
+    
+    /**
+     * @param creationTime the creationTime to set
+     */
+    public void setCreationTime(Date creationTime) throws Exception {
+        if (creationTime == null) {
+            this.creationTime = null;
+        } else {
+            GregorianCalendar cal = new GregorianCalendar();
+            cal.setTime(creationTime);
+            this.creationTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
+        }
+    }
+
+    /**
+     * @return the deployTime
+     */
+    public XMLGregorianCalendar getDeployTime() {
+            return deployTime;
+    }
+
+    /**
+     * @param deployTime the deployTime to set
+     */
+    public void setDeployTime(XMLGregorianCalendar deployTime) {
+            this.deployTime = deployTime;
+    }
+
+    /**
+     * @param creationTime the creationTime to set
+     */
+    public void setDeployTime(Date deployTime) throws Exception {
+        if (deployTime == null) {
+            this.deployTime = null;
+        } else {
+            GregorianCalendar cal = new GregorianCalendar();
+            cal.setTime(deployTime);
+            this.deployTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
+        }
+    }
+    
+    /**
+     * @return the lastUpdateTime
+     */
+    public XMLGregorianCalendar getLastUpdateTime() {
+            return lastUpdateTime;
+    }
+
+    /**
+     * @param lastUpdateTime the lastUpdateTime to set
+     */
+    public void setLastUpdateTime(XMLGregorianCalendar lastUpdateTime) {
+            this.lastUpdateTime = lastUpdateTime;
+    }
+
+    /**
+     * @param creationTime the creationTime to set
+     */
+    public void setLastUpdateTime(Date lastUpdateTime) throws Exception {
+        if (lastUpdateTime == null) {
+            this.lastUpdateTime = null;
+        } else {
+            GregorianCalendar cal = new GregorianCalendar();
+            cal.setTime(lastUpdateTime);
+            this.lastUpdateTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
+        }
+    }
+    
+    /**
+     * @return the state
+     */
+    public String getState() {
+            return state;
+    }
+
+    /**
+     * @param State the state to set
+     */
+    public void setState(String state) {
+            this.state = state;
+    }
 
 }

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ObjectFactory.java?rev=1177145&r1=1177144&r2=1177145&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ObjectFactory.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ObjectFactory.java Thu Sep 29 01:18:02 2011
@@ -129,15 +129,7 @@ public class ObjectFactory {
     public ClusterDefinition createClusterType() {
         return new ClusterDefinition();
     }
-
-    /**
-     * Create an instance of {@link Services }
-     * 
-     */
-    public Services createServicesType() {
-        return new Services();
-    }
-
+    
     /**
      * Create an instance of {@link Blueprint }
      * 
@@ -163,14 +155,6 @@ public class ObjectFactory {
     }
 
     /**
-     * Create an instance of {@link Service }
-     * 
-     */
-    public Service createServiceType() {
-        return new Service();
-    }
-
-    /**
      * Create an instance of {@link NodeState }
      * 
      */

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Role.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Role.java?rev=1177145&r1=1177144&r2=1177145&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Role.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Role.java Thu Sep 29 01:18:02 2011
@@ -23,26 +23,6 @@ import javax.xml.bind.annotation.XmlElem
 import javax.xml.bind.annotation.XmlType;
 
 
-/**
- * <p>Java class for RoleType complex type.
- * 
- * <p>The following schema fragment specifies the expected content contained within this class.
- * 
- * <pre>
- * &lt;complexType name="RoleType">
- *   &lt;complexContent>
- *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       &lt;sequence>
- *         &lt;element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         &lt;element name="Configuration" type="{}ConfigurationType"/>
- *       &lt;/sequence>
- *     &lt;/restriction>
- *   &lt;/complexContent>
- * &lt;/complexType>
- * </pre>
- * 
- * 
- */
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "RoleType", propOrder = {
     "name",

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=1177145&r1=1177144&r2=1177145&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 Sep 29 01:18:02 2011
@@ -55,7 +55,35 @@ public class Clusters {
     
     private static Clusters ClustersTypeRef=null;
         
-    private Clusters() {}
+    private Clusters() {
+        ClusterDefinition cluster123 = new ClusterDefinition();
+        
+        cluster123.setName("blue.dev.Cluster123");
+        cluster123.setBlueprintName("cluster123-blueprint");
+        cluster123.setDescription("cluster123 - development cluster");
+        cluster123.setGoalState(ClusterState.CLUSTER_STATE_ACTIVE);
+        List<String> activeServices = new ArrayList<String>();
+        activeServices.add("hdfs");
+        activeServices.add("mapred");
+        cluster123.setActiveServices(activeServices);
+        
+        ClusterDefinition cluster124 = new ClusterDefinition();
+        cluster124.setName("blue.research.Cluster124");
+        cluster124.setBlueprintName("cluster124-blueprint");
+        cluster124.setDescription("cluster124 - research cluster");
+        cluster124.setGoalState(ClusterState.CLUSTER_STATE_INACTIVE);
+        activeServices = new ArrayList<String>();
+        activeServices.add("hdfs");
+        activeServices.add("mapred");
+        cluster124.setActiveServices(activeServices);
+        
+        try {
+            addCluster(cluster123);
+            addCluster(cluster124);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
     
     public static synchronized Clusters getInstance() {
         if(ClustersTypeRef == null) {
@@ -89,7 +117,7 @@ public class Clusters {
     	 */
     	if (c.getName() == null ||  c.getName().equals("")) {
     		Exception e = new Exception("Cluster Name must be specified and must be non-empty string");
-    		throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+    		throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
     	}
     	
     	synchronized (operational_clusters) {
@@ -110,7 +138,7 @@ public class Clusters {
     		clsState.setCreationTime(requestTime);
     		clsState.setLastUpdateTime(requestTime);
     		clsState.setDeployTime((Date)null);
-    		clsState.setRepresentativeState(ClusterState.CLUSTER_STATE_INACTIVE);
+    		clsState.setState(ClusterState.CLUSTER_STATE_INACTIVE);
     		
     		cls.setID(UUID.randomUUID().toString());
     		cls.setClusterDefinition(c);
@@ -370,10 +398,11 @@ public class Clusters {
     /* 
      * Get the cluster definition by name
      */
-    public ClusterDefinition getClusterDefinition(String clusterName) throws WebApplicationException  {
+    public ClusterDefinition getClusterDefinition(String clusterName) throws Exception  {
         if (!this.operational_clusters.containsKey(clusterName)) {
             Exception e = new Exception("Cluster ["+clusterName+"] does not exits");
-            throw new WebApplicationException(e, Response.Status.NOT_FOUND);
+            //throw new WebApplicationException(e, Response.Status.NOT_FOUND);
+            throw e;
         }
         return this.operational_clusters.get(clusterName).getClusterDefinition();
     }
@@ -400,7 +429,7 @@ public class Clusters {
         if (state.equals("ALL")) {
           list.add(cls.getClusterDefinition());
         } else {
-          if (cls.getClusterState().getRepresentativeState().equals(state)) {
+          if (cls.getClusterState().getState().equals(state)) {
             list.add(cls.getClusterDefinition());
           }
         }
@@ -418,7 +447,7 @@ public class Clusters {
           list.addAll(this.operational_clusters.values());
         } else {
           for (Cluster cls : this.operational_clusters.values()) {
-            if (cls.getClusterState().getRepresentativeState().equals(state)) {
+            if (cls.getClusterState().getState().equals(state)) {
               list.add(cls);
             }
           }

Added: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/ExceptionResponse.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/ExceptionResponse.java?rev=1177145&view=auto
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/ExceptionResponse.java (added)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/ExceptionResponse.java Thu Sep 29 01:18:02 2011
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.controller;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+public class ExceptionResponse  {
+
+    Response r;
+    
+    public ExceptionResponse (Exception e) {
+        ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
+        builder.header("ErrorMessage", e.getMessage());
+        builder.header("ErrorCode", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+        r = builder.build();
+    }
+    
+    public ExceptionResponse (String exceptionMessage, Response.Status rs) {
+        ResponseBuilder builder = Response.status(rs);
+        builder.header("ErrorMessage",exceptionMessage);
+        builder.header("ErrorCode", rs.getStatusCode());
+        r = builder.build();
+    }
+    
+    public Response get() {
+        return this.r;
+    }
+}

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=1177145&r1=1177144&r2=1177145&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 Thu Sep 29 01:18:02 2011
@@ -59,7 +59,28 @@ public class Stacks {
     
     private static Stacks StacksTypeRef=null;
         
-    private Stacks() {}
+    private Stacks() {
+        /*
+         * Add stack and default blueprint 
+         */
+        Stack x = new Stack();
+        x.setName("ambari-hortonworks-1.0");
+        x.setBlueprintLocationURL("http://hortonworks.com/ambari");
+        x.setDescription("Hortonworks ambari stack");
+        x.setStackRevision(0);
+        ConcurrentHashMap<Integer,Stack> y = new ConcurrentHashMap<Integer,Stack>();
+        y.put(x.getStackRevision(), x);
+        this.stacks.put(x.getName(), y);
+        
+        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());
+        
+        this.default_blueprints.put(x.getName()+":"+x.getStackRevision(), bp);
+    }
     
     public static synchronized Stacks getInstance() {
         if(StacksTypeRef == null) {
@@ -210,4 +231,5 @@ public class Stacks {
             is.close();
         }
     }
+    
 }

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=1177145&r1=1177144&r2=1177145&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 Thu Sep 29 01:18:02 2011
@@ -30,6 +30,9 @@ 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 javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
 
 
 import org.apache.ambari.common.rest.entities.Cluster;
@@ -37,6 +40,7 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.Node;
 import org.apache.ambari.common.rest.entities.ClusterState;
 import org.apache.ambari.controller.Clusters;
+import org.apache.ambari.controller.ExceptionResponse;
 
 /** ClusterResource represents a Hadoop Cluster in a data center.
  *  
@@ -64,8 +68,14 @@ public class ClusterResource {
      */
     @GET
     @Produces({"application/json", "application/xml"})
-    public ClusterDefinition getClusterDefinition(@PathParam("clusterName") String clusterName) throws Exception {
-        return Clusters.getInstance().getClusterDefinition(clusterName);
+    public ClusterDefinition getClusterDefinition(@PathParam("clusterName") String clusterName) throws WebApplicationException {
+        try {
+            return Clusters.getInstance().getClusterDefinition(clusterName);
+        }catch (WebApplicationException we) {
+            throw we;
+        }catch (Exception e) {
+            throw new WebApplicationException((new ExceptionResponse(e)).get());
+        }       
     }
     
     /** Update cluster definition.

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=1177145&r1=1177144&r2=1177145&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 Thu Sep 29 01:18:02 2011
@@ -21,6 +21,8 @@ import java.util.List;
 
 import org.apache.ambari.common.rest.entities.ClusterDefinition;
 import org.apache.ambari.controller.Clusters;
+import org.apache.ambari.controller.ExceptionResponse;
+import org.apache.ambari.controller.Stacks;
 
 import com.sun.jersey.spi.resource.Singleton;
 import javax.ws.rs.GET;
@@ -37,21 +39,11 @@ import javax.ws.rs.core.Response;
 /**
  * Clusters Resource represents the collection of Hadoop clusters in a data center
  */
-@Singleton
 @Path(value = "/clusters")
 public class ClustersResource {
         
     public ClustersResource() throws Exception {        
-        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);
+        
     }  
     
     /** Get the list of clusters.
@@ -85,11 +77,16 @@ public class ClustersResource {
                                  @DefaultValue("ALL") @QueryParam("state") String state,
                                  @DefaultValue("") @QueryParam("search") String search) throws Exception {
         List<ClusterDefinition> searchResults = null;
-        searchResults = Clusters.getInstance().getClusterDefinitionsList(state);
-    
-        if (searchResults.isEmpty()) {
-                throw new WebApplicationException(Response.Status.NOT_FOUND);
-        }   
+        try {
+            searchResults = Clusters.getInstance().getClusterDefinitionsList(state);
+            if (searchResults.isEmpty()) {
+                throw new WebApplicationException(Response.Status.NO_CONTENT);
+            }   
+        }catch (WebApplicationException we) {
+            throw we;
+        }catch (Exception e) {
+            throw new WebApplicationException((new ExceptionResponse(e)).get());
+        } 
         return searchResults;
     }
     
@@ -122,6 +119,12 @@ public class ClustersResource {
     @POST
     @Consumes({"application/json", "application/xml"})
     public ClusterDefinition addCluster(ClusterDefinition cluster) throws Exception {
-        return Clusters.getInstance().addCluster(cluster);
+        try {
+            return Clusters.getInstance().addCluster(cluster);
+        }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/NodesResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/NodesResource.java?rev=1177145&r1=1177144&r2=1177145&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 Thu Sep 29 01:18:02 2011
@@ -32,7 +32,6 @@ import com.sun.jersey.spi.resource.Singl
 
 /** Nodes Resource represents collection of cluster nodes.
  */
-@Singleton
 @Path(value = "/nodes")
 public class NodesResource {
             

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=1177145&r1=1177144&r2=1177145&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 Thu Sep 29 01:18:02 2011
@@ -44,7 +44,6 @@ import com.sun.jersey.spi.resource.Singl
 
 /** Stacks resource represents a collection of Hadoop Stacks
  */
-@Singleton
 @Path(value = "/stacks")
 public class StacksResource {       
     
@@ -104,8 +103,7 @@ public class StacksResource {       
         try {
             List <String> list = Stacks.getInstance().getStackList();
             if (list.isEmpty()) {
-                Exception e = new Exception ("No stacks found");
-                throw new WebApplicationException (e, Response.Status.NO_CONTENT);
+                throw new WebApplicationException (Response.Status.NO_CONTENT);
             }
             return list;
         }catch (WebApplicationException we) {