فهرست منبع

YARN-11616. Fast fail for NodeConstraintParser when having multi attribute kvs (#6282)

Junfan Zhang 1 سال پیش
والد
کامیت
88e760bfc8

+ 4 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/constraint/PlacementConstraintParser.java

@@ -406,6 +406,10 @@ public final class PlacementConstraintParser {
         // 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();

+ 12 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/api/resource/TestPlacementConstraintParser.java

@@ -570,6 +570,18 @@ class TestPlacementConstraintParser {
     }
   }
 
+  @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 {