List of usage examples for org.apache.commons.cli OptionBuilder withArgName
public static OptionBuilder withArgName(String name)
From source file:edu.umd.cloud9.example.cooccur.ComputeCooccurrenceMatrixStripes.java
/** * Runs this tool./* w w w . j av a 2s . c o m*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("window size").create(WINDOW)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of reducers") .create(NUM_REDUCERS)); CommandLine cmdline; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); return -1; } if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String inputPath = cmdline.getOptionValue(INPUT); String outputPath = cmdline.getOptionValue(OUTPUT); int reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS)) : 1; int window = cmdline.hasOption(WINDOW) ? Integer.parseInt(cmdline.getOptionValue(WINDOW)) : 2; LOG.info("Tool: " + ComputeCooccurrenceMatrixStripes.class.getSimpleName()); LOG.info(" - input path: " + inputPath); LOG.info(" - output path: " + outputPath); LOG.info(" - window: " + window); LOG.info(" - number of reducers: " + reduceTasks); Job job = Job.getInstance(getConf()); job.setJobName(ComputeCooccurrenceMatrixStripes.class.getSimpleName()); job.setJarByClass(ComputeCooccurrenceMatrixStripes.class); // Delete the output directory if it exists already. Path outputDir = new Path(outputPath); FileSystem.get(getConf()).delete(outputDir, true); job.getConfiguration().setInt("window", window); job.setNumReduceTasks(reduceTasks); FileInputFormat.setInputPaths(job, new Path(inputPath)); FileOutputFormat.setOutputPath(job, new Path(outputPath)); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(HMapStIW.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(HMapStIW.class); job.setMapperClass(MyMapper.class); job.setCombinerClass(MyReducer.class); job.setReducerClass(MyReducer.class); long startTime = System.currentTimeMillis(); job.waitForCompletion(true); System.out.println("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds"); return 0; }
From source file:edu.umd.windmemory.BuildPersonalizedPageRankRecords.java
/** * Runs this tool./* w w w .j a v a2 s . com*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES)); options.addOption( OptionBuilder.withArgName("source").hasArg().withDescription("sources node").create(SOURCES)); CommandLine cmdline; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); return -1; } if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT) || !cmdline.hasOption(NUM_NODES) || !cmdline.hasOption(SOURCES)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String inputPath = cmdline.getOptionValue(INPUT); String outputPath = cmdline.getOptionValue(OUTPUT); int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); String sources = cmdline.getOptionValue(SOURCES); LOG.info("Tool name: " + BuildPersonalizedPageRankRecords.class.getSimpleName()); LOG.info(" - inputDir: " + inputPath); LOG.info(" - outputDir: " + outputPath); LOG.info(" - numNodes: " + n); LOG.info(" - sources: " + sources); Configuration conf = getConf(); conf.setInt(NODE_CNT_FIELD, n); conf.set(SOURCENODE, sources); conf.setInt("mapred.min.split.size", 1024 * 1024 * 1024); Job job = Job.getInstance(conf); job.setJobName(BuildPersonalizedPageRankRecords.class.getSimpleName() + ":" + inputPath); job.setJarByClass(BuildPersonalizedPageRankRecords.class); job.setNumReduceTasks(0); FileInputFormat.addInputPath(job, new Path(inputPath)); FileOutputFormat.setOutputPath(job, new Path(outputPath)); job.setInputFormatClass(TextInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(PageRankNode.class); job.setOutputKeyClass(IntWritable.class); job.setOutputValueClass(PageRankNode.class); job.setMapperClass(MyMapper.class); // Delete the output directory if it exists already. FileSystem.get(conf).delete(new Path(outputPath), true); job.waitForCompletion(true); return 0; }
From source file:fr.ens.transcriptome.corsen.Corsen.java
/** * Create the Options object for the command line. * @return The Option object/*from w w w . j ava2 s. c om*/ */ private static Options makeOptions() { Option help = new Option("help", "show this message"); Option about = new Option("about", "show information this software"); Option licence = new Option("licence", "show information about the licence of this software"); Option batchFile = OptionBuilder.withArgName("batchfile").hasArg().withDescription("batch file") .create("batchFile"); Option batch = new Option("batch", "batch mode"); Option conf = OptionBuilder.withArgName("file").hasArg().withDescription("configuration file") .create("conf"); Option typea = OptionBuilder.withArgName("typea").hasArg().withDescription("particle A type") .create("typea"); Option typeb = OptionBuilder.withArgName("typeb").hasArg().withDescription("particle B type") .create("typeb"); Option unit = OptionBuilder.withArgName("unit").hasArg().withDescription("unit").create("unit"); Option zfactor = OptionBuilder.withArgName("zfactor").hasArg().withDescription("z factor") .create("zfactor"); Option factor = OptionBuilder.withArgName("factor").hasArg().withDescription("coordinates factor") .create("factor"); Option threads = OptionBuilder.withArgName("number").hasArg().withDescription("number of threads") .create("threads"); Option od = new Option("od", "create output data files"); Option oiv = new Option("oiv", "create output iv files"); Option or = new Option("or", "create output results files"); Option ova = new Option("ova", "create output particle A R visualisation files"); Option ovac = new Option("ovac", "create output particle A cuboids R visualisation files"); Option ovb = new Option("ovb", "create output particle B R visualisation files"); Option ovbc = new Option("ovbc", "create output particle B cuboids R visualisation files"); Option ovd = new Option("ovd", "create output distances R visualisation files"); Options options = new Options(); options.addOption(help); options.addOption(about); options.addOption(licence); options.addOption(conf); options.addOption(batchFile); options.addOption(batch); options.addOption(threads); options.addOption(typea); options.addOption(typeb); options.addOption(unit); options.addOption(zfactor); options.addOption(factor); options.addOption(od); options.addOption(oiv); options.addOption(or); options.addOption(ova); options.addOption(ovac); options.addOption(ovb); options.addOption(ovbc); options.addOption(ovd); return options; }
From source file:edu.umd.honghongie.BuildInvertedIndexHBase.java
/** * Runs this tool./*from www . j a va 2 s . c o m*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption( OptionBuilder.withArgName("table").hasArg().withDescription("HBase table name").create(OUTPUT)); CommandLine cmdline; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); return -1; } if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String inputPath = cmdline.getOptionValue(INPUT); String outputTable = cmdline.getOptionValue(OUTPUT); // If the table doesn't exist, create it Configuration conf = getConf(); conf.addResource(new Path("/etc/hbase/conf/hbase-site.xml")); Configuration hbaseConfig = HBaseConfiguration.create(conf); HBaseAdmin admin = new HBaseAdmin(hbaseConfig); if (admin.tableExists(outputTable)) { LOG.info(String.format("Table '%s' exists: dropping table and recreating.", outputTable)); LOG.info(String.format("Disabling table '%s'", outputTable)); admin.disableTable(outputTable); LOG.info(String.format("Droppping table '%s'", outputTable)); admin.deleteTable(outputTable); } HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(outputTable)); for (int i = 0; i < FAMILIES.length; i++) { HColumnDescriptor hColumnDesc = new HColumnDescriptor(FAMILIES[i]); tableDesc.addFamily(hColumnDesc); } admin.createTable(tableDesc); LOG.info(String.format("Successfully created table '%s'", outputTable)); admin.close(); // Now we are ready to start running mapreduce LOG.info("Tool name: " + BuildInvertedIndexHBase.class.getSimpleName()); LOG.info(" - input path: " + inputPath); LOG.info(" - output table: " + outputTable); Job job = Job.getInstance(getConf()); job.setJobName(BuildInvertedIndexHBase.class.getSimpleName()); job.setJarByClass(BuildInvertedIndexHBase.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(PairOfInts.class); job.setMapperClass(MyMapper.class); FileInputFormat.setInputPaths(job, new Path(inputPath)); TableMapReduceUtil.initTableReducerJob(outputTable, MyTableReducer.class, job); long startTime = System.currentTimeMillis(); job.waitForCompletion(true); System.out.println("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds"); return 0; }
From source file:com.netflix.suro.SuroServer.java
@SuppressWarnings("static-access") private static Options createOptions() { Option propertyFile = OptionBuilder.withArgName("serverProperty").hasArg() .withDescription("server property file path").create('p'); Option mapFile = OptionBuilder.withArgName("routingMap").hasArg().isRequired(true) .withDescription("message routing map file path").create('m'); Option sinkFile = OptionBuilder.withArgName("sinkConfig").hasArg().isRequired(true).withDescription("sink") .create('s'); Option inputFile = OptionBuilder.withArgName("inputConfig").hasArg().isRequired(true) .withDescription("input").create('i'); Option accessKey = OptionBuilder.withArgName("AWSAccessKey").hasArg().isRequired(false) .withDescription("AWSAccessKey").create('a'); Option secretKey = OptionBuilder.withArgName("AWSSecretKey").hasArg().isRequired(false) .withDescription("AWSSecretKey").create('k'); Option controlPort = OptionBuilder.withArgName(OPT_CONTROL_PORT).hasArg().isRequired(false) .withDescription("The port used to send command to this server").create('c'); Options options = new Options(); options.addOption(propertyFile);// w w w . j a v a2s . c o m options.addOption(mapFile); options.addOption(sinkFile); options.addOption(inputFile); options.addOption(accessKey); options.addOption(secretKey); options.addOption(controlPort); return options; }
From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java
/** * Creates and adds a non-word infile option to a given {@link Options} * object.//from ww w. java 2 s.c o m * * @param options * The <code>Options</code> object to add to. */ private static void addNonwordInfileOption(final Options options) { OptionBuilder.withLongOpt(NONWORD_INFILE_KEY_LONG); OptionBuilder.withDescription(NONWORD_INFILE_DESCR); OptionBuilder.hasArg(); OptionBuilder.withArgName(INFILE_ARG_NAME); OptionBuilder.withType(File.class); final Option nonwordInfile = OptionBuilder.create(NONWORD_INFILE_KEY); options.addOption(nonwordInfile); }
From source file:com.xiaoxiaomo.mr.utils.kafka.HadoopJob.java
@SuppressWarnings("static-access") private Options buildOptions() { Options options = new Options(); options.addOption(OptionBuilder.withArgName("topics").withLongOpt("topics").hasArg() .withDescription("kafka topics").create("t")); options.addOption(OptionBuilder.withArgName("groupid").withLongOpt("consumer-group").hasArg() .withDescription("kafka consumer groupid").create("g")); options.addOption(OptionBuilder.withArgName("zk").withLongOpt("zk-connect").hasArg() .withDescription("ZooKeeper connection String").create("z")); options.addOption(OptionBuilder.withArgName("offset").withLongOpt("offset-reset").hasArg() .withDescription("Reset all offsets to either 'earliest' or 'latest'").create("o")); options.addOption(OptionBuilder.withArgName("compression").withLongOpt("compress-output").hasArg() .withDescription("GZip output compression on|off").create("c")); options.addOption(OptionBuilder.withArgName("ip_address").withLongOpt("remote").hasArg() .withDescription("Running on a remote hadoop node").create("r")); options.addOption(OptionBuilder.withLongOpt("help").withDescription("Show this help").create("h")); return options; }
From source file:edu.umd.windmemory.BooleanRetrievalCompressed.java
/** * Runs this tool./*from www. java 2s. c o m*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INDEX)); options.addOption( OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(COLLECTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INDEX) || !cmdline.hasOption(COLLECTION)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); // formatter.printHelp(LookupPostings.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String indexPath = cmdline.getOptionValue(INDEX); String collectionPath = cmdline.getOptionValue(COLLECTION); if (collectionPath.endsWith(".gz")) { System.out.println("gzipped collection is not seekable: use compressed version!"); System.exit(-1); } FileSystem fs = FileSystem.get(new Configuration()); initialize(indexPath, collectionPath, fs); String[] queries = { "outrageous fortune AND", "white rose AND", "means deceit AND", "white red OR rose AND pluck AND", "unhappy outrageous OR good your AND OR fortune AND" }; for (String q : queries) { System.out.println("Query: " + q); runQuery(q); System.out.println(""); } return 1; }
From source file:esg.common.shell.cmds.ESGFls.java
public void doInitOptions() { getOptions().addOption("d", "datasets", false, "lists All Datasets in CWD"); Option listfiles = OptionBuilder.withArgName("datasetdir").hasArg() .withDescription("lists the files of a particular dataset").create("files"); getOptions().addOption(listfiles);// www . j a va 2 s .c o m Option missingfiles = OptionBuilder.withArgName("datasetdir").hasArg() .withDescription("lists the missing files of a particular dataset").create("missing"); getOptions().addOption(missingfiles); Option localfiles = OptionBuilder.withArgName("datasetdir").hasArg() .withDescription("lists the files of a particular dataset").create("local"); getOptions().addOption(localfiles); }
From source file:esg.common.shell.cmds.ESGFtest.java
public void doInitOptions() { //TODO: Define options... getOptions().addOption("t", "test", false, "This is a simple test flag"); Option logfile = OptionBuilder.withArgName("file").hasArg().withDescription("use given file for log") .create("testfile"); getOptions().addOption(logfile);/*from ww w.ja v a 2 s . co m*/ }