Repository: storm Updated Branches: refs/heads/master 40b115f1d -> 82bea75c9
[STORM-1532]: Fix readCommandLineOpts to parse JSON correctly In Windows env, the storm.options are not url-encoded. The parsing logic needs to be fixed to not split in the middle of raw JSON objects. Project: http://git-wip-us.apache.org/repos/asf/storm/repo Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/0e62a2dc Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/0e62a2dc Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/0e62a2dc Branch: refs/heads/master Commit: 0e62a2dcd3d7358712cfab8ae18b2251066d0812 Parents: 5f1cba5 Author: Arun Mahadevan <[email protected]> Authored: Wed Feb 10 11:23:34 2016 +0530 Committer: Arun Mahadevan <[email protected]> Committed: Mon Feb 15 13:24:11 2016 +0530 ---------------------------------------------------------------------- bin/storm-config.cmd | 4 ++++ bin/storm.cmd | 2 +- storm-core/src/jvm/org/apache/storm/utils/Utils.java | 12 +++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/storm/blob/0e62a2dc/bin/storm-config.cmd ---------------------------------------------------------------------- diff --git a/bin/storm-config.cmd b/bin/storm-config.cmd index 2a91234..0a9ae5e 100644 --- a/bin/storm-config.cmd +++ b/bin/storm-config.cmd @@ -86,6 +86,10 @@ if not defined STORM_LOG_DIR ( @rem retrieve storm.log4j2.conf.dir from conf file @rem +if not defined CMD_TEMP_FILE ( + set CMD_TEMP_FILE=tmpfile +) + "%JAVA%" -client -Dstorm.options= -Dstorm.conf.file= -cp "%CLASSPATH%" org.apache.storm.command.config_value storm.log4j2.conf.dir > %CMD_TEMP_FILE% FOR /F "delims=" %%i in (%CMD_TEMP_FILE%) do ( http://git-wip-us.apache.org/repos/asf/storm/blob/0e62a2dc/bin/storm.cmd ---------------------------------------------------------------------- diff --git a/bin/storm.cmd b/bin/storm.cmd index 6f4e934..20b7a85 100644 --- a/bin/storm.cmd +++ b/bin/storm.cmd @@ -90,7 +90,7 @@ ) if "%c-opt%"=="second" ( - set config-options=%config-options%=%1 + set config-options=%config-options%=%~1 set c-opt= goto start ) http://git-wip-us.apache.org/repos/asf/storm/blob/0e62a2dc/storm-core/src/jvm/org/apache/storm/utils/Utils.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/utils/Utils.java b/storm-core/src/jvm/org/apache/storm/utils/Utils.java index 380f4dd..cb34168 100644 --- a/storm-core/src/jvm/org/apache/storm/utils/Utils.java +++ b/storm-core/src/jvm/org/apache/storm/utils/Utils.java @@ -330,7 +330,17 @@ public class Utils { Map ret = new HashMap(); String commandOptions = System.getProperty("storm.options"); if (commandOptions != null) { - String[] configs = commandOptions.split(","); + /* + Below regex uses negative lookahead to not split in the middle of json objects '{}' + or json arrays '[]'. This is needed to parse valid json object/arrays passed as options + via 'storm.cmd' in windows. This is not an issue while using 'storm.py' since it url-encodes + the options and the below regex just does a split on the commas that separates each option. + + Note:- This regex handles only valid json strings and could produce invalid results + if the options contain un-encoded invalid json or strings with unmatched '[, ], { or }'. We can + replace below code with split(",") once 'storm.cmd' is fixed to send url-encoded options. + */ + String[] configs = commandOptions.split(",(?![^\\[\\]{}]*(]|}))"); for (String config : configs) { config = URLDecoder.decode(config); String[] options = config.split("=", 2);
