Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B0599200B77 for ; Fri, 19 Aug 2016 19:11:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AEFE5160A79; Fri, 19 Aug 2016 17:11:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D4C57160AAB for ; Fri, 19 Aug 2016 19:11:49 +0200 (CEST) Received: (qmail 34346 invoked by uid 500); 19 Aug 2016 17:11:48 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 34318 invoked by uid 99); 19 Aug 2016 17:11:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Aug 2016 17:11:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A9B55EEF45; Fri, 19 Aug 2016 17:11:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mbertozzi@apache.org To: commits@hbase.apache.org Date: Fri, 19 Aug 2016 17:11:49 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/5] hbase git commit: HBASE-16452 Procedure v2 - Make ProcedureWALPrettyPrinter extend Tool archived-at: Fri, 19 Aug 2016 17:11:50 -0000 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 Authored: Fri Aug 19 09:53:50 2016 -0700 Committer: Matteo Bertozzi 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 stdout. @@ -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 files = new ArrayList(); - - ProcedureWALPrettyPrinter printer = new ProcedureWALPrettyPrinter(); - CommandLineParser parser = new PosixParser(); + final List files = new ArrayList(); 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); } }