Search in sources :

Example 1 with DefaultParser

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

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

the class HBTop method run.

@Override
public int run(String[] args) throws Exception {
    long initialRefreshDelay = 3 * 1000;
    Mode initialMode = Mode.REGION;
    List<Field> initialFields = null;
    Field initialSortField = null;
    Boolean initialAscendingSort = null;
    List<RecordFilter> initialFilters = null;
    long numberOfIterations = Long.MAX_VALUE;
    boolean batchMode = false;
    try {
        Options opts = getOptions();
        CommandLine commandLine = new DefaultParser().parse(opts, args);
        if (commandLine.hasOption("help")) {
            printUsage(opts);
            return 0;
        }
        if (commandLine.hasOption("mode")) {
            String mode = commandLine.getOptionValue("mode");
            switch(mode) {
                case "n":
                    initialMode = Mode.NAMESPACE;
                    break;
                case "t":
                    initialMode = Mode.TABLE;
                    break;
                case "r":
                    initialMode = Mode.REGION;
                    break;
                case "s":
                    initialMode = Mode.REGION_SERVER;
                    break;
                case "u":
                    initialMode = Mode.USER;
                    break;
                case "c":
                    initialMode = Mode.CLIENT;
                    break;
                default:
                    LOGGER.warn("Mode set invalid, using default");
                    break;
            }
        }
        if (commandLine.hasOption("outputFieldNames")) {
            initialMode.getFieldInfos().forEach(f -> System.out.println(f.getField().getHeader()));
            return 0;
        }
        if (commandLine.hasOption("delay")) {
            int delay = 0;
            try {
                delay = Integer.parseInt(commandLine.getOptionValue("delay"));
            } catch (NumberFormatException ignored) {
            }
            if (delay < 1) {
                LOGGER.warn("Delay set too low or invalid, using default");
            } else {
                initialRefreshDelay = delay * 1000L;
            }
        }
        if (commandLine.hasOption("numberOfIterations")) {
            try {
                numberOfIterations = Long.parseLong(commandLine.getOptionValue("numberOfIterations"));
            } catch (NumberFormatException ignored) {
                LOGGER.warn("The number of iterations set invalid, ignoring");
            }
        }
        if (commandLine.hasOption("sortField")) {
            String sortField = commandLine.getOptionValue("sortField");
            String field;
            boolean ascendingSort;
            if (sortField.startsWith("+")) {
                field = sortField.substring(1);
                ascendingSort = false;
            } else if (sortField.startsWith("-")) {
                field = sortField.substring(1);
                ascendingSort = true;
            } else {
                field = sortField;
                ascendingSort = false;
            }
            Optional<FieldInfo> fieldInfo = initialMode.getFieldInfos().stream().filter(f -> f.getField().getHeader().equals(field)).findFirst();
            if (fieldInfo.isPresent()) {
                initialSortField = fieldInfo.get().getField();
                initialAscendingSort = ascendingSort;
            } else {
                LOGGER.warn("The specified sort field " + field + " is not found, using default");
            }
        }
        if (commandLine.hasOption("fields")) {
            String[] fields = commandLine.getOptionValue("fields").split(",");
            initialFields = new ArrayList<>();
            for (String field : fields) {
                Optional<FieldInfo> fieldInfo = initialMode.getFieldInfos().stream().filter(f -> f.getField().getHeader().equals(field)).findFirst();
                if (fieldInfo.isPresent()) {
                    initialFields.add(fieldInfo.get().getField());
                } else {
                    LOGGER.warn("The specified field " + field + " is not found, ignoring");
                }
            }
        }
        if (commandLine.hasOption("filters")) {
            String[] filters = commandLine.getOptionValue("filters").split(",");
            List<Field> fields = initialMode.getFieldInfos().stream().map(FieldInfo::getField).collect(Collectors.toList());
            for (String filter : filters) {
                RecordFilter f = RecordFilter.parse(filter, fields, false);
                if (f != null) {
                    if (initialFilters == null) {
                        initialFilters = new ArrayList<>();
                    }
                    initialFilters.add(f);
                } else {
                    LOGGER.warn("The specified filter " + filter + " is invalid, ignoring");
                }
            }
        }
        if (commandLine.hasOption("batchMode")) {
            batchMode = true;
        }
    } catch (Exception e) {
        LOGGER.error("Unable to parse options", e);
        return 1;
    }
    try (Screen screen = new Screen(getConf(), initialRefreshDelay, initialMode, initialFields, initialSortField, initialAscendingSort, initialFilters, numberOfIterations, batchMode)) {
        screen.run();
    }
    return 0;
}
Also used : Logger(org.slf4j.Logger) Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) ToolRunner(org.apache.hadoop.util.ToolRunner) LoggerFactory(org.slf4j.LoggerFactory) HBaseInterfaceAudience(org.apache.hadoop.hbase.HBaseInterfaceAudience) HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) Collectors(java.util.stream.Collectors) Tool(org.apache.hadoop.util.Tool) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Screen(org.apache.hadoop.hbase.hbtop.screen.Screen) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Field(org.apache.hadoop.hbase.hbtop.field.Field) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Mode(org.apache.hadoop.hbase.hbtop.mode.Mode) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser) Configured(org.apache.hadoop.conf.Configured) Configuration(org.apache.hadoop.conf.Configuration) Optional(java.util.Optional) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) Screen(org.apache.hadoop.hbase.hbtop.screen.Screen) Mode(org.apache.hadoop.hbase.hbtop.mode.Mode) Field(org.apache.hadoop.hbase.hbtop.field.Field) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 3 with DefaultParser

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

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

use of org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser 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)9 DefaultParser (org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)9 Options (org.apache.hbase.thirdparty.org.apache.commons.cli.Options)8 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 HelpFormatter (org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 Configured (org.apache.hadoop.conf.Configured)1 Path (org.apache.hadoop.fs.Path)1 HBaseInterfaceAudience (org.apache.hadoop.hbase.HBaseInterfaceAudience)1 Field (org.apache.hadoop.hbase.hbtop.field.Field)1 FieldInfo (org.apache.hadoop.hbase.hbtop.field.FieldInfo)1