YARN-9209. When nodePartition is not set in Placement Constraints, containers are allocated only in default partition. Contributed by Tarun Parimi.

(cherry picked from commit 83dcb9d87e)
This commit is contained in:
Weiwei Yang 2019-06-21 17:40:55 +08:00
parent a5d76a4965
commit 1944a7d844
3 changed files with 22 additions and 4 deletions

View File

@ -791,4 +791,18 @@ public class AppSchedulingInfo {
public Map<String, String> getApplicationSchedulingEnvs() {
return applicationSchedulingEnvs;
}
/**
* Get the defaultNodeLabelExpression for the application's current queue.
*
* @return defaultNodeLabelExpression
*/
public String getDefaultNodeLabelExpression() {
try {
this.readLock.lock();
return queue.getDefaultNodeLabelExpression();
} finally {
this.readLock.unlock();
}
}
}

View File

@ -253,7 +253,10 @@ public class SingleConstraintAppPlacementAllocator<N extends SchedulerNode>
// Currently only single constraint is handled.
private String validateAndGetTargetNodePartition(
PlacementConstraint placementConstraint) {
String nodePartition = RMNodeLabelsManager.NO_LABEL;
String defaultNodeLabelExpression =
appSchedulingInfo.getDefaultNodeLabelExpression();
String nodePartition = defaultNodeLabelExpression == null ?
RMNodeLabelsManager.NO_LABEL : defaultNodeLabelExpression;
if (placementConstraint != null &&
placementConstraint.getConstraintExpr() != null) {
PlacementConstraint.AbstractConstraint ac =

View File

@ -67,7 +67,7 @@ public class TestSingleConstraintAppPlacementAllocator {
TestUtils.getMockApplicationId(1));
when(appSchedulingInfo.getApplicationAttemptId()).thenReturn(
TestUtils.getMockApplicationAttemptId(1, 1));
when(appSchedulingInfo.getDefaultNodeLabelExpression()).thenReturn("y");
// stub RMContext
rmContext = TestUtils.getMockRMContext();
@ -153,7 +153,8 @@ public class TestSingleConstraintAppPlacementAllocator {
.resourceSizing(
ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))
.build());
Assert.assertEquals("", allocator.getTargetNodePartition());
// Node partition is unspecified, use the default node label expression y
Assert.assertEquals("y", allocator.getTargetNodePartition());
// Valid (with application Id target)
assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType(
@ -167,7 +168,7 @@ public class TestSingleConstraintAppPlacementAllocator {
ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))
.build());
// Allocation tags should not include application Id
Assert.assertEquals("", allocator.getTargetNodePartition());
Assert.assertEquals("y", allocator.getTargetNodePartition());
// Invalid (without sizing)
assertInvalidSchedulingRequest(SchedulingRequest.newBuilder().executionType(