Search in sources :

Example 16 with ParseException

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

the class JMXGet method parseArgs.

/**
   * parse args
   */
private static CommandLine parseArgs(Options opts, String... args) throws IllegalArgumentException {
    OptionBuilder.withArgName("NameNode|DataNode");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("specify jmx service (NameNode by default)");
    Option jmx_service = OptionBuilder.create("service");
    OptionBuilder.withArgName("mbean server");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("specify mbean server (localhost by default)");
    Option jmx_server = OptionBuilder.create("server");
    OptionBuilder.withDescription("print help");
    Option jmx_help = OptionBuilder.create("help");
    OptionBuilder.withArgName("mbean server port");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("specify mbean server port, " + "if missing - it will try to connect to MBean Server in the same VM");
    Option jmx_port = OptionBuilder.create("port");
    OptionBuilder.withArgName("VM's connector url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("connect to the VM on the same machine;" + "\n use:\n jstat -J-Djstat.showUnsupported=true -snap <vmpid> | " + "grep sun.management.JMXConnectorServer.address\n " + "to find the url");
    Option jmx_localVM = OptionBuilder.create("localVM");
    opts.addOption(jmx_server);
    opts.addOption(jmx_help);
    opts.addOption(jmx_service);
    opts.addOption(jmx_port);
    opts.addOption(jmx_localVM);
    CommandLine commandLine = null;
    CommandLineParser parser = new GnuParser();
    try {
        commandLine = parser.parse(opts, args, true);
    } catch (ParseException e) {
        printUsage(opts);
        throw new IllegalArgumentException("invalid args: " + e.getMessage());
    }
    return commandLine;
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 17 with ParseException

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

the class OfflineEditsViewer method run.

/**
   * Main entry point for ToolRunner (see ToolRunner docs)
   *
   * @param argv The parameters passed to this program.
   * @return 0 on success, non zero on error.
   */
@Override
public int run(String[] argv) throws Exception {
    Options options = buildOptions();
    if (argv.length == 0) {
        printHelp();
        return 0;
    }
    // print help and exit with zero exit code
    if (argv.length == 1 && isHelpOption(argv[0])) {
        printHelp();
        return 0;
    }
    CommandLineParser parser = new PosixParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, argv);
    } catch (ParseException e) {
        System.out.println("Error parsing command-line options: " + e.getMessage());
        printHelp();
        return -1;
    }
    if (cmd.hasOption("h")) {
        // print help and exit with non zero exit code since
        // it is not expected to give help and other options together.
        printHelp();
        return -1;
    }
    String inputFileName = cmd.getOptionValue("i");
    String outputFileName = cmd.getOptionValue("o");
    String processor = cmd.getOptionValue("p");
    if (processor == null) {
        processor = defaultProcessor;
    }
    Flags flags = new Flags();
    if (cmd.hasOption("r")) {
        flags.setRecoveryMode();
    }
    if (cmd.hasOption("f")) {
        flags.setFixTxIds();
    }
    if (cmd.hasOption("v")) {
        flags.setPrintToScreen();
    }
    return go(inputFileName, outputFileName, processor, flags, null);
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 18 with ParseException

use of org.apache.commons.cli.ParseException in project hive by apache.

the class StreamingIntegrationTester method main.

public static void main(String[] args) {
    try {
        LogUtils.initHiveLog4j();
    } catch (LogUtils.LogInitializationException e) {
        System.err.println("Unable to initialize log4j " + StringUtils.stringifyException(e));
        System.exit(-1);
    }
    Options options = new Options();
    options.addOption(OptionBuilder.hasArg().withArgName("abort-pct").withDescription("Percentage of transactions to abort, defaults to 5").withLongOpt("abortpct").create('a'));
    options.addOption(OptionBuilder.hasArgs().withArgName("column-names").withDescription("column names of table to write to").withLongOpt("columns").withValueSeparator(',').isRequired().create('c'));
    options.addOption(OptionBuilder.hasArg().withArgName("database").withDescription("Database of table to write to").withLongOpt("database").isRequired().create('d'));
    options.addOption(OptionBuilder.hasArg().withArgName("frequency").withDescription("How often to commit a transaction, in seconds, defaults to 1").withLongOpt("frequency").create('f'));
    options.addOption(OptionBuilder.hasArg().withArgName("iterations").withDescription("Number of batches to write, defaults to 10").withLongOpt("num-batches").create('i'));
    options.addOption(OptionBuilder.hasArg().withArgName("metastore-uri").withDescription("URI of Hive metastore").withLongOpt("metastore-uri").isRequired().create('m'));
    options.addOption(OptionBuilder.hasArg().withArgName("num_transactions").withDescription("Number of transactions per batch, defaults to 100").withLongOpt("num-txns").create('n'));
    options.addOption(OptionBuilder.hasArgs().withArgName("partition-values").withDescription("partition values, must be provided in order of partition columns, " + "if not provided table is assumed to not be partitioned").withLongOpt("partition").withValueSeparator(',').create('p'));
    options.addOption(OptionBuilder.hasArg().withArgName("records-per-transaction").withDescription("records to write in each transaction, defaults to 100").withLongOpt("records-per-txn").withValueSeparator(',').create('r'));
    options.addOption(OptionBuilder.hasArgs().withArgName("column-types").withDescription("column types, valid values are string, int, float, decimal, date, " + "datetime").withLongOpt("schema").withValueSeparator(',').isRequired().create('s'));
    options.addOption(OptionBuilder.hasArg().withArgName("table").withDescription("Table to write to").withLongOpt("table").isRequired().create('t'));
    options.addOption(OptionBuilder.hasArg().withArgName("num-writers").withDescription("Number of writers to create, defaults to 2").withLongOpt("writers").create('w'));
    options.addOption(OptionBuilder.hasArg(false).withArgName("pause").withDescription("Wait on keyboard input after commit & batch close. default: disabled").withLongOpt("pause").create('x'));
    Parser parser = new GnuParser();
    CommandLine cmdline = null;
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        usage(options);
    }
    boolean pause = cmdline.hasOption('x');
    String db = cmdline.getOptionValue('d');
    String table = cmdline.getOptionValue('t');
    String uri = cmdline.getOptionValue('m');
    int txnsPerBatch = Integer.parseInt(cmdline.getOptionValue('n', "100"));
    int writers = Integer.parseInt(cmdline.getOptionValue('w', "2"));
    int batches = Integer.parseInt(cmdline.getOptionValue('i', "10"));
    int recordsPerTxn = Integer.parseInt(cmdline.getOptionValue('r', "100"));
    int frequency = Integer.parseInt(cmdline.getOptionValue('f', "1"));
    int ap = Integer.parseInt(cmdline.getOptionValue('a', "5"));
    float abortPct = ((float) ap) / 100.0f;
    String[] partVals = cmdline.getOptionValues('p');
    String[] cols = cmdline.getOptionValues('c');
    String[] types = cmdline.getOptionValues('s');
    StreamingIntegrationTester sit = new StreamingIntegrationTester(db, table, uri, txnsPerBatch, writers, batches, recordsPerTxn, frequency, abortPct, partVals, cols, types, pause);
    sit.go();
}
Also used : Options(org.apache.commons.cli.Options) GnuParser(org.apache.commons.cli.GnuParser) Parser(org.apache.commons.cli.Parser) GnuParser(org.apache.commons.cli.GnuParser) CommandLine(org.apache.commons.cli.CommandLine) LogUtils(org.apache.hadoop.hive.common.LogUtils) ParseException(org.apache.commons.cli.ParseException)

Example 19 with ParseException

use of org.apache.commons.cli.ParseException in project opennms by OpenNMS.

the class VmwareConfigBuilder method main.

public static void main(String[] args) throws ParseException {
    String hostname = null;
    String username = null;
    String password = null;
    String rrdRepository = null;
    final Options options = new Options();
    options.addOption("rrdRepository", true, "set rrdRepository path for generated config files, default: '/opt/opennms/share/rrd/snmp/'");
    final CommandLineParser parser = new PosixParser();
    final CommandLine cmd = parser.parse(options, args);
    @SuppressWarnings("unchecked") List<String> arguments = (List<String>) cmd.getArgList();
    if (arguments.size() < 3) {
        usage(options, cmd);
        System.exit(1);
    }
    hostname = arguments.remove(0);
    username = arguments.remove(0);
    password = arguments.remove(0);
    if (cmd.hasOption("rrdRepository")) {
        rrdRepository = cmd.getOptionValue("rrdRepository");
    } else {
        rrdRepository = "/opt/opennms/share/rrd/snmp/";
    }
    TrustManager[] trustAllCerts = new TrustManager[] { new AnyServerX509TrustManager() };
    SSLContext sc = null;
    try {
        sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, null);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HostnameVerifier hv = new HostnameVerifier() {

        @Override
        public boolean verify(String urlHostName, SSLSession session) {
            return true;
        }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
    VmwareConfigBuilder vmwareConfigBuilder;
    vmwareConfigBuilder = new VmwareConfigBuilder(hostname, username, password);
    try {
        vmwareConfigBuilder.generateData(rrdRepository);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Options(org.apache.commons.cli.Options) PosixParser(org.apache.commons.cli.PosixParser) SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) ParseException(org.apache.commons.cli.ParseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) TrustManager(javax.net.ssl.TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier) CommandLine(org.apache.commons.cli.CommandLine) List(java.util.List) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Example 20 with ParseException

use of org.apache.commons.cli.ParseException in project opennms by OpenNMS.

the class SpectrumTrapImporter method configureArgs.

private void configureArgs(String[] argv) {
    Options opts = new Options();
    opts.addOption("d", "dir", true, "Directory where Spectrum custom events are located");
    opts.addOption("t", "model-type-asset-field", true, "Name of asset field containing equivalent of Spectrum model type.  Defaults to 'manufacturer'.");
    opts.addOption("u", "base-uei", true, "Base value for UEI of generated OpenNMS events.  Defaults to 'uei.opennms.org/import/Spectrum'.");
    opts.addOption("f", "output-file", true, "File to which OpenNMS events will be written.  Defaults to standard output.");
    opts.addOption("k", "key", true, "Middle part of reduction- and clear-key, after UEI and before discriminators.  Defaults to '%dpname%:%nodeid%:%interface%'.");
    CommandLineParser parser = new GnuParser();
    try {
        CommandLine cmd = parser.parse(opts, argv);
        if (cmd.hasOption('d')) {
            m_customEventsDir = new FileSystemResource(cmd.getOptionValue('d'));
        }
        if (cmd.hasOption('t')) {
            m_modelTypeAssetField = cmd.getOptionValue('t');
        } else {
            m_modelTypeAssetField = "manufacturer";
        }
        if (cmd.hasOption('u')) {
            m_baseUei = cmd.getOptionValue('u');
        } else {
            m_baseUei = "uei.opennms.org/import/Spectrum";
        }
        if (cmd.hasOption('f')) {
            m_outputWriter = new PrintWriter(new FileSystemResource(cmd.getOptionValue('f')).getFile());
        } else {
            m_outputWriter = new PrintWriter(System.out);
        }
        if (cmd.hasOption('k')) {
            m_reductionKeyBody = cmd.getOptionValue('k');
        } else {
            m_reductionKeyBody = "%dpname%:%nodeid%:%interface%";
        }
    } catch (ParseException pe) {
        printHelp("Failed to parse command line options");
        System.exit(1);
    } catch (FileNotFoundException fnfe) {
        printHelp("Custom events input directory does not seem to exist");
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) FileNotFoundException(java.io.FileNotFoundException) CommandLineParser(org.apache.commons.cli.CommandLineParser) FileSystemResource(org.springframework.core.io.FileSystemResource) ParseException(org.apache.commons.cli.ParseException) PrintWriter(java.io.PrintWriter)

Aggregations

ParseException (org.apache.commons.cli.ParseException)587 CommandLine (org.apache.commons.cli.CommandLine)489 CommandLineParser (org.apache.commons.cli.CommandLineParser)381 Options (org.apache.commons.cli.Options)370 DefaultParser (org.apache.commons.cli.DefaultParser)220 HelpFormatter (org.apache.commons.cli.HelpFormatter)205 GnuParser (org.apache.commons.cli.GnuParser)173 IOException (java.io.IOException)124 Option (org.apache.commons.cli.Option)109 File (java.io.File)90 PosixParser (org.apache.commons.cli.PosixParser)65 Path (org.apache.hadoop.fs.Path)50 ArrayList (java.util.ArrayList)42 Properties (java.util.Properties)35 BasicParser (org.apache.commons.cli.BasicParser)32 FileInputStream (java.io.FileInputStream)29 Job (org.apache.hadoop.mapreduce.Job)27 Configuration (org.apache.hadoop.conf.Configuration)26 List (java.util.List)25 URI (java.net.URI)21