diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/resource/PlacementConstraints.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/resource/PlacementConstraints.java index 02138bd9429..d22a6bd90c0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/resource/PlacementConstraints.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/resource/PlacementConstraints.java @@ -258,15 +258,17 @@ public final class PlacementConstraints { /** * Constructs a target expression on an allocation tag. It is satisfied if - * there are allocations with one of the given tags. + * there are allocations with one of the given tags. The default namespace + * for these tags is {@link AllocationTagNamespaceType#SELF}, this only + * checks tags within the application. * * @param allocationTags the set of tags that the attribute should take * values from * @return the resulting expression on the allocation tags */ public static TargetExpression allocationTag(String... allocationTags) { - return new TargetExpression(TargetType.ALLOCATION_TAG, null, - allocationTags); + return allocationTagWithNamespace( + AllocationTagNamespaceType.SELF.toString(), allocationTags); } /** @@ -282,22 +284,6 @@ public final class PlacementConstraints { return new TargetExpression(TargetType.ALLOCATION_TAG, namespace, allocationTags); } - - /** - * Constructs a target expression on an allocation tag. It is satisfied if - * there are allocations with one of the given tags. Comparing to - * {@link PlacementTargets#allocationTag(String...)}, this only checks tags - * within the application. - * - * @param allocationTags the set of tags that the attribute should take - * values from - * @return the resulting expression on the allocation tags - */ - public static TargetExpression allocationTagToIntraApp( - String... allocationTags) { - return new TargetExpression(TargetType.ALLOCATION_TAG, - AllocationTagNamespaceType.SELF.toString(), allocationTags); - } } // Creation of compound constraints. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/resource/TestPlacementConstraints.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/resource/TestPlacementConstraints.java index 2f8cc6283c0..516ecfcd0c3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/resource/TestPlacementConstraints.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/resource/TestPlacementConstraints.java @@ -28,6 +28,7 @@ import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.targetNot import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.PlacementTargets.allocationTag; import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.PlacementTargets.nodeAttribute; +import org.apache.hadoop.yarn.api.records.AllocationTagNamespaceType; import org.apache.hadoop.yarn.api.resource.PlacementConstraint.AbstractConstraint; import org.apache.hadoop.yarn.api.resource.PlacementConstraint.And; import org.apache.hadoop.yarn.api.resource.PlacementConstraint.SingleConstraint; @@ -55,7 +56,8 @@ public class TestPlacementConstraints { Assert.assertEquals(1, sConstraint.getTargetExpressions().size()); TargetExpression tExpr = sConstraint.getTargetExpressions().iterator().next(); - Assert.assertNull(tExpr.getTargetKey()); + Assert.assertEquals(AllocationTagNamespaceType.SELF.toString(), + tExpr.getTargetKey()); Assert.assertEquals(TargetType.ALLOCATION_TAG, tExpr.getTargetType()); Assert.assertEquals(1, tExpr.getTargetValues().size()); Assert.assertEquals("hbase-m", tExpr.getTargetValues().iterator().next()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/component/Component.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/component/Component.java index 3a08eaa6fbd..782cc3beec6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/component/Component.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/component/Component.java @@ -486,7 +486,7 @@ public class Component implements EventHandler { List targetExpressions = new ArrayList<>(); // Currently only intra-application allocation tags are supported. if (!yarnServiceConstraint.getTargetTags().isEmpty()) { - targetExpressions.add(PlacementTargets.allocationTagToIntraApp( + targetExpressions.add(PlacementTargets.allocationTag( yarnServiceConstraint.getTargetTags().toArray(new String[0]))); } // Add all node attributes diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockAM.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockAM.java index 5eb667e144b..d6ffd7763ad 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockAM.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockAM.java @@ -336,7 +336,7 @@ public class MockAM { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp(tags), + .allocationTag(tags), PlacementConstraints.PlacementTargets .nodePartition(nodePartition)).build()) .resourceSizing(resourceSizing).build()), null); diff --git a/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 b/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 index 4c6afd41976..ccf428143dd 100644 --- a/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 +++ b/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 @@ -126,7 +126,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer"), + .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -142,7 +142,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer"), + .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("x")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -158,7 +158,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer")).build()) + .allocationTag("mapper", "reducer")).build()) .resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) .build()); @@ -173,7 +173,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer")).build()) + .allocationTag("mapper", "reducer")).build()) .resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) .build()); @@ -189,7 +189,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer")).build()) + .allocationTag("mapper", "reducer")).build()) .build(), true); // Invalid (without target tags) @@ -207,9 +207,9 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper"), + .allocationTag("mapper"), PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("reducer"), + .allocationTag("reducer"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -222,9 +222,9 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper"), + .allocationTag("mapper"), PlacementConstraints.PlacementTargets - .allocationTagToIntraApp(""), + .allocationTag(""), PlacementConstraints.PlacementTargets.nodePartition("x")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -237,7 +237,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetCardinality(PlacementConstraints.NODE, 1, 2, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper"), + .allocationTag("mapper"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -250,7 +250,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetCardinality(PlacementConstraints.NODE, 0, 2, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper"), + .allocationTag("mapper"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -263,7 +263,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.RACK, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer"), + .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -276,7 +276,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer"), + .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -292,7 +292,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer"), + .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -321,7 +321,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetCardinality(PlacementConstraints.NODE, 0, 1, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper"), + .allocationTag("mapper"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -338,7 +338,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer"), + .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -358,7 +358,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer"), + .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) @@ -379,7 +379,7 @@ public class TestSingleConstraintAppPlacementAllocator { .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets - .allocationTagToIntraApp("mapper", "reducer"), + .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("x")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))