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/30 09:29:32 UTC

svn commit: r1177539 - 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: Fri Sep 30 07:29:31 2011
New Revision: 1177539

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

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Blueprint.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ConfigPropertiesCategory.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Configuration.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Property.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodesMap.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/StacksResource.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1177539&r1=1177538&r2=1177539&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Fri Sep 30 07:29:31 2011
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-21. Fix the problem w/ Stacks Resource API
+
   AMBARI-20. Fix the rest API for getting the cluster nodes
 
   AMBARI-19. Fix Cluster resource API nodes reservation logic

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Blueprint.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Blueprint.java?rev=1177539&r1=1177538&r2=1177539&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Blueprint.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Blueprint.java Fri Sep 30 07:29:31 2011
@@ -22,6 +22,7 @@ import java.util.List;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
 
@@ -30,7 +31,7 @@ import javax.xml.bind.annotation.XmlType
  * 
  */
 @XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "BlueprintType", propOrder = {
+@XmlType(name = "Blueprint", propOrder = {
     "name",
     "revision",
     "stackName",
@@ -38,8 +39,10 @@ import javax.xml.bind.annotation.XmlType
     "parentRevision",
     "packageRepositories",
     "configuration",
-    "services"
+    "components",
+    "roles"
 })
+@XmlRootElement(name = "Blueprint")
 public class Blueprint {
 
     @XmlElement(name = "Name", required = true)

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ConfigPropertiesCategory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ConfigPropertiesCategory.java?rev=1177539&r1=1177538&r2=1177539&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ConfigPropertiesCategory.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ConfigPropertiesCategory.java Fri Sep 30 07:29:31 2011
@@ -22,6 +22,7 @@ import java.util.List;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
 
@@ -30,10 +31,11 @@ import javax.xml.bind.annotation.XmlType
  * 
  */
 @XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "CategoryType", propOrder = {
+@XmlType(name = "ConfigPropertiesCategory", propOrder = {
     "name",
     "property"
 })
+@XmlRootElement(name = "ConfigPropertiesCategory")
 public class ConfigPropertiesCategory {
 
     @XmlElement(name = "Name", required = true)

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Configuration.java?rev=1177539&r1=1177538&r2=1177539&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Configuration.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Configuration.java Fri Sep 30 07:29:31 2011
@@ -22,6 +22,7 @@ import java.util.List;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
 
@@ -30,12 +31,13 @@ import javax.xml.bind.annotation.XmlType
  *  
  */
 @XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "ConfigurationType", propOrder = {
+@XmlType(name = "Configuration", propOrder = {
     "category"
 })
+@XmlRootElement(name = "Configuration")
 public class Configuration {
 
-    @XmlElement(name = "Category", required = true)
+    @XmlElement(name = "ConfigPropertyCategories", required = true)
     protected List<ConfigPropertiesCategory> category;
 
     /**

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Property.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Property.java?rev=1177539&r1=1177538&r2=1177539&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Property.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Property.java Fri Sep 30 07:29:31 2011
@@ -20,44 +20,22 @@ package org.apache.ambari.common.rest.en
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
 
-/**
- * <p>Java class for PropertyType complex type.
- * 
- * <p>The following schema fragment specifies the expected content contained within this class.
- * 
- * <pre>
- * &lt;complexType name="PropertyType">
- *   &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="value" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         &lt;element name="final" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- *       &lt;/sequence>
- *     &lt;/restriction>
- *   &lt;/complexContent>
- * &lt;/complexType>
- * </pre>
- * 
- * 
- */
 @XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "PropertyType", propOrder = {
+@XmlType(name = "Property", propOrder = {
     "name",
-    "value",
-    "_final"
+    "value"
 })
+@XmlRootElement(name = "Property")
 public class Property {
 
     @XmlElement(required = true)
     protected String name;
     @XmlElement(required = true)
     protected String value;
-    @XmlElement(name = "final")
-    protected String _final;
 
     /**
      * Gets the value of the name property.
@@ -106,29 +84,4 @@ public class Property {
     public void setValue(String value) {
         this.value = value;
     }
-
-    /**
-     * Gets the value of the final property.
-     * 
-     * @return
-     *     possible object is
-     *     {@link String }
-     *     
-     */
-    public String getFinal() {
-        return _final;
-    }
-
-    /**
-     * Sets the value of the final property.
-     * 
-     * @param value
-     *     allowed object is
-     *     {@link String }
-     *     
-     */
-    public void setFinal(String value) {
-        this._final = value;
-    }
-
 }

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodesMap.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodesMap.java?rev=1177539&r1=1177538&r2=1177539&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodesMap.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/RoleToNodesMap.java Fri Sep 30 07:29:31 2011
@@ -45,12 +45,12 @@ import javax.xml.bind.annotation.XmlType
  * 
  */
 @XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "RoleToNodesMapType", propOrder = {
+@XmlType(name = "RoleToNodesMap", propOrder = {
     "roleToNodesMapEntry"
 })
 public class RoleToNodesMap {
 
-    @XmlElement(name = "RoleToNodesMapEntry", required = true)
+    @XmlElement(name = "RoleToNodesMapEntries", required = true)
     protected List<RoleToNodesMapEntry> roleToNodesMapEntry;
 
     /**

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=1177539&r1=1177538&r2=1177539&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 Fri Sep 30 07:29:31 2011
@@ -109,7 +109,6 @@ public class Clusters {
         rnm.getRoleToNodesMapEntry().add(rnme);
         
         cluster123.setRoleToNodesMap(rnm);
-       
         /*
         try {
             ObjectMapper m = new ObjectMapper();
@@ -118,8 +117,8 @@ public class Clusters {
             System.out.println ("CLUSTERDEF: <"+new String(x.toString()));
         } catch (Exception e) {
             e.printStackTrace();
-        }*/
-        
+        }
+        */
         
         /*
          * Cluster definition 

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=1177539&r1=1177538&r2=1177539&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 Fri Sep 30 07:29:31 2011
@@ -41,6 +41,7 @@ import javax.xml.bind.annotation.XmlType
 import org.apache.ambari.common.rest.entities.Blueprint;
 import org.apache.ambari.common.rest.entities.Stack;
 import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 
@@ -64,9 +65,9 @@ public class 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.setName("hortonworks-1.0");
+        x.setBlueprintLocationURL("http://localhost/~vgogate/ambari/hortonworks-1.0/default-blueprint.json");
+        x.setDescription("Hortonworks ambari stack 1.0");
         x.setStackRevision(0);
         ConcurrentHashMap<Integer,Stack> y = new ConcurrentHashMap<Integer,Stack>();
         y.put(x.getStackRevision(), x);
@@ -101,8 +102,8 @@ public class Stacks {
          * Check for stackLocation not null 
          */
         if (stackLocation == null || stackLocation.equals("")) {
-            Exception e = new Exception("Query parameter url must be specified");
-            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+            String msg = "Query parameter url must be specified";
+            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
         }
         
         /*
@@ -113,21 +114,23 @@ public class Stacks {
         try {
             stackLocationURL = new URL(stackLocation);
         } catch (MalformedURLException e) {
-            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+            String msg = "MalformedURLException for stack location URL";
+            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
         }
         
+        
         /*
          * Fetch the stack definition as JSON and create Stack object and 
          * add to stacks list
          */
         ObjectMapper m = new ObjectMapper();
         InputStream is = stackLocationURL.openStream();
-        Stack stack = m.readValue(is, Stack.class);
+        Stack stack = m.readValue(is, Stack.class);   
+        
         if (stacks.containsKey(stack.getName())) {
             if (stacks.get(stack.getName()).containsKey(stack.getStackRevision())) {
-                Exception e = new Exception(
-                      "Specified stack [Name:"+stack.getName()+", Revision: ["+stack.getStackRevision()+"] is already imported");
-                throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+                String msg = "Specified stack [Name:"+stack.getName()+", Revision: ["+stack.getStackRevision()+"] is already imported";
+                throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
             } else {
                 stacks.get(stack.getName()).put(stack.getStackRevision(), stack);
                 Blueprint blueprint = importDefaultBlueprint(stack);
@@ -148,8 +151,9 @@ public class Stacks {
      */
     public Blueprint importDefaultBlueprint (Stack stack) throws Exception {
         Blueprint blueprint;
+        URL blueprintUrl;
         try {
-            URL blueprintUrl = new URL(stack.getBlueprintLocationURL());
+            blueprintUrl = new URL(stack.getBlueprintLocationURL());
             ObjectMapper m = new ObjectMapper();
             InputStream is = blueprintUrl.openStream();
             blueprint = m.readValue(is, Blueprint.class);
@@ -158,7 +162,7 @@ public class Stacks {
             if (this.stacks.get(stack.getName()).keySet().isEmpty()) {
                 this.stacks.remove(stack.getName());
             }
-            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+            throw new WebApplicationException ((new ExceptionResponse(e)).get());
         }
         return blueprint;
     }
@@ -177,12 +181,10 @@ public class Stacks {
      * Get StackType from stack list given its name 
     */
     public Stack getStack(String stackName, int revision) throws Exception {
-
-        Stack sk = this.stacks.get(stackName).get(revision);
-       
+        Stack sk = this.stacks.get(stackName).get(revision); 
         if (sk == null) {
-            Exception e = new Exception ("Stack ["+stackName+"] revision ["+revision+"] does not exists");
-            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+            String msg = "Stack ["+stackName+"] revision ["+revision+"] does not exists";
+            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.NOT_FOUND)).get());
         }
         return sk;
     }
@@ -195,8 +197,8 @@ public class Stacks {
         Blueprint bp = this.default_blueprints.get(stackName+":"+revision);
         
         if (bp == null) {
-            Exception e = new Exception ("Stack ["+stackName+"] revision ["+revision+"] does not exists");
-            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+            String msg = "Stack ["+stackName+"] revision ["+revision+"] does not exists";
+            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.NOT_FOUND)).get());
         }
         return bp;
     }
@@ -204,10 +206,10 @@ public class Stacks {
     /*
      * Returns stack names
      */
-    public List<String> getStackList() {
+    public JSONArray getStackList() throws Exception {
         List<String> list = new ArrayList<String>();
         list.addAll(this.stacks.keySet());
-        return list;
+        return new JSONArray(list);
     }
     
     private static String readAll(Reader rd) throws IOException {

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=1177539&r1=1177538&r2=1177539&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 Fri Sep 30 07:29:31 2011
@@ -35,9 +35,12 @@ import javax.xml.bind.annotation.XmlElem
 
 import org.apache.ambari.common.rest.entities.Blueprint;
 import org.apache.ambari.common.rest.entities.Cluster;
+import org.apache.ambari.common.rest.entities.ClusterDefinition;
 import org.apache.ambari.common.rest.entities.Stack;
 import org.apache.ambari.controller.Clusters;
+import org.apache.ambari.controller.ExceptionResponse;
 import org.apache.ambari.controller.Stacks;
+import org.codehaus.jettison.json.JSONArray;
 
 import com.sun.jersey.spi.container.WebApplication;
 import com.sun.jersey.spi.resource.Singleton;
@@ -67,15 +70,15 @@ public class StacksResource {       
      * @throws  Exception               throws Exception
      */
     @POST
-    @Consumes({"application/json", "application/xml"})
+    @Produces({"application/json"})
     public Stack importStackDescription(@DefaultValue("") @QueryParam("url") String url) throws WebApplicationException {       
         try {
             return Stacks.getInstance().importStackDescription(url);
-        }catch (WebApplicationException we) {
+        } catch (WebApplicationException we) {
             throw we;
-        }catch (Exception e) {
-            throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
-        }
+        } catch (Exception e) {
+            throw new WebApplicationException((new ExceptionResponse(e)).get());
+        } 
     }
     
     /** Get the list of stacks installed with Ambari controller.
@@ -97,20 +100,21 @@ public class StacksResource {       
      * @throws Exception        throws Exception
      */
     @GET
-    @Consumes({"application/json", "application/xml"})
-    public List<String> getStackList (@DefaultValue("") @QueryParam("search") String searchToken) throws Exception {
+    @Produces({"application/json"})
+    public JSONArray getStackList (@DefaultValue("") @QueryParam("search") String searchToken) throws Exception {
         
+        JSONArray list;
         try {
-            List <String> list = Stacks.getInstance().getStackList();
-            if (list.isEmpty()) {
-                throw new WebApplicationException (Response.Status.NO_CONTENT);
-            }
-            return list;
+            list = Stacks.getInstance().getStackList();
+            if (list.length() == 0) {
+                throw new WebApplicationException(Response.Status.NO_CONTENT);
+            }   
         }catch (WebApplicationException we) {
             throw we;
         }catch (Exception e) {
-            throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
+            throw new WebApplicationException((new ExceptionResponse(e)).get());
         } 
+        return list;
     }
 
     /** Get the stack definition
@@ -138,14 +142,14 @@ public class StacksResource {       
                      @DefaultValue("") @QueryParam("revision") String revision) throws Exception {  
         try {
             if (revision == null || revision.equals("")) {
-                Exception e = new Exception ("Revision number not specified");
-                throw new WebApplicationException (e, Response.Status.BAD_REQUEST);
+                String msg = "Revision number not specified";
+                throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
             }
             return Stacks.getInstance().getStack(stackName, Integer.parseInt(revision));
         }catch (WebApplicationException we) {
             throw we;
         }catch (Exception e) {
-            throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
+            throw new WebApplicationException((new ExceptionResponse(e)).get());
         }      
     }
     
@@ -174,14 +178,14 @@ public class StacksResource {       
                      @DefaultValue("") @QueryParam("revision") String revision) throws Exception {
         try {
             if (revision == null || revision.equals("")) {
-                Exception e = new Exception ("Revision number not specified");
-                throw new WebApplicationException (e, Response.Status.BAD_REQUEST);
+                String msg = "Revision number not specified";
+                throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
             }
             return Stacks.getInstance().getDefaultBlueprint(stackName, Integer.parseInt(revision));
         }catch (WebApplicationException we) {
             throw we;
         }catch (Exception e) {
-            throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
+            throw new WebApplicationException((new ExceptionResponse(e)).get());
         }     
     }
 }