STORM-1264: port backtype.storm.command.list to java
Project: http://git-wip-us.apache.org/repos/asf/storm/repo Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/415310a9 Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/415310a9 Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/415310a9 Branch: refs/heads/master Commit: 415310a9a13306cd7f110712cee5f19d840d8f6a Parents: 7d7f5b6 Author: Robert (Bobby) Evans <[email protected]> Authored: Sat Feb 13 14:33:03 2016 -0600 Committer: Robert (Bobby) Evans <[email protected]> Committed: Sat Feb 13 14:33:03 2016 -0600 ---------------------------------------------------------------------- bin/storm.cmd | 2 +- bin/storm.py | 2 +- .../src/clj/org/apache/storm/command/list.clj | 38 --------------- .../src/jvm/org/apache/storm/command/List.java | 50 ++++++++++++++++++++ 4 files changed, 52 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/storm/blob/415310a9/bin/storm.cmd ---------------------------------------------------------------------- diff --git a/bin/storm.cmd b/bin/storm.cmd index 367574c..c8953bf 100644 --- a/bin/storm.cmd +++ b/bin/storm.cmd @@ -165,7 +165,7 @@ goto :eof :list - set CLASS=org.apache.storm.command.list + set CLASS=org.apache.storm.command.List set STORM_OPTS=%STORM_CLIENT_OPTS% %STORM_OPTS% goto :eof http://git-wip-us.apache.org/repos/asf/storm/blob/415310a9/bin/storm.py ---------------------------------------------------------------------- diff --git a/bin/storm.py b/bin/storm.py index cc8fe8f..a491b63 100755 --- a/bin/storm.py +++ b/bin/storm.py @@ -389,7 +389,7 @@ def listtopos(*args): List the running topologies and their statuses. """ exec_storm_class( - "org.apache.storm.command.list", + "org.apache.storm.command.List", args=args, jvmtype="-client", extrajars=[USER_CONF_DIR, STORM_BIN_DIR]) http://git-wip-us.apache.org/repos/asf/storm/blob/415310a9/storm-core/src/clj/org/apache/storm/command/list.clj ---------------------------------------------------------------------- diff --git a/storm-core/src/clj/org/apache/storm/command/list.clj b/storm-core/src/clj/org/apache/storm/command/list.clj deleted file mode 100644 index 87975cd..0000000 --- a/storm-core/src/clj/org/apache/storm/command/list.clj +++ /dev/null @@ -1,38 +0,0 @@ -;; Licensed to the Apache Software Foundation (ASF) under one -;; or more contributor license agreements. See the NOTICE file -;; distributed with this work for additional information -;; regarding copyright ownership. The ASF licenses this file -;; to you 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. -(ns org.apache.storm.command.list - (:use [org.apache.storm thrift log]) - (:import [org.apache.storm.generated TopologySummary]) - (:gen-class)) - -(defn -main [] - (with-configured-nimbus-connection nimbus - (let [cluster-info (.getClusterInfo nimbus) - topologies (.get_topologies cluster-info) - msg-format "%-20s %-10s %-10s %-12s %-10s"] - (if (or (nil? topologies) (empty? topologies)) - (println "No topologies running.") - (do - (println (format msg-format "Topology_name" "Status" "Num_tasks" "Num_workers" "Uptime_secs")) - (println "-------------------------------------------------------------------") - (doseq [^TopologySummary topology topologies] - (let [topology-name (.get_name topology) - topology-status (.get_status topology) - topology-num-tasks (.get_num_tasks topology) - topology-num-workers (.get_num_workers topology) - topology-uptime-secs (.get_uptime_secs topology)] - (println (format msg-format topology-name topology-status topology-num-tasks - topology-num-workers topology-uptime-secs))))))))) http://git-wip-us.apache.org/repos/asf/storm/blob/415310a9/storm-core/src/jvm/org/apache/storm/command/List.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/command/List.java b/storm-core/src/jvm/org/apache/storm/command/List.java new file mode 100644 index 0000000..7df0711 --- /dev/null +++ b/storm-core/src/jvm/org/apache/storm/command/List.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.storm.command; + +import org.apache.storm.generated.Nimbus; +import org.apache.storm.generated.TopologySummary; +import org.apache.storm.utils.NimbusClient; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class List { + private static final Logger LOG = LoggerFactory.getLogger(List.class); + private static final String MSG_FORMAT = "%-20s %-10s %-10s %-12s %-10s\n"; + + public static void main(String [] args) throws Exception { + NimbusClient.withConfiguredClient(new NimbusClient.WithNimbus() { + @Override + public void run(Nimbus.Client nimbus) throws Exception { + java.util.List<TopologySummary> topologies = nimbus.getClusterInfo().get_topologies(); + if (topologies == null || topologies.isEmpty()) { + System.out.println("No topologies running."); + } else { + System.out.printf(MSG_FORMAT, "Topology_name", "Status", "Num_tasks", "Num_workers", "Uptime_secs"); + System.out.println("-------------------------------------------------------------------"); + for (TopologySummary topology: topologies) { + System.out.printf(MSG_FORMAT, topology.get_name(), topology.get_status(), + topology.get_num_tasks(), topology.get_num_workers(), + topology.get_uptime_secs()); + } + } + } + }); + } +}
