Search in sources :

Example 6 with CommandLineParser

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

the class TestJoinedScanners method main.

/**
 * Command line interface:
 * @param args
 * @throws IOException if there is a bug while reading from disk
 */
public static void main(final String[] args) throws Exception {
    Option encodingOption = new Option("e", "blockEncoding", true, "Data block encoding; Default: FAST_DIFF");
    encodingOption.setRequired(false);
    options.addOption(encodingOption);
    Option ratioOption = new Option("r", "selectionRatio", true, "Ratio of selected rows using essential column family");
    ratioOption.setRequired(false);
    options.addOption(ratioOption);
    Option widthOption = new Option("w", "valueWidth", true, "Width of value for non-essential column family");
    widthOption.setRequired(false);
    options.addOption(widthOption);
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);
    if (args.length < 1) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("TestJoinedScanners", options, true);
    }
    if (cmd.hasOption("e")) {
        blockEncoding = DataBlockEncoding.valueOf(cmd.getOptionValue("e"));
    }
    if (cmd.hasOption("r")) {
        selectionRatio = Integer.parseInt(cmd.getOptionValue("r"));
    }
    if (cmd.hasOption("w")) {
        valueWidth = Integer.parseInt(cmd.getOptionValue("w"));
    }
    // run the test
    TestJoinedScanners test = new TestJoinedScanners();
    test.testJoinedScanners();
}
Also used : HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) GnuParser(org.apache.hbase.thirdparty.org.apache.commons.cli.GnuParser) Option(org.apache.hbase.thirdparty.org.apache.commons.cli.Option) StartTestingClusterOption(org.apache.hadoop.hbase.StartTestingClusterOption) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser)

Example 7 with CommandLineParser

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

the class HFilePrettyPrinter method parseOptions.

public boolean parseOptions(String[] args) throws ParseException, IOException {
    if (args.length == 0) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("hfile", options, true);
        return false;
    }
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
    verbose = cmd.hasOption("v");
    printValue = cmd.hasOption("p");
    printKey = cmd.hasOption("e") || printValue;
    shouldPrintMeta = cmd.hasOption("m");
    printBlockIndex = cmd.hasOption("b");
    printBlockHeaders = cmd.hasOption("h");
    printStats = cmd.hasOption("s");
    checkRow = cmd.hasOption("k");
    checkFamily = cmd.hasOption("a");
    checkMobIntegrity = cmd.hasOption("i");
    if (cmd.hasOption("f")) {
        files.add(new Path(cmd.getOptionValue("f")));
    }
    if (cmd.hasOption("w")) {
        String key = cmd.getOptionValue("w");
        if (key != null && key.length() != 0) {
            row = Bytes.toBytesBinary(key);
            isSeekToRow = true;
        } else {
            err.println("Invalid row is specified.");
            System.exit(-1);
        }
    }
    if (cmd.hasOption("r")) {
        String regionName = cmd.getOptionValue("r");
        byte[] rn = Bytes.toBytes(regionName);
        byte[][] hri = RegionInfo.parseRegionName(rn);
        Path rootDir = CommonFSUtils.getRootDir(getConf());
        Path tableDir = CommonFSUtils.getTableDir(rootDir, TableName.valueOf(hri[0]));
        String enc = RegionInfo.encodeRegionName(rn);
        Path regionDir = new Path(tableDir, enc);
        if (verbose)
            out.println("region dir -> " + regionDir);
        List<Path> regionFiles = HFile.getStoreFiles(FileSystem.get(getConf()), regionDir);
        if (verbose)
            out.println("Number of region files found -> " + regionFiles.size());
        if (verbose) {
            int i = 1;
            for (Path p : regionFiles) {
                if (verbose)
                    out.println("Found file[" + i++ + "] -> " + p);
            }
        }
        files.addAll(regionFiles);
    }
    if (checkMobIntegrity) {
        if (verbose) {
            System.out.println("checkMobIntegrity is enabled");
        }
        mobFileLocations = new HashMap<>();
    }
    cmd.getArgList().forEach((file) -> files.add(new Path(file)));
    return true;
}
Also used : HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) Path(org.apache.hadoop.fs.Path) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) PosixParser(org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser)

Example 8 with CommandLineParser

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

the class RSGroupMajorCompactionTTL 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 rsgroup = commandLine.getOptionValue("rsgroup");
    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");
    Configuration conf = getConf();
    return compactTTLRegionsOnGroup(conf, rsgroup, 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) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) 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 9 with CommandLineParser

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

the class CreateRandomStoreFile method run.

/**
 * Runs the tools.
 *
 * @param args command-line arguments
 * @return true in case of success
 * @throws IOException
 */
public boolean run(String[] args) throws IOException {
    options.addOption(OUTPUT_DIR_OPTION, "output_dir", true, "Output directory");
    options.addOption(NUM_KV_OPTION, "num_kv", true, "Number of key/value pairs");
    options.addOption(KEY_SIZE_OPTION, "key_size", true, "Average key size");
    options.addOption(VALUE_SIZE_OPTION, "value_size", true, "Average value size");
    options.addOption(HFILE_VERSION_OPTION, "hfile_version", true, "HFile version to create");
    options.addOption(COMPRESSION_OPTION, "compression", true, " Compression type, one of " + Arrays.toString(Compression.Algorithm.values()));
    options.addOption(BLOOM_FILTER_OPTION, "bloom_filter", true, "Bloom filter type, one of " + Arrays.toString(BloomType.values()));
    options.addOption(BLOOM_FILTER_PARAM_OPTION, "bloom_param", true, "the parameter of the bloom filter");
    options.addOption(BLOCK_SIZE_OPTION, "block_size", true, "HFile block size");
    options.addOption(BLOOM_BLOCK_SIZE_OPTION, "bloom_block_size", true, "Compound Bloom filters block size");
    options.addOption(INDEX_BLOCK_SIZE_OPTION, "index_block_size", true, "Index block size");
    if (args.length == 0) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(CreateRandomStoreFile.class.getSimpleName(), options, true);
        return false;
    }
    CommandLineParser parser = new PosixParser();
    CommandLine cmdLine;
    try {
        cmdLine = parser.parse(options, args);
    } catch (ParseException ex) {
        LOG.error(ex.toString(), ex);
        return false;
    }
    if (!cmdLine.hasOption(OUTPUT_DIR_OPTION)) {
        LOG.error("Output directory is not specified");
        return false;
    }
    if (!cmdLine.hasOption(NUM_KV_OPTION)) {
        LOG.error("The number of keys/values not specified");
        return false;
    }
    if (!cmdLine.hasOption(KEY_SIZE_OPTION)) {
        LOG.error("Key size is not specified");
        return false;
    }
    if (!cmdLine.hasOption(VALUE_SIZE_OPTION)) {
        LOG.error("Value size not specified");
        return false;
    }
    Configuration conf = HBaseConfiguration.create();
    Path outputDir = new Path(cmdLine.getOptionValue(OUTPUT_DIR_OPTION));
    long numKV = Long.parseLong(cmdLine.getOptionValue(NUM_KV_OPTION));
    configureKeyValue(numKV, Integer.parseInt(cmdLine.getOptionValue(KEY_SIZE_OPTION)), Integer.parseInt(cmdLine.getOptionValue(VALUE_SIZE_OPTION)));
    FileSystem fs = FileSystem.get(conf);
    Compression.Algorithm compr = Compression.Algorithm.NONE;
    if (cmdLine.hasOption(COMPRESSION_OPTION)) {
        compr = Compression.Algorithm.valueOf(cmdLine.getOptionValue(COMPRESSION_OPTION));
    }
    BloomType bloomType = BloomType.NONE;
    if (cmdLine.hasOption(BLOOM_FILTER_OPTION)) {
        bloomType = BloomType.valueOf(cmdLine.getOptionValue(BLOOM_FILTER_OPTION));
    }
    if (bloomType == BloomType.ROWPREFIX_FIXED_LENGTH) {
        if (!cmdLine.hasOption(BLOOM_FILTER_PARAM_OPTION)) {
            LOG.error("the parameter of bloom filter is not specified");
            return false;
        } else {
            conf.set(BloomFilterUtil.PREFIX_LENGTH_KEY, cmdLine.getOptionValue(BLOOM_FILTER_PARAM_OPTION));
        }
    }
    int blockSize = HConstants.DEFAULT_BLOCKSIZE;
    if (cmdLine.hasOption(BLOCK_SIZE_OPTION))
        blockSize = Integer.valueOf(cmdLine.getOptionValue(BLOCK_SIZE_OPTION));
    if (cmdLine.hasOption(BLOOM_BLOCK_SIZE_OPTION)) {
        conf.setInt(BloomFilterFactory.IO_STOREFILE_BLOOM_BLOCK_SIZE, Integer.valueOf(cmdLine.getOptionValue(BLOOM_BLOCK_SIZE_OPTION)));
    }
    if (cmdLine.hasOption(INDEX_BLOCK_SIZE_OPTION)) {
        conf.setInt(HFileBlockIndex.MAX_CHUNK_SIZE_KEY, Integer.valueOf(cmdLine.getOptionValue(INDEX_BLOCK_SIZE_OPTION)));
    }
    HFileContext meta = new HFileContextBuilder().withCompression(compr).withBlockSize(blockSize).build();
    StoreFileWriter sfw = new StoreFileWriter.Builder(conf, new CacheConfig(conf), fs).withOutputDir(outputDir).withBloomType(bloomType).withMaxKeyCount(numKV).withFileContext(meta).build();
    rand = new Random();
    LOG.info("Writing " + numKV + " key/value pairs");
    for (long i = 0; i < numKV; ++i) {
        sfw.append(generateKeyValue(i));
    }
    int numMetaBlocks = rand.nextInt(10) + 1;
    LOG.info("Writing " + numMetaBlocks + " meta blocks");
    for (int metaI = 0; metaI < numMetaBlocks; ++metaI) {
        sfw.getHFileWriter().appendMetaBlock(generateString(), new BytesWritable(generateValue()));
    }
    sfw.close();
    Path storeFilePath = sfw.getPath();
    long fileSize = fs.getFileStatus(storeFilePath).getLen();
    LOG.info("Created {}, {} bytes, compression={}", storeFilePath, fileSize, compr.toString());
    return true;
}
Also used : Path(org.apache.hadoop.fs.Path) Compression(org.apache.hadoop.hbase.io.compress.Compression) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) PosixParser(org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser) HFileContextBuilder(org.apache.hadoop.hbase.io.hfile.HFileContextBuilder) BytesWritable(org.apache.hadoop.io.BytesWritable) HFileContext(org.apache.hadoop.hbase.io.hfile.HFileContext) HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) Random(java.util.Random) 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) CacheConfig(org.apache.hadoop.hbase.io.hfile.CacheConfig)

Example 10 with CommandLineParser

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

the class ThriftServer method processOptions.

/**
 * Parse the command line options to set parameters the conf.
 */
protected void processOptions(final String[] args) throws Exception {
    if (args == null || args.length == 0) {
        return;
    }
    Options options = new Options();
    addOptions(options);
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption("help")) {
        printUsageAndExit(options, 1);
    }
    parseCommandLine(cmd, options);
}
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) 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