Search in sources :

Example 96 with CommandLine

use of org.apache.commons.cli.CommandLine in project core by s4.

the class Adapter method main.

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException, InterruptedException {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c"));
    options.addOption(OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i"));
    options.addOption(OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t"));
    options.addOption(OptionBuilder.withArgName("userconfig").hasArg().withDescription("user-defined legacy data adapter configuration file").create("d"));
    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException pe) {
        System.err.println(pe.getLocalizedMessage());
        System.exit(1);
    }
    int instanceId = -1;
    if (commandLine.hasOption("i")) {
        String instanceIdStr = commandLine.getOptionValue("i");
        try {
            instanceId = Integer.parseInt(instanceIdStr);
        } catch (NumberFormatException nfe) {
            System.err.println("Bad instance id: %s" + instanceIdStr);
            System.exit(1);
        }
    }
    if (commandLine.hasOption("c")) {
        coreHome = commandLine.getOptionValue("c");
    }
    String configType = "typical";
    if (commandLine.hasOption("t")) {
        configType = commandLine.getOptionValue("t");
    }
    String userConfigFilename = null;
    if (commandLine.hasOption("d")) {
        userConfigFilename = commandLine.getOptionValue("d");
    }
    File userConfigFile = new File(userConfigFilename);
    if (!userConfigFile.isFile()) {
        System.err.println("Bad user configuration file: " + userConfigFilename);
        System.exit(1);
    }
    File coreHomeFile = new File(coreHome);
    if (!coreHomeFile.isDirectory()) {
        System.err.println("Bad core home: " + coreHome);
        System.exit(1);
    }
    if (instanceId > -1) {
        System.setProperty("instanceId", "" + instanceId);
    } else {
        System.setProperty("instanceId", "" + S4Util.getPID());
    }
    String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType;
    String configPath = configBase + File.separatorChar + "client_adapter_conf.xml";
    File configFile = new File(configPath);
    if (!configFile.exists()) {
        System.err.printf("adapter config file %s does not exist\n", configPath);
        System.exit(1);
    }
    // load adapter config xml
    ApplicationContext coreContext;
    coreContext = new FileSystemXmlApplicationContext("file:" + configPath);
    ApplicationContext context = coreContext;
    Adapter adapter = (Adapter) context.getBean("client_adapter");
    ApplicationContext appContext = new FileSystemXmlApplicationContext(new String[] { "file:" + userConfigFilename }, context);
    Map<?, ?> inputStubBeanMap = appContext.getBeansOfType(InputStub.class);
    Map<?, ?> outputStubBeanMap = appContext.getBeansOfType(OutputStub.class);
    if (inputStubBeanMap.size() == 0 && outputStubBeanMap.size() == 0) {
        System.err.println("No user-defined input/output stub beans");
        System.exit(1);
    }
    ArrayList<InputStub> inputStubs = new ArrayList<InputStub>(inputStubBeanMap.size());
    ArrayList<OutputStub> outputStubs = new ArrayList<OutputStub>(outputStubBeanMap.size());
    // add all input stubs
    for (Map.Entry<?, ?> e : inputStubBeanMap.entrySet()) {
        String beanName = (String) e.getKey();
        System.out.println("Adding InputStub " + beanName);
        inputStubs.add((InputStub) e.getValue());
    }
    // add all output stubs
    for (Map.Entry<?, ?> e : outputStubBeanMap.entrySet()) {
        String beanName = (String) e.getKey();
        System.out.println("Adding OutputStub " + beanName);
        outputStubs.add((OutputStub) e.getValue());
    }
    adapter.setInputStubs(inputStubs);
    adapter.setOutputStubs(outputStubs);
}
Also used : Options(org.apache.commons.cli.Options) GnuParser(org.apache.commons.cli.GnuParser) ArrayList(java.util.ArrayList) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) CommandLine(org.apache.commons.cli.CommandLine) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 97 with CommandLine

use of org.apache.commons.cli.CommandLine in project core by s4.

the class LoadGenerator method main.

public static void main(String[] args) {
    Options options = new Options();
    boolean warmUp = false;
    options.addOption(OptionBuilder.withArgName("rate").hasArg().withDescription("Rate (events per second)").create("r"));
    options.addOption(OptionBuilder.withArgName("display_rate").hasArg().withDescription("Display Rate at specified second boundary").create("d"));
    options.addOption(OptionBuilder.withArgName("start_boundary").hasArg().withDescription("Start boundary in seconds").create("b"));
    options.addOption(OptionBuilder.withArgName("run_for").hasArg().withDescription("Run for a specified number of seconds").create("x"));
    options.addOption(OptionBuilder.withArgName("cluster_manager").hasArg().withDescription("Cluster manager").create("z"));
    options.addOption(OptionBuilder.withArgName("sender_application_name").hasArg().withDescription("Sender application name").create("a"));
    options.addOption(OptionBuilder.withArgName("listener_application_name").hasArg().withDescription("Listener application name").create("g"));
    options.addOption(OptionBuilder.withArgName("sleep_overhead").hasArg().withDescription("Sleep overhead").create("o"));
    options.addOption(new Option("w", "Warm-up"));
    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        System.exit(1);
    }
    int expectedRate = 250;
    if (line.hasOption("r")) {
        try {
            expectedRate = Integer.parseInt(line.getOptionValue("r"));
        } catch (Exception e) {
            System.err.println("Bad expected rate specified " + line.getOptionValue("r"));
            System.exit(1);
        }
    }
    int displayRateIntervalSeconds = 20;
    if (line.hasOption("d")) {
        try {
            displayRateIntervalSeconds = Integer.parseInt(line.getOptionValue("d"));
        } catch (Exception e) {
            System.err.println("Bad display rate value specified " + line.getOptionValue("d"));
            System.exit(1);
        }
    }
    int startBoundary = 2;
    if (line.hasOption("b")) {
        try {
            startBoundary = Integer.parseInt(line.getOptionValue("b"));
        } catch (Exception e) {
            System.err.println("Bad start boundary value specified " + line.getOptionValue("b"));
            System.exit(1);
        }
    }
    int updateFrequency = 0;
    if (line.hasOption("f")) {
        try {
            updateFrequency = Integer.parseInt(line.getOptionValue("f"));
        } catch (Exception e) {
            System.err.println("Bad query udpdate frequency specified " + line.getOptionValue("f"));
            System.exit(1);
        }
        System.out.printf("Update frequency is %d\n", updateFrequency);
    }
    int runForTime = 0;
    if (line.hasOption("x")) {
        try {
            runForTime = Integer.parseInt(line.getOptionValue("x"));
        } catch (Exception e) {
            System.err.println("Bad run for time specified " + line.getOptionValue("x"));
            System.exit(1);
        }
        System.out.printf("Run for time is %d\n", runForTime);
    }
    String clusterManagerAddress = null;
    if (line.hasOption("z")) {
        clusterManagerAddress = line.getOptionValue("z");
    }
    String senderApplicationName = null;
    if (line.hasOption("a")) {
        senderApplicationName = line.getOptionValue("a");
    }
    String listenerApplicationName = null;
    if (line.hasOption("a")) {
        listenerApplicationName = line.getOptionValue("g");
    }
    if (listenerApplicationName == null) {
        listenerApplicationName = senderApplicationName;
    }
    long sleepOverheadMicros = -1;
    if (line.hasOption("o")) {
        try {
            sleepOverheadMicros = Long.parseLong(line.getOptionValue("o"));
        } catch (NumberFormatException e) {
            System.err.println("Bad sleep overhead specified " + line.getOptionValue("o"));
            System.exit(1);
        }
        System.out.printf("Specified sleep overhead is %d\n", sleepOverheadMicros);
    }
    if (line.hasOption("w")) {
        warmUp = true;
    }
    List loArgs = line.getArgList();
    if (loArgs.size() < 1) {
        System.err.println("No input file specified");
        System.exit(1);
    }
    String inputFilename = (String) loArgs.get(0);
    EventEmitter emitter = null;
    SerializerDeserializer serDeser = new KryoSerDeser();
    CommLayerEmitter clEmitter = new CommLayerEmitter();
    clEmitter.setAppName(senderApplicationName);
    clEmitter.setListenerAppName(listenerApplicationName);
    clEmitter.setClusterManagerAddress(clusterManagerAddress);
    clEmitter.setSenderId(String.valueOf(System.currentTimeMillis() / 1000));
    clEmitter.setSerDeser(serDeser);
    clEmitter.init();
    emitter = clEmitter;
    long endTime = 0;
    if (runForTime > 0) {
        endTime = System.currentTimeMillis() + (runForTime * 1000);
    }
    LoadGenerator loadGenerator = new LoadGenerator();
    loadGenerator.setInputFilename(inputFilename);
    loadGenerator.setEventEmitter(clEmitter);
    loadGenerator.setDisplayRateInterval(displayRateIntervalSeconds);
    loadGenerator.setExpectedRate(expectedRate);
    loadGenerator.run();
    System.exit(0);
}
Also used : Options(org.apache.commons.cli.Options) GnuParser(org.apache.commons.cli.GnuParser) JSONException(org.json.JSONException) ParseException(org.apache.commons.cli.ParseException) KryoSerDeser(io.s4.serialize.KryoSerDeser) CommandLine(org.apache.commons.cli.CommandLine) EventEmitter(io.s4.emitter.EventEmitter) SerializerDeserializer(io.s4.serialize.SerializerDeserializer) Option(org.apache.commons.cli.Option) ArrayList(java.util.ArrayList) List(java.util.List) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) CommLayerEmitter(io.s4.emitter.CommLayerEmitter)

Example 98 with CommandLine

use of org.apache.commons.cli.CommandLine in project f5less by sky87.

the class TheBuilder method main.

public static void main(String[] argv) throws Exception {
    Options options = new Options();
    options.addOption("js", false, "Create f5less.js");
    options.addOption("p", "port", true, "ws:reload websocket server port");
    options.addOption("h", "host", true, "ws:reload websocket server host");
    options.addOption("d", "debounce", true, "debouncing for commands");
    CommandLine cmdLine = new PosixParser().parse(options, argv);
    String[] args = cmdLine.getArgs();
    if (cmdLine.hasOption("js")) {
        Files.copy(TheBuilder.class.getClassLoader().getResourceAsStream("f5less.js"), Paths.get("./f5less.js"), StandardCopyOption.REPLACE_EXISTING);
        System.out.println("\n  f5less.js created...\n  put the following\n" + "     <script type=\"text/javascript\" src=\"f5less.js\"></script>\n" + "     <script type=\"text/javascript\">f5less.connect()</script>\n" + "  in the page for which you want automatic reloading (assuming 'f5less.js' is in the same directory)\n");
    }
    if (args.length < 2) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("f5less [options] path1 cmd1 path2 cmd2 ...", options);
        System.exit(-1);
    }
    final List<String> reloadPaths = new LinkedList<String>();
    final int commandsDebounce = Integer.parseInt(cmdLine.getOptionValue("d", "100"));
    for (int i = 0; i < args.length / 2; i++) {
        final String path = args[i * 2];
        final String rawCmd = args[i * 2 + 1];
        if (rawCmd.equals("ws:reload"))
            reloadPaths.add(path);
        else
            Watcher.register(path, new CommandListener(path, rawCmd, commandsDebounce));
    }
    ReloadServer reloadServer = null;
    if (!reloadPaths.isEmpty()) {
        reloadServer = new ReloadServer(cmdLine.getOptionValue("h", "localhost"), Integer.parseInt(cmdLine.getOptionValue("p", "9999")), commandsDebounce + 50);
        reloadServer.monitor(reloadPaths);
    }
    System.out.println("Press enter to exit...");
    System.in.read();
    if (reloadServer != null)
        reloadServer.stop();
    Watcher.stop();
    CommandListener.stop();
    System.out.println("Bye bye");
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) LinkedList(java.util.LinkedList)

Example 99 with CommandLine

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

the class CliFrontendParser method parseRunCommand.

// --------------------------------------------------------------------------------------------
//  Line Parsing
// --------------------------------------------------------------------------------------------
public static RunOptions parseRunCommand(String[] args) throws CliArgsException {
    try {
        DefaultParser parser = new DefaultParser();
        CommandLine line = parser.parse(RUN_OPTIONS, args, true);
        return new RunOptions(line);
    } catch (ParseException e) {
        throw new CliArgsException(e.getMessage());
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 100 with CommandLine

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

the class CliFrontendParser method parseSavepointCommand.

public static SavepointOptions parseSavepointCommand(String[] args) throws CliArgsException {
    try {
        DefaultParser parser = new DefaultParser();
        CommandLine line = parser.parse(SAVEPOINT_OPTIONS, args, false);
        return new SavepointOptions(line);
    } catch (ParseException e) {
        throw new CliArgsException(e.getMessage());
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

CommandLine (org.apache.commons.cli.CommandLine)968 Options (org.apache.commons.cli.Options)560 ParseException (org.apache.commons.cli.ParseException)464 CommandLineParser (org.apache.commons.cli.CommandLineParser)459 HelpFormatter (org.apache.commons.cli.HelpFormatter)259 GnuParser (org.apache.commons.cli.GnuParser)230 DefaultParser (org.apache.commons.cli.DefaultParser)213 PosixParser (org.apache.commons.cli.PosixParser)177 File (java.io.File)165 IOException (java.io.IOException)162 Test (org.junit.Test)144 Option (org.apache.commons.cli.Option)131 ArrayList (java.util.ArrayList)63 Path (org.apache.hadoop.fs.Path)60 BasicParser (org.apache.commons.cli.BasicParser)50 Configuration (org.apache.hadoop.conf.Configuration)41 Configuration (org.apache.flink.configuration.Configuration)37 HashMap (java.util.HashMap)34 List (java.util.List)34 Properties (java.util.Properties)33