Return-Path: X-Original-To: apmail-incubator-ambari-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-ambari-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 60F6199DC for ; Tue, 11 Oct 2011 19:23:32 +0000 (UTC) Received: (qmail 67815 invoked by uid 500); 11 Oct 2011 19:23:31 -0000 Delivered-To: apmail-incubator-ambari-commits-archive@incubator.apache.org Received: (qmail 67798 invoked by uid 500); 11 Oct 2011 19:23:31 -0000 Mailing-List: contact ambari-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@incubator.apache.org Delivered-To: mailing list ambari-commits@incubator.apache.org Received: (qmail 67791 invoked by uid 99); 11 Oct 2011 19:23:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Oct 2011 19:23:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Oct 2011 19:23:28 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 707C7238889B; Tue, 11 Oct 2011 19:23:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1182043 - in /incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller: Cluster.java Clusters.java Date: Tue, 11 Oct 2011 19:23:06 -0000 To: ambari-commits@incubator.apache.org From: vgogate@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111011192306.707C7238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: vgogate Date: Tue Oct 11 19:23:05 2011 New Revision: 1182043 URL: http://svn.apache.org/viewvc?rev=1182043&view=rev Log: AMBARI-45 Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java?rev=1182043&r1=1182042&r2=1182043&view=diff ============================================================================== --- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java (original) +++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java Tue Oct 11 19:23:05 2011 @@ -63,7 +63,7 @@ public class Cluster { * @return the clusterDefinition */ public ClusterDefinition getClusterDefinition(long revision) { - return clusterDefinitionRevisionsList.get(revision); + return clusterDefinitionRevisionsList.get(revision); } /** 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=1182043&r1=1182042&r2=1182043&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 19:23:05 2011 @@ -173,27 +173,9 @@ public class Clusters { public ClusterDefinition addCluster(ClusterDefinition cdef, boolean dry_run) throws Exception { /* - * TODO: Validate the cluster definition + * TODO: Validate the cluster definition and set the default */ - if (cdef.getName() == null || cdef.getName().equals("")) { - String msg = "Cluster Name must be specified and must be non-empty string"; - 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 services = new ArrayList(); - services.add("ALL"); - cdef.setActiveServices(services); - } + validateClusterDefinition(cdef); synchronized (operational_clusters) { /* @@ -287,22 +269,53 @@ public class Clusters { } /* - * Update the nodes associated with cluster + * Validates the cluster definition */ - private synchronized void updateClusterNodesReservation (String clusterID, ClusterDefinition clsDef) throws Exception { - - String nodeRangeExpressions = clsDef.getNodes(); + public void validateClusterDefinition (ClusterDefinition cdef) throws Exception { + /* + * Check if name is not empty or null + */ + if (cdef.getName() == null || cdef.getName().equals("")) { + String msg = "Cluster Name must be specified and must be non-empty string"; + throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get()); + } - ConcurrentHashMap all_nodes = Nodes.getInstance().getNodes(); - List cluster_node_range = new ArrayList(); - cluster_node_range.addAll(getHostnamesFromRangeExpressions(nodeRangeExpressions)); + if (cdef.getNodes() == null || cdef.getNodes().equals("")) { + String msg = "Cluster node range must be specified and must be non-empty string"; + throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get()); + } + + if (cdef.getBlueprintName() == null || cdef.getBlueprintName().equals("")) { + String msg = "Cluster blueprint must be specified and must be non-empty string"; + 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); + } + /* + * TODO: If blueprint revision is -1, then use latest blueprint revision. + */ + if (cdef.getBlueprintRevision() == null) { cdef.setBlueprintRevision("-1"); + } + if (cdef.getActiveServices() == null) { + List services = new ArrayList(); + services.add("ALL"); + cdef.setActiveServices(services); + } /* * Check if all the nodes explicitly specified in the RoleToNodesMap belong the cluster node range specified */ - if (clsDef.getRoleToNodes() != null) { + List cluster_node_range = new ArrayList(); + cluster_node_range.addAll(getHostnamesFromRangeExpressions(cdef.getNodes())); + if (cdef.getRoleToNodes() != null) { List nodes_specified_using_role_association = new ArrayList(); - for (RoleToNodes e : clsDef.getRoleToNodes()) { + for (RoleToNodes e : cdef.getRoleToNodes()) { List hosts = getHostnamesFromRangeExpressions(e.getNodes()); nodes_specified_using_role_association.addAll(hosts); // TODO: Remove any duplicate nodes from nodes_specified_using_role_association @@ -315,7 +328,17 @@ public class Clusters { throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get()); } } - + } + + /* + * Update the nodes associated with cluster + */ + private synchronized void updateClusterNodesReservation (String clusterID, ClusterDefinition clsDef) throws Exception { + + ConcurrentHashMap all_nodes = Nodes.getInstance().getNodes(); + List cluster_node_range = new ArrayList(); + cluster_node_range.addAll(getHostnamesFromRangeExpressions(clsDef.getNodes())); + /* * Reserve the nodes as specified in the node range expressions * -- throw exception if any nodes are pre-associated with other cluster