This is an automated email from the ASF dual-hosted git repository.

zhuqi pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 88e760bfc88e YARN-11616. Fast fail for NodeConstraintParser when 
having multi attribute kvs (#6282)
88e760bfc88e is described below

commit 88e760bfc88eb7c30555ba1ddf93e3792444aaf5
Author: Junfan Zhang <zus...@apache.org>
AuthorDate: Fri Nov 24 14:34:35 2023 +0800

    YARN-11616. Fast fail for NodeConstraintParser when having multi attribute 
kvs (#6282)
---
 .../yarn/util/constraint/PlacementConstraintParser.java      |  4 ++++
 .../yarn/api/resource/TestPlacementConstraintParser.java     | 12 ++++++++++++
 2 files changed, 16 insertions(+)

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 d0bf888ea36b..3c810600f225 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 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();
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 ffc83735de47..1607bbf142ec 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 @@ 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 {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to