Search in sources :

Example 6 with CommandLine

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

use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine 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)

Example 8 with CommandLine

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

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

use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine 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)

Aggregations

CommandLine (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine)21 Options (org.apache.hbase.thirdparty.org.apache.commons.cli.Options)14 ParseException (org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)12 CommandLineParser (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser)9 DefaultParser (org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)9 Configuration (org.apache.hadoop.conf.Configuration)8 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)8 HelpFormatter (org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter)8 PosixParser (org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Path (org.apache.hadoop.fs.Path)4 GnuParser (org.apache.hbase.thirdparty.org.apache.commons.cli.GnuParser)4 List (java.util.List)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 TableName (org.apache.hadoop.hbase.TableName)2 MissingOptionException (org.apache.hbase.thirdparty.org.apache.commons.cli.MissingOptionException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1