Search in sources :

Example 91 with Options

use of org.apache.commons.cli.Options in project flink by apache.

the class CliFrontendParser method printHelpForSavepoint.

public static void printHelpForSavepoint() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLeftPadding(5);
    formatter.setWidth(80);
    System.out.println("\nAction \"savepoint\" triggers savepoints for a running job or disposes existing ones.");
    System.out.println("\n  Syntax: savepoint [OPTIONS] <Job ID> [<target directory>]");
    formatter.setSyntaxPrefix("  \"savepoint\" action options:");
    formatter.printHelp(" ", getSavepointOptionsWithoutDeprecatedOptions(new Options()));
    printCustomCliOptions(formatter, false);
    System.out.println();
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options)

Example 92 with Options

use of org.apache.commons.cli.Options in project flink by apache.

the class CliFrontendParser method getRunOptionsWithoutDeprecatedOptions.

// --------------------------------------------------------------------------------------------
//  Help
// --------------------------------------------------------------------------------------------
private static Options getRunOptionsWithoutDeprecatedOptions(Options options) {
    Options o = getProgramSpecificOptionsWithoutDeprecatedOptions(options);
    o.addOption(SAVEPOINT_PATH_OPTION);
    o.addOption(SAVEPOINT_ALLOW_NON_RESTORED_OPTION);
    return getJobManagerAddressOption(o);
}
Also used : Options(org.apache.commons.cli.Options)

Example 93 with Options

use of org.apache.commons.cli.Options in project flink by apache.

the class CliFrontendParser method printHelpForCancel.

public static void printHelpForCancel() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLeftPadding(5);
    formatter.setWidth(80);
    System.out.println("\nAction \"cancel\" cancels a running program.");
    System.out.println("\n  Syntax: cancel [OPTIONS] <Job ID>");
    formatter.setSyntaxPrefix("  \"cancel\" action options:");
    formatter.printHelp(" ", getCancelOptionsWithoutDeprecatedOptions(new Options()));
    printCustomCliOptions(formatter, false);
    System.out.println();
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options)

Example 94 with Options

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

the class HAAdmin method runCmd.

protected int runCmd(String[] argv) throws Exception {
    if (argv.length < 1) {
        printUsage(errOut);
        return -1;
    }
    String cmd = argv[0];
    if (!cmd.startsWith("-")) {
        errOut.println("Bad command '" + cmd + "': expected command starting with '-'");
        printUsage(errOut);
        return -1;
    }
    if (!USAGE.containsKey(cmd)) {
        errOut.println(cmd.substring(1) + ": Unknown command");
        printUsage(errOut);
        return -1;
    }
    Options opts = new Options();
    // Add command-specific options
    if ("-failover".equals(cmd)) {
        addFailoverCliOpts(opts);
    }
    if ("-transitionToActive".equals(cmd)) {
        addTransitionToActiveCliOpts(opts);
    }
    // Mutative commands take FORCEMANUAL option
    if ("-transitionToActive".equals(cmd) || "-transitionToStandby".equals(cmd) || "-failover".equals(cmd)) {
        opts.addOption(FORCEMANUAL, false, "force manual control even if auto-failover is enabled");
    }
    CommandLine cmdLine = parseOpts(cmd, opts, argv);
    if (cmdLine == null) {
        // error already printed
        return -1;
    }
    if (cmdLine.hasOption(FORCEMANUAL)) {
        if (!confirmForceManual()) {
            LOG.fatal("Aborted");
            return -1;
        }
        // Instruct the NNs to honor this request even if they're
        // configured for manual failover.
        requestSource = RequestSource.REQUEST_BY_USER_FORCED;
    }
    if ("-transitionToActive".equals(cmd)) {
        return transitionToActive(cmdLine);
    } else if ("-transitionToStandby".equals(cmd)) {
        return transitionToStandby(cmdLine);
    } else if ("-failover".equals(cmd)) {
        return failover(cmdLine);
    } else if ("-getServiceState".equals(cmd)) {
        return getServiceState(cmdLine);
    } else if ("-getAllServiceState".equals(cmd)) {
        return getAllServiceState();
    } else if ("-checkHealth".equals(cmd)) {
        return checkHealth(cmdLine);
    } else if ("-help".equals(cmd)) {
        return help(argv);
    } else {
        // would be a coding error
        throw new AssertionError("Should not get here, command: " + cmd);
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine)

Example 95 with Options

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

the class NodeInfo method main.

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {
    GenericOptionsParser genericParser = new GenericOptionsParser(args);
    String[] remainingArgs = genericParser.getRemainingArgs();
    Option conf = OptionBuilder.hasArg().create("conffile");
    Option help = OptionBuilder.withLongOpt("help").create('h');
    Options opts = new Options().addOption(conf).addOption(help);
    CommandLineParser specificParser = new GnuParser();
    CommandLine cmd = null;
    try {
        cmd = specificParser.parse(opts, remainingArgs);
    } catch (MissingArgumentException e) {
        terminate(1, "No argument specified for -conffile option");
    } catch (ParseException e) {
        terminate(1, USAGE);
    }
    if (cmd == null) {
        terminate(1, "Failed to parse options");
    }
    if (cmd.hasOption('h')) {
        terminate(0, USAGE);
    }
    List<File> files = new ArrayList<File>();
    if (cmd.hasOption("conffile")) {
        String[] values = cmd.getOptionValues("conffile");
        for (String value : values) {
            File confFile = new File(value);
            if (confFile.isFile()) {
                files.add(confFile);
            } else if (confFile.isDirectory()) {
                for (File file : listFiles(confFile)) {
                    files.add(file);
                }
            } else {
                terminate(1, confFile.getAbsolutePath() + " is neither a file nor directory");
            }
        }
    } else {
        String confDirName = System.getenv(HADOOP_CONF_DIR);
        if (confDirName == null) {
            terminate(1, HADOOP_CONF_DIR + " is not defined");
        }
        File confDir = new File(confDirName);
        if (!confDir.isDirectory()) {
            terminate(1, HADOOP_CONF_DIR + " is not a directory");
        }
        files = Arrays.asList(listFiles(confDir));
    }
    if (files.isEmpty()) {
        terminate(1, "No input file to validate");
    }
    boolean ok = true;
    for (File file : files) {
        String path = file.getAbsolutePath();
        List<String> errors = checkConf(new FileInputStream(file));
        if (errors.isEmpty()) {
            System.out.println(path + ": valid");
        } else {
            ok = false;
            System.err.println(path + ":");
            for (String error : errors) {
                System.err.println("\t" + error);
            }
        }
    }
    if (ok) {
        System.out.println("OK");
    } else {
        terminate(1, "Invalid file exists");
    }
}
Also used : Options(org.apache.commons.cli.Options) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) GnuParser(org.apache.commons.cli.GnuParser) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File)

Aggregations

Options (org.apache.commons.cli.Options)1086 CommandLine (org.apache.commons.cli.CommandLine)557 CommandLineParser (org.apache.commons.cli.CommandLineParser)382 ParseException (org.apache.commons.cli.ParseException)341 Option (org.apache.commons.cli.Option)325 HelpFormatter (org.apache.commons.cli.HelpFormatter)275 GnuParser (org.apache.commons.cli.GnuParser)207 DefaultParser (org.apache.commons.cli.DefaultParser)166 Test (org.junit.Test)148 PosixParser (org.apache.commons.cli.PosixParser)135 IOException (java.io.IOException)118 File (java.io.File)97 OptionGroup (org.apache.commons.cli.OptionGroup)56 DMLScript (org.apache.sysml.api.DMLScript)56 Path (org.apache.hadoop.fs.Path)54 ArrayList (java.util.ArrayList)38 BasicParser (org.apache.commons.cli.BasicParser)36 Properties (java.util.Properties)33 Configuration (org.apache.hadoop.conf.Configuration)31 FileInputStream (java.io.FileInputStream)29