diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/constraint/PlacementConstraintParser.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/constraint/PlacementConstraintParser.java index d0bf888ea3..3c810600f2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/constraint/PlacementConstraintParser.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/constraint/PlacementConstraintParser.java @@ -406,6 +406,10 @@ public AbstractConstraint parse() // multiple values are present for same attribute, it will also be // coming as next token. for example, java=1.8,1.9 or python!=2. if (attributeKV.countTokens() > 1) { + if (!constraintEntities.isEmpty()) { + throw new PlacementConstraintParseException( + "expecting valid expression like k=v or k!=v or k=v1,v2"); + } opCode = getAttributeOpCode(currentTag); attributeName = attributeKV.nextToken(); currentTag = attributeKV.nextToken(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/resource/TestPlacementConstraintParser.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/resource/TestPlacementConstraintParser.java index ffc83735de..1607bbf142 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/resource/TestPlacementConstraintParser.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/resource/TestPlacementConstraintParser.java @@ -570,6 +570,18 @@ void testParseNodeAttributeSpec() } } + @Test + public void testParseIllegalExprShouldThrowException() { + // A single node attribute constraint w/o source tags, it should fail when multiple + // attribute kvs are specified. + try { + PlacementConstraintParser.parseExpression("rm.yarn.io/foo=true,rm.yarn.io/bar=true"); + fail("Expected a failure!"); + } catch (PlacementConstraintParseException e) { + // ignore + } + } + @Test void testParseAllocationTagNameSpace() throws PlacementConstraintParseException {