You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ab...@apache.org on 2014/05/29 22:08:40 UTC
git commit: AMBARI-5931 - Change parse method of cluster properties
file for Ambari Server
Repository: ambari
Updated Branches:
refs/heads/trunk d4a037036 -> dc917a9f2
AMBARI-5931 - Change parse method of cluster properties file for Ambari Server
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/dc917a9f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/dc917a9f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/dc917a9f
Branch: refs/heads/trunk
Commit: dc917a9f275710f458d60f1552a749a3f52db3db
Parents: d4a0370
Author: Artem Baranchuk <ab...@hortonworks.com>
Authored: Thu May 29 21:48:35 2014 +0300
Committer: Artem Baranchuk <ab...@hortonworks.com>
Committed: Thu May 29 23:05:21 2014 +0300
----------------------------------------------------------------------
.../apache/ambari/msi/ClusterDefinition.java | 102 +++++++------------
.../ambari/msi/ClusterDefinitionTest.java | 8 ++
2 files changed, 44 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/dc917a9f/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/ClusterDefinition.java
----------------------------------------------------------------------
diff --git a/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/ClusterDefinition.java b/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/ClusterDefinition.java
index fb356a2..c52a27e 100644
--- a/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/ClusterDefinition.java
+++ b/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/ClusterDefinition.java
@@ -39,9 +39,8 @@ import java.util.Set;
*/
public class ClusterDefinition {
- private static final String HEADER_TAG = "#";
- private static final String HOSTS_HEADER = "hosts";
- private static final String HA_HEADER = "ha settings";
+ private static final String COMMENT_TAG = "#";
+ private static final String HA_PROPERTY_INDICATOR = "HA";
private static Boolean HA_ENABLE = Boolean.FALSE;
private final Set<String> services = new HashSet<String>();
@@ -128,7 +127,7 @@ public class ClusterDefinition {
}
if(majorStackVersion == 2) {
componentNameMap.put("JOURNALNODE_HOST", Collections.singleton("JOURNALNODE"));
- componentNameMap.put("HA_JOURNALNODE_HOSTS", Collections.singleton("JOURNALNODE"));
+ componentNameMap.put(minorStackVersion > 0 ? "NN_HA_JOURNALNODE_HOSTS" : "HA_JOURNALNODE_HOSTS", Collections.singleton("JOURNALNODE"));
Set<String> haNamenodeComponents = new HashSet<String>();
haNamenodeComponents.add("NAMENODE");
@@ -611,80 +610,51 @@ public class ClusterDefinition {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
- boolean hostsSection = false;
- boolean haSection = false;
-
while ((line = br.readLine()) != null) {
line = line.trim();
+ if (line.startsWith(COMMENT_TAG)) continue;
- if (line.startsWith(HEADER_TAG)) {
+ int i = line.indexOf('=');
+ if (i == -1) continue;
- String header = line.substring(HEADER_TAG.length()).toLowerCase();
- hostsSection = header.equalsIgnoreCase(HOSTS_HEADER);
- haSection = header.equalsIgnoreCase(HA_HEADER);
+ String propertyName = line.substring(0, i);
+ String propertyValue = line.substring(i + 1);
- if (!hostsSection && (header.startsWith(HOSTS_HEADER) ) ){
- char c = header.charAt(HOSTS_HEADER.length());
- hostsSection = c == ' ' || c == '(';
- }
+ if(propertyName.equalsIgnoreCase(HA_PROPERTY_INDICATOR)) {
+ HA_ENABLE = propertyValue.equalsIgnoreCase("YES") ? Boolean.TRUE : Boolean.FALSE;
+ }
- if(!haSection && header.startsWith(HA_HEADER)) {
- char c = header.charAt(HA_HEADER.length());
- haSection = c == ' ' || c == '(';
- }
- } else {
- if (hostsSection || haSection) {
+ Set<String> componentNames = componentNameMap.get(propertyName);
+ if (componentNames != null) {
+ for (String componentName : componentNames) {
+ String serviceName = componentServiceMap.get(componentName);
+ services.add(serviceName);
- if(haSection && line.toUpperCase().contains("HA=YES")) {
- HA_ENABLE = Boolean.TRUE;
+ Set<String> serviceComponents = components.get(serviceName);
+ if (serviceComponents == null) {
+ serviceComponents = new HashSet<String>();
+ components.put(serviceName, serviceComponents);
}
+ serviceComponents.add(componentName);
- int i = line.indexOf('=');
- if (i > -1) {
-
- String name = line.substring(0, i);
- String hostLine = line.substring(i + 1);
-
- Set<String> componentNames = componentNameMap.get(name);
-
- if (componentNames != null) {
-
- for (String componentName : componentNames) {
-
-
- String serviceName = componentServiceMap.get(componentName);
-
- services.add(serviceName);
- Set<String> serviceComponents = components.get(serviceName);
- if (serviceComponents == null) {
- serviceComponents = new HashSet<String>();
- components.put(serviceName, serviceComponents);
- }
- serviceComponents.add(componentName);
-
- Map<String, Set<String>> serviceHostComponents = hostComponents.get(serviceName);
- if (serviceHostComponents == null) {
- serviceHostComponents = new HashMap<String, Set<String>>();
- hostComponents.put(serviceName, serviceHostComponents);
- }
-
- String[] hostNames = hostLine.split(",");
- for (String hostName : hostNames) {
-
- hostName = hostName.trim();
-
- Set<String> hostHostComponents = serviceHostComponents.get(hostName);
- if (hostHostComponents == null) {
- hostHostComponents = new HashSet<String>();
- serviceHostComponents.put(hostName, hostHostComponents);
- }
- hostHostComponents.add(componentName);
+ Map<String, Set<String>> serviceHostComponents = hostComponents.get(serviceName);
+ if (serviceHostComponents == null) {
+ serviceHostComponents = new HashMap<String, Set<String>>();
+ hostComponents.put(serviceName, serviceHostComponents);
+ }
- hosts.add(hostName);
- }
- }
+ String[] hostNames = propertyValue.split(",");
+ for (String hostName : hostNames) {
+ hostName = hostName.trim();
+ Set<String> hostHostComponents = serviceHostComponents.get(hostName);
+ if (hostHostComponents == null) {
+ hostHostComponents = new HashSet<String>();
+ serviceHostComponents.put(hostName, hostHostComponents);
}
+ hostHostComponents.add(componentName);
+
+ hosts.add(hostName);
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/dc917a9f/contrib/ambari-scom/ambari-scom-server/src/test/java/org/apache/ambari/msi/ClusterDefinitionTest.java
----------------------------------------------------------------------
diff --git a/contrib/ambari-scom/ambari-scom-server/src/test/java/org/apache/ambari/msi/ClusterDefinitionTest.java b/contrib/ambari-scom/ambari-scom-server/src/test/java/org/apache/ambari/msi/ClusterDefinitionTest.java
index e8d15f4..0db728e 100644
--- a/contrib/ambari-scom/ambari-scom-server/src/test/java/org/apache/ambari/msi/ClusterDefinitionTest.java
+++ b/contrib/ambari-scom/ambari-scom-server/src/test/java/org/apache/ambari/msi/ClusterDefinitionTest.java
@@ -107,8 +107,14 @@ public class ClusterDefinitionTest {
Assert.assertTrue(components.contains("SECONDARY_NAMENODE"));
Assert.assertTrue(components.contains("DATANODE"));
Assert.assertTrue(components.contains("ZKFC"));
+ Assert.assertTrue(components.contains("JOURNALNODE"));
clusterDefinition = new ClusterDefinition(new TestStateProvider(), new TestClusterDefinitionProvider("clusterproperties_HDP21_HA.txt", "myCluster", "HDP-2.1.2"), new TestHostInfoProvider());
+ components = clusterDefinition.getComponents("HDFS");
+ Assert.assertTrue(components.contains("NAMENODE"));
+ Assert.assertTrue(components.contains("ZKFC"));
+ Assert.assertTrue(components.contains("JOURNALNODE"));
+
components = clusterDefinition.getComponents("YARN");
Assert.assertTrue(components.contains("RESOURCEMANAGER"));
}
@@ -150,12 +156,14 @@ public class ClusterDefinitionTest {
hostComponents = clusterDefinition.getHostComponents("HDFS", "WINHDP-1");
Assert.assertTrue(hostComponents.contains("NAMENODE"));
+ Assert.assertTrue(hostComponents.contains("JOURNALNODE"));
hostComponents = clusterDefinition.getHostComponents("YARN", "WINHDP-2");
Assert.assertTrue(hostComponents.contains("RESOURCEMANAGER"));
hostComponents = clusterDefinition.getHostComponents("HDFS", "WINHDP-2");
Assert.assertTrue(hostComponents.contains("NAMENODE"));
+ Assert.assertTrue(hostComponents.contains("JOURNALNODE"));
}
@Test