Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/2752#discussion_r200436771
--- Diff: storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java ---
@@ -295,9 +391,1104 @@ public static String getJsonResponseBody(Object
data, String callback, boolean n
return callback != null ? wrapJsonInCallback(callback,
serializedData) : serializedData;
}
+ /**
+ * Converts exception into json map.
+ * @param ex Exception to be converted.
+ * @param statusCode Status code to be returned.
+ * @return Map to be converted into json.
+ */
public static Map exceptionToJson(Exception ex, int statusCode) {
StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
- return ImmutableMap.of("error", statusCode + " " +
HttpStatus.getMessage(statusCode), "errorMessage", sw.toString());
+ return ImmutableMap.of(
+ "error", statusCode
+ + " "
+ + HttpStatus.getMessage(statusCode),
+ "errorMessage", sw.toString());
+ }
+
+ /**
+ * Converts thrift call result into map fit for UI/api.
+ * @param clusterSummary Obtained from Nimbus.
+ * @param user User Making request
+ * @param conf Storm Conf
+ * @return Cluster Summary for display on UI/monitoring purposes via
API
+ */
+ public static Map<String, Object> getClusterSummary(ClusterSummary
clusterSummary, String user,
+ Map<String,
Object> conf) {
+ Map<String, Object> result = new HashMap();
+ List<SupervisorSummary> supervisorSummaries =
clusterSummary.get_supervisors();
+ List<TopologySummary> topologySummaries =
clusterSummary.get_topologies();
+
+ Integer usedSlots =
--- End diff --
nit: Please make all of these `int` and not `Integer`. `sum()` returns an
`int` and we are not auto-boxing it to an `Integer` in multiple places, so it
is going to be a bit cleaner (imho).
---