Search in sources :

Example 1 with HelpFormatter

use of org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter in project hbase by apache.

the class RESTServer method printUsageAndExit.

private static void printUsageAndExit(Options options, int exitCode) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("hbase rest start", "", options, "\nTo run the REST server as a daemon, execute " + "hbase-daemon.sh start|stop rest [-i <port>] [-p <port>] [-ro]\n", true);
    System.exit(exitCode);
}
Also used : HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter)

Example 2 with HelpFormatter

use of org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter in project hbase by apache.

the class ProcedureWALPrettyPrinter method run.

/**
 * 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>.
 *
 * @param args
 *          Command line arguments
 * @throws IOException
 *           Thrown upon file system errors etc.
 */
@Override
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");
    final List<Path> files = new ArrayList<>();
    try {
        CommandLine cmd = new DefaultParser().parse(options, args);
        if (cmd.hasOption("f")) {
            files.add(new Path(cmd.getOptionValue("f")));
        }
        if (files.isEmpty() || cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("ProcedureWALPrettyPrinter ", options, true);
            return (-1);
        }
    } catch (ParseException e) {
        LOG.error("Failed to parse commandLine arguments", e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ProcedureWALPrettyPrinter ", options, true);
        return (-1);
    }
    // get configuration, file system, and process the given files
    for (Path file : files) {
        processFile(getConf(), file);
    }
    return (0);
}
Also used : Path(org.apache.hadoop.fs.Path) HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) ArrayList(java.util.ArrayList) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 3 with HelpFormatter

use of org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter in project hbase by apache.

the class RowCounter method printUsage.

@Override
protected void printUsage(final String usageStr, final String usageHeader, final String usageFooter) {
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setWidth(120);
    helpFormatter.setOptionComparator(new AbstractHBaseTool.OptionsOrderComparator());
    helpFormatter.setLongOptSeparator("=");
    helpFormatter.printHelp(usageStr, usageHeader, options, usageFooter);
}
Also used : HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) AbstractHBaseTool(org.apache.hadoop.hbase.util.AbstractHBaseTool)

Example 4 with HelpFormatter

use of org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter in project hbase by apache.

the class WALPrettyPrinter method run.

/**
 * 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>.
 *
 * @param args
 *          Command line arguments
 * @throws IOException
 *           Thrown upon file system errors etc.
 */
public static void run(String[] args) throws IOException {
    // create options
    Options options = new Options();
    options.addOption("h", "help", false, "Output help message");
    options.addOption("j", "json", false, "Output JSON");
    options.addOption("p", "printvals", false, "Print values");
    options.addOption("t", "tables", true, "Table names (comma separated) to filter by; eg: test1,test2,test3 ");
    options.addOption("r", "region", true, "Region to filter by. Pass encoded region name; e.g. '9192caead6a5a20acb4454ffbc79fa14'");
    options.addOption("s", "sequence", true, "Sequence to filter by. Pass sequence number.");
    options.addOption("k", "outputOnlyRowKey", false, "Print only row keys");
    options.addOption("w", "row", true, "Row to filter by. Pass row name.");
    options.addOption("f", "rowPrefix", true, "Row prefix to filter by.");
    options.addOption("g", "goto", true, "Position to seek to in the file");
    WALPrettyPrinter printer = new WALPrettyPrinter();
    CommandLineParser parser = new PosixParser();
    List<?> files = null;
    try {
        CommandLine cmd = parser.parse(options, args);
        files = cmd.getArgList();
        if (files.isEmpty() || cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("WAL <filename...>", options, true);
            System.exit(-1);
        }
        // configure the pretty printer using command line options
        if (cmd.hasOption("p")) {
            printer.enableValues();
        }
        if (cmd.hasOption("j")) {
            printer.enableJSON();
        }
        if (cmd.hasOption("k")) {
            printer.setOutputOnlyRowKey();
        }
        if (cmd.hasOption("t")) {
            printer.setTableFilter(cmd.getOptionValue("t"));
        }
        if (cmd.hasOption("r")) {
            printer.setRegionFilter(cmd.getOptionValue("r"));
        }
        if (cmd.hasOption("s")) {
            printer.setSequenceFilter(Long.parseLong(cmd.getOptionValue("s")));
        }
        if (cmd.hasOption("w")) {
            if (cmd.hasOption("f")) {
                throw new ParseException("Row and Row-prefix cannot be supplied together");
            }
            printer.setRowFilter(cmd.getOptionValue("w"));
        }
        if (cmd.hasOption("f")) {
            if (cmd.hasOption("w")) {
                throw new ParseException("Row and Row-prefix cannot be supplied together");
            }
            printer.setRowPrefixFilter(cmd.getOptionValue("f"));
        }
        if (cmd.hasOption("g")) {
            printer.setPosition(Long.parseLong(cmd.getOptionValue("g")));
        }
    } catch (ParseException e) {
        LOG.error("Failed to parse commandLine arguments", e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("HFile filename(s) ", options, true);
        System.exit(-1);
    }
    // get configuration, file system, and process the given files
    Configuration conf = HBaseConfiguration.create();
    CommonFSUtils.setFsDefault(conf, CommonFSUtils.getRootDir(conf));
    // begin output
    printer.beginPersistentOutput();
    for (Object f : files) {
        Path file = new Path((String) f);
        FileSystem fs = file.getFileSystem(conf);
        if (!fs.exists(file)) {
            System.err.println("ERROR, file doesnt exist: " + file);
            return;
        }
        printer.processFile(conf, file);
    }
    printer.endPersistentOutput();
}
Also used : HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) Path(org.apache.hadoop.fs.Path) Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) PosixParser(org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser) FileSystem(org.apache.hadoop.fs.FileSystem) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)

Example 5 with HelpFormatter

use of org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter in project hbase by apache.

the class ThriftServer method printUsageAndExit.

protected void printUsageAndExit(Options options, int exitCode) throws ExitCodeException {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("Thrift", null, options, "To start the Thrift server run 'hbase-daemon.sh start thrift' or " + "'hbase thrift'\n" + "To shutdown the thrift server run 'hbase-daemon.sh stop " + "thrift' or send a kill signal to the thrift server pid", true);
    throw new ExitCodeException(exitCode, "");
}
Also used : HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) ExitCodeException(org.apache.hadoop.util.Shell.ExitCodeException)

Aggregations

HelpFormatter (org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter)15 CommandLine (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine)7 Path (org.apache.hadoop.fs.Path)4 CommandLineParser (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser)4 ParseException (org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)4 Configuration (org.apache.hadoop.conf.Configuration)3 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)3 Options (org.apache.hbase.thirdparty.org.apache.commons.cli.Options)3 PosixParser (org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser)3 FileSystem (org.apache.hadoop.fs.FileSystem)2 DefaultParser (org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)2 GnuParser (org.apache.hbase.thirdparty.org.apache.commons.cli.GnuParser)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 StartTestingClusterOption (org.apache.hadoop.hbase.StartTestingClusterOption)1 TableName (org.apache.hadoop.hbase.TableName)1 Compression (org.apache.hadoop.hbase.io.compress.Compression)1 CacheConfig (org.apache.hadoop.hbase.io.hfile.CacheConfig)1 HFileContext (org.apache.hadoop.hbase.io.hfile.HFileContext)1