incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgog...@apache.org
Subject svn commit: r1178598 - 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 Mon, 03 Oct 2011 21:51:37 GMT
Author: vgogate
Date: Mon Oct  3 21:51:36 2011
New Revision: 1178598

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

Removed:
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Stack.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
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Blueprint.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/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

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1178598&r1=1178597&r2=1178598&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Mon Oct  3 21:51:36 2011
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-32. Remove stack resource Remove the Stack resource from Ambari (vgogate)
+
   AMBARI-25. Clean up the configuration entity to collapse some levels. 
   (omalley)
 

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=1178598&r1=1178597&r2=1178598&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
Mon Oct  3 21:51:36 2011
@@ -34,7 +34,6 @@ import javax.xml.bind.annotation.XmlType
 @XmlType(name = "Blueprint", propOrder = {
     "name",
     "revision",
-    "stackName",
     "parentName",
     "parentRevision",
     "packageRepositories",
@@ -49,8 +48,6 @@ public class Blueprint {
     protected String name;
     @XmlElement(name = "Revision", required = true)
     protected String revision;
-    @XmlElement(name = "StackName", required = true)
-    protected String stackName;
     @XmlElement(name = "ParentName", required = true)
     protected String parentName;
     @XmlElement(name = "ParentRevision", required = true)
@@ -90,18 +87,7 @@ public class Blueprint {
     public void setRevision(String revision) {
             this.revision = revision;
     }
-    /**
-     * @return the stackName
-     */
-    public String getStackName() {
-            return stackName;
-    }
-    /**
-     * @param stackName the stackName to set
-     */
-    public void setStackName(String stackName) {
-            this.stackName = stackName;
-    }
+    
     /**
      * @return the parentName
      */

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=1178598&r1=1178597&r2=1178598&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
Mon Oct  3 21:51:36 2011
@@ -22,21 +22,15 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
-import java.net.MalformedURLException;
+
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
-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;
 
 import org.apache.ambari.common.rest.entities.Blueprint;
 import org.apache.ambari.common.rest.entities.Cluster;
@@ -46,7 +40,6 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.PackageRepository;
 import org.apache.ambari.common.rest.entities.Property;
 import org.apache.ambari.common.rest.entities.Role;
-import org.apache.ambari.common.rest.entities.Stack;
 import org.apache.ambari.resource.statemachine.ClusterState;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jettison.json.JSONArray;
@@ -61,7 +54,6 @@ public class Blueprints {
       
         Blueprint bp = new Blueprint();
         bp.setName("MyClusterBlueprint");
-        bp.setStackName("hortonworks-3.0");
         bp.setParentName("MySiteBlueprint");
         bp.setRevision("0");
         bp.setParentRevision("0");
@@ -156,14 +148,11 @@ 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! 
+        /*
+         * Validate the blueprint
          */
-        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());
-        }
+        validateDefaultBlueprint(bp);
+        
         if (blueprints.containsKey(bp.getName())) {
             if (blueprints.get(bp.getName()).containsKey(new Integer(bp.getRevision())))
{
                 String msg = "Specified blueprint [Name:"+bp.getName()+", Revision: ["+bp.getRevision()+"]
already imported";
@@ -179,10 +168,37 @@ public class Blueprints {
     }
     
     /*
-     * Return list of blueprint names
+     * Import the default blueprint from the URL location
      */
+    public void importDefaultBlueprint (String locationURL) throws Exception {
+        Blueprint blueprint;
+        URL blueprintUrl;
+        try {
+            blueprintUrl = new URL(locationURL);
+            ObjectMapper m = new ObjectMapper();
+            InputStream is = blueprintUrl.openStream();
+            blueprint = m.readValue(is, Blueprint.class);
+            addBlueprint(blueprint);
+        } catch (WebApplicationException we) {
+            throw we;
+        } catch (Exception e) {
+            throw new WebApplicationException ((new ExceptionResponse(e)).get());
+        }
+    }
+   
+    /*
+     * Validate the default blueprint before importing into stack.
+     */
+    public void validateDefaultBlueprint(Blueprint blueprint) throws WebApplicationException
{
+        
+        if (blueprint.getName() == null || blueprint.getName().equals("")) {
+            String msg = "Blueprint must be associated with non-empty name";
+            throw new WebApplicationException ((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
+        }
+    }
+    
     /*
-     * Returns stack names
+     * Return list of blueprint names
      */
     public JSONArray getBlueprintList() throws Exception {
         List<String> list = new ArrayList<String>();
@@ -218,14 +234,14 @@ public class Blueprints {
         }
         
         /*
-         * If no cluster is associated then remvove the blueprint
+         * If no cluster is associated then remove the blueprint
          */
         this.blueprints.get(blueprintName).remove(revision);
         if (this.blueprints.get(blueprintName).keySet().isEmpty()) {
             this.blueprints.remove(blueprintName);
         }    
     }
-    
+   
     /*
      * UTIL methods
      */
@@ -235,4 +251,27 @@ public class Blueprints {
         p.setValue(value);
         return p;
     }
+    
+    private static String readAll(Reader rd) throws IOException {
+        StringBuilder sb = new StringBuilder();
+        int cp;
+        while ((cp = rd.read()) != -1) {
+            sb.append((char) cp);
+        }
+        return sb.toString();
+    }
+
+    public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException
{
+        ObjectMapper m = new ObjectMapper();
+        InputStream is = new URL(url).openStream();
+        try {
+            BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
+            String jsonText = readAll(rd);
+            JSONObject json = new JSONObject(jsonText);
+            return json;
+        } finally {
+            is.close();
+        }
+    }
+    
 }

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=1178598&r1=1178597&r2=1178598&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
Mon Oct  3 21:51:36 2011
@@ -35,7 +35,6 @@ import javax.ws.rs.core.Response;
 import org.apache.ambari.common.rest.entities.Blueprint;
 import org.apache.ambari.controller.Blueprints;
 import org.apache.ambari.controller.ExceptionResponse;
-import org.apache.ambari.controller.Stacks;
 
 /** BlueprintResource represents a Hadoop blueprint to be installed on a 
  *  cluster. Blueprints define a collection of Hadoop components that are

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=1178598&r1=1178597&r2=1178598&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
Mon Oct  3 21:51:36 2011
@@ -21,6 +21,7 @@ import java.util.List;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
@@ -34,7 +35,6 @@ import javax.ws.rs.core.Response;
 import org.apache.ambari.common.rest.entities.Blueprint;
 import org.apache.ambari.controller.Blueprints;
 import org.apache.ambari.controller.ExceptionResponse;
-import org.apache.ambari.controller.Stacks;
 import org.codehaus.jettison.json.JSONArray;
 
 /** 
@@ -56,9 +56,13 @@ public class BlueprintsResource {
      */
     @POST
     @Consumes ({"application/json"})
-    public void createBlueprint(Blueprint blueprint) throws Exception {   
+    public void createBlueprint(@DefaultValue("") @QueryParam("locationURL") String locationURL,
Blueprint blueprint) throws Exception {  
         try {
-            Blueprints.getInstance().addBlueprint(blueprint);
+            if (locationURL == null || locationURL.equals("")) {
+                Blueprints.getInstance().addBlueprint(blueprint);
+            } else {
+                Blueprints.getInstance().importDefaultBlueprint (locationURL);
+            }
         }catch (WebApplicationException we) {
             throw we;
         }catch (Exception e) {

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=1178598&r1=1178597&r2=1178598&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
Mon Oct  3 21:51:36 2011
@@ -22,7 +22,6 @@ 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;



Mime
View raw message