This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 200d175  Add resource close in CmdBrokerStats and some minor fixes. 
(#3589)
200d175 is described below

commit 200d175a02638086c850c732b6bd0f285aff7f42
Author: Fangbin Sun <[email protected]>
AuthorDate: Thu Feb 14 01:58:28 2019 +0800

    Add resource close in CmdBrokerStats and some minor fixes. (#3589)
---
 .../apache/pulsar/admin/cli/CmdBrokerStats.java    | 83 +++++++++++-----------
 site2/docs/reference-pulsar-admin.md               | 19 ++---
 2 files changed, 49 insertions(+), 53 deletions(-)

diff --git 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdBrokerStats.java
 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdBrokerStats.java
index a2567ee..c8e3e20 100644
--- 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdBrokerStats.java
+++ 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdBrokerStats.java
@@ -20,13 +20,12 @@ package org.apache.pulsar.admin.cli;
 
 import java.io.OutputStreamWriter;
 import java.io.Writer;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 import org.apache.pulsar.client.admin.PulsarAdmin;
 import org.apache.pulsar.common.stats.AllocatorStats;
 import org.apache.pulsar.common.util.ObjectMapperFactory;
-import org.apache.pulsar.policies.data.loadbalancer.LoadManagerReport;
 
 import com.google.gson.Gson;
 import com.google.gson.JsonArray;
@@ -40,55 +39,57 @@ import com.fasterxml.jackson.databind.ObjectWriter;
 
 @Parameters(commandDescription = "Operations to collect broker statistics")
 public class CmdBrokerStats extends CmdBase {
-    public static final String DEFAULT_INDENTATION = "    ";
-    public static final Charset UTF_8 = Charset.forName("UTF-8");
-    public static Writer out = new OutputStreamWriter(System.out, UTF_8);
+    private static final String DEFAULT_INDENTATION = "    ";
 
     @Parameters(commandDescription = "dump metrics for Monitoring")
-    class CmdMonitoringMetrics extends CliCommand {
+    private class CmdMonitoringMetrics extends CliCommand {
         @Parameter(names = { "-i", "--indent" }, description = "Indent JSON 
output", required = false)
-        boolean indent = false;
+        private boolean indent = false;
 
         @Override
         void run() throws Exception {
             JsonArray metrics = admin.brokerStats().getMetrics();
 
-            for (int i = 0; i < metrics.size(); i++) {
-                JsonObject m = (JsonObject) metrics.get(i);
-                JsonWriter jsonWriter = new JsonWriter(out);
-                if (indent) {
-                    jsonWriter.setIndent(DEFAULT_INDENTATION);
-                    new Gson().toJson(m, jsonWriter);
-                    out.write('\n');
-                    out.write('\n');
-                } else {
-                    new Gson().toJson(m, jsonWriter);
+            try (Writer out = new OutputStreamWriter(System.out, 
StandardCharsets.UTF_8);
+                 JsonWriter jsonWriter = new JsonWriter(out)) {
+                for (int i = 0; i < metrics.size(); i++) {
+                    JsonObject m = (JsonObject) metrics.get(i);
+                    if (indent) {
+                        jsonWriter.setIndent(DEFAULT_INDENTATION);
+                        new Gson().toJson(m, jsonWriter);
+                        out.write('\n');
+                        out.write('\n');
+                    } else {
+                        new Gson().toJson(m, jsonWriter);
+                    }
+                    out.flush();
                 }
-                out.flush();
             }
         }
     }
 
     @Parameters(commandDescription = "dump mbean stats")
-    public class CmdDumpMBeans extends CliCommand {
+    private class CmdDumpMBeans extends CliCommand {
         @Parameter(names = { "-i", "--indent" }, description = "Indent JSON 
output", required = false)
-        boolean indent = false;
+        private boolean indent = false;
 
         @Override
         void run() throws Exception {
             JsonArray result = admin.brokerStats().getMBeans();
-            JsonWriter jsonWriter = new JsonWriter(out);
-            if (indent) {
-                jsonWriter.setIndent(DEFAULT_INDENTATION);
+            try (Writer out = new OutputStreamWriter(System.out, 
StandardCharsets.UTF_8);
+                 JsonWriter jsonWriter = new JsonWriter(out)) {
+                if (indent) {
+                    jsonWriter.setIndent(DEFAULT_INDENTATION);
+                }
+                new Gson().toJson(result, jsonWriter);
+                out.flush();
             }
-            new Gson().toJson(result, jsonWriter);
-            out.flush();
         }
 
     }
 
     @Parameters(commandDescription = "dump broker load-report")
-    public class CmdLoadReport extends CliCommand {
+    private class CmdLoadReport extends CliCommand {
 
         @Override
         void run() throws Exception {
@@ -97,35 +98,39 @@ public class CmdBrokerStats extends CmdBase {
     }
 
     @Parameters(commandDescription = "dump topics stats")
-    public class CmdTopics extends CliCommand {
+    private class CmdTopics extends CliCommand {
         @Parameter(names = { "-i", "--indent" }, description = "Indent JSON 
output", required = false)
-        boolean indent = false;
+        private boolean indent = false;
 
         @Override
         void run() throws Exception {
             JsonObject result = admin.brokerStats().getTopics();
-            JsonWriter jsonWriter = new JsonWriter(out);
-            if (indent) {
-                jsonWriter.setIndent(DEFAULT_INDENTATION);
+            try (Writer out = new OutputStreamWriter(System.out, 
StandardCharsets.UTF_8);
+                 JsonWriter jsonWriter = new JsonWriter(out)) {
+                if (indent) {
+                    jsonWriter.setIndent(DEFAULT_INDENTATION);
+                }
+                new Gson().toJson(result, jsonWriter);
+                out.flush();
             }
-            new Gson().toJson(result, jsonWriter);
-            out.flush();
         }
 
     }
 
     @Parameters(commandDescription = "dump allocator stats")
-    public class CmdAllocatorStats extends CliCommand {
+    private class CmdAllocatorStats extends CliCommand {
         @Parameter(description = "allocator-name\n", required = true)
-        List<String> params;
+        private List<String> params;
 
         @Override
         void run() throws Exception {
             AllocatorStats stats = 
admin.brokerStats().getAllocatorStats(params.get(0));
             ObjectMapper mapper = ObjectMapperFactory.create();
             ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
-            out.write(writer.writeValueAsString(stats));
-            out.flush();
+            try (Writer out = new OutputStreamWriter(System.out, 
StandardCharsets.UTF_8)) {
+                out.write(writer.writeValueAsString(stats));
+                out.flush();
+            }
         }
 
     }
@@ -139,8 +144,4 @@ public class CmdBrokerStats extends CmdBase {
         jcommander.addCommand("load-report", new CmdLoadReport());
     }
 
-    public void addCommands(String commandName, CliCommand cliCommand) {
-        jcommander.addCommand(commandName, cliCommand);
-    }
-
 }
diff --git a/site2/docs/reference-pulsar-admin.md 
b/site2/docs/reference-pulsar-admin.md
index 42f6c9c..3100e55 100644
--- a/site2/docs/reference-pulsar-admin.md
+++ b/site2/docs/reference-pulsar-admin.md
@@ -35,10 +35,10 @@ $ pulsar-admin broker-stats subcommand
 
 Subcommands
 * `allocator-stats`
-* `destinations`
+* `topics(destinations)`
 * `mbeans`
 * `monitoring-metrics`
-* `topics`
+* `load-report`
 
 
 ### `allocator-stats`
@@ -50,13 +50,13 @@ Usage
 $ pulsar-admin broker-stats allocator-stats allocator-name
 ```
 
-### `desinations`
+### `topics(destinations)`
 
 Dump topic stats
 
 Usage
 ```bash
-$ pulsar-admin broker-stats destinations options
+$ pulsar-admin broker-stats topics options
 ```
 
 Options
@@ -94,20 +94,15 @@ Options
 |`-i`, `--indent`|Indent JSON output|false|
 
 
-### `topics`
+### `load-report`
 
-Dump topic stats
+Dump broker load-report
 
 Usage
 ```bash
-$ pulsar-admin broker-stats topics options
+$ pulsar-admin broker-stats load-report
 ```
 
-Options
-|Flag|Description|Default|
-|---|---|---|
-|`-i`, `--indent`|Indent JSON output|false|
-
 
 ## `brokers`
 

Reply via email to