Skip to content

Commit 8502242

Browse files
hotcodemachaaajisaka
authored andcommitted
YARN-10991. Fix to ignore the grouping "[]" for resourcesStr in parseResourcesString method (#3592)
Signed-off-by: Akira Ajisaka <[email protected]> (cherry picked from commit 08f3df3)
1 parent f5ff4e1 commit 8502242

File tree

2 files changed

+43
-1
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src
    • main/java/org/apache/hadoop/yarn/applications/distributedshell
    • test/java/org/apache/hadoop/yarn/applications/distributedshell

2 files changed

+43
-1
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ static Map<String, Long> parseResourcesString(String resourcesStr) {
12741274
resourcesStr = resourcesStr.substring(1);
12751275
}
12761276
if (resourcesStr.endsWith("]")) {
1277-
resourcesStr = resourcesStr.substring(0, resourcesStr.length());
1277+
resourcesStr = resourcesStr.substring(0, resourcesStr.length() - 1);
12781278
}
12791279

12801280
for (String resource : resourcesStr.trim().split(",")) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.yarn.applications.distributedshell;
20+
21+
import org.junit.Test;
22+
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
26+
import static org.junit.Assert.assertEquals;
27+
28+
public class TestClient {
29+
@Test
30+
public void testParseResourcesString() {
31+
// Setup
32+
final Map<String, Long> expectedResult = new HashMap<>();
33+
expectedResult.put("memory-mb", 3072L);
34+
expectedResult.put("vcores", 1L);
35+
36+
// Run the test
37+
final Map<String, Long> result = Client.parseResourcesString("[memory-mb=3072,vcores=1]");
38+
39+
// Verify the results
40+
assertEquals(expectedResult, result);
41+
}
42+
}

0 commit comments

Comments
 (0)