Repository: storm Updated Branches: refs/heads/1.x-branch 69cf90de4 -> cb4636c59
[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/b2f8c1b7 Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/b2f8c1b7 Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/b2f8c1b7 Branch: refs/heads/1.x-branch Commit: b2f8c1b71cd24854c8be064fbd8c0ff8cc18dfaa Parents: 6861ad3 Author: Arun Mahadevan <[email protected]> Authored: Wed Feb 10 11:23:34 2016 +0530 Committer: Arun Mahadevan <[email protected]> Committed: Wed Feb 17 11:04:38 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/b2f8c1b7/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/b2f8c1b7/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/b2f8c1b7/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 cbf34a2..1a76b8a 100644 --- a/storm-core/src/jvm/org/apache/storm/utils/Utils.java +++ b/storm-core/src/jvm/org/apache/storm/utils/Utils.java @@ -355,7 +355,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);
