Skip to content

Commit f509d98

Browse files
committed
YARN-10823. Expose all node labels for root without explicit configurations
1 parent f92c675 commit f509d98

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/AbstractCSQueue.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import java.util.concurrent.locks.ReentrantReadWriteLock;
7878

7979
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
80+
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.ROOT;
8081
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.UNDEFINED;
8182

8283
public abstract class AbstractCSQueue implements CSQueue {
@@ -463,8 +464,13 @@ private void initializeNodeLabels(
463464
if (csContext.getCapacitySchedulerQueueManager() != null
464465
&& csContext.getCapacitySchedulerQueueManager()
465466
.getConfiguredNodeLabels() != null) {
466-
this.configuredNodeLabels = csContext.getCapacitySchedulerQueueManager()
467-
.getConfiguredNodeLabels().getLabelsByQueue(getQueuePath());
467+
if (getQueuePath().equals(ROOT)) {
468+
this.configuredNodeLabels = csContext.getCapacitySchedulerQueueManager()
469+
.getConfiguredNodeLabels().getAllConfiguredLabels();
470+
} else {
471+
this.configuredNodeLabels = csContext.getCapacitySchedulerQueueManager()
472+
.getConfiguredNodeLabels().getLabelsByQueue(getQueuePath());
473+
}
468474
} else {
469475
// Fallback to suboptimal but correct logic
470476
this.configuredNodeLabels = csContext.getConfiguration()

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/ConfiguredNodeLabels.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.HashSet;
2626
import java.util.Map;
2727
import java.util.Set;
28+
import java.util.stream.Collectors;
2829

2930
/**
3031
* Contains node labels for all queues extracted from configuration properties.
@@ -74,4 +75,13 @@ public void setLabelsByQueue(
7475
String queuePath, Collection<String> nodeLabels) {
7576
configuredNodeLabelsByQueue.put(queuePath, new HashSet<>(nodeLabels));
7677
}
78+
79+
/**
80+
* Get all configured node labels aggregated from each queue.
81+
* @return all node labels
82+
*/
83+
public Set<String> getAllConfiguredLabels() {
84+
return configuredNodeLabelsByQueue.values().stream()
85+
.flatMap(Set::stream).collect(Collectors.toSet());
86+
}
7787
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.concurrent.atomic.AtomicBoolean;
5454

5555
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap;
56+
import org.apache.hadoop.util.Sets;
5657
import org.slf4j.Logger;
5758
import org.slf4j.LoggerFactory;
5859
import org.apache.hadoop.conf.Configuration;
@@ -5216,6 +5217,37 @@ public void testMaxApplicationsWithNodeLabels() throws IOException {
52165217
e.getMaxApplications());
52175218
}
52185219

5220+
@Test
5221+
public void testRootHasAllNodeLabelsOfItsDescendants() throws IOException {
5222+
CapacitySchedulerConfiguration conf = csConf;
5223+
String rootChild = root.getChildQueues().get(0).getQueuePath();
5224+
5225+
conf.setCapacityByLabel(rootChild, "test", 100);
5226+
conf.setCapacityByLabel(rootChild + "." + A, "test", 20);
5227+
conf.setCapacityByLabel(rootChild + "." + B, "test", 40);
5228+
conf.setCapacityByLabel(rootChild + "." + C, "test", 10);
5229+
conf.setCapacityByLabel(rootChild + "." + C + "." + C1, "test", 100);
5230+
conf.setCapacityByLabel(rootChild + "." + D, "test", 30);
5231+
conf.setCapacityByLabel(rootChild + "." + E, "test", 0);
5232+
5233+
conf.setCapacityByLabel(rootChild, "test2", 100);
5234+
conf.setCapacityByLabel(rootChild + "." + A, "test2", 20);
5235+
conf.setCapacityByLabel(rootChild + "." + B, "test2", 40);
5236+
conf.setCapacityByLabel(rootChild + "." + C, "test2", 10);
5237+
conf.setCapacityByLabel(rootChild + "." + C + "." + C1, "test2", 100);
5238+
conf.setCapacityByLabel(rootChild + "." + D, "test2", 30);
5239+
conf.setCapacityByLabel(rootChild + "." + E, "test2", 0);
5240+
5241+
cs.getCapacitySchedulerQueueManager().reinitConfiguredNodeLabels(conf);
5242+
cs.setMaxRunningAppsEnforcer(new CSMaxRunningAppsEnforcer(cs));
5243+
cs.reinitialize(conf, cs.getRMContext());
5244+
5245+
ParentQueue root = (ParentQueue) cs.getRootQueue();
5246+
5247+
Assert.assertEquals(Sets.newHashSet("", "test", "test2"),
5248+
root.configuredNodeLabels);
5249+
}
5250+
52195251
@After
52205252
public void tearDown() throws Exception {
52215253
if (cs != null) {

0 commit comments

Comments
 (0)