You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by mb...@apache.org on 2016/08/19 17:11:49 UTC

[2/5] hbase git commit: HBASE-16452 Procedure v2 - Make ProcedureWALPrettyPrinter extend Tool

HBASE-16452 Procedure v2 - Make ProcedureWALPrettyPrinter extend Tool


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/aba2b033
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/aba2b033
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/aba2b033

Branch: refs/heads/branch-1.3
Commit: aba2b03378d2acaa033aedd2a7d775b77e05a1af
Parents: e3ed8ec
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Fri Aug 19 09:53:50 2016 -0700
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Fri Aug 19 10:01:58 2016 -0700

----------------------------------------------------------------------
 .../store/wal/ProcedureWALPrettyPrinter.java    | 40 ++++++++++----------
 1 file changed, 20 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/aba2b033/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/wal/ProcedureWALPrettyPrinter.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/wal/ProcedureWALPrettyPrinter.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/wal/ProcedureWALPrettyPrinter.java
index 9c33ac2..fb195b6 100644
--- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/wal/ProcedureWALPrettyPrinter.java
+++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/wal/ProcedureWALPrettyPrinter.java
@@ -29,6 +29,7 @@ import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -40,14 +41,16 @@ import org.apache.hadoop.hbase.classification.InterfaceStability;
 import org.apache.hadoop.hbase.procedure2.Procedure;
 import org.apache.hadoop.hbase.protobuf.generated.ProcedureProtos.ProcedureWALEntry;
 import org.apache.hadoop.hbase.protobuf.generated.ProcedureProtos.ProcedureWALHeader;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
 
 /**
  * ProcedureWALPrettyPrinter prints the contents of a given ProcedureWAL file
  */
 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
 @InterfaceStability.Evolving
-public class ProcedureWALPrettyPrinter {
-  private PrintStream out;
+public class ProcedureWALPrettyPrinter extends Configured implements Tool {
+  private final PrintStream out;
 
   public ProcedureWALPrettyPrinter() {
     out = System.out;
@@ -85,7 +88,6 @@ public class ProcedureWALPrettyPrinter {
   }
 
   public void processProcedureWALFile(ProcedureWALFile log) throws IOException {
-
     log.open();
     ProcedureWALHeader header = log.getHeader();
     printHeader(header);
@@ -96,7 +98,7 @@ public class ProcedureWALPrettyPrinter {
       while (hasMore) {
         ProcedureWALEntry entry = ProcedureWALFormat.readEntry(stream);
         if (entry == null) {
-          out.print("No more entry, exiting with missing EOF");
+          out.println("No more entry, exiting with missing EOF");
           hasMore = false;
           break;
         }
@@ -109,7 +111,7 @@ public class ProcedureWALPrettyPrinter {
         }
       }
     } catch (IOException e) {
-      out.print("got an exception while reading the procedure WAL " + e.getMessage());
+      out.println("got an exception while reading the procedure WAL " + e.getMessage());
     }
     finally {
       log.close();
@@ -138,10 +140,6 @@ public class ProcedureWALPrettyPrinter {
     out.println();
   }
 
-  public static void main(String[] args) throws IOException {
-    run(args);
-  }
-
   /**
    * Pass one or more log file names and formatting options and it will dump out
    * a text version of the contents on <code>stdout</code>.
@@ -151,18 +149,15 @@ public class ProcedureWALPrettyPrinter {
    * @throws IOException
    *           Thrown upon file system errors etc.
    */
-  public static void run(String[] args) throws IOException {
+  public int run(final String[] args) throws IOException {
     // create options
     Options options = new Options();
     options.addOption("h", "help", false, "Output help message");
     options.addOption("f", "file", true, "File to print");
 
-    List<Path> files = new ArrayList<Path>();
-
-    ProcedureWALPrettyPrinter printer = new ProcedureWALPrettyPrinter();
-    CommandLineParser parser = new PosixParser();
+    final List<Path> files = new ArrayList<Path>();
     try {
-      CommandLine cmd = parser.parse(options, args);
+      CommandLine cmd = new PosixParser().parse(options, args);
 
       if (cmd.hasOption("f")) {
         files.add(new Path(cmd.getOptionValue("f")));
@@ -171,19 +166,24 @@ public class ProcedureWALPrettyPrinter {
       if (files.size() == 0 || cmd.hasOption("h")) {
         HelpFormatter formatter = new HelpFormatter();
         formatter.printHelp("ProcedureWALPrettyPrinter ", options, true);
-        System.exit(-1);
+        return(-1);
       }
-
     } catch (ParseException e) {
       e.printStackTrace();
       HelpFormatter formatter = new HelpFormatter();
       formatter.printHelp("ProcedureWALPrettyPrinter ", options, true);
-      System.exit(-1);
+      return(-1);
     }
     // get configuration, file system, and process the given files
-    Configuration conf = HBaseConfiguration.create();
     for (Path file : files) {
-      printer.processFile(conf, file);
+      processFile(getConf(), file);
     }
+    return(0);
+  }
+
+  public static void main(String[] args) throws Exception {
+    final Configuration conf = HBaseConfiguration.create();
+    int exitCode = ToolRunner.run(conf, new ProcedureWALPrettyPrinter(), args);
+    System.exit(exitCode);
   }
 }