You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2018/12/27 18:40:47 UTC

[GitHub] mikewalch closed pull request #857: Updates to DumpZookeeper utility

mikewalch closed pull request #857: Updates to DumpZookeeper utility
URL: https://github.com/apache/accumulo/pull/857
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/assemble/bin/accumulo-util b/assemble/bin/accumulo-util
index 4a8b9ba957..b5827da8b4 100755
--- a/assemble/bin/accumulo-util
+++ b/assemble/bin/accumulo-util
@@ -21,6 +21,7 @@ Usage: accumulo-util <command> (<argument> ...)
 
 Commands:
   build-native        Builds Accumulo native libraries
+  dump-zoo            Dumps data in ZooKeeper
   hadoop-jar          Runs 'hadoop jar' command with Accumulo jars
   gen-monitor-cert    Generates Accumulo monitor certficate
   load-jars-hdfs      Loads Accumulo jars in lib/ to HDFS for VFS classloader
@@ -263,6 +264,9 @@ function main() {
     build-native)
       build_native "${@:2}"
       ;;
+    dump-zoo)
+      "$bin"/accumulo org.apache.accumulo.server.util.DumpZookeeper "${@:2}"
+      ;;
     hadoop-jar)
       hadoop_jar "${@:2}"
       ;;
diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/DumpZookeeper.java b/server/base/src/main/java/org/apache/accumulo/server/util/DumpZookeeper.java
index 24329ff7b3..7fe7a8c4b9 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/util/DumpZookeeper.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/DumpZookeeper.java
@@ -21,8 +21,7 @@
 import java.io.PrintStream;
 import java.util.Base64;
 
-import org.apache.accumulo.core.cli.Help;
-import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.core.cli.ConfigOpts;
 import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
 import org.apache.accumulo.fate.zookeeper.ZooReaderWriter;
 import org.apache.log4j.Level;
@@ -34,7 +33,7 @@
 
 public class DumpZookeeper {
 
-  static IZooReaderWriter zk = null;
+  private static IZooReaderWriter zk = null;
 
   private static final Logger log = Logger.getLogger(DumpZookeeper.class);
 
@@ -48,9 +47,13 @@
     }
   }
 
-  static class Opts extends Help {
-    @Parameter(names = "--root", description = "the root of the znode tree to dump")
+  static class Opts extends ConfigOpts {
+    @Parameter(names = {"-r", "-root", "--root"},
+        description = "Root ZooKeeper directory to start dump at")
     String root = "/";
+    @Parameter(names = {"-x", "-xml", "--xml"},
+        description = "Output dump as XML (instead of human readable")
+    boolean xml = false;
   }
 
   public static void main(String[] args) {
@@ -60,19 +63,27 @@ public static void main(String[] args) {
     Logger.getRootLogger().setLevel(Level.WARN);
     PrintStream out = System.out;
     try {
-      zk = new ZooReaderWriter(new SiteConfiguration());
-
-      write(out, 0, "<dump root='%s'>", opts.root);
-      for (String child : zk.getChildren(opts.root, null))
-        if (!child.equals("zookeeper"))
-          dump(out, opts.root, child, 1);
-      write(out, 0, "</dump>");
+      zk = new ZooReaderWriter(opts.getSiteConfiguration());
+      if (opts.xml) {
+        writeXml(out, opts.root);
+      } else {
+        writeHumanReadable(out, opts.root);
+      }
     } catch (Exception ex) {
       log.error(ex, ex);
     }
   }
 
-  private static void dump(PrintStream out, String root, String child, int indent)
+  private static void writeXml(PrintStream out, String root)
+      throws KeeperException, InterruptedException {
+    write(out, 0, "<dump root='%s'>", root);
+    for (String child : zk.getChildren(root, null))
+      if (!child.equals("zookeeper"))
+        childXml(out, root, child, 1);
+    write(out, 0, "</dump>");
+  }
+
+  private static void childXml(PrintStream out, String root, String child, int indent)
       throws KeeperException, InterruptedException {
     String path = root + "/" + child;
     if (root.endsWith("/"))
@@ -101,7 +112,7 @@ private static void dump(PrintStream out, String root, String child, int indent)
             value.value);
       }
       for (String c : zk.getChildren(path, null)) {
-        dump(out, path, c, indent + 1);
+        childXml(out, path, c, indent + 1);
       }
       write(out, indent, "</node>");
     }
@@ -119,7 +130,39 @@ private static Encoded value(String path) throws KeeperException, InterruptedExc
 
   private static void write(PrintStream out, int indent, String fmt, Object... args) {
     for (int i = 0; i < indent; i++)
-      out.print(" ");
+      out.print("  ");
     out.println(String.format(fmt, args));
   }
+
+  private static void writeHumanReadable(PrintStream out, String root)
+      throws KeeperException, InterruptedException {
+    write(out, 0, "%s:", root);
+    for (String child : zk.getChildren(root, null))
+      if (!child.equals("zookeeper"))
+        childHumanReadable(out, root, child, 1);
+  }
+
+  private static void childHumanReadable(PrintStream out, String root, String child, int indent)
+      throws KeeperException, InterruptedException {
+    String path = root + "/" + child;
+    if (root.endsWith("/"))
+      path = root + child;
+    Stat stat = zk.getStatus(path);
+    if (stat == null)
+      return;
+    String node = child;
+    if (stat.getEphemeralOwner() != 0) {
+      node = "*" + child + "*";
+    }
+    if (stat.getDataLength() == 0) {
+      write(out, indent, "%s:", node);
+    } else {
+      write(out, indent, "%s:  %s", node, value(path).value);
+    }
+    if (stat.getNumChildren() > 0) {
+      for (String c : zk.getChildren(path, null)) {
+        childHumanReadable(out, path, c, indent + 1);
+      }
+    }
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services