Skip to content

Commit 83dcb9d

Browse files
committed
YARN-9209. When nodePartition is not set in Placement Constraints, containers are allocated only in default partition. Contributed by Tarun Parimi.
1 parent b95a58e commit 83dcb9d

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,4 +795,18 @@ public boolean precheckNode(SchedulerRequestKey schedulerKey,
795795
public Map<String, String> getApplicationSchedulingEnvs() {
796796
return applicationSchedulingEnvs;
797797
}
798+
799+
/**
800+
* Get the defaultNodeLabelExpression for the application's current queue.
801+
*
802+
* @return defaultNodeLabelExpression
803+
*/
804+
public String getDefaultNodeLabelExpression() {
805+
try {
806+
this.readLock.lock();
807+
return queue.getDefaultNodeLabelExpression();
808+
} finally {
809+
this.readLock.unlock();
810+
}
811+
}
798812
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ private void validateAndSetSchedulingRequest(SchedulingRequest
255255
// Currently only single constraint is handled.
256256
private String validateAndGetTargetNodePartition(
257257
PlacementConstraint placementConstraint) {
258-
String nodePartition = RMNodeLabelsManager.NO_LABEL;
258+
String defaultNodeLabelExpression =
259+
appSchedulingInfo.getDefaultNodeLabelExpression();
260+
String nodePartition = defaultNodeLabelExpression == null ?
261+
RMNodeLabelsManager.NO_LABEL : defaultNodeLabelExpression;
259262
if (placementConstraint != null &&
260263
placementConstraint.getConstraintExpr() != null) {
261264
PlacementConstraint.AbstractConstraint ac =

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/TestSingleConstraintAppPlacementAllocator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void setup() throws Exception {
6767
TestUtils.getMockApplicationId(1));
6868
when(appSchedulingInfo.getApplicationAttemptId()).thenReturn(
6969
TestUtils.getMockApplicationAttemptId(1, 1));
70-
70+
when(appSchedulingInfo.getDefaultNodeLabelExpression()).thenReturn("y");
7171
// stub RMContext
7272
rmContext = TestUtils.getMockRMContext();
7373

@@ -153,7 +153,8 @@ public void testSchedulingRequestValidation() {
153153
.resourceSizing(
154154
ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))
155155
.build());
156-
Assert.assertEquals("", allocator.getTargetNodePartition());
156+
// Node partition is unspecified, use the default node label expression y
157+
Assert.assertEquals("y", allocator.getTargetNodePartition());
157158

158159
// Valid (with application Id target)
159160
assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType(
@@ -167,7 +168,7 @@ public void testSchedulingRequestValidation() {
167168
ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))
168169
.build());
169170
// Allocation tags should not include application Id
170-
Assert.assertEquals("", allocator.getTargetNodePartition());
171+
Assert.assertEquals("y", allocator.getTargetNodePartition());
171172

172173
// Invalid (without sizing)
173174
assertInvalidSchedulingRequest(SchedulingRequest.newBuilder().executionType(

0 commit comments

Comments
 (0)