All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.hadoop.hbase.util.AbstractHBaseTool Maven / Gradle / Ivy

There is a newer version: 3.0.0-beta-1
Show newest version
/*
 * 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.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hbase.thirdparty.org.apache.commons.cli.BasicParser;
import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser;
import org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser;
import org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter;
import org.apache.hbase.thirdparty.org.apache.commons.cli.MissingOptionException;
import org.apache.hbase.thirdparty.org.apache.commons.cli.Option;
import org.apache.hbase.thirdparty.org.apache.commons.cli.Options;
import org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException;

/**
 * Common base class used for HBase command-line tools. Simplifies workflow and command-line
 * argument parsing.
 */
@InterfaceAudience.Private
public abstract class AbstractHBaseTool implements Tool {
  public static final int EXIT_SUCCESS = 0;
  public static final int EXIT_FAILURE = 1;

  public static final String SHORT_HELP_OPTION = "h";
  public static final String LONG_HELP_OPTION = "help";

  private static final Option HELP_OPTION =
    new Option("h", "help", false, "Prints help for this tool.");

  private static final Logger LOG = LoggerFactory.getLogger(AbstractHBaseTool.class);

  protected final Options options = new Options();

  protected Configuration conf = null;

  protected String[] cmdLineArgs = null;

  // To print options in order they were added in help text.
  private HashMap optionsOrder = new HashMap<>();
  private int optionsCount = 0;

  public class OptionsOrderComparator implements Comparator




© 2015 - 2024 Weber Informatics LLC | Privacy Policy