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 4F8079177 for ; Mon, 28 Nov 2011 21:56:33 +0000 (UTC) Received: (qmail 56543 invoked by uid 500); 28 Nov 2011 21:56:33 -0000 Delivered-To: apmail-incubator-ambari-commits-archive@incubator.apache.org Received: (qmail 56524 invoked by uid 500); 28 Nov 2011 21:56:33 -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 56517 invoked by uid 99); 28 Nov 2011 21:56:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Nov 2011 21:56:32 +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; Mon, 28 Nov 2011 21:56:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0E881238889B; Mon, 28 Nov 2011 21:56:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1207644 - in /incubator/ambari/trunk: ./ controller/src/main/java/org/apache/ambari/controller/ Date: Mon, 28 Nov 2011 21:56:07 -0000 To: ambari-commits@incubator.apache.org From: vgogate@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111128215608.0E881238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: vgogate Date: Mon Nov 28 21:56:05 2011 New Revision: 1207644 URL: http://svn.apache.org/viewvc?rev=1207644&view=rev Log: AMBARI-142. Add cluster must validate if requested nodes are pre-allocated to any other existing cluster Modified: incubator/ambari/trunk/CHANGES.txt incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Stacks.java Modified: incubator/ambari/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1207644&r1=1207643&r2=1207644&view=diff ============================================================================== --- incubator/ambari/trunk/CHANGES.txt (original) +++ incubator/ambari/trunk/CHANGES.txt Mon Nov 28 21:56:05 2011 @@ -2,6 +2,8 @@ Ambari Change log Release 0.1.0 - unreleased + AMBZRI-142. Add cluster must validate if requested nodes are pre-allocated to any other existing cluster (vgogate) + AMBARI-140. Refactors the heartbeat handling w.r.t simplification of state management. (ddas) 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=1207644&r1=1207643&r2=1207644&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 Mon Nov 28 21:56:05 2011 @@ -57,93 +57,6 @@ public class Clusters { private static Clusters ClustersTypeRef=null; private Clusters() { - - /* - * Cluster definition - */ - ClusterDefinition cluster123 = new ClusterDefinition(); - - cluster123.setName("blue.dev.Cluster123"); - cluster123.setStackName("cluster123"); - cluster123.setStackRevision("0"); - cluster123.setDescription("cluster123 - development cluster"); - cluster123.setGoalState(ClusterState.CLUSTER_STATE_ATTIC); - List activeServices = new ArrayList(); - activeServices.add("hdfs"); - //activeServices.add("mapred"); - cluster123.setActiveServices(activeServices); - - String nodes = "jt-nodex,nn-nodex,hostname-1x,hostname-2x,hostname-3x,"+ - "hostname-4x,node-2x,node-3x,node-4x"; - cluster123.setNodes(nodes); - - List rnm = new ArrayList(); - - RoleToNodes rnme = new RoleToNodes(); - rnme.setRoleName("jobtracker-role"); - rnme.setNodes("jt-nodex"); - rnm.add(rnme); - - rnme = new RoleToNodes(); - rnme.setRoleName("namenode-role"); - rnme.setNodes("nn-nodex"); - rnm.add(rnme); - - rnme = new RoleToNodes(); - rnme.setRoleName("slaves-role"); - rnme.setNodes("hostname-1x,hostname-2x,hostname-3x,"+ - "hostname-4x,node-2x,node-3x,node-4x"); - rnm.add(rnme); - - cluster123.setRoleToNodesMap(rnm); - - /* - * Cluster definition - */ - ClusterDefinition cluster124 = new ClusterDefinition(); - cluster124.setName("blue.research.Cluster124"); - cluster124.setStackName("cluster124"); - cluster124.setStackRevision("0"); - cluster124.setDescription("cluster124 - research cluster"); - cluster124.setGoalState(ClusterState.CLUSTER_STATE_INACTIVE); - activeServices = new ArrayList(); - activeServices.add("hdfs"); - //activeServices.add("mapred"); - cluster124.setActiveServices(activeServices); - - nodes = "jt-node,nn-node,hostname-1,hostname-2,hostname-3,hostname-4,"+ - "node-2,node-3,node-4"; - cluster124.setNodes(nodes); - - rnm = new ArrayList(); - - rnme = new RoleToNodes(); - rnme.setRoleName("jobtracker-role"); - rnme.setNodes("jt-node"); - rnm.add(rnme); - - rnme = new RoleToNodes(); - rnme.setRoleName("namenode-role"); - rnme.setNodes("nn-node"); - rnm.add(rnme); - - rnme = new RoleToNodes(); - rnme.setRoleName("slaves-role"); - rnme.setNodes("hostname-1,hostname-2,hostname-3,hostname-4,"+ - "node-2,node-3,node-4"); - rnm.add(rnme); - - cluster124.setRoleToNodesMap(rnm); - try { - if (!clusterExists(cluster123.getName())) { - addCluster(cluster123.getName(), cluster123, false); - } - if (!clusterExists(cluster124.getName())) { - addCluster(cluster124.getName(), cluster124, false); - } - } catch (Exception e) { - e.printStackTrace(); - } } public static synchronized Clusters getInstance() { @@ -462,12 +375,12 @@ public class Clusters { /* * TODO: Create and update the puppet configuration - + */ String puppetConfig = this.getPuppetConfigString (cdef); System.out.println("=============================="); System.out.println(puppetConfig); System.out.println("=============================="); - */ + /* * Persist the new cluster and add entry to cache @@ -589,10 +502,40 @@ public class Clusters { /* - * Check if all the nodes explicitly specified in the RoleToNodesMap belong the cluster node range specified + * Check if nodes requested for cluster are not already allocated to other clusters */ + ConcurrentHashMap all_nodes = Nodes.getInstance().getNodes(); List cluster_node_range = new ArrayList(); cluster_node_range.addAll(getHostnamesFromRangeExpressions(cdef.getNodes())); + List preallocatedhosts = new ArrayList(); + for (String n : cluster_node_range) { + if (all_nodes.containsKey(n) && + (all_nodes.get(n).getNodeState().getClusterName() != null || + all_nodes.get(n).getNodeState().getAllocatedToCluster() + ) + ) { + /* + * Following check is for a very specific case + * When controller starts w/ no persistent data in data store, it adds default clusters + * and down the road restart recovery code re-validates the cluster definition when + * it finds nodes already allocated. + if (all_nodes.get(n).getNodeState().getClusterName() != null && + all_nodes.get(n).getNodeState().getClusterName().equals(clusterName)) { + continue; + } */ + preallocatedhosts.add(n); + } + } + + if (!preallocatedhosts.isEmpty()) { + String msg = "Some of the nodes specified for the cluster roles are allocated to other cluster: ["+preallocatedhosts+"]"; + throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.CONFLICT)).get()); + } + + + /* + * Check if all the nodes explicitly specified in the RoleToNodesMap belong the cluster node range specified + */ if (cdef.getRoleToNodesMap() != null) { List nodes_specified_using_role_association = new ArrayList(); for (RoleToNodes e : cdef.getRoleToNodesMap()) { @@ -608,6 +551,8 @@ public class Clusters { throw new WebApplicationException((new ExceptionResponse(msg, Response.Status.BAD_REQUEST)).get()); } } + + } /* @@ -934,18 +879,27 @@ public class Clusters { Stacks stacksCtx = Stacks.getInstance(); Stack stack = stacksCtx.getStack(c.getStackName(), Integer.parseInt(c.getStackRevision())); String config = "\n$hadoop_stack_conf = { "; - for (Component comp : stack.getComponents()) { - for (Role role : comp.getRoles()) { - config = config + comp.getName()+"_"+role.getName()+" => { "; - for (ConfigurationCategory cat : role.getConfiguration().getCategory()) { - config = config+"\""+cat.getName()+"\" => { "; - for (Property p : cat.getProperty()) { - config = config+p.getName()+" => "+p.getValue()+", "; - } - config = config +" }, \n"; + if (stack.getComponents() != null) { + for (Component comp : stack.getComponents()) { + if (comp.getRoles() != null) { + for (Role role : comp.getRoles()) { + //config = config + comp.getName()+"_"+role.getName()+" => { "; + config = config+role.getName()+" => { "; + if (role.getConfiguration() != null && role.getConfiguration().getCategory() != null) { + for (ConfigurationCategory cat : role.getConfiguration().getCategory()) { + config = config+"\""+cat.getName()+"\" => { "; + if (cat.getProperty() != null) { + for (Property p : cat.getProperty()) { + config = config+p.getName()+" => "+p.getValue()+", "; + } + } + config = config +" }, \n"; + } + } + config = config + "}, \n"; + } } - config = config + "}, \n"; - } + } } config = config + "} \n"; @@ -955,7 +909,7 @@ public class Clusters { for (String host : this.getHostnamesFromRangeExpressions(roleToNodesEntry.getNodes())) { config = config + "\'"+host+"\',"; } - config = config + "] \n"; + config = config + "], \n"; } config = config + "} \n"; Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java?rev=1207644&r1=1207643&r2=1207644&view=diff ============================================================================== --- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java (original) +++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java Mon Nov 28 21:56:05 2011 @@ -123,7 +123,9 @@ public class Controller { */ server.start(); } catch (Exception e) { + e.printStackTrace(); LOG.error(ExceptionUtil.getStackTrace(e)); + } } 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=1207644&r1=1207643&r2=1207644&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 Mon Nov 28 21:56:05 2011 @@ -59,13 +59,6 @@ public class Stacks { if (!this.dataStore.stackExists("hadoop-security")) { loadDummyStack(jaxbContext, "hadoop-security", 0); } - if (!this.dataStore.stackExists("cluster123")) { - loadDummyStack(jaxbContext, "cluster123", 0); - } - if (!this.dataStore.stackExists("cluster124")) { - loadDummyStack(jaxbContext, "cluster124", 0); - } - //loadDummyStack(jaxbContext, "puppet1", 0); } catch (JAXBException e) { throw new RuntimeException("Can't create jaxb context", e); } catch (Exception e) {