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

This commit is contained in:
Junfan Zhang 2023-11-24 14:34:35 +08:00 committed by GitHub
parent f1e4376626
commit 88e760bfc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -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();

View File

@ -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 {