You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by bo...@apache.org on 2015/11/20 23:26:35 UTC

[10/15] storm git commit: Able to solve mkgMKG and list of strings

Able to solve mkgMKG and list of strings


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/2e56ede5
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/2e56ede5
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/2e56ede5

Branch: refs/heads/master
Commit: 2e56ede5d00af774796344be6581af99076a9590
Parents: bac4a05
Author: zhuol <zh...@yahoo-inc.com>
Authored: Fri Nov 20 14:45:40 2015 -0600
Committer: zhuol <zh...@yahoo-inc.com>
Committed: Fri Nov 20 14:45:40 2015 -0600

----------------------------------------------------------------------
 .../jvm/backtype/storm/scheduler/Cluster.java   |  6 ++--
 .../src/jvm/backtype/storm/utils/Utils.java     | 29 +++++++++++++++-----
 2 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/2e56ede5/storm-core/src/jvm/backtype/storm/scheduler/Cluster.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/scheduler/Cluster.java b/storm-core/src/jvm/backtype/storm/scheduler/Cluster.java
index 571ee1b..a8ff2ab 100644
--- a/storm-core/src/jvm/backtype/storm/scheduler/Cluster.java
+++ b/storm-core/src/jvm/backtype/storm/scheduler/Cluster.java
@@ -474,8 +474,8 @@ public class Cluster {
 
         String topologyWorkerChildopts = Utils.getString(topConf.get(Config.TOPOLOGY_WORKER_CHILDOPTS), null);
         String workerChildopts = Utils.getString(topConf.get(Config.WORKER_CHILDOPTS), null);
-        Double memTopologyWorkerChildopts = Utils.parseWorkerChildOpts(topologyWorkerChildopts, null);
-        Double memWorkerChildopts = Utils.parseWorkerChildOpts(workerChildopts, null);
+        Double memTopologyWorkerChildopts = Utils.parseJvmHeapMemByChildOpts(topologyWorkerChildopts, null);
+        Double memWorkerChildopts = Utils.parseJvmHeapMemByChildOpts(workerChildopts, null);
 
         if (memTopologyWorkerChildopts != null) {
             totalWorkerMemory += memTopologyWorkerChildopts;
@@ -487,7 +487,7 @@ public class Cluster {
 
         String topoWorkerLwChildopts = Utils.getString(topConf.get(Config.TOPOLOGY_WORKER_LOGWRITER_CHILDOPTS), null);
         if (topoWorkerLwChildopts != null) {
-            totalWorkerMemory += Utils.parseWorkerChildOpts(topoWorkerLwChildopts, 0.0);
+            totalWorkerMemory += Utils.parseJvmHeapMemByChildOpts(topoWorkerLwChildopts, 0.0);
         }
         return totalWorkerMemory;
     }

http://git-wip-us.apache.org/repos/asf/storm/blob/2e56ede5/storm-core/src/jvm/backtype/storm/utils/Utils.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/utils/Utils.java b/storm-core/src/jvm/backtype/storm/utils/Utils.java
index 9400c44..766b10f 100644
--- a/storm-core/src/jvm/backtype/storm/utils/Utils.java
+++ b/storm-core/src/jvm/backtype/storm/utils/Utils.java
@@ -509,9 +509,15 @@ public class Utils {
         if (null == o) {
             return defaultValue;
         }
-
         if (o instanceof String) {
             return (String) o;
+        } else if (o instanceof List) {
+            StringBuilder sb = new StringBuilder();
+            for (String s : (List<String>) o) {
+                sb.append(s);
+                sb.append(" ");
+            }
+            return sb.toString();
         } else {
             throw new IllegalArgumentException("Don't know how to convert " + o + " + to String");
         }
@@ -780,22 +786,31 @@ public class Utils {
     }
 
     /**
-     * parses the arguments to extract jvm heap memory size.
+     * parses the arguments to extract jvm heap memory size in MB.
      * @param input
      * @param defaultValue
-     * @return the value of the JVM heap memory setting in a java command.
+     * @return the value of the JVM heap memory setting (in MB) in a java command.
      */
-    public static Double parseWorkerChildOpts(String input, Double defaultValue) {
+    public static Double parseJvmHeapMemByChildOpts(String input, Double defaultValue) {
         if (input != null) {
-            Pattern optsPattern = Pattern.compile("Xmx[0-9]+m");
+            Pattern optsPattern = Pattern.compile("Xmx[0-9]+[mkgMKG]");
             Matcher m = optsPattern.matcher(input);
             String memoryOpts = null;
             while (m.find()) {
                 memoryOpts = m.group();
             }
-            if(memoryOpts != null) {
+            if (memoryOpts != null) {
+                int unit = 1;
+                if (memoryOpts.toLowerCase().endsWith("k")) {
+                    unit = 1024;
+                } else if (memoryOpts.toLowerCase().endsWith("m")) {
+                    unit = 1024 * 1024;
+                } else if (memoryOpts.toLowerCase().endsWith("g")) {
+                    unit = 1024 * 1024 * 1024;
+                }
                 memoryOpts = memoryOpts.replaceAll("[a-zA-Z]", "");
-                return Double.parseDouble(memoryOpts);
+                Double result =  Double.parseDouble(memoryOpts) * unit / 1024.0 / 1024.0;
+                return (result < 1.0) ? 1.0 : result;
             } else {
                 return defaultValue;
             }