Skip to content

Commit 4e4c185

Browse files
committed
Fix queueContext reinit related test issues.
1 parent 2abb2ec commit 4e4c185

File tree

12 files changed

+124
-33
lines changed

12 files changed

+124
-33
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/CapacityScheduler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void initScheduler(Configuration configuration) throws
326326
this.workflowPriorityMappingsMgr = new WorkflowPriorityMappingsManager();
327327
this.activitiesManager = new ActivitiesManager(rmContext);
328328
activitiesManager.init(conf);
329-
this.queueContext = new CapacitySchedulerQueueContext(this, appPriorityACLManager);
329+
this.queueContext = new CapacitySchedulerQueueContext(this);
330330
initializeQueues(this.conf);
331331
this.isLazyPreemptionEnabled = conf.getLazyPreemptionEnabled();
332332
this.assignMultipleEnabled = this.conf.getAssignMultipleEnabled();
@@ -852,6 +852,7 @@ private void initializeQueues(CapacitySchedulerConfiguration conf)
852852
@Lock(CapacityScheduler.class)
853853
private void reinitializeQueues(CapacitySchedulerConfiguration newConf)
854854
throws IOException {
855+
queueContext.reinitialize(newConf);
855856
this.queueManager.reinitializeQueues(newConf);
856857
updatePlacementRules();
857858

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class CapacitySchedulerQueueContext {
4646
private final CapacitySchedulerQueueManager queueManager;
4747
private final RMNodeLabelsManager labelManager;
4848
private final PreemptionManager preemptionManager;
49-
private final AppPriorityACLsManager appPriorityACLManager;
5049
private final ActivitiesManager activitiesManager;
5150
private final ResourceCalculator resourceCalculator;
5251

@@ -55,17 +54,25 @@ public class CapacitySchedulerQueueContext {
5554

5655
private Resource minimumAllocation;
5756

58-
public CapacitySchedulerQueueContext(CapacitySchedulerContext csContext,
59-
AppPriorityACLsManager appPriorityACLManager) {
57+
public CapacitySchedulerQueueContext(CapacitySchedulerContext csContext) {
6058
this.csContext = csContext;
6159
this.queueManager = csContext.getCapacitySchedulerQueueManager();
6260
this.labelManager = csContext.getRMContext().getNodeLabelManager();
6361
this.preemptionManager = csContext.getPreemptionManager();
64-
this.appPriorityACLManager = appPriorityACLManager;
6562
this.activitiesManager = csContext.getActivitiesManager();
6663
this.resourceCalculator = csContext.getResourceCalculator();
6764

68-
this.configuration = csContext.getConfiguration();
65+
this.configuration = new CapacitySchedulerConfiguration(csContext.getConfiguration());
66+
this.minimumAllocation = csContext.getMinimumResourceCapability();
67+
}
68+
69+
public void reinitialize() {
70+
this.configuration = new CapacitySchedulerConfiguration(csContext.getConfiguration());
71+
this.minimumAllocation = csContext.getMinimumResourceCapability();
72+
}
73+
74+
public void reinitialize(CapacitySchedulerConfiguration newConfiguration) {
75+
this.configuration = new CapacitySchedulerConfiguration(newConfiguration);
6976
this.minimumAllocation = csContext.getMinimumResourceCapability();
7077
}
7178

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public CSQueue getRootQueue() {
106106
return this.root;
107107
}
108108

109+
@VisibleForTesting
110+
protected void setRootQueue(CSQueue rootQueue) {
111+
this.root = rootQueue;
112+
}
113+
109114
@Override
110115
public Map<String, CSQueue> getQueues() {
111116
return queues.getFullNameQueues();

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@ public void setUp() throws IOException {
118118
thenReturn(clusterResource);
119119
when(csContext.getResourceCalculator()).
120120
thenReturn(resourceCalculator);
121+
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
122+
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(new CapacitySchedulerQueueManager(conf,
123+
rmContext.getNodeLabelManager(), null));
124+
121125
when(csContext.getRMContext()).thenReturn(rmContext);
122126
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
123127

124-
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext, null);
128+
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext);
125129

126130
RMContainerTokenSecretManager containerTokenSecretManager =
127131
new RMContainerTokenSecretManager(conf);
@@ -290,20 +294,26 @@ public void testLimitsComputation() throws Exception {
290294
when(csContext.getMaximumResourceCapability()).
291295
thenReturn(Resources.createResource(16*GB, 16));
292296
when(csContext.getResourceCalculator()).thenReturn(resourceCalculator);
297+
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
293298
when(csContext.getRMContext()).thenReturn(rmContext);
294299
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
295300

296-
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext, null);
301+
CapacitySchedulerQueueManager queueManager = new CapacitySchedulerQueueManager(conf,
302+
rmContext.getNodeLabelManager(), null);
303+
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
297304

298305
// Say cluster has 100 nodes of 16G each
299306
Resource clusterResource =
300307
Resources.createResource(100 * 16 * GB, 100 * 16);
301308
when(csContext.getClusterResource()).thenReturn(clusterResource);
302309

310+
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext);
311+
303312
CSQueueStore queues = new CSQueueStore();
304313
CSQueue root =
305314
CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
306315
"root", queues, queues, TestUtils.spyHook);
316+
queueManager.setRootQueue(root);
307317
root.updateClusterResource(clusterResource,
308318
new ResourceLimits(clusterResource));
309319

@@ -371,12 +381,14 @@ public void testLimitsComputation() throws Exception {
371381
// Change the per-queue max AM resources percentage.
372382
csConf.setFloat(PREFIX + queue.getQueuePath()
373383
+ ".maximum-am-resource-percent", 0.5f);
384+
queueContext.reinitialize();
374385
// Re-create queues to get new configs.
375386
queues = new CSQueueStore();
376387
root = CapacitySchedulerQueueManager.parseQueue(
377388
queueContext, csConf, null, "root",
378389
queues, queues, TestUtils.spyHook);
379390
clusterResource = Resources.createResource(100 * 16 * GB);
391+
queueManager.setRootQueue(root);
380392
root.updateClusterResource(clusterResource, new ResourceLimits(
381393
clusterResource));
382394

@@ -395,6 +407,7 @@ public void testLimitsComputation() throws Exception {
395407
// Change the per-queue max applications.
396408
csConf.setInt(PREFIX + queue.getQueuePath() + ".maximum-applications",
397409
9999);
410+
queueContext.reinitialize();
398411
// Re-create queues to get new configs.
399412
queues = new CSQueueStore();
400413
root = CapacitySchedulerQueueManager.parseQueue(
@@ -603,16 +616,21 @@ public void testHeadroom() throws Exception {
603616
when(csContext.getResourceCalculator()).thenReturn(resourceCalculator);
604617
when(csContext.getRMContext()).thenReturn(rmContext);
605618
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
606-
619+
620+
CapacitySchedulerQueueManager queueManager = new CapacitySchedulerQueueManager(conf,
621+
rmContext.getNodeLabelManager(), null);
622+
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
623+
607624
// Say cluster has 100 nodes of 16G each
608625
Resource clusterResource = Resources.createResource(100 * 16 * GB);
609626
when(csContext.getClusterResource()).thenReturn(clusterResource);
610627

611-
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext, null);
628+
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext);
612629

613630
CSQueueStore queues = new CSQueueStore();
614631
CSQueue rootQueue = CapacitySchedulerQueueManager.parseQueue(queueContext,
615632
csConf, null, "root", queues, queues, TestUtils.spyHook);
633+
queueManager.setRootQueue(rootQueue);
616634
rootQueue.updateClusterResource(clusterResource,
617635
new ResourceLimits(clusterResource));
618636

@@ -969,14 +987,19 @@ public void testAMResourceLimitWithDRCAndFullParent() throws Exception {
969987
thenReturn(Resources.createResource(16*GB));
970988
when(csContext.getResourceCalculator()).
971989
thenReturn(new DominantResourceCalculator());
990+
CapacitySchedulerQueueManager queueManager = new CapacitySchedulerQueueManager(conf,
991+
rmContext.getNodeLabelManager(), null);
992+
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
993+
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
994+
972995
when(csContext.getRMContext()).thenReturn(rmContext);
973996
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
974997

975998
// Total cluster resources.
976999
Resource clusterResource = Resources.createResource(100 * GB, 1000);
9771000
when(csContext.getClusterResource()).thenReturn(clusterResource);
9781001

979-
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext, null);
1002+
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext);
9801003

9811004
// Set up queue hierarchy.
9821005
CSQueueStore queues = new CSQueueStore();

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,12 @@ public void testHeadroom() throws Exception {
777777
when(spyRMContext.getNodeLabelManager()).thenReturn(mgr);
778778
when(csContext.getRMContext()).thenReturn(spyRMContext);
779779
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
780+
CapacitySchedulerQueueManager queueManager =
781+
new CapacitySchedulerQueueManager(csConf, mgr, null);
782+
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
783+
784+
// Setup nodelabels
785+
queueManager.reinitConfiguredNodeLabels(csConf);
780786

781787
mgr.activateNode(NodeId.newInstance("h0", 0),
782788
Resource.newInstance(160 * GB, 16)); // default Label
@@ -789,18 +795,15 @@ public void testHeadroom() throws Exception {
789795
Resource clusterResource = Resources.createResource(160 * GB);
790796
when(csContext.getClusterResource()).thenReturn(clusterResource);
791797

792-
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext, null);
798+
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext);
793799

794800
CSQueueStore queues = new CSQueueStore();
795801
CSQueue rootQueue = CapacitySchedulerQueueManager.parseQueue(queueContext,
796802
csConf, null, "root", queues, queues, TestUtils.spyHook);
803+
queueManager.setRootQueue(rootQueue);
797804
rootQueue.updateClusterResource(clusterResource,
798805
new ResourceLimits(clusterResource));
799806

800-
ResourceUsage queueResUsage = rootQueue.getQueueResourceUsage();
801-
when(csContext.getClusterResourceUsage())
802-
.thenReturn(queueResUsage);
803-
804807
// Manipulate queue 'a'
805808
LeafQueue queue = TestLeafQueue.stubLeafQueue((LeafQueue) queues.get("b2"));
806809
queue.updateClusterResource(clusterResource,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ public void setup() throws IOException {
9292
when(preemptionManager.getKillableResource(any(), anyString()))
9393
.thenReturn(Resource.newInstance(0, 0));
9494
when(scheduler.getPreemptionManager()).thenReturn(preemptionManager);
95+
when(scheduler.getActivitiesManager()).thenReturn(activitiesManager);
9596
queueManager = new CapacitySchedulerQueueManager(csConfig, labelManager,
9697
appPriorityACLManager);
9798
queueManager.setCapacitySchedulerContext(scheduler);
99+
when(scheduler.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
100+
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(scheduler);
101+
when(scheduler.getQueueContext()).thenReturn(queueContext);
98102
queueManager.initializeQueues(csConfig);
99103
}
100104

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ public void setUp() throws IOException {
6363
when(csContext.getResourceCalculator()).
6464
thenReturn(resourceCalculator);
6565
when(csContext.getRMContext()).thenReturn(rmContext);
66+
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(
67+
new CapacitySchedulerQueueManager(csConf, null, null));
6668

67-
queueContext = new CapacitySchedulerQueueContext(csContext, null);
69+
queueContext = new CapacitySchedulerQueueContext(csContext);
6870

6971
CSQueueStore queues = new CSQueueStore();
7072
root = CapacitySchedulerQueueManager

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ public void setUp() throws Exception {
101101
thenReturn(resourceComparator);
102102
when(csContext.getRMContext()).thenReturn(rmContext);
103103
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
104+
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(
105+
new CapacitySchedulerQueueManager(csConf, rmContext.getNodeLabelManager(), null));
104106

105-
queueContext = new CapacitySchedulerQueueContext(csContext, null);
107+
queueContext = new CapacitySchedulerQueueContext(csContext);
106108
}
107109

108110
private FiCaSchedulerApp getMockApplication(int appId, String user) {
@@ -222,6 +224,7 @@ private void setupSortedQueues(CapacitySchedulerConfiguration conf) {
222224
public void testSortedQueues() throws Exception {
223225
// Setup queue configs
224226
setupSortedQueues(csConf);
227+
queueContext.reinitialize();
225228
CSQueueStore queues = new CSQueueStore();
226229
CSQueue root =
227230
CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,

0 commit comments

Comments
 (0)