Search in sources :

Example 16 with Options

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

the class LoadTestTool method newParser.

@Override
protected CommandLineParser newParser() {
    // Validate in parse() to get helpful error messages instead of exploding in processOptions()
    return new DefaultParser() {

        @Override
        public CommandLine parse(Options opts, String[] args, Properties props, boolean stop) throws ParseException {
            CommandLine cl = super.parse(opts, args, props, stop);
            boolean isReadWriteUpdate = cmd.hasOption(OPT_READ) || cmd.hasOption(OPT_WRITE) || cmd.hasOption(OPT_UPDATE);
            boolean isInitOnly = cmd.hasOption(OPT_INIT_ONLY);
            if (!isInitOnly && !isReadWriteUpdate) {
                throw new MissingOptionException("Must specify either -" + OPT_INIT_ONLY + " or at least one of -" + OPT_READ + ", -" + OPT_WRITE + ", -" + OPT_UPDATE);
            }
            if (isInitOnly && isReadWriteUpdate) {
                throw new AlreadySelectedException(OPT_INIT_ONLY + " cannot be specified with any of -" + OPT_READ + ", -" + OPT_WRITE + ", -" + OPT_UPDATE);
            }
            if (isReadWriteUpdate && !cmd.hasOption(OPT_NUM_KEYS)) {
                throw new MissingOptionException(OPT_NUM_KEYS + " must be specified in read/write mode.");
            }
            return cl;
        }
    };
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) AlreadySelectedException(org.apache.hbase.thirdparty.org.apache.commons.cli.AlreadySelectedException) Properties(java.util.Properties) MissingOptionException(org.apache.hbase.thirdparty.org.apache.commons.cli.MissingOptionException) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 17 with Options

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

the class RESTServer method parseCommandLine.

private static void parseCommandLine(String[] args, Configuration conf) {
    Options options = new Options();
    options.addOption("p", "port", true, "Port to bind to [default: " + DEFAULT_LISTEN_PORT + "]");
    options.addOption("ro", "readonly", false, "Respond only to GET HTTP " + "method requests [default: false]");
    options.addOption("i", "infoport", true, "Port for WEB UI");
    CommandLine commandLine = null;
    try {
        commandLine = new PosixParser().parse(options, args);
    } catch (ParseException e) {
        LOG.error("Could not parse: ", e);
        printUsageAndExit(options, -1);
    }
    // check for user-defined port setting, if so override the conf
    if (commandLine != null && commandLine.hasOption("port")) {
        String val = commandLine.getOptionValue("port");
        conf.setInt("hbase.rest.port", Integer.parseInt(val));
        if (LOG.isDebugEnabled()) {
            LOG.debug("port set to " + val);
        }
    }
    // check if server should only process GET requests, if so override the conf
    if (commandLine != null && commandLine.hasOption("readonly")) {
        conf.setBoolean("hbase.rest.readonly", true);
        if (LOG.isDebugEnabled()) {
            LOG.debug("readonly set to true");
        }
    }
    // check for user-defined info server port setting, if so override the conf
    if (commandLine != null && commandLine.hasOption("infoport")) {
        String val = commandLine.getOptionValue("infoport");
        conf.setInt("hbase.rest.info.port", Integer.parseInt(val));
        if (LOG.isDebugEnabled()) {
            LOG.debug("WEB UI port set to " + val);
        }
    }
    if (commandLine != null && commandLine.hasOption("skipLogin")) {
        conf.setBoolean(SKIP_LOGIN_KEY, true);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Skipping Kerberos login for REST server");
        }
    }
    List<String> remainingArgs = commandLine != null ? commandLine.getArgList() : new ArrayList<>();
    if (remainingArgs.size() != 1) {
        printUsageAndExit(options, 1);
    }
    String command = remainingArgs.get(0);
    if ("start".equals(command)) {
    // continue and start container
    } else if ("stop".equals(command)) {
        System.exit(1);
    } else {
        printUsageAndExit(options, 1);
    }
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) PosixParser(org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)

Example 18 with Options

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

the class RegionPlacementMaintainer method main.

public static void main(String[] args) throws IOException {
    Options opt = new Options();
    opt.addOption("w", "write", false, "write the assignments to hbase:meta only");
    opt.addOption("u", "update", false, "update the assignments to hbase:meta and RegionServers together");
    opt.addOption("n", "dry-run", false, "do not write assignments to META");
    opt.addOption("v", "verify", false, "verify current assignments against META");
    opt.addOption("p", "print", false, "print the current assignment plan in META");
    opt.addOption("h", "help", false, "print usage");
    opt.addOption("d", "verification-details", false, "print the details of verification report");
    opt.addOption("zk", true, "to set the zookeeper quorum");
    opt.addOption("fs", true, "to set HDFS");
    opt.addOption("hbase_root", true, "to set hbase_root directory");
    opt.addOption("overwrite", false, "overwrite the favored nodes for a single region," + "for example: -update -r regionName -f server1:port,server2:port,server3:port");
    opt.addOption("r", true, "The region name that needs to be updated");
    opt.addOption("f", true, "The new favored nodes");
    opt.addOption("tables", true, "The list of table names splitted by ',' ;" + "For example: -tables: t1,t2,...,tn");
    opt.addOption("l", "locality", true, "enforce the maximum locality");
    opt.addOption("m", "min-move", true, "enforce minimum assignment move");
    opt.addOption("diff", false, "calculate difference between assignment plans");
    opt.addOption("munkres", false, "use munkres to place secondaries and tertiaries");
    opt.addOption("ld", "locality-dispersion", false, "print locality and dispersion " + "information for current plan");
    try {
        CommandLine cmd = new GnuParser().parse(opt, args);
        Configuration conf = HBaseConfiguration.create();
        boolean enforceMinAssignmentMove = true;
        boolean enforceLocality = true;
        boolean verificationDetails = false;
        // Read all the options
        if ((cmd.hasOption("l") && cmd.getOptionValue("l").equalsIgnoreCase("false")) || (cmd.hasOption("locality") && cmd.getOptionValue("locality").equalsIgnoreCase("false"))) {
            enforceLocality = false;
        }
        if ((cmd.hasOption("m") && cmd.getOptionValue("m").equalsIgnoreCase("false")) || (cmd.hasOption("min-move") && cmd.getOptionValue("min-move").equalsIgnoreCase("false"))) {
            enforceMinAssignmentMove = false;
        }
        if (cmd.hasOption("zk")) {
            conf.set(HConstants.ZOOKEEPER_QUORUM, cmd.getOptionValue("zk"));
            LOG.info("Setting the zk quorum: " + conf.get(HConstants.ZOOKEEPER_QUORUM));
        }
        if (cmd.hasOption("fs")) {
            conf.set(FileSystem.FS_DEFAULT_NAME_KEY, cmd.getOptionValue("fs"));
            LOG.info("Setting the HDFS: " + conf.get(FileSystem.FS_DEFAULT_NAME_KEY));
        }
        if (cmd.hasOption("hbase_root")) {
            conf.set(HConstants.HBASE_DIR, cmd.getOptionValue("hbase_root"));
            LOG.info("Setting the hbase root directory: " + conf.get(HConstants.HBASE_DIR));
        }
        // Create the region placement obj
        try (RegionPlacementMaintainer rp = new RegionPlacementMaintainer(conf, enforceLocality, enforceMinAssignmentMove)) {
            if (cmd.hasOption("d") || cmd.hasOption("verification-details")) {
                verificationDetails = true;
            }
            if (cmd.hasOption("tables")) {
                String tableNameListStr = cmd.getOptionValue("tables");
                String[] tableNames = StringUtils.split(tableNameListStr, ",");
                rp.setTargetTableName(tableNames);
            }
            if (cmd.hasOption("munkres")) {
                USE_MUNKRES_FOR_PLACING_SECONDARY_AND_TERTIARY = true;
            }
            // Read all the modes
            if (cmd.hasOption("v") || cmd.hasOption("verify")) {
                // Verify the region placement.
                rp.verifyRegionPlacement(verificationDetails);
            } else if (cmd.hasOption("n") || cmd.hasOption("dry-run")) {
                // Generate the assignment plan only without updating the hbase:meta and RS
                FavoredNodesPlan plan = rp.getNewAssignmentPlan();
                printAssignmentPlan(plan);
            } else if (cmd.hasOption("w") || cmd.hasOption("write")) {
                // Generate the new assignment plan
                FavoredNodesPlan plan = rp.getNewAssignmentPlan();
                // Print the new assignment plan
                printAssignmentPlan(plan);
                // Write the new assignment plan to META
                rp.updateAssignmentPlanToMeta(plan);
            } else if (cmd.hasOption("u") || cmd.hasOption("update")) {
                // Generate the new assignment plan
                FavoredNodesPlan plan = rp.getNewAssignmentPlan();
                // Print the new assignment plan
                printAssignmentPlan(plan);
                // Update the assignment to hbase:meta and Region Servers
                rp.updateAssignmentPlan(plan);
            } else if (cmd.hasOption("diff")) {
                FavoredNodesPlan newPlan = rp.getNewAssignmentPlan();
                Map<String, Map<String, Float>> locality = FSUtils.getRegionDegreeLocalityMappingFromFS(conf);
                Map<TableName, Integer> movesPerTable = rp.getRegionsMovement(newPlan);
                rp.checkDifferencesWithOldPlan(movesPerTable, locality, newPlan);
                System.out.println("Do you want to update the assignment plan? [y/n]");
                Scanner s = new Scanner(System.in);
                String input = s.nextLine().trim();
                if (input.equals("y")) {
                    System.out.println("Updating assignment plan...");
                    rp.updateAssignmentPlan(newPlan);
                }
                s.close();
            } else if (cmd.hasOption("ld")) {
                Map<String, Map<String, Float>> locality = FSUtils.getRegionDegreeLocalityMappingFromFS(conf);
                rp.printLocalityAndDispersionForCurrentPlan(locality);
            } else if (cmd.hasOption("p") || cmd.hasOption("print")) {
                FavoredNodesPlan plan = rp.getRegionAssignmentSnapshot().getExistingAssignmentPlan();
                printAssignmentPlan(plan);
            } else if (cmd.hasOption("overwrite")) {
                if (!cmd.hasOption("f") || !cmd.hasOption("r")) {
                    throw new IllegalArgumentException("Please specify: " + " -update -r regionName -f server1:port,server2:port,server3:port");
                }
                String regionName = cmd.getOptionValue("r");
                String favoredNodesStr = cmd.getOptionValue("f");
                LOG.info("Going to update the region " + regionName + " with the new favored nodes " + favoredNodesStr);
                List<ServerName> favoredNodes = null;
                RegionInfo regionInfo = rp.getRegionAssignmentSnapshot().getRegionNameToRegionInfoMap().get(regionName);
                if (regionInfo == null) {
                    LOG.error("Cannot find the region " + regionName + " from the META");
                } else {
                    try {
                        favoredNodes = getFavoredNodeList(favoredNodesStr);
                    } catch (IllegalArgumentException e) {
                        LOG.error("Cannot parse the invalid favored nodes because " + e);
                    }
                    FavoredNodesPlan newPlan = new FavoredNodesPlan();
                    newPlan.updateFavoredNodesMap(regionInfo, favoredNodes);
                    rp.updateAssignmentPlan(newPlan);
                }
            } else {
                printHelp(opt);
            }
        }
    } catch (ParseException e) {
        printHelp(opt);
    }
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) Scanner(java.util.Scanner) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) GnuParser(org.apache.hbase.thirdparty.org.apache.commons.cli.GnuParser) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) FavoredNodesPlan(org.apache.hadoop.hbase.favored.FavoredNodesPlan) TableName(org.apache.hadoop.hbase.TableName) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 19 with Options

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

Options (org.apache.hbase.thirdparty.org.apache.commons.cli.Options)19 CommandLine (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine)14 ParseException (org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)10 DefaultParser (org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)8 Configuration (org.apache.hadoop.conf.Configuration)7 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)7 CommandLineParser (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser)6 HelpFormatter (org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter)4 ArrayList (java.util.ArrayList)3 GnuParser (org.apache.hbase.thirdparty.org.apache.commons.cli.GnuParser)3 PosixParser (org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser)3 List (java.util.List)2 Path (org.apache.hadoop.fs.Path)2 TableName (org.apache.hadoop.hbase.TableName)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1