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/10/11 09:21:10 UTC
svn commit: r1181642 - in /incubator/ambari/trunk:
client/src/main/java/org/apache/ambari/client/
controller/src/main/java/org/apache/ambari/controller/
controller/src/main/java/org/apache/ambari/controller/rest/resources/
src/site/apt/
Author: vgogate
Date: Tue Oct 11 07:21:10 2011
New Revision: 1181642
URL: http://svn.apache.org/viewvc?rev=1181642&view=rev
Log:
AMBARI-45
Modified:
incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.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/ExceptionResponse.java
incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/resources/ClustersResource.java
incubator/ambari/trunk/src/site/apt/cli.apt
Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java?rev=1181642&r1=1181641&r2=1181642&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java Tue Oct 11 07:21:10 2011
@@ -28,6 +28,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import org.apache.ambari.common.rest.entities.ClusterDefinition;
+import org.apache.ambari.common.rest.entities.ClusterState;
import org.apache.ambari.common.rest.entities.RoleToNodes;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
@@ -51,19 +52,11 @@ public class ClusterCreate extends Comma
String urlPath = "/clusters";
URL resourceURL = null;
-
- String clusterName = null;
- String description = null;
- String blueprint = null;
- String blueprint_revision = "-1";
- String goalState = null;
- String activeServices = null;
- String nodeRangeExpressions = null;
+ CommandLine line;
+ String dry_run = "false";
Properties roleToNodeExpressions = null;
- List<RoleToNodes> roleToNodeMap = null;
- Boolean wait = false;
- Boolean dry_run = false;
+ List<RoleToNodes> roleToNodeList = null;
public ClusterCreate (String [] args) throws Exception {
/*
@@ -106,7 +99,7 @@ public class ClusterCreate extends Comma
OptionBuilder.withArgName( "blueprint_revision" );
OptionBuilder.hasArg();
OptionBuilder.withDescription( "Blueprint revision, if not specified latest revision is used" );
- Option blueprint_revision = OptionBuilder.create( "revision" );
+ Option revision = OptionBuilder.create( "revision" );
OptionBuilder.withArgName( "description" );
OptionBuilder.hasArg();
@@ -134,7 +127,7 @@ public class ClusterCreate extends Comma
options.addOption(dry_run);
options.addOption( name );
options.addOption( blueprint );
- options.addOption(blueprint_revision);
+ options.addOption(revision);
options.addOption( desc );
options.addOption( role );
options.addOption( goalstate );
@@ -149,48 +142,17 @@ public class ClusterCreate extends Comma
CommandLineParser parser = new GnuParser();
try {
// parse the command line arguments
- CommandLine line = parser.parse(this.options, this.args );
+ line = parser.parse(this.options, this.args );
if (line.hasOption("help")) {
printUsage();
System.exit(0);
}
- this.clusterName=line.getOptionValue("name");
- this.blueprint=line.getOptionValue("blueprint");
- this.nodeRangeExpressions=line.getOptionValue("nodes");
-
- if (line.hasOption("revision")){
- this.blueprint_revision=line.getOptionValue("revision");
- System.out.println("Blueprint Revision = "+this.blueprint_revision);
- }
- if (line.hasOption("desc")){
- this.description=line.getOptionValue("desc");
- System.out.println("DESCRIPTION = "+this.description);
- }
- if (line.hasOption("role")){
- this.roleToNodeExpressions = line.getOptionProperties("role");
- /*
- System.out.println ("RoleToNodesMap");
- for (String roleName : this.roleToNodeExpressions.stringPropertyNames()) {
- System.out.println (" <"+roleName+">:<"+ this.roleToNodeExpressions.getProperty(roleName)+">");
- }
- */
- }
- if (line.hasOption("goalstate")){
- this.goalState=line.getOptionValue("goalstate");
- System.out.println("Goalstate = "+this.goalState);
- }
- if (line.hasOption("services")){
- this.activeServices=line.getOptionValue("services");
- System.out.println("Active Services = "+this.activeServices);
- }
- if (line.hasOption("wait")) {
- this.wait = true;
- }
if (line.hasOption("dry_run")) {
- this.dry_run = true;
- }
+ dry_run = "true";
+ }
+
}
catch( ParseException exp ) {
// oops, something went wrong
@@ -206,7 +168,7 @@ public class ClusterCreate extends Comma
}
public static
- List<RoleToNodes> getRoleToNodesMap (Properties roleToNodeExpressions) {
+ List<RoleToNodes> getRoleToNodesList (Properties roleToNodeExpressions) {
if (roleToNodeExpressions == null) { return null; };
List<RoleToNodes> roleToNodesMap = new ArrayList<RoleToNodes>();
@@ -241,24 +203,56 @@ public class ClusterCreate extends Comma
// Create Cluster Definition
ClusterDefinition clsDef = new ClusterDefinition();
- clsDef.setName(this.clusterName);
- clsDef.setBlueprintName(this.blueprint);
- clsDef.setNodes(this.nodeRangeExpressions);
-
- clsDef.setGoalState(this.goalState);
- clsDef.setBlueprintRevision(this.blueprint_revision);
- clsDef.setActiveServices(splitServices(this.activeServices));
- clsDef.setDescription(this.description);
- clsDef.setRoleToNodesMap(getRoleToNodesMap(this.roleToNodeExpressions));
+ clsDef.setName(line.getOptionValue("name"));
+ clsDef.setBlueprintName(line.getOptionValue("blueprint"));
+ clsDef.setNodes(line.getOptionValue("nodes"));
+
+ clsDef.setGoalState(line.getOptionValue("goalstate"));
+ clsDef.setBlueprintRevision(line.getOptionValue("revision"));
+ clsDef.setActiveServices(splitServices(line.getOptionValue("services")));
+ clsDef.setDescription(line.getOptionValue("desc"));
+ clsDef.setRoleToNodesMap(getRoleToNodesList(line.getOptionProperties("role")));
- ClientResponse response = service.path("clusters").accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, clsDef);
+ /*
+ * Create cluster
+ */
+ ClientResponse response = service.path("clusters").queryParam("dry_run", dry_run).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, clsDef);
if (response.getStatus() != 200) {
System.err.println("Cluster create command failed. Reason [Code: <"+response.getStatus()+">, Message: <"+response.getHeaders().getFirst("ErrorMessage")+">]");
System.exit(-1);
}
+ /*
+ * Retrieve the cluster definition from the response
+ */
ClusterDefinition def = response.getEntity(ClusterDefinition.class);
+
System.out.println("CLUSTER NAME ["+def.getName()+"]");
- System.out.println("CLUSTER NAME ["+def.getDescription()+"]");
+ System.out.println("CLUSTER DESC ["+def.getDescription()+"]");
+ if (!line.hasOption("wait")) {
+ return;
+ }
+
+ /*
+ * If wait option is specified then wait for cluster state to reach the desired state
+ */
+ ClusterState clusterState;
+ for (;;) {
+ response = service.path("clusters/"+def.getName()+"/state").accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+ if (response.getStatus() != 200) {
+ System.err.println("Failed to get the cluster state. Reason [Code: <"+response.getStatus()+">, Message: <"+response.getHeaders().getFirst("ErrorMessage")+">]");
+ System.exit(-1);
+ }
+
+ clusterState = response.getEntity(ClusterState.class);
+ if (clusterState.getState().equals(def.getGoalState())) {
+ break;
+ }
+ System.out.println("Waiting for cluster ["+def.getName()+"] to get to desired goalstate");
+ Thread.sleep(15 * 60000);
+ }
+
+ System.out.println("Cluster Goal State ["+def.getGoalState());
+ System.out.println("Cluster state ["+clusterState.getState());
}
}
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=1181642&r1=1181641&r2=1181642&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 Tue Oct 11 07:21:10 2011
@@ -69,7 +69,7 @@ public class Clusters {
cluster123.setBlueprintName("cluster123-blueprint");
cluster123.setBlueprintRevision("0");
cluster123.setDescription("cluster123 - development cluster");
- cluster123.setGoalState(ClusterState.CLUSTER_STATE_ACTIVE);
+ cluster123.setGoalState(ClusterState.CLUSTER_STATE_ATTIC);
List<String> activeServices = new ArrayList<String>();
activeServices.add("hdfs");
activeServices.add("mapred");
@@ -138,8 +138,8 @@ public class Clusters {
cluster124.setRoleToNodesMap(rnm);
try {
- addCluster(cluster123);
- addCluster(cluster124);
+ addCluster(cluster123, false);
+ addCluster(cluster124, false);
} catch (Exception e) {
e.printStackTrace();
}
@@ -170,7 +170,7 @@ public class Clusters {
* (daemon can keep track of which nodes agent is already installed or check it by ssh to nodes, if nodes added
* are in UNREGISTERED state).
*/
- public ClusterDefinition addCluster(ClusterDefinition cdef) throws Exception {
+ public ClusterDefinition addCluster(ClusterDefinition cdef, boolean dry_run) throws Exception {
/*
* TODO: Validate the cluster definition
@@ -180,6 +180,21 @@ public class Clusters {
throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get());
}
+ /*
+ * Populate the input cluster definition w/ default values
+ */
+ if (cdef.getDescription() == null) {
+ cdef.setDescription("Ambari cluster : ["+cdef.getName()+"]");
+ }
+ if (cdef.getGoalState() == null) {
+ cdef.setGoalState(cdef.GOAL_STATE_INACTIVE);
+ }
+ if (cdef.getActiveServices() == null) {
+ List<String> services = new ArrayList<String>();
+ services.add("ALL");
+ cdef.setActiveServices(services);
+ }
+
synchronized (operational_clusters) {
/*
* Check if cluster already exists
@@ -188,7 +203,7 @@ public class Clusters {
String msg = "Cluster ["+cdef.getName()+"] already exists";
throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.CONFLICT)).get());
}
-
+
/*
* Create new cluster object
*/
@@ -197,37 +212,49 @@ public class Clusters {
ClusterState clsState = new ClusterState();
clsState.setCreationTime(requestTime);
clsState.setLastUpdateTime(requestTime);
- clsState.setDeployTime((Date)null);
- clsState.setState(ClusterState.CLUSTER_STATE_INACTIVE);
-
+ clsState.setDeployTime((Date)null);
+ if (cdef.getGoalState().equals(ClusterDefinition.GOAL_STATE_ATTIC)) {
+ clsState.setState(ClusterState.CLUSTER_STATE_ATTIC);
+ } else {
+ clsState.setState(ClusterDefinition.GOAL_STATE_INACTIVE);
+ }
cls.setID(UUID.randomUUID().toString());
cls.addClusterDefinition(cdef);
cls.setClusterState(clsState);
/*
+ * If dry run then update roles to nodes map, if not specified explicitly
+ * and return
+ */
+ if (dry_run) {
+ List<RoleToNodes> role2NodesList = generateRoleToNodesListBasedOnNodeAttributes (cdef);
+ cdef.setRoleToNodesMap(role2NodesList);
+ return cdef;
+ }
+
+ /*
* Update cluster nodes reservation.
*/
- if (cdef.getNodes() != null) {
+ if (cdef.getNodes() != null
+ && !cdef.getGoalState().equals(ClusterDefinition.GOAL_STATE_ATTIC)) {
updateClusterNodesReservation (cls.getID(), cdef);
}
/*
* Update the Node to Roles association, if specified
- * Create map of <Cluster - nodeToRolesMap>
- * If role is not explicitly associated w/ any node then assign it w/ default role
- * If RoleToNodes map is not specified then derive it based on the node attributes
- *
+ * If role is not explicitly associated w/ any node, then assign it w/ default role
+ * If RoleToNodes list is not specified then derive it based on the node attributes
*/
- if (cdef.getRoleToNodes() != null) {
+ if (!cdef.getGoalState().equals(ClusterDefinition.GOAL_STATE_ATTIC)) {
+ if (cdef.getRoleToNodes() == null) {
+ /*
+ * TODO: Derive the role to nodes map based on nodes attributes
+ * then populate the node to roles association.
+ */
+ List<RoleToNodes> role2NodesList = generateRoleToNodesListBasedOnNodeAttributes (cdef);
+ cdef.setRoleToNodesMap(role2NodesList);
+ }
updateNodeToRolesAssociation(cdef.getNodes(), cdef.getRoleToNodes());
- } else {
- /*
- * TODO: Derive the role to nodes map based on nodes attributes
- * then populate the node to roles association.
- */
- //RoleToNodesMap rnm = new RoleToNodesMap();
- // TODO: Populate RoleToNodesMap based on node attributes
- //updateNodeToRolesAssociation(cdef, rnm);
}
/*
@@ -235,14 +262,15 @@ public class Clusters {
* Persist reserved nodes against the cluster & service/role
*/
- // Add the cluster to the list, when definition is persisted
+ // Add the cluster to the list, after definition is persisted
this.operational_clusters.put(cdef.getName(), cls);
this.operational_clusters_id_to_name.put(cls.getID(), cdef.getName());
-
+
/*
- * Activate the cluster if the goal state is activate
+ * Activate the cluster if the goal state is ACTIVE
+ * TODO: What to do if activate fails ???
*/
- if(cdef.getGoalState().equals(ClusterState.CLUSTER_STATE_ACTIVE)) {
+ if(cdef.getGoalState().equals(ClusterDefinition.GOAL_STATE_ACTIVE)) {
org.apache.ambari.resource.statemachine.ClusterFSM cs = StateMachineInvoker.createCluster(cls);
}
}
@@ -250,6 +278,15 @@ public class Clusters {
}
/*
+ * Create RoleToNodes list based on node attributes
+ * TODO: For now just pick some nodes randomly
+ */
+ public List<RoleToNodes> generateRoleToNodesListBasedOnNodeAttributes (ClusterDefinition cdef) {
+ List<RoleToNodes> role2NodesList = new ArrayList<RoleToNodes>();
+ return role2NodesList;
+ }
+
+ /*
* Update the nodes associated with cluster
*/
private synchronized void updateClusterNodesReservation (String clusterID, ClusterDefinition clsDef) throws Exception {
@@ -593,7 +630,10 @@ public class Clusters {
cluster.setClusterState(clusterState);
this.operational_clusters.put(clusterName, cluster);
} catch (Exception e) {
- LOG.error(ExceptionUtil.getStackTrace(e));
+ String msg = "Internal error retriving cluster state for : ["+clusterName+"]";
+ throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.INTERNAL_SERVER_ERROR)).get());
+ // TODO: log the error instead of STDOUT - also in ExceptionResponse
+ // LOG.error(ExceptionUtil.getStackTrace(e));
}
return this.operational_clusters.get(clusterName).getClusterState();
}
Modified: 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=1181642&r1=1181641&r2=1181642&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/ExceptionResponse.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/ExceptionResponse.java Tue Oct 11 07:21:10 2011
@@ -19,8 +19,13 @@ package org.apache.ambari.controller;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.ambari.common.util.ExceptionUtil;
public class ExceptionResponse {
+ private static Log LOG = LogFactory.getLog(ExceptionResponse.class);
Response r;
@@ -30,6 +35,7 @@ public class ExceptionResponse {
builder.header("ErrorCode", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
r = builder.build();
e.printStackTrace();
+ LOG.error(ExceptionUtil.getStackTrace(e));
}
public ExceptionResponse (String exceptionMessage, Response.Status rs) {
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=1181642&r1=1181641&r2=1181642&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 Tue Oct 11 07:21:10 2011
@@ -79,25 +79,37 @@ public class ClustersResource {
/**
* Add new cluster definition.
*
- * Cluster goal state can be either "ACTIVE" or "INACTIVE". In the
- * "INACTIVE" state, nodes specified in the cluster definition will be
- * reserved for the cluster. Although the actual deployment and starting
- * of services would begin when cluster definition is updated to be "ACTIVE"
+ * Cluster definition must specify name, blueprint name and nodes associated with
+ * the cluster.
+ * Default values of cluster definition parameters, if not specified
+ * -- goalstate = "INACTIVE" (optionally, it can be set to ACTIVE)
+ * -- blueprint revision = latest revision
+ * -- RoleToNodes = If explicit association is not specified then Ambari
+ * will determine the optimal role to nodes association.
+ * User can view it by running the command in dry_run.
+ * -- active services = "ALL" i.e. if not specified all the configured
+ * services will be activated
+ * -- description = Default description will be associated
+ * -- dry_run = false
+ *
*
* For cluster to be in active state cluster definition needs to be
* complete & valid e.g. number of nodes associated are sufficient for
* each role, specified blueprint for cluster configuration should exist
* etc.
*
+ * @param dry_run Enable dry run by setting it to true
* @param cluster Definition of the cluster to be created
* @return Returns the cluster definition
* @throws Exception Throws exception (TBD)
*/
@POST
@Consumes({"application/json", "application/xml"})
- public ClusterDefinition addCluster(ClusterDefinition cluster) throws Exception {
+ public ClusterDefinition addCluster(
+ @DefaultValue("false") @QueryParam("dry_run") boolean dry_run,
+ ClusterDefinition cluster) throws Exception {
try {
- return Clusters.getInstance().addCluster(cluster);
+ return Clusters.getInstance().addCluster(cluster, dry_run);
}catch (WebApplicationException we) {
throw we;
}catch (Exception e) {
Modified: incubator/ambari/trunk/src/site/apt/cli.apt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/src/site/apt/cli.apt?rev=1181642&r1=1181641&r2=1181642&view=diff
==============================================================================
--- incubator/ambari/trunk/src/site/apt/cli.apt (original)
+++ incubator/ambari/trunk/src/site/apt/cli.apt Tue Oct 11 07:21:10 2011
@@ -87,6 +87,10 @@ Cluster Commands
* Name of the user defined blueprint defining cluster configuration
+ * <<--blueprint_revision>> [ BLUEPRINT REVISION ]
+
+ * Revision of the blueprint. If not specified latest one is used.
+
* <<--goalstate>> [ACTIVE]
* Default is INACTIVE