Skip to content

Commit 8b146c1

Browse files
YARN-10274. Merge QueueMapping and QueueMappingEntity. Contributed by Gergely Pollak
1 parent a4835db commit 8b146c1

File tree

8 files changed

+74
-146
lines changed

8 files changed

+74
-146
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/AppNameMappingPlacementRule.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public class AppNameMappingPlacementRule extends PlacementRule {
4848
private static final String QUEUE_MAPPING_NAME = "app-name";
4949

5050
private boolean overrideWithQueueMappings = false;
51-
private List<QueueMappingEntity> mappings = null;
51+
private List<QueueMapping> mappings = null;
5252
protected CapacitySchedulerQueueManager queueManager;
5353

5454
public AppNameMappingPlacementRule() {
5555
this(false, null);
5656
}
5757

5858
public AppNameMappingPlacementRule(boolean overrideWithQueueMappings,
59-
List<QueueMappingEntity> newMappings) {
59+
List<QueueMapping> newMappings) {
6060
this.overrideWithQueueMappings = overrideWithQueueMappings;
6161
this.mappings = newMappings;
6262
}
@@ -76,16 +76,16 @@ public boolean initialize(ResourceScheduler scheduler)
7676
LOG.info(
7777
"Initialized App Name queue mappings, override: " + overrideWithQueueMappings);
7878

79-
List<QueueMappingEntity> queueMappings =
79+
List<QueueMapping> queueMappings =
8080
conf.getQueueMappingEntity(QUEUE_MAPPING_NAME);
8181

8282
// Get new user mappings
83-
List<QueueMappingEntity> newMappings = new ArrayList<>();
83+
List<QueueMapping> newMappings = new ArrayList<>();
8484

8585
queueManager = schedulerContext.getCapacitySchedulerQueueManager();
8686

8787
// check if mappings refer to valid queues
88-
for (QueueMappingEntity mapping : queueMappings) {
88+
for (QueueMapping mapping : queueMappings) {
8989
QueuePath queuePath = mapping.getQueuePath();
9090

9191
if (isStaticQueueMapping(mapping)) {
@@ -109,7 +109,7 @@ public boolean initialize(ResourceScheduler scheduler)
109109
//validate if parent queue is specified,
110110
// then it should exist and
111111
// be an instance of AutoCreateEnabledParentQueue
112-
QueueMappingEntity newMapping =
112+
QueueMapping newMapping =
113113
validateAndGetAutoCreatedQueueMapping(queueManager, mapping,
114114
queuePath);
115115
if (newMapping == null) {
@@ -123,7 +123,7 @@ public boolean initialize(ResourceScheduler scheduler)
123123
// if its an instance of leaf queue
124124
// if its an instance of auto created leaf queue,
125125
// then extract parent queue name and update queue mapping
126-
QueueMappingEntity newMapping = validateAndGetQueueMapping(
126+
QueueMapping newMapping = validateAndGetQueueMapping(
127127
queueManager, queue, mapping, queuePath);
128128
newMappings.add(newMapping);
129129
}
@@ -134,7 +134,7 @@ public boolean initialize(ResourceScheduler scheduler)
134134
// if parent queue is specified, then
135135
// parent queue exists and an instance of AutoCreateEnabledParentQueue
136136
//
137-
QueueMappingEntity newMapping = validateAndGetAutoCreatedQueueMapping(
137+
QueueMapping newMapping = validateAndGetAutoCreatedQueueMapping(
138138
queueManager, mapping, queuePath);
139139
if (newMapping != null) {
140140
newMappings.add(newMapping);
@@ -160,7 +160,7 @@ private static boolean ifQueueDoesNotExist(CSQueue queue) {
160160

161161
private ApplicationPlacementContext getAppPlacementContext(String user,
162162
String applicationName) throws IOException {
163-
for (QueueMappingEntity mapping : mappings) {
163+
for (QueueMapping mapping : mappings) {
164164
if (mapping.getSource().equals(CURRENT_APP_MAPPING)) {
165165
if (mapping.getQueue().equals(CURRENT_APP_MAPPING)) {
166166
return getPlacementContext(mapping, applicationName, queueManager);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/QueueMapping.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,17 @@ private QueueMapping(QueueMappingBuilder builder) {
8282
this.source = builder.source;
8383
this.queue = builder.queue;
8484
this.parentQueue = builder.parentQueue;
85+
this.fullPath = (parentQueue != null) ? (parentQueue + DOT + queue) : queue;
8586
}
8687

8788
/**
8889
* Different types of mapping.
8990
*
9091
*/
9192
public enum MappingType {
92-
93-
USER("u"), GROUP("g");
93+
USER("u"),
94+
GROUP("g"),
95+
APPLICATION("a");
9496

9597
private final String type;
9698

@@ -108,6 +110,7 @@ public String toString() {
108110
private String source;
109111
private String queue;
110112
private String parentQueue;
113+
private String fullPath;
111114

112115
private final static String DELIMITER = ":";
113116

@@ -132,7 +135,7 @@ public String getSource() {
132135
}
133136

134137
public String getFullPath() {
135-
return (parentQueue != null ? parentQueue + DOT + queue : queue);
138+
return fullPath;
136139
}
137140

138141
public QueuePath getQueuePath() {
@@ -197,4 +200,10 @@ public String toString() {
197200
return type.toString() + DELIMITER + source + DELIMITER
198201
+ (parentQueue != null ? parentQueue + "." + queue : queue);
199202
}
203+
204+
public String toTypelessString() {
205+
return source + DELIMITER
206+
+ (parentQueue != null ? parentQueue + "." + queue : queue);
207+
}
208+
200209
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/QueueMappingEntity.java

Lines changed: 0 additions & 98 deletions
This file was deleted.

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/QueuePlacementRuleUtils.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,28 @@ public static void validateQueueMappingUnderParentQueue(
6565
}
6666
}
6767

68-
public static QueueMappingEntity validateAndGetAutoCreatedQueueMapping(
69-
CapacitySchedulerQueueManager queueManager, QueueMappingEntity mapping,
68+
public static QueueMapping validateAndGetAutoCreatedQueueMapping(
69+
CapacitySchedulerQueueManager queueManager, QueueMapping mapping,
7070
QueuePath queuePath) throws IOException {
7171
if (queuePath.hasParentQueue()) {
7272
//if parent queue is specified,
7373
// then it should exist and be an instance of ManagedParentQueue
7474
validateQueueMappingUnderParentQueue(queueManager.getQueue(
7575
queuePath.getParentQueue()), queuePath.getParentQueue(),
7676
queuePath.getFullPath());
77-
return new QueueMappingEntity(mapping.getSource(),
78-
queuePath.getFullPath(), queuePath.getParentQueue());
77+
return QueueMapping.QueueMappingBuilder.create()
78+
.type(mapping.getType())
79+
.source(mapping.getSource())
80+
.queuePath(queuePath)
81+
.build();
7982
}
8083

8184
return null;
8285
}
8386

84-
public static QueueMappingEntity validateAndGetQueueMapping(
87+
public static QueueMapping validateAndGetQueueMapping(
8588
CapacitySchedulerQueueManager queueManager, CSQueue queue,
86-
QueueMappingEntity mapping, QueuePath queuePath) throws IOException {
89+
QueueMapping mapping, QueuePath queuePath) throws IOException {
8790
if (!(queue instanceof LeafQueue)) {
8891
throw new IOException(
8992
"mapping contains invalid or non-leaf queue : " +
@@ -93,7 +96,7 @@ public static QueueMappingEntity validateAndGetQueueMapping(
9396
if (queue instanceof AutoCreatedLeafQueue && queue
9497
.getParent() instanceof ManagedParentQueue) {
9598

96-
QueueMappingEntity newMapping = validateAndGetAutoCreatedQueueMapping(
99+
QueueMapping newMapping = validateAndGetAutoCreatedQueueMapping(
97100
queueManager, mapping, queuePath);
98101
if (newMapping == null) {
99102
throw new IOException(
@@ -105,7 +108,7 @@ public static QueueMappingEntity validateAndGetQueueMapping(
105108
return mapping;
106109
}
107110

108-
public static boolean isStaticQueueMapping(QueueMappingEntity mapping) {
111+
public static boolean isStaticQueueMapping(QueueMapping mapping) {
109112
return !mapping.getQueue().contains(CURRENT_USER_MAPPING) && !mapping
110113
.getQueue().contains(PRIMARY_GROUP_MAPPING)
111114
&& !mapping.getQueue().contains(SECONDARY_GROUP_MAPPING);
@@ -126,13 +129,13 @@ public static QueuePath extractQueuePath(String queuePath) {
126129
}
127130

128131
public static ApplicationPlacementContext getPlacementContext(
129-
QueueMappingEntity mapping, CapacitySchedulerQueueManager queueManager)
132+
QueueMapping mapping, CapacitySchedulerQueueManager queueManager)
130133
throws IOException {
131134
return getPlacementContext(mapping, mapping.getQueue(), queueManager);
132135
}
133136

134137
public static ApplicationPlacementContext getPlacementContext(
135-
QueueMappingEntity mapping, String leafQueueName,
138+
QueueMapping mapping, String leafQueueName,
136139
CapacitySchedulerQueueManager queueManager) throws IOException {
137140

138141
//leafQueue name no longer identifies a queue uniquely checking ambiguity

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
4343
import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMapping;
4444
import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMapping.QueueMappingBuilder;
45-
import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMappingEntity;
4645
import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationSchedulerConfiguration;
4746
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerUtils;
4847
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLConfigurationParser.AppPriorityACLKeyType;
@@ -1039,12 +1038,12 @@ public void setOverrideWithQueueMappings(boolean overrideWithQueueMappings) {
10391038
setBoolean(ENABLE_QUEUE_MAPPING_OVERRIDE, overrideWithQueueMappings);
10401039
}
10411040

1042-
public List<QueueMappingEntity> getQueueMappingEntity(
1041+
public List<QueueMapping> getQueueMappingEntity(
10431042
String queueMappingSuffix) {
10441043
String queueMappingName = buildQueueMappingRuleProperty(queueMappingSuffix);
10451044

1046-
List<QueueMappingEntity> mappings =
1047-
new ArrayList<QueueMappingEntity>();
1045+
List<QueueMapping> mappings =
1046+
new ArrayList<QueueMapping>();
10481047
Collection<String> mappingsString =
10491048
getTrimmedStringCollection(queueMappingName);
10501049
for (String mappingValue : mappingsString) {
@@ -1058,10 +1057,11 @@ public List<QueueMappingEntity> getQueueMappingEntity(
10581057

10591058
//Mappings should be consistent, and have the parent path parsed
10601059
// from the beginning
1061-
QueueMappingEntity m = new QueueMappingEntity(
1062-
mapping[0],
1063-
QueuePlacementRuleUtils.extractQueuePath(mapping[1]));
1064-
1060+
QueueMapping m = QueueMapping.QueueMappingBuilder.create()
1061+
.type(QueueMapping.MappingType.APPLICATION)
1062+
.source(mapping[0])
1063+
.queuePath(QueuePlacementRuleUtils.extractQueuePath(mapping[1]))
1064+
.build();
10651065
mappings.add(m);
10661066
}
10671067

@@ -1076,15 +1076,15 @@ private String buildQueueMappingRuleProperty (String queueMappingSuffix) {
10761076
}
10771077

10781078
@VisibleForTesting
1079-
public void setQueueMappingEntities(List<QueueMappingEntity> queueMappings,
1079+
public void setQueueMappingEntities(List<QueueMapping> queueMappings,
10801080
String queueMappingSuffix) {
10811081
if (queueMappings == null) {
10821082
return;
10831083
}
10841084

10851085
List<String> queueMappingStrs = new ArrayList<>();
1086-
for (QueueMappingEntity mapping : queueMappings) {
1087-
queueMappingStrs.add(mapping.toString());
1086+
for (QueueMapping mapping : queueMappings) {
1087+
queueMappingStrs.add(mapping.toTypelessString());
10881088
}
10891089

10901090
String mappingRuleProp = buildQueueMappingRuleProperty(queueMappingSuffix);

0 commit comments

Comments
 (0)