Repository: hadoop
Updated Branches:
  refs/heads/trunk 561b61cfb -> 37eb919c5


YARN-9078. [Submarine] Clean up the code of CliUtils#parseResourcesString. 
(Zhankun Tang via wangda)

Change-Id: I21ac5757b6115d55ec3157ba25db1b65bc85a37b


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8a536111
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8a536111
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8a536111

Branch: refs/heads/trunk
Commit: 8a5361116e6158b28b185ba903ece4aa454344c8
Parents: 561b61c
Author: Wangda Tan <[email protected]>
Authored: Wed Dec 12 11:42:44 2018 -0800
Committer: Wangda Tan <[email protected]>
Committed: Wed Dec 12 11:42:44 2018 -0800

----------------------------------------------------------------------
 .../yarn/submarine/client/cli/CliUtils.java     | 23 +++++++-------------
 1 file changed, 8 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/8a536111/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/CliUtils.java
----------------------------------------------------------------------
diff --git 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/CliUtils.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/CliUtils.java
index 588a9e6..f3eee7c 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/CliUtils.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/CliUtils.java
@@ -74,19 +74,10 @@ public class CliUtils {
     return newCli;
   }
 
-  // TODO, this duplicated to Client of distributed shell, should cleanup
   private static Map<String, Long> parseResourcesString(String resourcesStr) {
     Map<String, Long> resources = new HashMap<>();
-
-    // Ignore the grouping "[]"
-    if (resourcesStr.startsWith("[")) {
-      resourcesStr = resourcesStr.substring(1);
-    }
-    if (resourcesStr.endsWith("]")) {
-      resourcesStr = resourcesStr.substring(0, resourcesStr.length() - 1);
-    }
-
-    for (String resource : resourcesStr.trim().split(",")) {
+    String[] pairs = resourcesStr.trim().split(",");
+    for (String resource : pairs) {
       resource = resource.trim();
       if (!resource.matches(RES_PATTERN)) {
         throw new IllegalArgumentException("\"" + resource + "\" is not a "
@@ -97,8 +88,9 @@ public class CliUtils {
       String key = splits[0], value = splits[1];
       String units = ResourceUtils.getUnits(value);
 
-      String valueWithoutUnit = value.substring(0, value.length() - 
units.length()).trim();
-      Long resourceValue = Long.valueOf(valueWithoutUnit);
+      String valueWithoutUnit = value.substring(0,
+          value.length()- units.length()).trim();
+      long resourceValue = Long.parseLong(valueWithoutUnit);
 
       // Convert commandline unit to standard YARN unit.
       if (units.equals("M") || units.equals("m")) {
@@ -107,7 +99,7 @@ public class CliUtils {
         units = "Gi";
       } else if (units.isEmpty()) {
         // do nothing;
-      } else{
+      } else {
         throw new IllegalArgumentException("Acceptable units are M/G or 
empty");
       }
 
@@ -121,7 +113,8 @@ public class CliUtils {
 
       if (key.equals("memory")) {
         key = ResourceInformation.MEMORY_URI;
-        resourceValue = UnitsConversionUtil.convert(units, "Mi", 
resourceValue);
+        resourceValue = UnitsConversionUtil.convert(units, "Mi",
+            resourceValue);
       }
 
       // special handle gpu


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to