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 20:49:11 UTC
svn commit: r1177770 - 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 18:49:11 2011
New Revision: 1177770
URL: http://svn.apache.org/viewvc?rev=1177770&view=rev
Log:
AMBARI-22
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java
incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintResource.java
incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/BlueprintsResource.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1177770&r1=1177769&r2=1177770&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Fri Sep 30 18:49:11 2011
@@ -2,6 +2,8 @@ Ambari Change log
Release 0.1.0 - unreleased
+ AMBARI-22. Implement Blueprint Resource API
+
AMBARI-21. Fix the problem w/ Stacks Resource API
AMBARI-20. Fix the rest API for getting the cluster nodes
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=1177770&r1=1177769&r2=1177770&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 Fri Sep 30 18:49:11 2011
@@ -36,6 +36,7 @@ import javax.xml.bind.annotation.XmlType
"name",
"description",
"blueprintName",
+ "blueprintRevision",
"goalState",
"activeServices",
"nodeRangeExpressions",
@@ -54,6 +55,8 @@ public class ClusterDefinition {
protected String description = null;
@XmlElement(name = "BlueprintName")
protected String blueprintName = null;
+ @XmlElement(name = "BlueprintRevision")
+ protected String blueprintRevision = null;
@XmlElement(name = "GoalState")
protected String goalState = null;
@XmlElement(name = "ActiveServices")
@@ -65,6 +68,20 @@ public class ClusterDefinition {
/**
+ * @return the blueprintRevision
+ */
+ public String getBlueprintRevision() {
+ return blueprintRevision;
+ }
+
+ /**
+ * @param blueprintRevision the blueprintRevision to set
+ */
+ public void setBlueprintRevision(String blueprintRevision) {
+ this.blueprintRevision = blueprintRevision;
+ }
+
+ /**
* @return the name
*/
public String getName() {
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=1177770&r1=1177769&r2=1177770&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 Fri Sep 30 18:49:11 2011
@@ -39,8 +39,17 @@ 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.Cluster;
+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.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;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -48,7 +57,65 @@ public class Blueprints {
private static Blueprints BlueprintsRef=null;
- private Blueprints() {}
+ private Blueprints() {
+
+ Blueprint bp = new Blueprint();
+ bp.setName("MyClusterBlueprint");
+ bp.setStackName("hortonworks-3.0");
+ bp.setParentName("MySiteBlueprint");
+ bp.setRevision("0");
+ bp.setParentRevision("0");
+
+ Component hdfsC = new Component(); hdfsC.setName("hdfs");
+ hdfsC.getProperty().add(getProperty ("dfs.name.dir", "${HADOOP_NN_DIR}"));
+ hdfsC.getProperty().add(getProperty ("dfs.data.dir", "${HADOOP_DATA_DIR}"));
+ Component mapredC = new Component(); mapredC.setName("hdfs");
+ mapredC.getProperty().add(getProperty ("mapred.system.dir", "/mapred/mapredsystem"));
+ mapredC.getProperty().add(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(getProperty ("dfs.name.dir", "/tmp/namenode"));
+ hdfs_site.getProperty().add(getProperty ("dfs.data.dir", "/tmp/datanode"));
+ mapred_site.getProperty().add(getProperty ("mapred.system.dir", "/mapred/mapredsystem"));
+ mapred_site.getProperty().add(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);
+
+ ConcurrentHashMap<Integer, Blueprint> x = new ConcurrentHashMap<Integer, Blueprint>();
+ x.put(new Integer(bp.getRevision()), bp);
+ this.blueprints.put(bp.getName(), x);
+ }
public static synchronized Blueprints getInstance() {
if(BlueprintsRef == null) {
@@ -103,18 +170,53 @@ public class Blueprints {
/*
* Return list of blueprint names
*/
- public List<String> getBlueprintList() throws Exception {
+ /*
+ * Returns stack names
+ */
+ public JSONArray getBlueprintList() throws Exception {
List<String> list = new ArrayList<String>();
list.addAll(this.blueprints.keySet());
- return list;
+ return new JSONArray(list);
}
+
/*
* Delete the specified version of blueprint
+ * 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));
+
+ 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;
+ }
+ Blueprint bpx = Blueprints.getInstance().blueprints.get(bpName).get(new Integer(bpRevision));
+ if (bpx.getName().equals(bp.getName()) && bpx.getRevision().equals(bp.getRevision()) ||
+ bpx.getParentName().equals(bp.getParentName()) && bpx.getParentRevision().equals(bp.getParentRevision())) {
+ String msg = "One or more clusters are associated with the specified blueprint";
+ throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.NOT_ACCEPTABLE)).get());
+ }
+ }
+
+ /*
+ * If no cluster is associated then remvove the blueprint
+ */
this.blueprints.get(blueprintName).remove(revision);
if (this.blueprints.get(blueprintName).keySet().isEmpty()) {
this.blueprints.remove(blueprintName);
}
}
+
+ /*
+ * UTIL methods
+ */
+ public Property getProperty(String key, String value) {
+ Property p = new Property();
+ p.setName(key);
+ p.setValue(value);
+ return p;
+ }
}
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=1177770&r1=1177769&r2=1177770&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 18:49:11 2011
@@ -66,6 +66,7 @@ public class Clusters {
cluster123.setName("blue.dev.Cluster123");
cluster123.setBlueprintName("cluster123-blueprint");
+ cluster123.setBlueprintRevision("0");
cluster123.setDescription("cluster123 - development cluster");
cluster123.setGoalState(ClusterState.CLUSTER_STATE_ACTIVE);
List<String> activeServices = new ArrayList<String>();
@@ -126,6 +127,7 @@ public class Clusters {
ClusterDefinition cluster124 = new ClusterDefinition();
cluster124.setName("blue.research.Cluster124");
cluster124.setBlueprintName("cluster124-blueprint");
+ cluster124.setBlueprintRevision("0");
cluster124.setDescription("cluster124 - research cluster");
cluster124.setGoalState(ClusterState.CLUSTER_STATE_INACTIVE);
activeServices = new ArrayList<String>();
@@ -447,6 +449,7 @@ public class Clusters {
Cluster cls = this.operational_clusters.get(clusterName);
synchronized (cls.getClusterDefinition()) {
if (c.getBlueprintName() != null) cls.getClusterDefinition().setBlueprintName(c.getBlueprintName());
+ if (c.getBlueprintRevision() != null) cls.getClusterDefinition().setBlueprintRevision(c.getBlueprintRevision());
if (c.getDescription() != null) cls.getClusterDefinition().setDescription(c.getDescription());
if (c.getGoalState() != null) cls.getClusterDefinition().setGoalState(c.getGoalState());
if (c.getActiveServices() != null) cls.getClusterDefinition().setActiveServices(c.getActiveServices());
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=1177770&r1=1177769&r2=1177770&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 Fri Sep 30 18:49:11 2011
@@ -34,6 +34,7 @@ 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
@@ -65,18 +66,18 @@ public class BlueprintResource {
@GET
@Produces({"application/json", "application/xml"})
public Blueprint getBlueprint(@PathParam("blueprintName") String blueprintName,
- @DefaultValue("") @QueryParam("revision") String revision) throws Exception {
+ @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 Blueprints.getInstance().getBlueprint(blueprintName, 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());
+ }
}
/** Delete the blueprint
@@ -99,18 +100,19 @@ 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("")) {
- 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());
}
Blueprints.getInstance().deleteBlueprint(blueprintName, 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());
+ }
}
/** Update a current blueprint.
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=1177770&r1=1177769&r2=1177770&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 Fri Sep 30 18:49:11 2011
@@ -33,7 +33,9 @@ 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;
/** BlueprintResource represents a Hadoop blueprint to be installed on a
* cluster. Blueprints define a collection of Hadoop components that are
@@ -62,7 +64,7 @@ public class BlueprintsResource {
* @throws Exception throws Exception
*/
@POST
- @Consumes
+ @Consumes ({"application/json"})
public void createBlueprint(Blueprint blueprint) throws Exception {
Blueprints.getInstance().addBlueprint(blueprint);
}
@@ -84,19 +86,19 @@ public class BlueprintsResource {
* @throws Exception throws Exception
*/
@GET
- @Consumes
- public List<String> listBlueprints() throws Exception {
+ @Produces({"application/json"})
+ public JSONArray listBlueprints() throws Exception {
+ JSONArray list;
try {
- List <String> list = Blueprints.getInstance().getBlueprintList();
- if (list.isEmpty()) {
- Exception e = new Exception ("No user defined blueprints found");
- throw new WebApplicationException (e, Response.Status.NO_CONTENT);
- }
+ list = Blueprints.getInstance().getBlueprintList();
+ if (list.length() == 0) {
+ throw new WebApplicationException(Response.Status.NO_CONTENT);
+ }
return list;
}catch (WebApplicationException we) {
throw we;
}catch (Exception e) {
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
+ throw new WebApplicationException((new ExceptionResponse(e)).get());
}
}