hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject hbase git commit: HBASE-16467 Move AbstractHBaseTool to hbase-common.
Date Tue, 23 Aug 2016 00:20:51 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.0 a049e518f -> cf2e2fde0


HBASE-16467 Move AbstractHBaseTool to hbase-common.

Change-Id: Iea3a3cd91fe4ecc9ff253e2795ab885945fa6a25


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

Branch: refs/heads/branch-1.0
Commit: cf2e2fde0d66ebc8abc773f0a70825ac4a38523c
Parents: a049e51
Author: Apekshit Sharma <appy@apache.org>
Authored: Mon Aug 22 17:19:40 2016 -0700
Committer: Apekshit Sharma <appy@apache.org>
Committed: Mon Aug 22 17:19:40 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/util/AbstractHBaseTool.java    | 203 +++++++++++++++++++
 .../hadoop/hbase/util/AbstractHBaseTool.java    | 203 -------------------
 2 files changed, 203 insertions(+), 203 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/cf2e2fde/hbase-common/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
new file mode 100644
index 0000000..a876aef
--- /dev/null
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
@@ -0,0 +1,203 @@
+/*
+ * 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.hadoop.hbase.util;
+
+import java.io.IOException;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.commons.cli.BasicParser;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.classification.InterfaceAudience;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
+
+/**
+ * Common base class used for HBase command-line tools. Simplifies workflow and
+ * command-line argument parsing.
+ */
+@InterfaceAudience.Private
+public abstract class AbstractHBaseTool implements Tool {
+
+  protected static final int EXIT_SUCCESS = 0;
+  protected static final int EXIT_FAILURE = 1;
+
+  private static final String SHORT_HELP_OPTION = "h";
+  private static final String LONG_HELP_OPTION = "help";
+
+  private static final Log LOG = LogFactory.getLog(AbstractHBaseTool.class);
+
+  private final Options options = new Options();
+
+  protected Configuration conf = null;
+
+  private static final Set<String> requiredOptions = new TreeSet<String>();
+
+  protected String[] cmdLineArgs = null;
+
+  /**
+   * Override this to add command-line options using {@link #addOptWithArg}
+   * and similar methods.
+   */
+  protected abstract void addOptions();
+
+  /**
+   * This method is called to process the options after they have been parsed.
+   */
+  protected abstract void processOptions(CommandLine cmd);
+
+  /** The "main function" of the tool */
+  protected abstract int doWork() throws Exception;
+
+  @Override
+  public Configuration getConf() {
+    return conf;
+  }
+
+  @Override
+  public void setConf(Configuration conf) {
+    this.conf = conf;
+  }
+
+  @Override
+  public final int run(String[] args) throws IOException {
+    if (conf == null) {
+      LOG.error("Tool configuration is not initialized");
+      throw new NullPointerException("conf");
+    }
+
+    CommandLine cmd;
+    try {
+      // parse the command line arguments
+      cmd = parseArgs(args);
+      cmdLineArgs = args;
+    } catch (ParseException e) {
+      LOG.error("Error when parsing command-line arguments", e);
+      printUsage();
+      return EXIT_FAILURE;
+    }
+
+    if (cmd.hasOption(SHORT_HELP_OPTION) || cmd.hasOption(LONG_HELP_OPTION) ||
+        !sanityCheckOptions(cmd)) {
+      printUsage();
+      return EXIT_FAILURE;
+    }
+
+    processOptions(cmd);
+
+    int ret = EXIT_FAILURE;
+    try {
+      ret = doWork();
+    } catch (Exception e) {
+      LOG.error("Error running command-line tool", e);
+      return EXIT_FAILURE;
+    }
+    return ret;
+  }
+
+  private boolean sanityCheckOptions(CommandLine cmd) {
+    boolean success = true;
+    for (String reqOpt : requiredOptions) {
+      if (!cmd.hasOption(reqOpt)) {
+        LOG.error("Required option -" + reqOpt + " is missing");
+        success = false;
+      }
+    }
+    return success;
+  }
+
+  protected CommandLine parseArgs(String[] args) throws ParseException {
+    options.addOption(SHORT_HELP_OPTION, LONG_HELP_OPTION, false, "Show usage");
+    addOptions();
+    CommandLineParser parser = new BasicParser();
+    return parser.parse(options, args);
+  }
+
+  protected void printUsage() {
+    printUsage("bin/hbase " + getClass().getName() + " <options>", "Options:", "");
+  }
+
+  protected void printUsage(final String usageStr, final String usageHeader,
+      final String usageFooter) {
+    HelpFormatter helpFormatter = new HelpFormatter();
+    helpFormatter.setWidth(120);
+    helpFormatter.printHelp(usageStr, usageHeader, options, usageFooter);
+  }
+
+  protected void addRequiredOptWithArg(String opt, String description) {
+    requiredOptions.add(opt);
+    addOptWithArg(opt, description);
+  }
+
+  protected void addRequiredOptWithArg(String shortOpt, String longOpt, String description)
{
+    requiredOptions.add(longOpt);
+    addOptWithArg(shortOpt, longOpt, description);
+  }
+
+  protected void addOptNoArg(String opt, String description) {
+    options.addOption(opt, false, description);
+  }
+
+  protected void addOptNoArg(String shortOpt, String longOpt, String description) {
+    options.addOption(shortOpt, longOpt, false, description);
+  }
+
+  protected void addOptWithArg(String opt, String description) {
+    options.addOption(opt, true, description);
+  }
+
+  protected void addOptWithArg(String shortOpt, String longOpt, String description) {
+    options.addOption(shortOpt, longOpt, true, description);
+  }
+
+  /**
+   * Parse a number and enforce a range.
+   */
+  public static long parseLong(String s, long minValue, long maxValue) {
+    long l = Long.parseLong(s);
+    if (l < minValue || l > maxValue) {
+      throw new IllegalArgumentException("The value " + l
+          + " is out of range [" + minValue + ", " + maxValue + "]");
+    }
+    return l;
+  }
+
+  public static int parseInt(String s, int minValue, int maxValue) {
+    return (int) parseLong(s, minValue, maxValue);
+  }
+
+  /** Call this from the concrete tool class's main function. */
+  protected void doStaticMain(String args[]) {
+    int ret;
+    try {
+      ret = ToolRunner.run(HBaseConfiguration.create(), this, args);
+    } catch (Exception ex) {
+      LOG.error("Error running command-line tool", ex);
+      ret = EXIT_FAILURE;
+    }
+    System.exit(ret);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/cf2e2fde/hbase-server/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
deleted file mode 100644
index a876aef..0000000
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
+++ /dev/null
@@ -1,203 +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.
- */
-package org.apache.hadoop.hbase.util;
-
-import java.io.IOException;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.apache.commons.cli.BasicParser;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.classification.InterfaceAudience;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.util.Tool;
-import org.apache.hadoop.util.ToolRunner;
-
-/**
- * Common base class used for HBase command-line tools. Simplifies workflow and
- * command-line argument parsing.
- */
-@InterfaceAudience.Private
-public abstract class AbstractHBaseTool implements Tool {
-
-  protected static final int EXIT_SUCCESS = 0;
-  protected static final int EXIT_FAILURE = 1;
-
-  private static final String SHORT_HELP_OPTION = "h";
-  private static final String LONG_HELP_OPTION = "help";
-
-  private static final Log LOG = LogFactory.getLog(AbstractHBaseTool.class);
-
-  private final Options options = new Options();
-
-  protected Configuration conf = null;
-
-  private static final Set<String> requiredOptions = new TreeSet<String>();
-
-  protected String[] cmdLineArgs = null;
-
-  /**
-   * Override this to add command-line options using {@link #addOptWithArg}
-   * and similar methods.
-   */
-  protected abstract void addOptions();
-
-  /**
-   * This method is called to process the options after they have been parsed.
-   */
-  protected abstract void processOptions(CommandLine cmd);
-
-  /** The "main function" of the tool */
-  protected abstract int doWork() throws Exception;
-
-  @Override
-  public Configuration getConf() {
-    return conf;
-  }
-
-  @Override
-  public void setConf(Configuration conf) {
-    this.conf = conf;
-  }
-
-  @Override
-  public final int run(String[] args) throws IOException {
-    if (conf == null) {
-      LOG.error("Tool configuration is not initialized");
-      throw new NullPointerException("conf");
-    }
-
-    CommandLine cmd;
-    try {
-      // parse the command line arguments
-      cmd = parseArgs(args);
-      cmdLineArgs = args;
-    } catch (ParseException e) {
-      LOG.error("Error when parsing command-line arguments", e);
-      printUsage();
-      return EXIT_FAILURE;
-    }
-
-    if (cmd.hasOption(SHORT_HELP_OPTION) || cmd.hasOption(LONG_HELP_OPTION) ||
-        !sanityCheckOptions(cmd)) {
-      printUsage();
-      return EXIT_FAILURE;
-    }
-
-    processOptions(cmd);
-
-    int ret = EXIT_FAILURE;
-    try {
-      ret = doWork();
-    } catch (Exception e) {
-      LOG.error("Error running command-line tool", e);
-      return EXIT_FAILURE;
-    }
-    return ret;
-  }
-
-  private boolean sanityCheckOptions(CommandLine cmd) {
-    boolean success = true;
-    for (String reqOpt : requiredOptions) {
-      if (!cmd.hasOption(reqOpt)) {
-        LOG.error("Required option -" + reqOpt + " is missing");
-        success = false;
-      }
-    }
-    return success;
-  }
-
-  protected CommandLine parseArgs(String[] args) throws ParseException {
-    options.addOption(SHORT_HELP_OPTION, LONG_HELP_OPTION, false, "Show usage");
-    addOptions();
-    CommandLineParser parser = new BasicParser();
-    return parser.parse(options, args);
-  }
-
-  protected void printUsage() {
-    printUsage("bin/hbase " + getClass().getName() + " <options>", "Options:", "");
-  }
-
-  protected void printUsage(final String usageStr, final String usageHeader,
-      final String usageFooter) {
-    HelpFormatter helpFormatter = new HelpFormatter();
-    helpFormatter.setWidth(120);
-    helpFormatter.printHelp(usageStr, usageHeader, options, usageFooter);
-  }
-
-  protected void addRequiredOptWithArg(String opt, String description) {
-    requiredOptions.add(opt);
-    addOptWithArg(opt, description);
-  }
-
-  protected void addRequiredOptWithArg(String shortOpt, String longOpt, String description)
{
-    requiredOptions.add(longOpt);
-    addOptWithArg(shortOpt, longOpt, description);
-  }
-
-  protected void addOptNoArg(String opt, String description) {
-    options.addOption(opt, false, description);
-  }
-
-  protected void addOptNoArg(String shortOpt, String longOpt, String description) {
-    options.addOption(shortOpt, longOpt, false, description);
-  }
-
-  protected void addOptWithArg(String opt, String description) {
-    options.addOption(opt, true, description);
-  }
-
-  protected void addOptWithArg(String shortOpt, String longOpt, String description) {
-    options.addOption(shortOpt, longOpt, true, description);
-  }
-
-  /**
-   * Parse a number and enforce a range.
-   */
-  public static long parseLong(String s, long minValue, long maxValue) {
-    long l = Long.parseLong(s);
-    if (l < minValue || l > maxValue) {
-      throw new IllegalArgumentException("The value " + l
-          + " is out of range [" + minValue + ", " + maxValue + "]");
-    }
-    return l;
-  }
-
-  public static int parseInt(String s, int minValue, int maxValue) {
-    return (int) parseLong(s, minValue, maxValue);
-  }
-
-  /** Call this from the concrete tool class's main function. */
-  protected void doStaticMain(String args[]) {
-    int ret;
-    try {
-      ret = ToolRunner.run(HBaseConfiguration.create(), this, args);
-    } catch (Exception ex) {
-      LOG.error("Error running command-line tool", ex);
-      ret = EXIT_FAILURE;
-    }
-    System.exit(ret);
-  }
-
-}


Mime
View raw message