Java Code Examples for org.apache.commons.cli.CommandLineParser

The following examples show how to use org.apache.commons.cli.CommandLineParser. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public static void main(String[] args) {
    Options options = new Options();
    options.addOption("t", "to", true, "Providers xml to migrate to.");
    CommandLineParser parser = new DefaultParser();

    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException e) {
        log.error("Unable to parse command line.", e);

        new HelpFormatter().printHelp("persistence-toolkit [args]", options);

        System.exit(PARSE_EXCEPTION);
    }

    NiFiRegistryProperties fromProperties = NiFiRegistry.initializeProperties(NiFiRegistry.getMasterKeyProvider());

    DataSource dataSource = new DataSourceFactory(fromProperties).getDataSource();
    DatabaseMetadataService fromMetadataService = new DatabaseMetadataService(new JdbcTemplate(dataSource));
    FlowPersistenceProvider fromPersistenceProvider = createFlowPersistenceProvider(fromProperties, dataSource);
    FlowPersistenceProvider toPersistenceProvider = createFlowPersistenceProvider(createToProperties(commandLine, fromProperties), dataSource);

    new FlowPersistenceProviderMigrator().doMigrate(fromMetadataService, fromPersistenceProvider, toPersistenceProvider);
}
 
Example 2
Source Project: singer   Source File: FileSystemEventReader.java    License: Apache License 2.0 6 votes vote down vote up
private static CommandLine parseCommandLine(String[] args) {
  Option path = new Option(PATH, true, "path to be monitored");
  Option poll_interval_ms =
      new Option(POLL_INTERVAL_MS, true, "interval in milliseconds to poll for file system events");
  options.addOption(path).addOption(poll_interval_ms);

  if (args.length < 1) {
    printUsageAndExit();
  }
  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
Example 3
Source Project: flink   Source File: MesosSessionClusterEntrypoint.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	// startup checks and logging
	EnvironmentInformation.logEnvironmentInfo(LOG, MesosSessionClusterEntrypoint.class.getSimpleName(), args);
	SignalHandler.register(LOG);
	JvmShutdownSafeguard.installAsShutdownHook(LOG);

	// load configuration incl. dynamic properties
	CommandLineParser parser = new PosixParser();
	CommandLine cmd;
	try {
		cmd = parser.parse(ALL_OPTIONS, args);
	}
	catch (Exception e){
		LOG.error("Could not parse the command-line options.", e);
		System.exit(STARTUP_FAILURE_RETURN_CODE);
		return;
	}

	Configuration dynamicProperties = BootstrapTools.parseDynamicProperties(cmd);
	Configuration configuration = MesosEntrypointUtils.loadConfiguration(dynamicProperties, LOG);

	MesosSessionClusterEntrypoint clusterEntrypoint = new MesosSessionClusterEntrypoint(configuration, dynamicProperties);

	ClusterEntrypoint.runClusterEntrypoint(clusterEntrypoint);
}
 
Example 4
Source Project: rocketmq-4.3.0   Source File: ServerUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static CommandLine parseCmdLine(final String appName, String[] args, Options options,
    CommandLineParser parser) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp(appName, options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp(appName, options, true);
    }

    return commandLine;
}
 
Example 5
Source Project: hadoop   Source File: TestTFileSeek.java    License: Apache License 2.0 6 votes vote down vote up
public MyOptions(String[] args) {
  seed = System.nanoTime();

  try {
    Options opts = buildOptions();
    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(opts, args, true);
    processOptions(line, opts);
    validateOptions();
  }
  catch (ParseException e) {
    System.out.println(e.getMessage());
    System.out.println("Try \"--help\" option for details.");
    setStopProceed();
  }
}
 
Example 6
@Test
public void testCustomProvider() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(new Options(), new String[]{});
    final ProtocolFactory factory = new ProtocolFactory(new LinkedHashSet<>(Collections.singletonList(new SwiftProtocol())));
    final Profile rackspace = new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/Rackspace US.cyberduckprofile"));
    assertEquals(new SwiftProtocol(), rackspace.getProtocol());
    factory.register(rackspace);
    final Profile generic = new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/Openstack Swift (Keystone 2).cyberduckprofile"));
    assertEquals(new SwiftProtocol(), generic.getProtocol());
    factory.register(generic);
    assertEquals(rackspace, new CommandLineUriParser(input, factory).parse("rackspace://container//").getProtocol());
    assertEquals(0, new Host(rackspace, "identity.api.rackspacecloud.com", 443, "/container")
        .compareTo(new CommandLineUriParser(input, factory).parse("rackspace://container/")));

    assertEquals(generic, new CommandLineUriParser(input, factory).parse("swift://auth.cloud.ovh.net/container/").getProtocol());
    assertEquals(0, new Host(generic, "auth.cloud.ovh.net", 443, "/container")
        .compareTo(new CommandLineUriParser(input, factory).parse("swift://auth.cloud.ovh.net/container/")));
}
 
Example 7
Source Project: doctorkafka   Source File: DoctorKafkaActionWriter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  Usage:  KafkaWriter  \
 *             --zookeeper zookeeper001:2181/cluster1 --topic kafka_test    \
 *             --message "this is a test message"
 */
private static CommandLine parseCommandLine(String[] args) {
  Option zookeeper = new Option(ZOOKEEPER, true, "zookeeper connection string");
  Option topic = new Option(TOPIC, true, "action report topic name");
  Option message = new Option(MESSAGE, true, "messags that writes to kafka");
  options.addOption(zookeeper).addOption(topic).addOption(message);

  if (args.length < 6) {
    printUsageAndExit();
  }

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
Example 8
Source Project: act   Source File: CLIUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
public CommandLine parseCommandLine(String[] args) {
  CommandLine cl = null;
  try {
    CommandLineParser parser = new DefaultParser();
    cl = parser.parse(opts, args);
  } catch (ParseException e) {
    LOGGER.error("Argument parsing failed: %s\n", e.getMessage());
    HELP_FORMATTER.printHelp(callingClass.getCanonicalName(), helpMessage, opts, null, true);
    System.exit(1);
  }

  if (cl.hasOption("help")) {
    HELP_FORMATTER.printHelp(callingClass.getCanonicalName(), helpMessage, opts, null, true);
    System.exit(0);
  }

  commandLine = cl;

  return cl;
}
 
Example 9
Source Project: capillary   Source File: EcdsaKeyPairGenerator.java    License: Apache License 2.0 6 votes vote down vote up
private static CommandLine generateCommandLine(String[] commandLineArguments)
    throws ParseException {
  Option ecdsaPublicKeyPath = Option.builder()
      .longOpt(ECDSA_PUBLIC_KEY_PATH_OPTION)
      .desc("The path to store ECDSA public key.")
      .hasArg()
      .required()
      .build();
  Option ecdsaPrivateKeyPath = Option.builder()
      .longOpt(ECDSA_PRIVATE_KEY_PATH_OPTION)
      .desc("The path to store ECDSA private key.")
      .hasArg()
      .required()
      .build();

  Options options = new Options();
  options.addOption(ecdsaPublicKeyPath);
  options.addOption(ecdsaPrivateKeyPath);

  CommandLineParser cmdLineParser = new DefaultParser();
  return cmdLineParser.parse(options, commandLineArguments);
}
 
Example 10
Source Project: SikuliX1   Source File: CommandArgs.java    License: MIT License 6 votes vote down vote up
public CommandLine getCommandLine(String[] args) {
  CommandLineParser parser = new PosixParser();
  CommandLine cmd = null;

  boolean isUserArg = false;
  for (int i = 0; i < args.length; i++) {
    if (!isUserArg && args[i].startsWith("--")) {
      isUserArg = true;
      continue;
    }
    if (isUserArg) {
      userArgs.add(args[i]);
    } else {
      sikuliArgs.add(args[i]);
    }
  }
  try {
    cmd = parser.parse(cmdArgs, sikuliArgs.toArray(new String[]{}), true);
  } catch (ParseException exp) {
    Debug.error(exp.getMessage());
  }
  return cmd;
}
 
Example 11
Source Project: localization_nifi   Source File: BaseCommandLine.java    License: Apache License 2.0 6 votes vote down vote up
protected CommandLine doParse(String[] args) throws CommandLineParseException {
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption(HELP_ARG)) {
            return printUsageAndThrow(null, ExitCode.HELP);
        }
        certificateAuthorityHostname = commandLine.getOptionValue(CERTIFICATE_AUTHORITY_HOSTNAME_ARG, TlsConfig.DEFAULT_HOSTNAME);
        days = getIntValue(commandLine, DAYS_ARG, TlsConfig.DEFAULT_DAYS);
        keySize = getIntValue(commandLine, KEY_SIZE_ARG, TlsConfig.DEFAULT_KEY_SIZE);
        keyAlgorithm = commandLine.getOptionValue(KEY_ALGORITHM_ARG, TlsConfig.DEFAULT_KEY_PAIR_ALGORITHM);
        keyStoreType = commandLine.getOptionValue(KEY_STORE_TYPE_ARG, getKeyStoreTypeDefault());
        if (KeystoreType.PKCS12.toString().equalsIgnoreCase(keyStoreType)) {
            logger.info("Command line argument --" + KEY_STORE_TYPE_ARG + "=" + keyStoreType + " only applies to keystore, recommended truststore type of " + KeystoreType.JKS.toString() +
                    " unaffected.");
        }
        signingAlgorithm = commandLine.getOptionValue(SIGNING_ALGORITHM_ARG, TlsConfig.DEFAULT_SIGNING_ALGORITHM);
        differentPasswordForKeyAndKeystore = commandLine.hasOption(DIFFERENT_KEY_AND_KEYSTORE_PASSWORDS_ARG);
    } catch (ParseException e) {
        return printUsageAndThrow("Error parsing command line. (" + e.getMessage() + ")", ExitCode.ERROR_PARSING_COMMAND_LINE);
    }
    return commandLine;
}
 
Example 12
Source Project: amazon-mq-workshop   Source File: StompClient.java    License: Apache License 2.0 6 votes vote down vote up
private static CommandLine parseAndValidateCommandLineArguments(String[] args) throws ParseException {
    Options options = new Options();
    options.addOption("help", false, "Print the help message.");
    options.addOption("url", true, "The broker connection url.");
    options.addOption("user", true, "The user to connect to the broker.");
    options.addOption("password", true, "The password for the user.");
    options.addOption("mode", true, "Whether to act as 'sender' or 'receiver'");
    options.addOption("type", true, "Whether to use a queue or a topic.");
    options.addOption("destination", true, "The name of the queue or topic");
    options.addOption("name", true, "The name of the sender");
    options.addOption("interval", true, "The interval in msec at which messages are generated. Default 1000");
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("help")) {
        printUsage(options);
    }

    if (!(cmd.hasOption("url") && cmd.hasOption("mode") && cmd.hasOption("destination"))) {
        printUsage(options);
    }

    return cmd;
}
 
Example 13
Source Project: Dhalion   Source File: HealthManager.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  CommandLineParser parser = new DefaultParser();
  Options slaManagerCliOptions = constructCliOptions();

  // parse the help options first.
  Options helpOptions = constructHelpOptions();
  CommandLine cmd = parser.parse(helpOptions, args, true);
  if (cmd.hasOption("h")) {
    usage(slaManagerCliOptions);
    return;
  }

  try {
    cmd = parser.parse(slaManagerCliOptions, args);
  } catch (ParseException e) {
    usage(slaManagerCliOptions);
    throw new RuntimeException("Error parsing command line options: ", e);
  }

  LOG.info("Initializing the health manager");
  HealthManager healthmgr = new HealthManager(cmd);
  healthmgr.start();
}
 
Example 14
Source Project: steady   Source File: DigestAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>main.</p>
 *
 * @param _args an array of {@link java.lang.String} objects.
 */
public static void main(String[] _args){
	// Prepare parsing of cmd line arguments
	final Options options = new Options();
	
	options.addOption("digest", "digest", true, "Delete all existing results before upload; otherwise only upload results for AffectedLibraries not already existing in the backend");
	
				 
	try {
		final CommandLineParser parser = new DefaultParser();
	    CommandLine cmd = parser.parse(options, _args);
		
		if(cmd.hasOption("digest")){
			String digest = cmd.getOptionValue("digest");
			log.info("Running patcheval to assess all bugs of digest["+digest+"], all other options will be ignored.");
			DigestAnalyzer d = new DigestAnalyzer(digest);
			d.analyze();
		}
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 15
Source Project: yb-sample-apps   Source File: CmdLineOpts.java    License: Apache License 2.0 6 votes vote down vote up
private static void parseHelpDetailed(String[] args, Options options) throws Exception {
  Options helpOptions = new Options();
  helpOptions.addOption("help", true, "Print help.");
  CommandLineParser helpParser = new BasicParser();
  CommandLine helpCommandLine = null;
  try {
    helpCommandLine = helpParser.parse(helpOptions, args);
  } catch (org.apache.commons.cli.MissingArgumentException e1) {
    // This is ok since there was no help argument passed.
    return;
  }  catch (ParseException e) {
    return;
  }
  if (helpCommandLine.hasOption("help")) {
    printUsageDetails(options, "Usage:", helpCommandLine.getOptionValue("help"));
    System.exit(0);
  }
}
 
Example 16
public static void prepare(String[] args) throws Exception {
    // commons-cli命令行参数,需要带参数值
    Options options = new Options();
    // sql文件路径
    options.addOption("sql", true, "sql config");
    // 任务名称
    options.addOption("name", true, "job name");

    // 解析命令行参数
    CommandLineParser parser = new DefaultParser();
    CommandLine cl = parser.parse(options, args);
    String sql = cl.getOptionValue("sql");
    String name = cl.getOptionValue("name");

    System.out.println("sql : " + sql);
    System.out.println("name : " + name);
}
 
Example 17
Source Project: validator   Source File: CommandLineApplication.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Hauptprogramm für die Kommandozeilen-Applikation.
 *
 * @param args die Eingabe-Argumente
 */
static int mainProgram(final String[] args) {
    int returnValue = 0;
    final Options options = createOptions();
    if (isHelpRequested(args)) {
        printHelp(options);
    } else {
        try {
            final CommandLineParser parser = new DefaultParser();
            final CommandLine cmd = parser.parse(options, args);
            if (cmd.hasOption(SERVER.getOpt())) {
                returnValue = startDaemonMode(cmd);
            } else if (cmd.getArgList().isEmpty()) {
                printHelp(createOptions());
            } else {
                returnValue = processActions(cmd);
            }
        } catch (final ParseException e) {
            log.error("Error processing command line arguments: " + e.getMessage());
            printHelp(options);
        }
    }
    return returnValue;
}
 
Example 18
Source Project: doctorkafka   Source File: BrokerReplacement.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  Usage: BrokerReplacement -broker broker1  -command "relaunch host script"
 */
private static CommandLine parseCommandLine(String[] args) {
  Option broker = new Option(BROKER, true, "broker name");
  Option command = new Option(COMMAND, true, "command for relaunching a host");
  options.addOption(broker).addOption(command);

  if (args.length < 3) {
    printUsageAndExit();
  }

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
Example 19
Source Project: Bats   Source File: ApexCli.java    License: Apache License 2.0 5 votes vote down vote up
static GetOperatorClassesCommandLineInfo getGetOperatorClassesCommandLineInfo(String[] args) throws ParseException
{
  CommandLineParser parser = new PosixParser();
  GetOperatorClassesCommandLineInfo result = new GetOperatorClassesCommandLineInfo();
  CommandLine line = parser.parse(GET_OPERATOR_CLASSES_OPTIONS.options, args);
  result.parent = line.getOptionValue("parent");
  result.args = line.getArgs();
  return result;
}
 
Example 20
Source Project: Bats   Source File: ApexCli.java    License: Apache License 2.0 5 votes vote down vote up
static LaunchCommandLineInfo getLaunchCommandLineInfo(String[] args) throws ParseException
{
  CommandLineParser parser = new PosixParser();
  LaunchCommandLineInfo result = new LaunchCommandLineInfo();
  CommandLine line = parser.parse(LAUNCH_OPTIONS.options, args);
  result.localMode = line.hasOption(LAUNCH_OPTIONS.local.getOpt());
  result.configFile = line.getOptionValue(LAUNCH_OPTIONS.configFile.getOpt());
  result.apConfigFile = line.getOptionValue(LAUNCH_OPTIONS.apConfigFile.getOpt());
  result.ignorePom = line.hasOption(LAUNCH_OPTIONS.ignorePom.getOpt());
  String[] defs = line.getOptionValues(LAUNCH_OPTIONS.defProperty.getOpt());
  if (defs != null) {
    result.overrideProperties = new HashMap<>();
    for (String def : defs) {
      int equal = def.indexOf('=');
      if (equal < 0) {
        result.overrideProperties.put(def, null);
      } else {
        result.overrideProperties.put(def.substring(0, equal), def.substring(equal + 1));
      }
    }
  }
  result.libjars = line.getOptionValue(LAUNCH_OPTIONS.libjars.getOpt());
  result.archives = line.getOptionValue(LAUNCH_OPTIONS.archives.getOpt());
  result.files = line.getOptionValue(LAUNCH_OPTIONS.files.getOpt());
  result.queue = line.getOptionValue(LAUNCH_OPTIONS.queue.getOpt());
  result.tags = line.getOptionValue(LAUNCH_OPTIONS.tags.getOpt());
  result.args = line.getArgs();
  result.origAppId = line.getOptionValue(LAUNCH_OPTIONS.originalAppID.getOpt());
  result.exactMatch = line.hasOption("exactMatch");
  result.force = line.hasOption("force");
  result.useConfigApps = line.getOptionValue(LAUNCH_OPTIONS.useConfigApps.getOpt());

  return result;
}
 
Example 21
Source Project: Bats   Source File: ApexCli.java    License: Apache License 2.0 5 votes vote down vote up
private static ShowLogicalPlanCommandLineInfo getShowLogicalPlanCommandLineInfo(String[] args) throws ParseException
{
  CommandLineParser parser = new PosixParser();
  ShowLogicalPlanCommandLineInfo result = new ShowLogicalPlanCommandLineInfo();
  CommandLine line = parser.parse(getShowLogicalPlanCommandLineOptions(), args);
  result.libjars = line.getOptionValue("libjars");
  result.ignorePom = line.hasOption("ignorepom");
  result.args = line.getArgs();
  result.exactMatch = line.hasOption("exactMatch");
  return result;
}
 
Example 22
Source Project: vividus   Source File: BddScenariosCounter.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws ParseException, InitializationError, ReflectiveOperationException
{
    Vividus.init();
    CommandLineParser parser = new DefaultParser();
    Option helpOption = new Option("h", "help", false, "print this message.");
    Option directoryOption = new Option("d", "dir", true, "directory to count scenarios in (e.g. story/release).");
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(directoryOption);
    CommandLine commandLine = parser.parse(options, args);
    if (commandLine.hasOption(helpOption.getOpt()))
    {
        new HelpFormatter().printHelp("BddScenariosCounter", options);
        return;
    }

    String storyLocation = commandLine.hasOption(directoryOption.getOpt())
            ? commandLine.getOptionValue(directoryOption.getOpt()) : DEFAULT_STORY_LOCATION;
    configureStoryLocation(storyLocation);

    System.out.println("Story parsing may take up to 5 minutes. Please be patient.");
    JUnitReportingRunner runner = new JUnitReportingRunner(StoriesRunner.class);

    print(getNumberOfChildren(runner.getDescription(), BDDLevel.STORY.getLevel()), "Stories");
    print(getNumberOfChildren(runner.getDescription(), BDDLevel.SCENARIO.getLevel()), "Scenarios");
    print(getNumberOfChildren(runner.getDescription(), BDDLevel.EXAMPLE.getLevel()), "Scenarios with Examples");
}
 
Example 23
Source Project: AILibs   Source File: MLPlanCLI.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private static CommandLine generateCommandLine(final Options options, final String[] commandLineArguments) {
	final CommandLineParser cmdLineParser = new DefaultParser();
	CommandLine commandLine = null;
	try {
		commandLine = cmdLineParser.parse(options, commandLineArguments);
	}

	catch (ParseException parseException) {
		logger.error("ERROR: Unable to parse command-line arguments {} due to {}", Arrays.toString(commandLineArguments), parseException);
	}

	return commandLine;
}
 
Example 24
Source Project: act   Source File: GenbankInterpreter.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Options opts = new Options();
  for (Option.Builder b : OPTION_BUILDERS) {
    opts.addOption(b.build());
  }

  CommandLine cl = null;
  try {
    CommandLineParser parser = new DefaultParser();
    cl = parser.parse(opts, args);
  } catch (ParseException e) {
    LOGGER.error("Argument parsing failed: %s", e.getMessage());
    HELP_FORMATTER.printHelp(GenbankInterpreter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
    System.exit(1);
  }

  if (cl.hasOption("help")) {
    HELP_FORMATTER.printHelp(GenbankInterpreter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
    System.exit(1);
  }

  File genbankFile = new File(cl.getOptionValue(OPTION_GENBANK_PATH));
  String seq_type = cl.getOptionValue(OPTION_SEQ_TYPE);

  if (!genbankFile.exists()) {
    String msg = "Genbank file path is null";
    LOGGER.error(msg);
    throw new RuntimeException(msg);
  } else {
    GenbankInterpreter reader = new GenbankInterpreter(genbankFile, seq_type);
    reader.init();
    reader.printSequences();
  }
}
 
Example 25
Source Project: twister2   Source File: DataflowAddNodeExperiment.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws ParseException {
  // first load the configurations from command line and config files
  Config config = ResourceAllocator.loadConfig(new HashMap<>());

  // build JobConfig
  HashMap<String, Object> configurations = new HashMap<>();
  configurations.put(SchedulerContext.THREADS_PER_WORKER, 8);

  Options options = new Options();
  options.addOption(DataObjectConstants.ARGS_ITERATIONS, true, "iter");
  options.addOption(DataObjectConstants.PARALLELISM_VALUE, true, "parallelism");
  options.addOption(DataObjectConstants.WORKERS, true, "workers");
  options.addOption(DataObjectConstants.DSIZE, true, "dsize");

  CommandLineParser commandLineParser = new DefaultParser();
  CommandLine cmd = commandLineParser.parse(options, args);
  int workers = Integer.parseInt(cmd.getOptionValue(DataObjectConstants.WORKERS));
  int parallelismValue = Integer.parseInt(cmd.getOptionValue(
      DataObjectConstants.PARALLELISM_VALUE));
  int iterations = Integer.parseInt(cmd.getOptionValue(
      DataObjectConstants.ARGS_ITERATIONS));
  int dsize = Integer.parseInt(cmd.getOptionValue(DataObjectConstants.DSIZE));

  // build JobConfig
  JobConfig jobConfig = new JobConfig();
  jobConfig.put(DataObjectConstants.DSIZE, Integer.toString(dsize));
  jobConfig.put(DataObjectConstants.WORKERS, Integer.toString(workers));
  jobConfig.put(DataObjectConstants.PARALLELISM_VALUE, Integer.toString(parallelismValue));
  jobConfig.put(DataObjectConstants.ARGS_ITERATIONS, Integer.toString(iterations));
  jobConfig.putAll(configurations);

  Twister2Job.Twister2JobBuilder jobBuilder = Twister2Job.newBuilder();
  jobBuilder.setJobName("Experiment2");
  jobBuilder.setWorkerClass(DataflowAddNodeExperiment.class.getName());
  jobBuilder.addComputeResource(2, 512, 1.0, workers);
  jobBuilder.setConfig(jobConfig);

  // now submit the job
  Twister2Submitter.submitJob(jobBuilder.build(), config);
}
 
Example 26
Source Project: Flink-CEPplus   Source File: FlinkYarnSessionCliTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDynamicProperties() throws Exception {

	FlinkYarnSessionCli cli = new FlinkYarnSessionCli(
		new Configuration(),
		tmp.getRoot().getAbsolutePath(),
		"",
		"",
		false);
	Options options = new Options();
	cli.addGeneralOptions(options);
	cli.addRunOptions(options);

	CommandLineParser parser = new DefaultParser();
	CommandLine cmd = parser.parse(options, new String[]{"run", "-j", "fake.jar", "-n", "15",
			"-D", "akka.ask.timeout=5 min", "-D", "env.java.opts=-DappName=foobar"});

	AbstractYarnClusterDescriptor flinkYarnDescriptor = cli.createClusterDescriptor(cmd);

	Assert.assertNotNull(flinkYarnDescriptor);

	Map<String, String> dynProperties =
		FlinkYarnSessionCli.getDynamicProperties(flinkYarnDescriptor.getDynamicPropertiesEncoded());
	assertEquals(2, dynProperties.size());
	assertEquals("5 min", dynProperties.get("akka.ask.timeout"));
	assertEquals("-DappName=foobar", dynProperties.get("env.java.opts"));
}
 
Example 27
Source Project: act   Source File: ProductScorer.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

    // Build command line parser.
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
      opts.addOption(b.build());
    }
    CommandLine cl = null;
    try {
      CommandLineParser parser = new DefaultParser();
      cl = parser.parse(opts, args);
    } catch (ParseException e) {
      LOGGER.error("Argument parsing failed: %s", e.getMessage());
      HELP_FORMATTER.printHelp(L2FilteringDriver.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
      System.exit(1);
    }

    File inputCorpusFile = new File(cl.getOptionValue(OPTION_PREDICTION_CORPUS));
    File lcmsFile = new File(cl.getOptionValue(OPTION_LCMS_RESULTS));
    File scoredSarsFile = new File(cl.getOptionValue(OPTION_SCORED_SARS));
    File outputFile = new File(cl.getOptionValue(OPTION_OUTPUT_PATH));

    JavaRunnable productScoreRunner = getProductScorer(
        inputCorpusFile,
        scoredSarsFile,
        lcmsFile,
        outputFile);

    LOGGER.info("Scoring products.");
    productScoreRunner.run();
    LOGGER.info("Complete!.");
  }
 
Example 28
Source Project: hadoop   Source File: SecondaryNameNode.java    License: Apache License 2.0 5 votes vote down vote up
public void parse(String ... argv) throws ParseException {
  CommandLineParser parser = new PosixParser();
  CommandLine cmdLine = parser.parse(options, argv);
  
  if (cmdLine.hasOption(helpOpt.getOpt())
      || cmdLine.hasOption(helpOpt.getLongOpt())) {
    shouldPrintHelp = true;
    return;
  }
  
  boolean hasGetEdit = cmdLine.hasOption(geteditsizeOpt.getOpt());
  boolean hasCheckpoint = cmdLine.hasOption(checkpointOpt.getOpt()); 
  if (hasGetEdit && hasCheckpoint) {
    throw new ParseException("May not pass both "
        + geteditsizeOpt.getOpt() + " and "
        + checkpointOpt.getOpt());
  }
  
  if (hasGetEdit) {
    cmd = Command.GETEDITSIZE;
  } else if (hasCheckpoint) {
    cmd = Command.CHECKPOINT;
    
    String arg = cmdLine.getOptionValue(checkpointOpt.getOpt());
    if ("force".equals(arg)) {
      shouldForce = true;
    } else if (arg != null) {
      throw new ParseException("-checkpoint may only take 'force' as an "
          + "argument");
    }
  }
  
  if (cmdLine.hasOption(formatOpt.getOpt())) {
    shouldFormat = true;
  }
}
 
Example 29
Source Project: Quicksql   Source File: OptionsParser.java    License: MIT License 5 votes vote down vote up
private void parseOptions(String[] args) throws ParseException {
    SubmitOption[] values = SubmitOption.values();
    List<Option> optionList = Arrays.stream(values)
        .map(option ->
            Option.builder().longOpt(option.key).hasArg().build()).collect(Collectors.toList());
    Options options = new Options();
    optionList.forEach(options::addOption);
    CommandLineParser parser = new DefaultParser();
    commandLine = parser.parse(options, args);
}
 
Example 30
Source Project: twister2   Source File: DataflowNodeExperiment.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws ParseException {
  // first load the configurations from command line and config files
  Config config = ResourceAllocator.loadConfig(new HashMap<>());

  // build JobConfig
  HashMap<String, Object> configurations = new HashMap<>();
  configurations.put(SchedulerContext.THREADS_PER_WORKER, 8);

  Options options = new Options();
  options.addOption(DataObjectConstants.ARGS_ITERATIONS, true, "iter");
  options.addOption(DataObjectConstants.PARALLELISM_VALUE, true, "parallelism");
  options.addOption(DataObjectConstants.WORKERS, true, "workers");
  options.addOption(DataObjectConstants.DSIZE, true, "dsize");

  CommandLineParser commandLineParser = new DefaultParser();
  CommandLine cmd = commandLineParser.parse(options, args);
  int workers = Integer.parseInt(cmd.getOptionValue(DataObjectConstants.WORKERS));
  int parallelismValue = Integer.parseInt(cmd.getOptionValue(
      DataObjectConstants.PARALLELISM_VALUE));
  int iterations = Integer.parseInt(cmd.getOptionValue(
      DataObjectConstants.ARGS_ITERATIONS));
  int dsize = Integer.parseInt(cmd.getOptionValue(DataObjectConstants.DSIZE));

  // build JobConfig
  JobConfig jobConfig = new JobConfig();
  jobConfig.put(DataObjectConstants.DSIZE, Integer.toString(dsize));
  jobConfig.put(DataObjectConstants.WORKERS, Integer.toString(workers));
  jobConfig.put(DataObjectConstants.PARALLELISM_VALUE, Integer.toString(parallelismValue));
  jobConfig.put(DataObjectConstants.ARGS_ITERATIONS, Integer.toString(iterations));
  jobConfig.putAll(configurations);

  Twister2Job.Twister2JobBuilder jobBuilder = Twister2Job.newBuilder();
  jobBuilder.setJobName("Experiment1");
  jobBuilder.setWorkerClass(DataflowNodeExperiment.class.getName());
  jobBuilder.addComputeResource(2, 512, 1.0, workers);
  jobBuilder.setConfig(jobConfig);

  // now submit the job
  Twister2Submitter.submitJob(jobBuilder.build(), config);
}