下面列出了怎么用org.apache.commons.cli.CommandLineParser的API类实例代码及写法,或者点击链接到github查看源代码。
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);
}
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;
}
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);
}
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;
}
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();
}
}
@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/")));
}
/**
* 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;
}
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;
}
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);
}
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;
}
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;
}
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;
}
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();
}
/**
* <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();
}
}
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);
}
}
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);
}
/**
* 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;
}
/**
* 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;
}
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;
}
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;
}
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;
}
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");
}
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;
}
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();
}
}
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);
}
@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"));
}
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!.");
}
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;
}
}
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);
}
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);
}