Search in sources :

Example 1 with CommandLineParser

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

the class AbstractHBaseTool method parseArgs.

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);
}
Also used : BasicParser(org.apache.hbase.thirdparty.org.apache.commons.cli.BasicParser) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser)

Example 2 with CommandLineParser

use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser 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 3 with CommandLineParser

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

the class DataBlockEncodingTool method main.

/**
 * A command line interface to benchmarks. Parses command-line arguments and
 * runs the appropriate benchmarks.
 * @param args Should have length at least 1 and holds the file path to HFile.
 * @throws IOException If you specified the wrong file.
 */
public static void main(final String[] args) throws IOException {
    // set up user arguments
    Options options = new Options();
    options.addOption(OPT_HFILE_NAME, true, "HFile to analyse (REQUIRED)");
    options.getOption(OPT_HFILE_NAME).setArgName("FILENAME");
    options.addOption(OPT_KV_LIMIT, true, "Maximum number of KeyValues to process. A benchmark stops running " + "after iterating over this many KV pairs.");
    options.getOption(OPT_KV_LIMIT).setArgName("NUMBER");
    options.addOption(OPT_MEASURE_THROUGHPUT, false, "Measure read throughput");
    options.addOption(OPT_OMIT_CORRECTNESS_TEST, false, "Omit corectness tests.");
    options.addOption(OPT_COMPRESSION_ALGORITHM, true, "What kind of compression algorithm use for comparison.");
    options.addOption(OPT_BENCHMARK_N_TIMES, true, "Number of times to run each benchmark. Default value: " + DEFAULT_BENCHMARK_N_TIMES);
    options.addOption(OPT_BENCHMARK_N_OMIT, true, "Number of first runs of every benchmark to exclude from " + "statistics (" + DEFAULT_BENCHMARK_N_OMIT + " by default, so that " + "only the last " + (DEFAULT_BENCHMARK_N_TIMES - DEFAULT_BENCHMARK_N_OMIT) + " times are included in statistics.)");
    // parse arguments
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Could not parse arguments!");
        System.exit(-1);
        // avoid warning
        return;
    }
    int kvLimit = Integer.MAX_VALUE;
    if (cmd.hasOption(OPT_KV_LIMIT)) {
        kvLimit = Integer.parseInt(cmd.getOptionValue(OPT_KV_LIMIT));
        if (kvLimit <= 0) {
            LOG.error("KV_LIMIT should not less than 1.");
        }
    }
    // basic argument sanity checks
    if (!cmd.hasOption(OPT_HFILE_NAME)) {
        LOG.error("Please specify HFile name using the " + OPT_HFILE_NAME + " option");
        printUsage(options);
        System.exit(-1);
    }
    String pathName = cmd.getOptionValue(OPT_HFILE_NAME);
    String compressionName = DEFAULT_COMPRESSION.getName();
    if (cmd.hasOption(OPT_COMPRESSION_ALGORITHM)) {
        compressionName = cmd.getOptionValue(OPT_COMPRESSION_ALGORITHM).toLowerCase(Locale.ROOT);
    }
    boolean doBenchmark = cmd.hasOption(OPT_MEASURE_THROUGHPUT);
    boolean doVerify = !cmd.hasOption(OPT_OMIT_CORRECTNESS_TEST);
    if (cmd.hasOption(OPT_BENCHMARK_N_TIMES)) {
        benchmarkNTimes = Integer.valueOf(cmd.getOptionValue(OPT_BENCHMARK_N_TIMES));
    }
    if (cmd.hasOption(OPT_BENCHMARK_N_OMIT)) {
        benchmarkNOmit = Integer.valueOf(cmd.getOptionValue(OPT_BENCHMARK_N_OMIT));
    }
    if (benchmarkNTimes < benchmarkNOmit) {
        LOG.error("The number of times to run each benchmark (" + benchmarkNTimes + ") must be greater than the number of benchmark runs to exclude " + "from statistics (" + benchmarkNOmit + ")");
        System.exit(1);
    }
    LOG.info("Running benchmark " + benchmarkNTimes + " times. " + "Excluding the first " + benchmarkNOmit + " times from statistics.");
    final Configuration conf = HBaseConfiguration.create();
    testCodecs(conf, kvLimit, pathName, compressionName, doBenchmark, doVerify);
}
Also used : 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) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)

Example 4 with CommandLineParser

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

the class MajorCompactor method run.

@Override
public int run(String[] args) throws Exception {
    Options options = getCommonOptions();
    options.addOption(Option.builder("table").required().desc("table name").hasArg().build());
    options.addOption(Option.builder("cf").optionalArg(true).desc("column families: comma separated eg: a,b,c").hasArg().build());
    final CommandLineParser cmdLineParser = new DefaultParser();
    CommandLine commandLine = null;
    try {
        commandLine = cmdLineParser.parse(options, args);
    } catch (ParseException parseException) {
        System.out.println("ERROR: Unable to parse command-line arguments " + Arrays.toString(args) + " due to: " + parseException);
        printUsage(options);
        return -1;
    }
    if (commandLine == null) {
        System.out.println("ERROR: Failed parse, empty commandLine; " + Arrays.toString(args));
        printUsage(options);
        return -1;
    }
    String tableName = commandLine.getOptionValue("table");
    String cf = commandLine.getOptionValue("cf", null);
    Set<String> families = Sets.newHashSet();
    if (cf != null) {
        Iterables.addAll(families, Splitter.on(",").split(cf));
    }
    Configuration configuration = getConf();
    int concurrency = Integer.parseInt(commandLine.getOptionValue("servers"));
    long minModTime = Long.parseLong(commandLine.getOptionValue("minModTime", String.valueOf(EnvironmentEdgeManager.currentTime())));
    String quorum = commandLine.getOptionValue("zk", configuration.get(HConstants.ZOOKEEPER_QUORUM));
    String rootDir = commandLine.getOptionValue("rootDir", configuration.get(HConstants.HBASE_DIR));
    long sleep = Long.parseLong(commandLine.getOptionValue("sleep", Long.toString(30000)));
    int numServers = Integer.parseInt(commandLine.getOptionValue("numservers", "-1"));
    int numRegions = Integer.parseInt(commandLine.getOptionValue("numregions", "-1"));
    configuration.set(HConstants.HBASE_DIR, rootDir);
    configuration.set(HConstants.ZOOKEEPER_QUORUM, quorum);
    MajorCompactor compactor = new MajorCompactor(configuration, TableName.valueOf(tableName), families, concurrency, minModTime, sleep);
    compactor.setNumServers(numServers);
    compactor.setNumRegions(numRegions);
    compactor.setSkipWait(commandLine.hasOption("skipWait"));
    compactor.initializeWorkQueues();
    if (!commandLine.hasOption("dryRun")) {
        compactor.compactAllRegions();
    }
    compactor.shutdown();
    return ERRORS.size();
}
Also used : 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) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 5 with CommandLineParser

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

the class MajorCompactorTTL method run.

@Override
public int run(String[] args) throws Exception {
    Options options = getOptions();
    final CommandLineParser cmdLineParser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = cmdLineParser.parse(options, args);
    } catch (ParseException parseException) {
        System.out.println("ERROR: Unable to parse command-line arguments " + Arrays.toString(args) + " due to: " + parseException);
        printUsage(options);
        return -1;
    }
    if (commandLine == null) {
        System.out.println("ERROR: Failed parse, empty commandLine; " + Arrays.toString(args));
        printUsage(options);
        return -1;
    }
    String table = commandLine.getOptionValue("table");
    int numServers = Integer.parseInt(commandLine.getOptionValue("numservers", "-1"));
    int numRegions = Integer.parseInt(commandLine.getOptionValue("numregions", "-1"));
    int concurrency = Integer.parseInt(commandLine.getOptionValue("servers", "1"));
    long sleep = Long.parseLong(commandLine.getOptionValue("sleep", Long.toString(30000)));
    boolean dryRun = commandLine.hasOption("dryRun");
    boolean skipWait = commandLine.hasOption("skipWait");
    return compactRegionsTTLOnTable(HBaseConfiguration.create(), table, concurrency, sleep, numServers, numRegions, dryRun, skipWait);
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Aggregations

CommandLineParser (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser)10 CommandLine (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine)9 Options (org.apache.hbase.thirdparty.org.apache.commons.cli.Options)6 ParseException (org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)6 Configuration (org.apache.hadoop.conf.Configuration)5 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)5 DefaultParser (org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)4 HelpFormatter (org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter)4 PosixParser (org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser)4 Path (org.apache.hadoop.fs.Path)3 FileSystem (org.apache.hadoop.fs.FileSystem)2 Random (java.util.Random)1 StartTestingClusterOption (org.apache.hadoop.hbase.StartTestingClusterOption)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 HFileContextBuilder (org.apache.hadoop.hbase.io.hfile.HFileContextBuilder)1 BytesWritable (org.apache.hadoop.io.BytesWritable)1 BasicParser (org.apache.hbase.thirdparty.org.apache.commons.cli.BasicParser)1 GnuParser (org.apache.hbase.thirdparty.org.apache.commons.cli.GnuParser)1