You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by revans2 <gi...@git.apache.org> on 2018/10/17 22:05:45 UTC
[GitHub] storm pull request #2882: STORM-3260: Add in support to print some state
GitHub user revans2 opened a pull request:
https://github.com/apache/storm/pull/2882
STORM-3260: Add in support to print some state
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/revans2/incubator-storm STORM-3260
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/storm/pull/2882.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #2882
----
commit 6828ecae38c79522c3b7c9ab590d54ececf6d4c3
Author: Robert (Bobby) Evans <ev...@...>
Date: 2018-10-17T22:02:40Z
STORM-3260: Add in support to print some state
----
---
[GitHub] storm pull request #2882: STORM-3260: Add in support to print some state
Posted by kishorvpatil <gi...@git.apache.org>.
Github user kishorvpatil commented on a diff in the pull request:
https://github.com/apache/storm/pull/2882#discussion_r227061504
--- Diff: storm-core/src/jvm/org/apache/storm/command/AdminCommands.java ---
@@ -104,6 +115,164 @@ public void printCliHelp(String command, PrintStream out) {
}
}
+ /**
+ * Print value in a human readable format.
+ * @param value what to print.
+ * @return a human readable string
+ */
+ public static String prettyPrint(TBase value) {
+ StringBuilder builder = new StringBuilder();
+ prettyPrint(value, 0, builder);
+ return builder.toString();
+ }
+
+ private static void println(StringBuilder out, int depth, Object value) {
+ for (int i = 0; i < depth; i++) {
+ out.append("\t");
+ }
+ out.append(value);
+ out.append("\n");
+ }
+
+ private static void prettyPrint(TBase value, int depth, StringBuilder out) {
+ if (value == null) {
+ println(out, depth,"null");
+ return;
+ }
+ println(out, depth, "{");
+ prettyPrintFields(value, depth + 1, out);
+ println(out, depth, "}");
+ }
+
+ private static void prettyPrintFields(TBase value, int depth, StringBuilder out) {
+ for (Map.Entry<? extends TFieldIdEnum, FieldMetaData> entry : FieldMetaData.getStructMetaDataMap(value.getClass()).entrySet()) {
+ TFieldIdEnum key = entry.getKey();
+ if (!value.isSet(key)) {
+ println(out, depth, key.getFieldName() + ": not set");
--- End diff --
Simply make this empty "" String result or `{}`. not set is not exactly parsable json
---
[GitHub] storm pull request #2882: STORM-3260: Add in support to print some state
Posted by kishorvpatil <gi...@git.apache.org>.
Github user kishorvpatil commented on a diff in the pull request:
https://github.com/apache/storm/pull/2882#discussion_r227061218
--- Diff: storm-core/src/jvm/org/apache/storm/command/AdminCommands.java ---
@@ -104,6 +115,164 @@ public void printCliHelp(String command, PrintStream out) {
}
}
+ /**
+ * Print value in a human readable format.
+ * @param value what to print.
+ * @return a human readable string
+ */
+ public static String prettyPrint(TBase value) {
+ StringBuilder builder = new StringBuilder();
+ prettyPrint(value, 0, builder);
+ return builder.toString();
+ }
+
+ private static void println(StringBuilder out, int depth, Object value) {
+ for (int i = 0; i < depth; i++) {
+ out.append("\t");
+ }
+ out.append(value);
+ out.append("\n");
+ }
+
+ private static void prettyPrint(TBase value, int depth, StringBuilder out) {
+ if (value == null) {
+ println(out, depth,"null");
+ return;
+ }
+ println(out, depth, "{");
+ prettyPrintFields(value, depth + 1, out);
+ println(out, depth, "}");
+ }
+
+ private static void prettyPrintFields(TBase value, int depth, StringBuilder out) {
+ for (Map.Entry<? extends TFieldIdEnum, FieldMetaData> entry : FieldMetaData.getStructMetaDataMap(value.getClass()).entrySet()) {
+ TFieldIdEnum key = entry.getKey();
+ if (!value.isSet(key)) {
+ println(out, depth, key.getFieldName() + ": not set");
+ } else {
+ Object o = value.getFieldValue(key);
+ prettyPrintKeyValue(key.getFieldName(), o, depth, out);
+ }
+ }
+ }
+
+ private static String keyStr(String key) {
+ return key == null ? "" : (key + ": ");
+ }
+
+ private static void prettyPrintKeyValue(String key, Object o, int depth, StringBuilder out) {
+ //Special cases for storm...
+ if ("json_conf".equals(key) && o instanceof String) {
+ try {
+ o = Utils.parseJson((String)o);
+ } catch (Exception e) {
+ LOG.error("Could not parse json_conf as JSON", e);
+ }
+ }
+ if (o instanceof TBase) {
+ println(out, depth, keyStr(key) + "{");
+ prettyPrintFields((TBase) o, depth + 1, out);
+ println(out, depth, "}");
+ } else if (o instanceof Map) {
+ println(out, depth, keyStr(key) + "{");
+ for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) o).entrySet()) {
+ prettyPrintKeyValue(entry.getKey().toString(), entry.getValue(), depth + 1, out);
+ }
+ println(out, depth, "}");
+ } else if (o instanceof Collection) {
+ println(out, depth, keyStr(key) + "[");
+ for (Object sub: (Collection)o) {
+ prettyPrintKeyValue(null, sub, depth + 1, out);
+ }
+ println(out, depth, "]");
+ } else if (o instanceof String) {
+ println(out, depth, keyStr(key) + "\"" + o + "\"");
+ } else {
+ println(out, depth, keyStr(key) + o);
+ }
+ }
+
+ private static class PrintTopo implements AdminCommand {
+
+ @Override
+ public void run(String[] args, Map<String, Object> conf, String command) throws Exception {
+ for (String arg: args) {
+ System.out.println(arg + ":");
--- End diff --
We should probably print quotes around `arg` to make it more compatible json like output
---
[GitHub] storm issue #2882: STORM-3260: Add in support to print some state
Posted by kishorvpatil <gi...@git.apache.org>.
Github user kishorvpatil commented on the issue:
https://github.com/apache/storm/pull/2882
Travis-ci build failures seems unrelated to the changes.
---
[GitHub] storm pull request #2882: STORM-3260: Add in support to print some state
Posted by kishorvpatil <gi...@git.apache.org>.
Github user kishorvpatil commented on a diff in the pull request:
https://github.com/apache/storm/pull/2882#discussion_r227061728
--- Diff: storm-core/src/jvm/org/apache/storm/command/AdminCommands.java ---
@@ -104,6 +115,164 @@ public void printCliHelp(String command, PrintStream out) {
}
}
+ /**
+ * Print value in a human readable format.
+ * @param value what to print.
+ * @return a human readable string
+ */
+ public static String prettyPrint(TBase value) {
+ StringBuilder builder = new StringBuilder();
+ prettyPrint(value, 0, builder);
+ return builder.toString();
+ }
+
+ private static void println(StringBuilder out, int depth, Object value) {
+ for (int i = 0; i < depth; i++) {
+ out.append("\t");
+ }
+ out.append(value);
+ out.append("\n");
+ }
+
+ private static void prettyPrint(TBase value, int depth, StringBuilder out) {
+ if (value == null) {
+ println(out, depth,"null");
+ return;
+ }
+ println(out, depth, "{");
+ prettyPrintFields(value, depth + 1, out);
+ println(out, depth, "}");
+ }
+
+ private static void prettyPrintFields(TBase value, int depth, StringBuilder out) {
+ for (Map.Entry<? extends TFieldIdEnum, FieldMetaData> entry : FieldMetaData.getStructMetaDataMap(value.getClass()).entrySet()) {
+ TFieldIdEnum key = entry.getKey();
+ if (!value.isSet(key)) {
+ println(out, depth, key.getFieldName() + ": not set");
+ } else {
+ Object o = value.getFieldValue(key);
+ prettyPrintKeyValue(key.getFieldName(), o, depth, out);
+ }
+ }
+ }
+
+ private static String keyStr(String key) {
+ return key == null ? "" : (key + ": ");
--- End diff --
should be probably "key" I guess
---
[GitHub] storm issue #2882: STORM-3260: Add in support to print some state
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the issue:
https://github.com/apache/storm/pull/2882
@kishorvpatil
I didn't intend the data to be true JSON. There are some things Thrift supports that JSON does not, like non-string map keys. Storm uses those in our thrift data structures.
The goal is to be able to get something out that a human can look at and understand.
To me `not set` is less ambiguous than `"not set"`, `""`, or `{}` because it would never parse as JSON and it is actually not set. A `null` would probably be fine seeing how setting something to null in thrift is the same as not setting it.
---
[GitHub] storm issue #2882: STORM-3260: Add in support to print some state
Posted by kishorvpatil <gi...@git.apache.org>.
Github user kishorvpatil commented on the issue:
https://github.com/apache/storm/pull/2882
@revans2 , ok, looking at output, I thought it was trying to output JSON data. Thanks for the explanation.
---
[GitHub] storm pull request #2882: STORM-3260: Add in support to print some state
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/storm/pull/2882
---