You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by om...@apache.org on 2011/12/09 18:14:44 UTC
svn commit: r1212526 - in /incubator/ambari/trunk: CHANGES.txt
controller/src/main/java/org/apache/ambari/controller/StackFlattener.java
controller/src/test/java/org/apache/ambari/controller/TestStackFlattener.java
Author: omalley
Date: Fri Dec 9 17:14:43 2011
New Revision: 1212526
URL: http://svn.apache.org/viewvc?rev=1212526&view=rev
Log:
AMBARI-149. Filter the meta ambari category out of the flattened stacks.
(omalley)
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/StackFlattener.java
incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestStackFlattener.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1212526&r1=1212525&r2=1212526&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Fri Dec 9 17:14:43 2011
@@ -2,6 +2,9 @@ Ambari Change log
Release 0.1.0 - unreleased
+ AMBARI-149. Filter the meta ambari category out of the flattened stacks.
+ (omalley)
+
AMBARI-141. Update the heartbeat on controller/agent (ddas)
AMBARI-147. Create a stack flattener and introduce Guice. (omalley)
Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/StackFlattener.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/StackFlattener.java?rev=1212526&r1=1212525&r2=1212526&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/StackFlattener.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/StackFlattener.java Fri Dec 9 17:14:43 2011
@@ -48,8 +48,17 @@ import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
+/**
+ * This class flattens a stack and its ancestors into a single stack. The
+ * resulting stack has a client configuration at the top and a fully expanded
+ * configuration for each of the roles. The configuration at the components
+ * level (other than being pushed down into the appropriate roles) is also
+ * removed. Finally the "ambari" category is removed from the role configs.
+ */
public class StackFlattener {
+ private static final String META_CATEGORY = "ambari";
+
private final Stacks stacks;
private final ComponentPluginFactory plugins;
@@ -120,17 +129,25 @@ public class StackFlattener {
return result;
}
+ /**
+ * Merge the given Configuration into the map that we are building.
+ * @param map the map to update
+ * @param conf the configuration to merge in
+ * @param dropMeta should we drop the meta category
+ */
private void mergeInConfiguration(Map<String, Map<String, Property>> map,
- Configuration conf) {
+ Configuration conf, boolean dropMeta) {
if (conf != null) {
for (ConfigurationCategory category: conf.getCategory()) {
- Map<String, Property> categoryMap = map.get(category.getName());
- if (categoryMap == null) {
- categoryMap = new TreeMap<String, Property>();
- map.put(category.getName(), categoryMap);
- }
- for (Property prop: category.getProperty()) {
- categoryMap.put(prop.getName(), prop);
+ if (!dropMeta || !META_CATEGORY.equals(category.getName())) {
+ Map<String, Property> categoryMap = map.get(category.getName());
+ if (categoryMap == null) {
+ categoryMap = new TreeMap<String, Property>();
+ map.put(category.getName(), categoryMap);
+ }
+ for (Property prop: category.getProperty()) {
+ categoryMap.put(prop.getName(), prop);
+ }
}
}
}
@@ -155,7 +172,7 @@ public class StackFlattener {
Map<String, Map<String, Property>> newConfig =
new TreeMap<String, Map<String, Property>>();
for(Stack stack: stacks) {
- mergeInConfiguration(newConfig, stack.getConfiguration());
+ mergeInConfiguration(newConfig, stack.getConfiguration(), false);
}
return buildConfig(newConfig);
}
@@ -166,15 +183,15 @@ public class StackFlattener {
Map<String, Map<String, Property>> newConfig =
new TreeMap<String, Map<String,Property>>();
for(Stack stack: stacks) {
- mergeInConfiguration(newConfig, stack.getConfiguration());
+ mergeInConfiguration(newConfig, stack.getConfiguration(), true);
for (Component component: stack.getComponents()) {
if (component.getName().equals(componentName)) {
- mergeInConfiguration(newConfig, component.getConfiguration());
+ mergeInConfiguration(newConfig, component.getConfiguration(), true);
List<Role> roleList = component.getRoles();
if (roleList != null) {
for (Role role: roleList) {
if (role.getName().equals(roleName)) {
- mergeInConfiguration(newConfig, role.getConfiguration());
+ mergeInConfiguration(newConfig, role.getConfiguration(), true);
}
}
}
Modified: incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestStackFlattener.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestStackFlattener.java?rev=1212526&r1=1212525&r2=1212526&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestStackFlattener.java (original)
+++ incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestStackFlattener.java Fri Dec 9 17:14:43 2011
@@ -178,6 +178,7 @@ public class TestStackFlattener {
childHdfsConfig, hdfsRoles));
Configuration nnConf = new Configuration();
hdfsRoles.add(new Role("namenode", nnConf));
+ setConfigParam(parentConfiguration, "ambari", "global", "global-value");
setConfigParam(parentConfiguration, "cat1", "b", "parent");
setConfigParam(parentConfiguration, "cat1", "a", "a-value");
setConfigParam(parentConfiguration, "cat2", "b", "cat2-value");
@@ -194,6 +195,7 @@ public class TestStackFlattener {
assertEquals("a-value", getConfigParam(conf, "cat1", "a"));
assertEquals("cat2-value", getConfigParam(conf, "cat2", "b"));
assertEquals("grandchild", getConfigParam(conf, "cat1", "b"));
+ assertEquals("global-value", getConfigParam(conf, "ambari", "global"));
assertEquals(null, getConfigParam(conf, "cat1", "c"));
assertEquals(null, getConfigParam(conf, "cat1", "d"));
Component comp = flat.getComponents().get(0);
@@ -205,6 +207,7 @@ public class TestStackFlattener {
assertEquals("a-value", getConfigParam(conf, "cat1", "a"));
assertEquals("cat2-value", getConfigParam(conf, "cat2", "b"));
assertEquals("grandchild", getConfigParam(conf, "cat1", "b"));
+ assertEquals(null, getConfigParam(conf, "ambari", "global"));
assertEquals("nn-c", getConfigParam(conf, "cat1", "c"));
assertEquals("d-value", getConfigParam(conf, "cat1", "d"));
role = comp.getRoles().get(1);
@@ -213,6 +216,7 @@ public class TestStackFlattener {
assertEquals("a-value", getConfigParam(conf, "cat1", "a"));
assertEquals("cat2-value", getConfigParam(conf, "cat2", "b"));
assertEquals("grandchild", getConfigParam(conf, "cat1", "b"));
+ assertEquals(null, getConfigParam(conf, "ambari", "global"));
assertEquals(null, getConfigParam(conf, "cat1", "c"));
assertEquals("d-value", getConfigParam(conf, "cat1", "d"));
}