list = getChildren(tagName);
+ if (list == null || list.isEmpty()) {
+ return null;
+ }
+
+ for (SchedulerConfNode n : list) {
+ if (n.getName().equals(name)) {
+ return n;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Return value of this element itself.
+ *
+ * value
+ *
+ * Call getValue on now will return "value"
+ */
+ public String getValue() {
+ return value;
+ }
+
+ public String getValue(String tagName) {
+ return getValue(tagName, null);
+ }
+
+ public String getValue(String tagName, String defaultValue) {
+ return getValue(tagName, defaultValue, false);
+ }
+
+ public String getValue(String tagName, String defaultValue,
+ boolean policyProperty) {
+ return getValue(tagName, defaultValue, policyProperty, false);
+ }
+
+ /**
+ * Return value of direct child with given tagName, return empty string if no
+ * value; return null if no element with given tagName existed.
+ *
+ *
+ * {@code
+ *
+ * value1
+ *
+ * }
+ *
+ *
+ * Call getValue("option1") will return value1. If no tag ,
+ * defaultValue will be returned
+ *
+ * When inherit=true, it will try to find lowest ancestor with the option,
+ * such as:
+ *
+ *
+ * {@code
+ *
+ * value1
+ *
+ * value2
+ *
+ *
+ *
+ *
+ * }
+ *
+ *
+ * Execute getValue("key", inherit=true) on "now" will returns value2
+ */
+ public String getValue(String tagName, String defaultValue,
+ boolean policyProperty, boolean inherit) {
+ if (!policyProperty) {
+ // First to getValue on this node, like
+ //
+ // {@code
+ //
+ // value
+ //
+ // }
+ //
+ SchedulerConfNode node = getChild(tagName);
+ if (null != node) {
+ return node.getValue();
+ }
+ } else {
+ // If it's a policy property, we will get it from
+ //
+ // {@code
+ //
+ //
+ // value
+ //
+ //
+ // }
+ //
+ SchedulerConfNode policyPropertiesNode = getChild(POLICY_PROPERTIES_TAGNAME);
+ if (null != policyPropertiesNode && null != policyPropertiesNode.getChild(tagName)) {
+ return policyPropertiesNode.getChild(tagName).getValue();
+ }
+ }
+
+ if (inherit) {
+ // When inherit enabled:
+ if (null == parent) {
+ // We're root, try to get value directly
+ return getValue(tagName, defaultValue, policyProperty, false);
+ } else {
+ // We're not root, try to inherit value from parent
+ return parent.getValue(tagName, defaultValue, policyProperty, true);
+ }
+ } else {
+ return defaultValue;
+ }
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public void setValue(String tagName, String value, boolean policyProperty) {
+ if (!policyProperty) {
+ SchedulerConfNode node = getChild(tagName);
+ if (null != node) {
+ node.setValue(value);
+ } else {
+ fields
+ .put(tagName, new SchedulerConfNode("", value, tagName, null));
+ }
+ } else {
+ // trying to add policyProperties node
+ SchedulerConfNode policyPropertiesNode =
+ getChild(POLICY_PROPERTIES_TAGNAME);
+ if (null == policyPropertiesNode) {
+ policyPropertiesNode =
+ new SchedulerConfNode("", "", POLICY_PROPERTIES_TAGNAME, null);
+ fields.put(POLICY_PROPERTIES_TAGNAME, policyPropertiesNode);
+ }
+ policyPropertiesNode.setValue(tagName, value, false);
+ }
+ }
+
+ public SchedulerConfNode addChild(String tagName, String name) {
+ SchedulerConfNode child = new SchedulerConfNode(name, "", tagName, null);
+ fields.put(tagName, child);
+ return child;
+ }
+
+ public boolean isLeafNode() {
+ return fields.isEmpty();
+ }
+
+ @VisibleForTesting
+ public ListMultimap getFields() {
+ return fields;
+ }
+
+ private int getDepth() {
+ int hierarchy = 0;
+ SchedulerConfNode p = parent;
+ while (null != p) {
+ hierarchy ++;
+ p = p.parent;
+ }
+ return hierarchy;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ String indent = StringUtils.repeat(" ", getDepth() * 4);
+ sb.append(indent + "tag=" + tag + ", name=" + name + ", value=" + value
+ + " children=[\n");
+ for (String key : fields.keySet()) {
+ for (SchedulerConfNode node : fields.get(key)) {
+ sb.append(node.toString());
+ }
+ }
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/config/SchedulerConfParser.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/config/SchedulerConfParser.java
new file mode 100644
index 0000000..2472f20
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/config/SchedulerConfParser.java
@@ -0,0 +1,150 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.config;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.SAXException;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+
+/**
+ * Parse hierarchy scheduler configuration file
+ */
+public class SchedulerConfParser {
+ private static final String NAME = "name";
+
+ public static SchedulerConfNode parse(String content) throws YarnRuntimeException {
+ try {
+ Document doc = parseDocument(content);
+ return internalParse(doc.getDocumentElement());
+ } catch (ParserConfigurationException | SAXException | IOException e) {
+ throw new YarnRuntimeException(e);
+ }
+ }
+
+ public static SchedulerConfNode parse(InputStream is) throws YarnRuntimeException {
+ try {
+ Document doc = parseDocument(is);
+ return internalParse(doc.getDocumentElement());
+ } catch (ParserConfigurationException | SAXException | IOException e) {
+ throw new YarnRuntimeException(e);
+ }
+ }
+
+ public SchedulerConfNode parse(File file) throws YarnRuntimeException {
+ try {
+ Document doc = parseDocument(file);
+ return internalParse(doc.getDocumentElement());
+ } catch (ParserConfigurationException | SAXException | IOException e) {
+ throw new YarnRuntimeException(e);
+ }
+ }
+
+ private static SchedulerConfNode internalParse(Element current) {
+ // Get name
+ String name = current.getAttribute(NAME);
+
+ // Get tag
+ String tag = current.getTagName();
+
+ // Get value
+ String value = "";
+
+ // Initial fields
+ ListMultimap fields = ArrayListMultimap.create();
+ List childrenElements = new ArrayList();
+ NodeList nodes = current.getChildNodes();
+
+ if (nodes.getLength() > 0) {
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if (!(node instanceof Element)) {
+ continue;
+ }
+ Element element = (Element) node;
+ childrenElements.add(element);
+ SchedulerConfNode childConfNode = internalParse(element);
+ fields.put(element.getTagName(), childConfNode);
+ }
+ }
+
+ if (childrenElements.isEmpty()) {
+ if (current.getFirstChild() != null) {
+ // Value will only be set when this element has no child
+ value = ((Text) current.getFirstChild()).getData().trim();
+ }
+ }
+
+ SchedulerConfNode now =
+ new SchedulerConfNode(name, value, tag, fields);
+
+ // setParent for all children
+ for (SchedulerConfNode child : fields.values()) {
+ child.setParent(now);
+ }
+
+ return now;
+ }
+
+ private static DocumentBuilder getDocumentBuilder()
+ throws ParserConfigurationException {
+ DocumentBuilderFactory docBuilderFactor =
+ DocumentBuilderFactory.newInstance();
+ docBuilderFactor.setIgnoringComments(true);
+ DocumentBuilder builder = docBuilderFactor.newDocumentBuilder();
+ return builder;
+ }
+
+ private static Document parseDocument(String content)
+ throws ParserConfigurationException, SAXException, IOException {
+ ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes());
+ return parseDocument(bais);
+ }
+
+ private static Document parseDocument(InputStream is)
+ throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilder builder = getDocumentBuilder();
+ Document doc = builder.parse(is);
+ return doc;
+ }
+
+ private static Document parseDocument(File file)
+ throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilder builder = getDocumentBuilder();
+ Document doc = builder.parse(file);
+ return doc;
+ }
+}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/AllocationConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/AllocationConfiguration.java
index 9cb767d..f10c554 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/AllocationConfiguration.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/AllocationConfiguration.java
@@ -36,7 +36,7 @@
import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe
-public class AllocationConfiguration extends ReservationSchedulerConfiguration {
+public class AllocationConfiguration implements ReservationSchedulerConfiguration {
private static final AccessControlList EVERYBODY_ACL = new AccessControlList("*");
private static final AccessControlList NOBODY_ACL = new AccessControlList(" ");
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterService.java
index d1f0ede..f8ee42c 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterService.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterService.java
@@ -273,7 +273,7 @@ public void testResourceTypes() throws Exception {
CapacitySchedulerConfiguration csconf =
new CapacitySchedulerConfiguration();
- csconf.setResourceComparator(DominantResourceCalculator.class);
+ csconf.setResourceCalculator(DominantResourceCalculator.class);
YarnConfiguration testCapacityDRConf = new YarnConfiguration(csconf);
testCapacityDRConf.setClass(YarnConfiguration.RM_SCHEDULER,
CapacityScheduler.class, ResourceScheduler.class);
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSHierarchyConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSHierarchyConfiguration.java
new file mode 100644
index 0000000..18aa56f
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSHierarchyConfiguration.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
+
+import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestCSHierarchyConfiguration {
+ @Test
+ public void testBasicCSHierarchyConfiguration() {
+ CSHierarchyConfiguration conf =
+ new CSHierarchyConfiguration("test-capacity-scheduler-hierarchy.xml");
+
+ // Check global configurations
+ Assert.assertEquals(9999, conf.getMaximumSystemApplications());
+ Assert.assertEquals(0.3f,
+ conf.getMaximumApplicationMasterResourcePercent(), 1e-6);
+
+ // Check global-policy configurations
+ Assert.assertEquals(DominantResourceCalculator.class.getName(), conf
+ .getResourceCalculator().getClass().getName());
+
+ // Check queue (root) configurations
+ Assert.assertEquals(100f, conf.getNonLabeledQueueCapacity("root"), 1e-6);
+
+ // Check queue (root.default) configurations
+ Assert.assertEquals(50f, conf.getNonLabeledQueueCapacity("root.default"),
+ 1e-6);
+
+ // Check queue (root.default) accessible node labels
+ Assert.assertTrue(conf.getAccessibleNodeLabels("root.default").contains("x"));
+
+ // Check node label configurations
+ Assert.assertEquals(20f, conf.getLabeledQueueCapacity("root.default", "x"),
+ 1e-6);
+ }
+}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java
index fabf47d..16ec7ed 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java
@@ -2019,7 +2019,7 @@ public void testKillAllAppsInvalidSource() throws Exception {
public void testAppReservationWithDominantResourceCalculator() throws Exception {
CapacitySchedulerConfiguration csconf =
new CapacitySchedulerConfiguration();
- csconf.setResourceComparator(DominantResourceCalculator.class);
+ csconf.setResourceCalculator(DominantResourceCalculator.class);
YarnConfiguration conf = new YarnConfiguration(csconf);
conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/config/TestBaseSchedulerHierarchyConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/config/TestBaseSchedulerHierarchyConfiguration.java
new file mode 100644
index 0000000..b2f7ce7
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/config/TestBaseSchedulerHierarchyConfiguration.java
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.config;
+
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestBaseSchedulerHierarchyConfiguration {
+ @Test
+ public void testBaseSchedulerHierarchyConfiguration() throws YarnException {
+ String content = ""
+ + ""
+ + " "
+ + " "
+ + " "
+ + " a-2"
+ + " "
+ + " "
+ + " a1-1"
+ + " "
+ + " a1-1"
+ + " a1-3"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+
+ + " global-1"
+ + " global-3"
+
+ + " "
+ + " global-1"
+ + " global-2"
+ + " "
+ + "";
+
+ SchedulerConfNode root = SchedulerConfParser.parse(content);
+ BaseSchedulerHierarchyConfiguration conf =
+ new BaseSchedulerHierarchyConfiguration(root);
+
+ Assert
+ .assertEquals("global-1", conf.getGlobalConfig("param1", null, false));
+ Assert.assertEquals(null, conf.getGlobalConfig("param2", null, false));
+
+ // root.a doesn't have param1 specify
+ Assert.assertEquals(null,
+ conf.getQueueConfig("root.a", "param1", null, false));
+
+ // root.a param1 will inherit global-1
+ Assert.assertEquals("global-1",
+ conf.getQueueConfig("root.a", "param1", null, false, true));
+
+ // root.a.a1 has param1
+ Assert.assertEquals("a1-1",
+ conf.getQueueConfig("root.a.a1", "param1", null, false));
+
+ // root.a.a1 param2 will inherit root.a
+ Assert.assertEquals("a-2",
+ conf.getQueueConfig("root.a.a1", "param2", null, false, true));
+
+ // root.b will inherit global as well
+ Assert.assertEquals("global-3",
+ conf.getQueueConfig("root.b", "param3", null, false, true));
+
+ // check specifying
+ Assert.assertEquals("global-1",
+ conf.getGlobalConfig("policy-1", null, true));
+ Assert.assertEquals("a1-1",
+ conf.getQueueConfig("root.a.a1", "policy-1", null, true));
+ Assert.assertEquals("global-2",
+ conf.getQueueConfig("root.a.a1", "policy-2", null, true, true));
+
+ try {
+ conf.getQueueConfig("root.a.a3", "param1", null, false);
+ Assert.fail("try to fetch an non-existed queue, should fail");
+ } catch (YarnRuntimeException e) {
+ // expected
+ }
+
+ try {
+ conf.getQueueConfig("root.c", "param1", null, false);
+ Assert.fail("try to fetch an non-existed queue, should fail");
+ } catch (YarnRuntimeException e) {
+ // expected
+ }
+
+ try {
+ conf.getQueueConfig("non-existed", "param1", null, false, false);
+ Assert.fail("try to fetch an non-existed queue, should fail");
+ } catch (YarnRuntimeException e) {
+ // expected
+ }
+ }
+}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/config/TestSchedulerConfParser.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/config/TestSchedulerConfParser.java
new file mode 100644
index 0000000..d7ce709
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/config/TestSchedulerConfParser.java
@@ -0,0 +1,117 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.config;
+
+import java.util.Iterator;
+
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+
+public class TestSchedulerConfParser {
+ @Test
+ public void testSimpleSchedulerConfParser() throws YarnException {
+ String content = ""
+ + ""
+ + " "
+ + " "
+ + " "
+ + " "
+ + " value3 "
+ + " value4"
+ + " "
+ + " "
+ + " value5"
+ + " value6"
+ + " "
+ + " "
+ + " "
+ + " "
+ + " "
+ + " value1"
+ + " "
+ + " value2"
+ + "";
+
+ SchedulerConfNode root = SchedulerConfParser.parse(content);
+ SchedulerConfNode expectedRoot = getExpectedSimpleSchedulerConfNode();
+
+ assertEquals(expectedRoot, root);
+ }
+
+ public void assertEquals(SchedulerConfNode left, SchedulerConfNode right) {
+ Assert.assertEquals(left.getTag(), right.getTag());
+ Assert.assertEquals(left.getName(), right.getName());
+ Assert.assertEquals(left.getValue(), right.getValue());
+ Assert.assertEquals(left.getFields().values().size(), right.getFields().values().size());
+
+ Iterator leftIterator =
+ left.getFields().values().iterator();
+ Iterator rightIterator =
+ right.getFields().values().iterator();
+ while (leftIterator.hasNext()) {
+ assertEquals(leftIterator.next(), rightIterator.next());
+ }
+ }
+
+ private SchedulerConfNode getExpectedSimpleSchedulerConfNode() {
+ ListMultimap fields = ArrayListMultimap.create();
+
+ // leaf1
+ fields.put("param3", new SchedulerConfNode("", "value3", "param3", null));
+ fields.put("param4", new SchedulerConfNode("", "value4", "param4", null));
+ SchedulerConfNode leaf1 = new SchedulerConfNode("leaf1", "", "leaf", fields);
+
+ // leaf2
+ fields = ArrayListMultimap.create();
+ fields.put("param5", new SchedulerConfNode("", "value5", "param5", null));
+ fields.put("param6", new SchedulerConfNode("", "value6", "param6", null));
+ SchedulerConfNode leaf2 = new SchedulerConfNode("", "", "leaf", fields);
+
+ // inner children
+ fields = ArrayListMultimap.create();
+ fields.put("leaf", leaf1);
+ fields.put("leaf", leaf2);
+ SchedulerConfNode innerChildren =
+ new SchedulerConfNode("", "", "children", fields);
+
+ // parent
+ fields = ArrayListMultimap.create();
+ fields.put("children", innerChildren);
+ SchedulerConfNode parent =
+ new SchedulerConfNode("parent", "", "parent", fields);
+
+ // outer children
+ fields = ArrayListMultimap.create();
+ fields.put("parent", parent);
+ SchedulerConfNode outerChildren = new SchedulerConfNode("", "", "children", fields);
+
+ // root
+ fields = ArrayListMultimap.create();
+ fields.put("children", outerChildren);
+ fields.put("param1", new SchedulerConfNode("", "value1", "param1", null));
+ fields.put("param2", new SchedulerConfNode("", "value2", "param2", null));
+ SchedulerConfNode root = new SchedulerConfNode("", "", "root", fields);
+
+ return root;
+ }
+}
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/resources/test-capacity-scheduler-hierarchy.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/resources/test-capacity-scheduler-hierarchy.xml
new file mode 100644
index 0000000..1b5d9ea
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/resources/test-capacity-scheduler-hierarchy.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+ capacity
+ 9999
+
+
+ 0.3
+
+
+
+ org.apache.hadoop.yarn.util.resource.DominantResourceCalculator
+
+
+
+
+
+
+ RUNNING
+ *
+ *
+ x
+
+
+ 2
+ 50
+ 90
+ 30
+
+
+ 20
+ 50
+
+
+
+
+
+
+
+
\ No newline at end of file