This is an automated email from the ASF dual-hosted git repository.
yaliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-heron.git
The following commit(s) were added to refs/heads/master by this push:
new 9f3def0 Add json format for dry-run (#2842)
9f3def0 is described below
commit 9f3def0238f5d845a8217bc131d0da849e38c98a
Author: Andrew Jorgensen
AuthorDate: Wed Apr 4 18:39:03 2018 -0400
Add json format for dry-run (#2842)
This adds JSON as an optional format for the dry-run output. JSON is
more easily machine readable than the other output formats and can be
used to make deploy decisions based on the resources required and the
resources available at deploy time.
---
.../heron/common/basics/DryRunFormatType.java | 3 +-
heron/scheduler-core/src/java/BUILD| 15 ++--
.../heron/scheduler/dryrun/JsonFormatterUtils.java | 87 ++
.../scheduler/dryrun/SubmitJsonDryRunRenderer.java | 44 +++
.../scheduler/dryrun/UpdateJsonDryRunRenderer.java | 57 ++
.../heron/scheduler/utils/DryRunRenders.java | 7 ++
heron/scheduler-core/tests/java/BUILD | 71 +-
.../scheduler/dryrun/JsonFormatterUtilsTest.java | 70 +
.../resources/JsonFormatterUtilsExpectedJson.txt | 1 +
heron/tools/cli/src/python/args.py | 2 +-
10 files changed, 313 insertions(+), 44 deletions(-)
diff --git
a/heron/common/src/java/com/twitter/heron/common/basics/DryRunFormatType.java
b/heron/common/src/java/com/twitter/heron/common/basics/DryRunFormatType.java
index ff85d4f..407ac4c 100644
---
a/heron/common/src/java/com/twitter/heron/common/basics/DryRunFormatType.java
+++
b/heron/common/src/java/com/twitter/heron/common/basics/DryRunFormatType.java
@@ -20,7 +20,8 @@ package com.twitter.heron.common.basics;
public enum DryRunFormatType {
RAW,
TABLE,
- COLORED_TABLE;
+ COLORED_TABLE,
+ JSON;
public static DryRunFormatType getDryRunFormatType(String dryRunFormatType) {
return DryRunFormatType.valueOf(dryRunFormatType.toUpperCase());
diff --git a/heron/scheduler-core/src/java/BUILD
b/heron/scheduler-core/src/java/BUILD
index 30aa30b..b471af4 100644
--- a/heron/scheduler-core/src/java/BUILD
+++ b/heron/scheduler-core/src/java/BUILD
@@ -1,13 +1,14 @@
package(default_visibility = ["//visibility:public"])
common_deps_files = [
- "//heron/common/src/java:basics-java",
- "//heron/common/src/java:config-java",
- "//heron/common/src/java:utils-java",
- "//heron/api/src/java:classification",
- "@commons_cli_commons_cli//jar",
- "@com_google_guava_guava//jar",
- "@org_apache_commons_commons_lang3//jar",
+"//heron/common/src/java:basics-java",
+"//heron/common/src/java:config-java",
+"//heron/common/src/java:utils-java",
+"//heron/api/src/java:classification",
+"@commons_cli_commons_cli//jar",
+"@com_google_guava_guava//jar",
+"@org_apache_commons_commons_lang3//jar",
+"//third_party/java:jackson",
]
spi_deps_files = [
diff --git
a/heron/scheduler-core/src/java/com/twitter/heron/scheduler/dryrun/JsonFormatterUtils.java
b/heron/scheduler-core/src/java/com/twitter/heron/scheduler/dryrun/JsonFormatterUtils.java
new file mode 100644
index 000..c2c0b6c
--- /dev/null
+++
b/heron/scheduler-core/src/java/com/twitter/heron/scheduler/dryrun/JsonFormatterUtils.java
@@ -0,0 +1,87 @@
+// Copyright 2018 Twitter. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.twitter.heron.scheduler.dryrun;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import com.twitter.heron.spi.packing.PackingPlan;
+import com.twitter.heron.spi.packing.Resource;
+
+public class JsonFormatterUtils {
+
+ private final ObjectMapper mapper;
+
+ public JsonFormatterUtils() {
+mapper = new ObjectMapper();
+ }
+
+ public String renderPackingPlan(String topologyName, String packingClass,
+ PackingPlan packingPlan) throws
JsonProcessingException {
+ObjectNode topLevel = mapper.createObjectNode();
+topLevel.put("packingClass", packingClass);
+topLevel.put("topology", topologyName);
+
+ArrayNode