Search in sources :

Example 1 with MissingArgumentException

use of org.apache.commons.cli.MissingArgumentException in project hadoop by apache.

the class ClusterCLI method run.

@Override
public int run(String[] args) throws Exception {
    Options opts = new Options();
    opts.addOption("lnl", LIST_LABELS_CMD, false, "List cluster node-label collection");
    opts.addOption("h", HELP_CMD, false, "Displays help for all commands.");
    opts.addOption("dnl", DIRECTLY_ACCESS_NODE_LABEL_STORE, false, "This is DEPRECATED, will be removed in future releases. Directly access node label store, " + "with this option, all node label related operations" + " will NOT connect RM. Instead, they will" + " access/modify stored node labels directly." + " By default, it is false (access via RM)." + " AND PLEASE NOTE: if you configured " + YarnConfiguration.FS_NODE_LABELS_STORE_ROOT_DIR + " to a local directory" + " (instead of NFS or HDFS), this option will only work" + " when the command run on the machine where RM is running." + " Also, this option is UNSTABLE, could be removed in future" + " releases.");
    int exitCode = -1;
    CommandLine parsedCli = null;
    try {
        parsedCli = new GnuParser().parse(opts, args);
    } catch (MissingArgumentException ex) {
        sysout.println("Missing argument for options");
        printUsage(opts);
        return exitCode;
    }
    if (parsedCli.hasOption(DIRECTLY_ACCESS_NODE_LABEL_STORE)) {
        accessLocal = true;
    }
    if (parsedCli.hasOption(LIST_LABELS_CMD)) {
        printClusterNodeLabels();
    } else if (parsedCli.hasOption(HELP_CMD)) {
        printUsage(opts);
        return 0;
    } else {
        syserr.println("Invalid Command Usage : ");
        printUsage(opts);
    }
    return 0;
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) GnuParser(org.apache.commons.cli.GnuParser)

Example 2 with MissingArgumentException

use of org.apache.commons.cli.MissingArgumentException in project hadoop by apache.

the class NodeCLI method run.

@Override
public int run(String[] args) throws Exception {
    Options opts = new Options();
    opts.addOption(HELP_CMD, false, "Displays help for all commands.");
    opts.addOption(STATUS_CMD, true, "Prints the status report of the node.");
    opts.addOption(LIST_CMD, false, "List all running nodes. " + "Supports optional use of -states to filter nodes " + "based on node state, all -all to list all nodes, " + "-showDetails to display more details about each node.");
    Option nodeStateOpt = new Option(NODE_STATE_CMD, true, "Works with -list to filter nodes based on input comma-separated " + "list of node states. " + getAllValidNodeStates());
    nodeStateOpt.setValueSeparator(',');
    nodeStateOpt.setArgs(Option.UNLIMITED_VALUES);
    nodeStateOpt.setArgName("States");
    opts.addOption(nodeStateOpt);
    Option allOpt = new Option(NODE_ALL, false, "Works with -list to list all nodes.");
    opts.addOption(allOpt);
    Option showDetailsOpt = new Option(NODE_SHOW_DETAILS, false, "Works with -list to show more details about each node.");
    opts.addOption(showDetailsOpt);
    opts.getOption(STATUS_CMD).setArgName("NodeId");
    if (args != null && args.length > 0) {
        for (int i = args.length - 1; i >= 0; i--) {
            if (args[i].equalsIgnoreCase("-" + NODE_ALL)) {
                args[i] = "-" + NODE_ALL;
            }
        }
    }
    int exitCode = -1;
    CommandLine cliParser = null;
    try {
        cliParser = new GnuParser().parse(opts, args);
    } catch (MissingArgumentException ex) {
        sysout.println("Missing argument for options");
        printUsage(opts);
        return exitCode;
    }
    if (cliParser.hasOption("status")) {
        if (args.length != 2) {
            printUsage(opts);
            return exitCode;
        }
        printNodeStatus(cliParser.getOptionValue("status"));
    } else if (cliParser.hasOption("list")) {
        Set<NodeState> nodeStates = new HashSet<NodeState>();
        if (cliParser.hasOption(NODE_ALL)) {
            for (NodeState state : NodeState.values()) {
                nodeStates.add(state);
            }
        } else if (cliParser.hasOption(NODE_STATE_CMD)) {
            String[] types = cliParser.getOptionValues(NODE_STATE_CMD);
            if (types != null) {
                for (String type : types) {
                    if (!type.trim().isEmpty()) {
                        try {
                            nodeStates.add(NodeState.valueOf(org.apache.hadoop.util.StringUtils.toUpperCase(type.trim())));
                        } catch (IllegalArgumentException ex) {
                            sysout.println("The node state " + type + " is invalid.");
                            sysout.println(getAllValidNodeStates());
                            return exitCode;
                        }
                    }
                }
            }
        } else {
            nodeStates.add(NodeState.RUNNING);
        }
        // List all node details with more information.
        if (cliParser.hasOption(NODE_SHOW_DETAILS)) {
            listDetailedClusterNodes(nodeStates);
        } else {
            listClusterNodes(nodeStates);
        }
    } else if (cliParser.hasOption(HELP_CMD)) {
        printUsage(opts);
        return 0;
    } else {
        syserr.println("Invalid Command Usage : ");
        printUsage(opts);
    }
    return 0;
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) NodeState(org.apache.hadoop.yarn.api.records.NodeState) HashSet(java.util.HashSet) Set(java.util.Set) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) GnuParser(org.apache.commons.cli.GnuParser) Option(org.apache.commons.cli.Option)

Example 3 with MissingArgumentException

use of org.apache.commons.cli.MissingArgumentException in project hadoop by apache.

the class RMAdminCLI method handleAddToClusterNodeLabels.

private int handleAddToClusterNodeLabels(String[] args, String cmd, boolean isHAEnabled) throws IOException, YarnException, ParseException {
    Options opts = new Options();
    opts.addOption("addToClusterNodeLabels", true, "Add to cluster node labels.");
    opts.addOption("directlyAccessNodeLabelStore", false, "Directly access node label store.");
    int exitCode = -1;
    CommandLine cliParser = null;
    try {
        cliParser = new GnuParser().parse(opts, args);
    } catch (MissingArgumentException ex) {
        System.err.println(NO_LABEL_ERR_MSG);
        printUsage(args[0], isHAEnabled);
        return exitCode;
    }
    List<NodeLabel> labels = buildNodeLabelsFromStr(cliParser.getOptionValue("addToClusterNodeLabels"));
    if (cliParser.hasOption("directlyAccessNodeLabelStore")) {
        getNodeLabelManagerInstance(getConf()).addToCluserNodeLabels(labels);
    } else {
        ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
        AddToClusterNodeLabelsRequest request = AddToClusterNodeLabelsRequest.newInstance(labels);
        adminProtocol.addToClusterNodeLabels(request);
    }
    return 0;
}
Also used : Options(org.apache.commons.cli.Options) ResourceManagerAdministrationProtocol(org.apache.hadoop.yarn.server.api.ResourceManagerAdministrationProtocol) CommandLine(org.apache.commons.cli.CommandLine) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) GnuParser(org.apache.commons.cli.GnuParser) AddToClusterNodeLabelsRequest(org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsRequest)

Example 4 with MissingArgumentException

use of org.apache.commons.cli.MissingArgumentException in project hadoop by apache.

the class RMAdminCLI method handleRefreshNodes.

// A helper method to reduce the number of lines of run()
private int handleRefreshNodes(String[] args, String cmd, boolean isHAEnabled) throws IOException, YarnException, ParseException {
    Options opts = new Options();
    opts.addOption("refreshNodes", false, "Refresh the hosts information at the ResourceManager.");
    Option gracefulOpt = new Option("g", "graceful", true, "Wait for timeout before marking the NodeManager as decommissioned.");
    gracefulOpt.setOptionalArg(true);
    opts.addOption(gracefulOpt);
    opts.addOption("client", false, "Indicates the timeout tracking should be handled by the client.");
    opts.addOption("server", false, "Indicates the timeout tracking should be handled by the RM.");
    int exitCode = -1;
    CommandLine cliParser = null;
    try {
        cliParser = new GnuParser().parse(opts, args);
    } catch (MissingArgumentException ex) {
        System.out.println("Missing argument for options");
        printUsage(args[0], isHAEnabled);
        return exitCode;
    }
    int timeout = -1;
    if (cliParser.hasOption("g")) {
        String strTimeout = cliParser.getOptionValue("g");
        if (strTimeout != null) {
            timeout = validateTimeout(strTimeout);
        }
        String trackingMode = null;
        if (cliParser.hasOption("client")) {
            trackingMode = "client";
        } else if (cliParser.hasOption("server")) {
            trackingMode = "server";
        } else {
            printUsage(cmd, isHAEnabled);
            return -1;
        }
        return refreshNodes(timeout, trackingMode);
    } else {
        return refreshNodes();
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) GnuParser(org.apache.commons.cli.GnuParser) ResourceOption(org.apache.hadoop.yarn.api.records.ResourceOption) Option(org.apache.commons.cli.Option)

Example 5 with MissingArgumentException

use of org.apache.commons.cli.MissingArgumentException in project hadoop by apache.

the class RMAdminCLI method handleReplaceLabelsOnNodes.

private int handleReplaceLabelsOnNodes(String[] args, String cmd, boolean isHAEnabled) throws IOException, YarnException, ParseException {
    Options opts = new Options();
    opts.addOption("replaceLabelsOnNode", true, "Replace label on node.");
    opts.addOption("failOnUnknownNodes", false, "Fail on unknown nodes.");
    opts.addOption("directlyAccessNodeLabelStore", false, "Directly access node label store.");
    int exitCode = -1;
    CommandLine cliParser = null;
    try {
        cliParser = new GnuParser().parse(opts, args);
    } catch (MissingArgumentException ex) {
        System.err.println(NO_MAPPING_ERR_MSG);
        printUsage(args[0], isHAEnabled);
        return exitCode;
    }
    Map<NodeId, Set<String>> map = buildNodeLabelsMapFromStr(cliParser.getOptionValue("replaceLabelsOnNode"));
    return replaceLabelsOnNodes(map, cliParser.hasOption("failOnUnknownNodes"), cliParser.hasOption("directlyAccessNodeLabelStore"));
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) GnuParser(org.apache.commons.cli.GnuParser) NodeId(org.apache.hadoop.yarn.api.records.NodeId)

Aggregations

MissingArgumentException (org.apache.commons.cli.MissingArgumentException)16 CommandLine (org.apache.commons.cli.CommandLine)14 Options (org.apache.commons.cli.Options)11 GnuParser (org.apache.commons.cli.GnuParser)9 Option (org.apache.commons.cli.Option)5 ParseException (org.apache.commons.cli.ParseException)4 UnrecognizedOptionException (org.apache.commons.cli.UnrecognizedOptionException)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 CommandLineParser (org.apache.commons.cli.CommandLineParser)3 MissingOptionException (org.apache.commons.cli.MissingOptionException)3 IOException (java.io.IOException)2 AlreadySelectedException (org.apache.commons.cli.AlreadySelectedException)2 DefaultParser (org.apache.commons.cli.DefaultParser)2 ResourceManagerAdministrationProtocol (org.apache.hadoop.yarn.server.api.ResourceManagerAdministrationProtocol)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1