Skip to content

Commit 4b5bc05

Browse files
committed
YARN-10512. CS Flexible Auto Queue Creation: Modify RM /scheduler endpoint to include mode of operation for CS. Contributed by Szilard Nemeth.
1 parent 68bc721 commit 4b5bc05

File tree

9 files changed

+367
-6
lines changed

9 files changed

+367
-6
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public abstract class AbstractCSQueue implements CSQueue {
128128
// either at this level or anywhere in the queue's hierarchy.
129129
private volatile boolean defaultAppLifetimeWasSpecifiedInConfig = false;
130130

131-
protected enum CapacityConfigType {
131+
public enum CapacityConfigType {
132132
// FIXME, from what I can see, Percentage mode can almost apply to weighted
133133
// and percentage mode at the same time, there's only small area need to be
134134
// changed, we need to rename "PERCENTAGE" to "PERCENTAGE" and "WEIGHT"

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/CapacitySchedulerInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
3333
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.LeafQueue;
3434
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.ParentQueue;
35+
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.helper.CapacitySchedulerInfoHelper;
3536

3637
import java.util.ArrayList;
3738
import java.util.Map;
@@ -53,6 +54,7 @@ public class CapacitySchedulerInfo extends SchedulerInfo {
5354
protected QueueAclsInfo queueAcls;
5455
protected int queuePriority;
5556
protected String orderingPolicyInfo;
57+
protected String mode;
5658

5759
@XmlTransient
5860
static final float EPSILON = 1e-8f;
@@ -98,6 +100,7 @@ public CapacitySchedulerInfo(CSQueue parent, CapacityScheduler cs) {
98100
orderingPolicyInfo = ((ParentQueue) parent).getQueueOrderingPolicy()
99101
.getConfigName();
100102
}
103+
mode = CapacitySchedulerInfoHelper.getMode(parent);
101104
}
102105

103106
public float getCapacity() {
@@ -173,4 +176,9 @@ protected CapacitySchedulerQueueInfoList getQueues(
173176
}
174177
return queuesInfo;
175178
}
179+
180+
public String getMode() {
181+
return mode;
182+
}
183+
176184
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/CapacitySchedulerQueueInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.ParentQueue;
4343
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.PlanQueue;
4444
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacities;
45+
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.helper.CapacitySchedulerInfoHelper;
4546

4647
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.
4748
CapacitySchedulerConfiguration.RESOURCE_PATTERN;
@@ -86,6 +87,7 @@ public class CapacitySchedulerQueueInfo {
8687
protected String orderingPolicyInfo;
8788
protected boolean autoCreateChildQueueEnabled;
8889
protected LeafQueueTemplateInfo leafQueueTemplate;
90+
protected String mode;
8991

9092
CapacitySchedulerQueueInfo() {
9193
};
@@ -128,6 +130,8 @@ public class CapacitySchedulerQueueInfo {
128130
QueueResourceQuotas qResQuotas = q.getQueueResourceQuotas();
129131
populateQueueCapacities(qCapacities, qResQuotas);
130132

133+
mode = CapacitySchedulerInfoHelper.getMode(q);
134+
131135
ResourceUsage queueResourceUsage = q.getQueueResourceUsage();
132136
populateQueueResourceUsage(queueResourceUsage);
133137

@@ -306,4 +310,8 @@ public boolean isAutoCreateChildQueueEnabled() {
306310
public LeafQueueTemplateInfo getLeafQueueTemplate() {
307311
return leafQueueTemplate;
308312
}
313+
314+
public String getMode() {
315+
return mode;
316+
}
309317
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.helper;
18+
19+
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
20+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue;
21+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueue;
22+
23+
public class CapacitySchedulerInfoHelper {
24+
25+
private CapacitySchedulerInfoHelper() {}
26+
27+
public static String getMode(CSQueue queue) throws YarnRuntimeException {
28+
if (queue.getCapacityConfigType() ==
29+
AbstractCSQueue.CapacityConfigType.ABSOLUTE_RESOURCE) {
30+
return "absolute";
31+
} else if (queue.getCapacityConfigType() ==
32+
AbstractCSQueue.CapacityConfigType.PERCENTAGE) {
33+
float weight = queue.getQueueCapacities().getWeight();
34+
if (weight == -1) {
35+
//-1 indicates we are not in weight mode
36+
return "percentage";
37+
} else {
38+
return "weight";
39+
}
40+
}
41+
throw new YarnRuntimeException("Unknown mode for queue: " +
42+
queue.getQueuePath() + ". Queue details: " + queue);
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* This package contains helper classes for any Info object.
21+
*/
22+
@InterfaceAudience.Private
23+
@InterfaceStability.Unstable
24+
package org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.helper;
25+
26+
import org.apache.hadoop.classification.InterfaceAudience;
27+
import org.apache.hadoop.classification.InterfaceStability;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static Configuration createBasicCSConfiguration() {
4646
conf.put("yarn.scheduler.capacity.root.test1.state", "RUNNING");
4747
conf.put("yarn.scheduler.capacity.root.test2.state", "RUNNING");
4848
conf.put("yarn.scheduler.capacity.queue-mappings",
49-
"u:test1:test1,u:test2:test2");
49+
"u:test1:root.test1,u:test2:root.test2");
5050
return createConfiguration(conf);
5151
}
5252

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesCapacitySched.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ private void verifyClusterScheduler(JSONObject json) throws JSONException,
362362
JSONObject info = json.getJSONObject("scheduler");
363363
assertEquals("incorrect number of elements in: " + info, 1, info.length());
364364
info = info.getJSONObject("schedulerInfo");
365-
assertEquals("incorrect number of elements in: " + info, 12, info.length());
365+
assertEquals("incorrect number of elements in: " + info, 13, info.length());
366366
verifyClusterSchedulerGeneric(info.getString("type"),
367367
(float) info.getDouble("usedCapacity"),
368368
(float) info.getDouble("capacity"),
@@ -413,10 +413,10 @@ private void verifyClusterSchedulerGeneric(String type, float usedCapacity,
413413
private void verifySubQueue(JSONObject info, String q,
414414
float parentAbsCapacity, float parentAbsMaxCapacity)
415415
throws JSONException, Exception {
416-
int numExpectedElements = 27;
416+
int numExpectedElements = 28;
417417
boolean isParentQueue = true;
418418
if (!info.has("queues")) {
419-
numExpectedElements = 45;
419+
numExpectedElements = 46;
420420
isParentQueue = false;
421421
}
422422
assertEquals("incorrect number of elements", numExpectedElements, info.length());

0 commit comments

Comments
 (0)