From d6e8c2713402e9ddf8336a00cc6c6769fd7d0911 Mon Sep 17 00:00:00 2001 From: Sunil G Date: Tue, 23 Jan 2018 14:56:23 +0530 Subject: [PATCH] YARN-7791 --- .../distributedshell/PlacementSpec.java | 49 ++++++++++++---------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/PlacementSpec.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/PlacementSpec.java index ed13ee0aa93..8a92576683f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/PlacementSpec.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/PlacementSpec.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.applications.distributedshell; import org.apache.hadoop.yarn.api.resource.PlacementConstraint; +import org.apache.hadoop.yarn.api.resource.PlacementConstraint.TargetExpression; import org.apache.hadoop.yarn.api.resource.PlacementConstraints; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,6 +64,7 @@ public PlacementSpec(String sourceTag, int numContainers, // NumContainers => int (number of containers) // Scope => "NODE"|"RACK" // TargetTag => String (Target Tag) + // TargetKey => "intra_app" (For default CS placement with allocator) // MinCard => int (min cardinality - needed if ConstraintType == cardinality) // MaxCard => int (max cardinality - needed if ConstraintType == cardinality) @@ -98,37 +100,42 @@ public PlacementSpec(String sourceTag, int numContainers, scope = scope.equals("rack") ? PlacementConstraints.RACK : PlacementConstraints.NODE; + TargetExpression targetExp = PlacementConstraints.PlacementTargets + .allocationTag(targetTag); + if (ps.hasNext()) { + if (ps.next().toLowerCase().equals("intra_app")) { + targetExp = PlacementConstraints.PlacementTargets + .allocationTagToIntraApp(targetTag); + } + } + PlacementConstraint pc; if (cType.equals(IN)) { - pc = PlacementConstraints.build( - PlacementConstraints.targetIn(scope, - PlacementConstraints.PlacementTargets.allocationTag( - targetTag))); - LOG.info("Creating IN Constraint for source tag [{}], num[{}]: " + - "scope[{}], target[{}]", + pc = PlacementConstraints + .build(PlacementConstraints.targetIn(scope, targetExp)); + LOG.info( + "Creating IN Constraint for source tag [{}], num[{}]: " + + "scope[{}], target[{}]", sourceTag, numContainers, scope, targetTag); } else if (cType.equals(NOT_IN)) { - pc = PlacementConstraints.build( - PlacementConstraints.targetNotIn(scope, - PlacementConstraints.PlacementTargets.allocationTag( - targetTag))); - LOG.info("Creating NOT_IN Constraint for source tag [{}], num[{}]: " + - "scope[{}], target[{}]", + pc = PlacementConstraints + .build(PlacementConstraints.targetNotIn(scope, targetExp)); + LOG.info( + "Creating NOT_IN Constraint for source tag [{}], num[{}]: " + + "scope[{}], target[{}]", sourceTag, numContainers, scope, targetTag); } else if (cType.equals(CARDINALITY)) { int minCard = ps.nextInt(); int maxCard = ps.nextInt(); - pc = PlacementConstraints.build( - PlacementConstraints.targetCardinality(scope, minCard, maxCard, - PlacementConstraints.PlacementTargets.allocationTag( - targetTag))); - LOG.info("Creating CARDINALITY Constraint source tag [{}], num[{}]: " + - "scope[{}], min[{}], max[{}], target[{}]", + pc = PlacementConstraints.build(PlacementConstraints + .targetCardinality(scope, minCard, maxCard, targetExp)); + LOG.info( + "Creating CARDINALITY Constraint source tag [{}], num[{}]: " + + "scope[{}], min[{}], max[{}], target[{}]", sourceTag, numContainers, scope, minCard, maxCard, targetTag); } else { - throw new RuntimeException( - "Could not parse constraintType [" + cType + "]" + - " in [" + specSplit[1] + "]"); + throw new RuntimeException("Could not parse constraintType [" + cType + + "]" + " in [" + specSplit[1] + "]"); } pSpecs.put(sourceTag, new PlacementSpec(sourceTag, numContainers, pc)); } -- 2.14.3 (Apple Git-98)