use of org.apache.commons.cli.ParseException in project SSM by Intel-bigdata.
the class MoverCli method run.
@Override
public int run(String[] args) throws Exception {
final long startTime = Time.monotonicNow();
status.begin();
final Configuration conf = getConf();
try {
final Map<URI, List<Path>> map = getNameNodePathsToMove(conf, args);
return Mover.run(map, conf, status);
} catch (IOException e) {
LOG.info(e + ". Exiting ...");
return ExitStatus.IO_EXCEPTION.getExitCode();
} catch (InterruptedException e) {
LOG.info(e + ". Exiting ...");
return ExitStatus.INTERRUPTED.getExitCode();
} catch (ParseException e) {
LOG.info(e + ". Exiting ...");
return ExitStatus.ILLEGAL_ARGUMENTS.getExitCode();
} catch (IllegalArgumentException e) {
LOG.info(e + ". Exiting ...");
return ExitStatus.ILLEGAL_ARGUMENTS.getExitCode();
} finally {
status.end();
long runningTime = Time.monotonicNow() - startTime;
Log.format("%-24s ", DateFormat.getDateTimeInstance().format(new Date()));
LOG.info("Mover took " + StringUtils.formatTime(runningTime));
}
}
use of org.apache.commons.cli.ParseException in project streamsx.health by IBMStreams.
the class PrintService method main.
public static void main(String[] args) throws Exception {
Option subscribeTopicOption = Option.builder("s").longOpt("subscribe-topic").hasArg().argName("subscribe topic").required().build();
Option contextTypeOption = Option.builder("c").longOpt("context-type").hasArg().argName("context type").required(false).build();
Options options = new Options();
options.addOption(subscribeTopicOption);
options.addOption(contextTypeOption);
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("help", options);
throw (e);
}
Type contextType = Type.valueOf(cmd.getOptionValue("c", Type.DISTRIBUTED.name()));
String subscribeTopic = cmd.getOptionValue("s");
PrintService svc = new PrintService(subscribeTopic);
svc.run(contextType, new HashMap<String, Object>());
}
use of org.apache.commons.cli.ParseException in project streamsx.health by IBMStreams.
the class AbstractEventService method launchService.
protected static void launchService(String[] args, Class<? extends AbstractEventService> eventServiceClass) throws Exception {
Option hostOption = Option.builder("x").longOpt("host").hasArg().argName("watson explorer host").required().build();
Option portOption = Option.builder("p").longOpt("port").hasArg().argName("watson explorer port").required().build();
Option collectionOption = Option.builder("c").longOpt("collection").hasArg().argName("collection name").required().build();
Option patientIdFieldOption = Option.builder("f").longOpt("patient-field").hasArg().argName("patient ID field name").required(false).build();
Option toolkitOption = Option.builder("t").longOpt("toolkit-path").hasArg().argName("watson explorer toolkit path").required().build();
Option subscribeOption = Option.builder("s").longOpt("subscription-topic").hasArg().argName("subscription topic").required().build();
Option debugOption = Option.builder("d").longOpt("debug").hasArg().argName("isDebugEnabled").required(false).type(Boolean.class).build();
Options options = new Options();
options.addOption(hostOption);
options.addOption(portOption);
options.addOption(collectionOption);
options.addOption(patientIdFieldOption);
options.addOption(toolkitOption);
options.addOption(subscribeOption);
options.addOption(debugOption);
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("help", options);
throw (e);
}
boolean isDebug = cmd.getOptionValue("d", "false").equals("true");
AbstractEventService svc = eventServiceClass.getConstructor(String.class).newInstance(cmd.getOptionValue("t"));
//MedicationEventService svc = new MedicationEventService(cmd.getOptionValue("t"));
svc.setContextType(Type.DISTRIBUTED);
svc.addSubmissionTimeParam("wex.host", cmd.getOptionValue("x"));
svc.addSubmissionTimeParam("wex.port", Integer.valueOf(cmd.getOptionValue("p")));
svc.addSubmissionTimeParam("wex.patient.field.name", cmd.getOptionValue("f", "patient_id"));
svc.addSubmissionTimeParam("collectionName", cmd.getOptionValue("c"));
svc.setSubscriptionTopic(cmd.getOptionValue("s"));
if (isDebug) {
svc.setTraceLevel(TraceLevel.TRACE);
}
svc.buildAndRun();
if (isDebug) {
new EventBeacon(svc.getPublishedTopic()).run();
}
}
use of org.apache.commons.cli.ParseException in project tika by apache.
the class TikaEvalCLI method handleProfile.
private void handleProfile(String[] subsetArgs) throws Exception {
List<String> argList = new ArrayList(Arrays.asList(subsetArgs));
boolean containsBC = false;
String inputDir = null;
String extracts = null;
String alterExtract = null;
//confirm there's a batch-config file
for (int i = 0; i < argList.size(); i++) {
String arg = argList.get(i);
if (arg.equals("-bc")) {
containsBC = true;
} else if (arg.equals("-inputDir")) {
if (i + 1 >= argList.size()) {
System.err.println("Must specify directory after -inputDir");
ExtractProfiler.USAGE();
return;
}
inputDir = argList.get(i + 1);
i++;
} else if (arg.equals("-extracts")) {
if (i + 1 >= argList.size()) {
System.err.println("Must specify directory after -extracts");
ExtractProfiler.USAGE();
return;
}
extracts = argList.get(i + 1);
i++;
} else if (arg.equals("-alterExtract")) {
if (i + 1 >= argList.size()) {
System.err.println("Must specify type 'as_is', 'first_only' or " + "'concatenate_content' after -alterExtract");
ExtractComparer.USAGE();
return;
}
alterExtract = argList.get(i + 1);
i++;
}
}
if (alterExtract != null && !alterExtract.equals("as_is") && !alterExtract.equals("concatenate_content") && !alterExtract.equals("first_only")) {
System.out.println("Sorry, I don't understand:" + alterExtract + ". The values must be one of: as_is, first_only, concatenate_content");
ExtractProfiler.USAGE();
return;
}
//this allows the user to specify either extracts or inputDir
if (extracts == null && inputDir != null) {
argList.add("-extracts");
argList.add(inputDir);
} else if (inputDir == null && extracts != null) {
argList.add("-inputDir");
argList.add(extracts);
}
Path tmpBCConfig = null;
try {
tmpBCConfig = Files.createTempFile("tika-eval-profiler", ".xml");
if (!containsBC) {
Files.copy(this.getClass().getResourceAsStream("/tika-eval-profiler-config.xml"), tmpBCConfig, StandardCopyOption.REPLACE_EXISTING);
argList.add("-bc");
argList.add(tmpBCConfig.toAbsolutePath().toString());
}
String[] updatedArgs = argList.toArray(new String[argList.size()]);
DefaultParser defaultCLIParser = new DefaultParser();
try {
CommandLine commandLine = defaultCLIParser.parse(ExtractProfiler.OPTIONS, updatedArgs);
if (commandLine.hasOption("db") && commandLine.hasOption("jdbc")) {
System.out.println("Please specify either the default -db or the full -jdbc, not both");
ExtractProfiler.USAGE();
return;
}
} catch (ParseException e) {
System.out.println(e.getMessage() + "\n");
ExtractProfiler.USAGE();
return;
}
FSBatchProcessCLI.main(updatedArgs);
} finally {
if (tmpBCConfig != null && Files.isRegularFile(tmpBCConfig)) {
Files.delete(tmpBCConfig);
}
}
}
use of org.apache.commons.cli.ParseException in project symmetric-ds by JumpMind.
the class DbCompareCommand method executeWithOptions.
@Override
protected boolean executeWithOptions(CommandLine line) throws Exception {
String source = line.getOptionValue('s');
if (source == null) {
source = line.getOptionValue(OPTION_SOURCE);
}
if (StringUtils.isEmpty(source)) {
throw new ParseException(String.format("-source properties file is required."));
}
File sourceProperies = new File(source);
if (!sourceProperies.exists()) {
throw new SymmetricException("Source properties file '" + sourceProperies + "' does not exist.");
}
String target = line.getOptionValue('t');
if (target == null) {
target = line.getOptionValue(OPTION_TARGET);
}
if (StringUtils.isEmpty(target)) {
throw new ParseException(String.format("-target properties file is required."));
}
File targetProperties = new File(target);
if (!targetProperties.exists()) {
throw new SymmetricException("Target properties file '" + targetProperties + "' does not exist.");
}
DbCompareConfig config = new DbCompareConfig();
if (line.hasOption(OPTION_OUTPUT_SQL)) {
config.setSqlDiffFileName(line.getOptionValue(OPTION_OUTPUT_SQL));
}
if (line.hasOption(OPTION_USE_SYM_CONFIG)) {
config.setUseSymmetricConfig(Boolean.valueOf(line.getOptionValue(OPTION_USE_SYM_CONFIG)));
}
if (line.hasOption(OPTION_EXCLUDE)) {
config.setExcludedTableNames(Arrays.asList(line.getOptionValue(OPTION_EXCLUDE).split(",")));
}
config.setWhereClauses(parseWhereClauses(line));
if (!CollectionUtils.isEmpty(line.getArgList())) {
config.setIncludedTableNames(Arrays.asList(line.getArgList().get(0).toString().split(",")));
}
String numericScaleArg = line.getOptionValue(OPTION_NUMERIC_SCALE);
if (!StringUtils.isEmpty(numericScaleArg)) {
try {
config.setNumericScale(Integer.parseInt(numericScaleArg.trim()));
} catch (Exception ex) {
throw new ParseException("Failed to parse arg [" + numericScaleArg + "] " + ex);
}
}
ISymmetricEngine sourceEngine = new ClientSymmetricEngine(sourceProperies);
ISymmetricEngine targetEngine = new ClientSymmetricEngine(targetProperties);
DbCompare dbCompare = new DbCompare(sourceEngine, targetEngine, config);
DbCompareReport report = dbCompare.compare();
return false;
}
Aggregations