Search in sources :

Example 26 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project WSPerfLab by Netflix-Skunkworks.

the class WSClient method main.

public static void main(String[] rawArgs) {
    Options options = new Options();
    options.addOption("j", false, "output JSON");
    options.addOption("o", true, "output file path");
    options.addOption("p", "port", true, "port");
    options.addOption("h", "host", true, "host");
    options.addOption("f", "step", true, "first step");
    options.addOption("d", "duration", true, "duration");
    options.addOption("q", "query", true, "query");
    options.addOption("s", "stepsize", true, "step size");
    CommandLineParser parser = new BasicParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, rawArgs);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
    WSClient client = null;
    try {
        String host = "localhost";
        if (cmd.hasOption('h')) {
            host = cmd.getOptionValue('h');
        }
        int port = 8976;
        if (cmd.hasOption('p')) {
            port = Integer.parseInt(cmd.getOptionValue('p'));
        }
        int firstStep = 1;
        if (cmd.hasOption('f')) {
            firstStep = Integer.parseInt(cmd.getOptionValue('f'));
        }
        int stepSize = 200;
        if (cmd.hasOption('s')) {
            stepSize = Integer.parseInt(cmd.getOptionValue('s'));
        }
        int duration = 30;
        if (cmd.hasOption('d')) {
            duration = Integer.parseInt(cmd.getOptionValue('d'));
        }
        String query = "/?id=12345";
        if (cmd.hasOption('q')) {
            query = cmd.getOptionValue('q');
        }
        client = new WSClient(host, port, firstStep, stepSize, duration, query);
        if (cmd.hasOption('j'))
            client.setEnableJsonLogging(true);
        if (cmd.hasOption("o"))
            client.setOutputPath(cmd.getOptionValue("o"));
    } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
    }
    client.startMonitoring();
    client.startLoad().toBlocking().last();
}
Also used : Options(org.apache.commons.cli.Options) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PoolExhaustedException(io.reactivex.netty.client.PoolExhaustedException) ParseException(org.apache.commons.cli.ParseException)

Example 27 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project Apktool by iBotPeaches.

the class Main method main.

public static void main(String[] args) throws IOException, InterruptedException, BrutException {
    // set verbosity default
    Verbosity verbosity = Verbosity.NORMAL;
    // cli parser
    CommandLineParser parser = new PosixParser();
    CommandLine commandLine;
    // load options
    _Options();
    try {
        commandLine = parser.parse(allOptions, args, false);
    } catch (ParseException ex) {
        System.err.println(ex.getMessage());
        usage();
        return;
    }
    // check for verbose / quiet
    if (commandLine.hasOption("-v") || commandLine.hasOption("--verbose")) {
        verbosity = Verbosity.VERBOSE;
    } else if (commandLine.hasOption("-q") || commandLine.hasOption("--quiet")) {
        verbosity = Verbosity.QUIET;
    }
    setupLogging(verbosity);
    // check for advance mode
    if (commandLine.hasOption("advance") || commandLine.hasOption("advanced")) {
        setAdvanceMode(true);
    }
    // @todo use new ability of apache-commons-cli to check hasOption for non-prefixed items
    boolean cmdFound = false;
    for (String opt : commandLine.getArgs()) {
        if (opt.equalsIgnoreCase("d") || opt.equalsIgnoreCase("decode")) {
            cmdDecode(commandLine);
            cmdFound = true;
        } else if (opt.equalsIgnoreCase("b") || opt.equalsIgnoreCase("build")) {
            cmdBuild(commandLine);
            cmdFound = true;
        } else if (opt.equalsIgnoreCase("if") || opt.equalsIgnoreCase("install-framework")) {
            cmdInstallFramework(commandLine);
            cmdFound = true;
        } else if (opt.equalsIgnoreCase("empty-framework-dir")) {
            cmdEmptyFrameworkDirectory(commandLine);
            cmdFound = true;
        } else if (opt.equalsIgnoreCase("publicize-resources")) {
            cmdPublicizeResources(commandLine);
            cmdFound = true;
        }
    }
    // if no commands ran, run the version / usage check.
    if (cmdFound == false) {
        if (commandLine.hasOption("version")) {
            _version();
        } else {
            usage();
        }
    }
}
Also used : 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 28 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project pinot by linkedin.

the class FileBasedServer method processCommandLineArgs.

private static void processCommandLineArgs(String[] cliArgs) throws ParseException {
    CommandLineParser cliParser = new GnuParser();
    Options cliOptions = buildCommandLineOptions();
    CommandLine cmd = cliParser.parse(cliOptions, cliArgs, true);
    if (!cmd.hasOption(SERVER_CONFIG_OPT_NAME) || !cmd.hasOption(SERVER_PORT_OPT_NAME)) {
        System.err.println("Missing required arguments !!");
        System.err.println(cliOptions);
        throw new RuntimeException("Missing required arguments !!");
    }
    _serverConfigPath = cmd.getOptionValue(SERVER_CONFIG_OPT_NAME);
    _serverPort = Integer.parseInt(cmd.getOptionValue(SERVER_PORT_OPT_NAME));
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Example 29 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project pinot by linkedin.

the class ScatterGatherPerfServer method main.

/**
   * @param args
   */
public static void main(String[] args) throws Exception {
    CommandLineParser cliParser = new GnuParser();
    Options cliOptions = buildCommandLineOptions();
    CommandLine cmd = cliParser.parse(cliOptions, args, true);
    if (!cmd.hasOption(RESPONSE_SIZE_OPT_NAME) || !cmd.hasOption(SERVER_PORT_OPT_NAME)) {
        System.err.println("Missing required arguments !!");
        System.err.println(cliOptions);
        throw new RuntimeException("Missing required arguments !!");
    }
    int responseSize = Integer.parseInt(cmd.getOptionValue(RESPONSE_SIZE_OPT_NAME));
    int serverPort = Integer.parseInt(cmd.getOptionValue(SERVER_PORT_OPT_NAME));
    // 2ms latency
    ScatterGatherPerfServer server = new ScatterGatherPerfServer(serverPort, responseSize, 2);
    server.run();
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Example 30 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project pinot by linkedin.

the class ScatterGatherPerfClient method main.

public static void main(String[] args) throws Exception {
    //Process Command Line to get config and port
    CommandLineParser cliParser = new GnuParser();
    Options cliOptions = buildCommandLineOptions();
    CommandLine cmd = cliParser.parse(cliOptions, args, true);
    if ((!cmd.hasOption(BROKER_CONFIG_OPT_NAME)) || (!cmd.hasOption(REQUEST_SIZE_OPT_NAME)) || (!cmd.hasOption(TABLE_NAME_OPT_NAME)) || (!cmd.hasOption(TABLE_NAME_OPT_NAME))) {
        System.err.println("Missing required arguments !!");
        System.err.println(cliOptions);
        throw new RuntimeException("Missing required arguments !!");
    }
    String brokerConfigPath = cmd.getOptionValue(BROKER_CONFIG_OPT_NAME);
    int requestSize = Integer.parseInt(cmd.getOptionValue(REQUEST_SIZE_OPT_NAME));
    int numRequests = Integer.parseInt(cmd.getOptionValue(NUM_REQUESTS_OPT_NAME));
    String resourceName = cmd.getOptionValue(TABLE_NAME_OPT_NAME);
    // build  brokerConf
    PropertiesConfiguration brokerConf = new PropertiesConfiguration();
    brokerConf.setDelimiterParsingDisabled(false);
    brokerConf.load(brokerConfigPath);
    RoutingTableConfig config = new RoutingTableConfig();
    config.init(brokerConf.subset(ROUTING_CFG_PREFIX));
    ScatterGatherPerfClient client = new ScatterGatherPerfClient(config, requestSize, resourceName, false, numRequests, 1, 1);
    client.run();
    System.out.println("Shutting down !!");
    client.shutdown();
    System.out.println("Shut down complete !!");
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) RoutingTableConfig(com.linkedin.pinot.transport.config.RoutingTableConfig) CommandLineParser(org.apache.commons.cli.CommandLineParser) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Aggregations

CommandLineParser (org.apache.commons.cli.CommandLineParser)265 CommandLine (org.apache.commons.cli.CommandLine)246 Options (org.apache.commons.cli.Options)206 ParseException (org.apache.commons.cli.ParseException)186 GnuParser (org.apache.commons.cli.GnuParser)158 HelpFormatter (org.apache.commons.cli.HelpFormatter)111 PosixParser (org.apache.commons.cli.PosixParser)61 Option (org.apache.commons.cli.Option)52 IOException (java.io.IOException)48 Path (org.apache.hadoop.fs.Path)42 File (java.io.File)41 DefaultParser (org.apache.commons.cli.DefaultParser)29 Job (org.apache.hadoop.mapreduce.Job)27 Configuration (org.apache.hadoop.conf.Configuration)19 FileInputStream (java.io.FileInputStream)16 Properties (java.util.Properties)15 ArrayList (java.util.ArrayList)14 BasicParser (org.apache.commons.cli.BasicParser)14 FileSystem (org.apache.hadoop.fs.FileSystem)12 URI (java.net.URI)10