List of usage examples for org.apache.commons.cli HelpFormatter setWidth
public void setWidth(int width)
From source file:layer.AutoCoder.java
/** * Runs this tool./* w w w. ja v a2s. 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("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 inputPath0 = cmdline.getOptionValue(INPUT); String outputPath = cmdline.getOptionValue(OUTPUT); int reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS)) : 1; LOG.info("Tool: " + AutoCoder.class.getSimpleName()); LOG.info(" - input path: " + inputPath0); LOG.info(" - output path: " + outputPath); LOG.info(" - number of reducers: " + reduceTasks); Configuration conf = getConf(); initialParameters(conf); for (int iterations = 1; iterations < GlobalUtil.NUM_LAYER + 1; iterations++) { LOG.info("** Layer: " + iterations); try { Job job = Job.getInstance(conf); job.setJobName(AutoCoder.class.getSimpleName()); job.setJarByClass(AutoCoder.class); // set the path of the information of k clusters in this iteration job.getConfiguration().set("sidepath", inputPath0 + "/side_output"); job.getConfiguration().setInt("layer_ind", iterations); job.setNumReduceTasks(reduceTasks); String inputPath = inputPath0 + "/train"; dataShuffle(); FileInputFormat.setInputPaths(job, new Path(inputPath)); FileOutputFormat.setOutputPath(job, new Path(outputPath)); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(ModelNode.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(ModelNode.class); job.setMapperClass(MyMapper.class); job.setReducerClass(MyReducer.class); job.setPartitionerClass(MyPartitioner.class); // Delete the output directory if it exists already. Path outputDir = new Path(outputPath); FileSystem.get(getConf()).delete(outputDir, true); long startTime = System.currentTimeMillis(); job.waitForCompletion(true); LOG.info("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds"); prepareNextIteration(inputPath0, outputPath, iterations, conf, reduceTasks); } catch (Exception exp) { exp.printStackTrace(); } } return 0; }
From source file:edu.umd.JBizz.RunPersonalizedPageRankBasic.java
/** * Runs this tool./* ww w . ja v a 2 s .c om*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); //options.addOption(new Option(COMBINER, "use combiner")); //options.addOption(new Option(INMAPPER_COMBINER, "user in-mapper combiner")); options.addOption(new Option(RANGE, "use range partitioner")); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("base path").create(BASE)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("start iteration").create(START)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("end iteration").create(END)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES)); options.addOption(OptionBuilder.withArgName("sources").hasArg().withDescription("Personalization Nodes") .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(BASE) || !cmdline.hasOption(START) || !cmdline.hasOption(END) || !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 basePath = cmdline.getOptionValue(BASE); int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int s = Integer.parseInt(cmdline.getOptionValue(START)); int e = Integer.parseInt(cmdline.getOptionValue(END)); //boolean useCombiner = cmdline.hasOption(COMBINER); //boolean useInmapCombiner = cmdline.hasOption(INMAPPER_COMBINER); boolean useRange = cmdline.hasOption(RANGE); String sources = cmdline.getOptionValue(SOURCES); LOG.info("Tool name: RunPageRank"); LOG.info(" - base path: " + basePath); LOG.info(" - num nodes: " + n); LOG.info(" - start iteration: " + s); LOG.info(" - end iteration: " + e); //LOG.info(" - use combiner: " + useCombiner); //LOG.info(" - use in-mapper combiner: " + useInmapCombiner); LOG.info(" - user range partitioner: " + useRange); // Iterate PageRank. for (int i = s; i < e; i++) { iteratePageRank(i, i + 1, basePath, n, sources); } return 0; }
From source file:cycronix.cttraveler.CTtraveler.java
public CTtraveler(String[] arg) { long defaultDT = 100; // Concatenate all of the CTWriteMode types String possibleWriteModes = ""; for (CTWriteMode wm : CTWriteMode.values()) { possibleWriteModes = possibleWriteModes + ", " + wm.name(); }// w w w . j a v a2 s . c om // Remove ", " from start of string possibleWriteModes = possibleWriteModes.substring(2); // // Argument processing using Apache Commons CLI // // 1. Setup command line options Options options = new Options(); options.addOption("h", "help", false, "Print this message."); options.addOption(Option.builder("o").argName("base output dir").hasArg().desc( "Base output directory when writing data to local folder (i.e., CTdata location); default = \"" + outLoc + "\".") .build()); options.addOption(Option.builder("s").argName("session name").hasArg() .desc("Session name to be prefixed to the source path; default = " + sessionName + ".").build()); options.addOption(Option.builder("d").argName("delta-Time").hasArg() .desc("Fixed delta-time (msec) between frames; default = " + Long.toString(defaultDT) + ".") .build()); options.addOption(Option.builder("f").argName("autoFlush").hasArg().desc( "Flush interval (sec); amount of data per zipfile; default = " + Double.toString(autoFlush) + ".") .build()); options.addOption(Option.builder("t").argName("trim-Time").hasArg().desc( "Trim (ring-buffer loop) time (sec); this is only used when writing data to local folder; specify 0 for indefinite; default = " + Double.toString(trimTime) + ".") .build()); options.addOption(Option.builder("bps").argName("blocks per seg").hasArg() .desc("Number of blocks per segment; specify 0 for no segments; default = " + Long.toString(blocksPerSegment) + ".") .build()); options.addOption(Option.builder("mc").argName("model color").hasArg().desc( "Color of the Unity model; must be one of: Red, Blue, Green, Yellow; default = " + modelColor + ".") .build()); options.addOption(Option.builder("mt").argName("model type").hasArg().desc( "Type of the Unity model; must be one of: Primplane, Ball, Biplane; default = " + modelType + ".") .build()); options.addOption( Option.builder("w").argName("write mode").hasArg().desc("Type of CT write connection; one of " + possibleWriteModes + "; default = " + writeMode.name() + ".").build()); options.addOption(Option.builder("host").argName("host[:port]").hasArg() .desc("Host:port when writing to CT via FTP, HTTP, HTTPS.").build()); options.addOption(Option.builder("u").argName("username,password").hasArg() .desc("Comma-delimited username and password when writing to CT via FTP, HTTP or HTTPS.").build()); options.addOption("x", "debug", false, "Enable CloudTurbine debug output."); // 2. Parse command line options CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, arg); } catch (ParseException exp) { // oops, something went wrong System.err.println("Command line argument parsing failed: " + exp.getMessage()); return; } // 3. Retrieve the command line values if (line.hasOption("help")) { // Display help message and quit HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp("CTtraveler", options); return; } outLoc = line.getOptionValue("o", outLoc); if (!outLoc.endsWith("\\") && !outLoc.endsWith("/")) { outLoc = outLoc + File.separator; } // Make sure the base output folder location ends in "CTdata" if (!outLoc.endsWith("CTdata\\") && !outLoc.endsWith("CTdata/")) { outLoc = outLoc + "CTdata" + File.separator; } sessionName = line.getOptionValue("s", sessionName); if (sessionName.isEmpty()) { System.err.println("You must specify a Session name."); System.exit(0); } if (!sessionName.endsWith("\\") && !sessionName.endsWith("/")) { sessionName = sessionName + File.separator; } String sdt = line.getOptionValue("d", Long.toString(defaultDT)); long dt = Long.parseLong(sdt); autoFlush = Double.parseDouble(line.getOptionValue("f", "" + autoFlush)); if (autoFlush <= 0.0) { System.err.println("Auto flush must be a value greater than 0."); System.exit(0); } trimTime = Double.parseDouble(line.getOptionValue("t", Double.toString(trimTime))); blocksPerSegment = Long.parseLong(line.getOptionValue("bps", Long.toString(blocksPerSegment))); debug = line.hasOption("debug"); // Type of output connection String writeModeStr = line.getOptionValue("w", writeMode.name()); boolean bMatch = false; for (CTWriteMode wm : CTWriteMode.values()) { if (wm.name().toLowerCase().equals(writeModeStr.toLowerCase())) { writeMode = wm; bMatch = true; } } if (!bMatch) { System.err.println("Unrecognized write mode, \"" + writeModeStr + "\"; write mode must be one of " + possibleWriteModes); System.exit(0); } if (writeMode != CTWriteMode.LOCAL) { // User must have specified the host serverHost = line.getOptionValue("host", serverHost); if (serverHost.isEmpty()) { System.err.println( "When using write mode \"" + writeModeStr + "\", you must specify the server host."); System.exit(0); } } String userpassStr = line.getOptionValue("u", ""); if (!userpassStr.isEmpty()) { if (writeMode == CTWriteMode.LOCAL) { System.err.println("Username and password are not used when writing local CT files."); System.exit(0); } // This string should be comma-delimited username and password String[] userpassCSV = userpassStr.split(","); if (userpassCSV.length != 2) { System.err.println( "When specifying a username and password, separate the username and password by a comma."); System.exit(0); } serverUser = userpassCSV[0]; serverPassword = userpassCSV[1]; } if ((writeMode == CTWriteMode.HTTP) && (!serverUser.isEmpty())) { System.err.println( "Please note that the username and password are not encrypted when writing CT files via HTTP."); } // CT/Unity model parameters String modelColorRequest = line.getOptionValue("mc", modelColor); modelColor = ""; for (ModelColor mc : ModelColor.values()) { if (mc.name().toLowerCase().equals(modelColorRequest.toLowerCase())) { modelColor = mc.name(); } } if (modelColor.isEmpty()) { System.err.println( "Unrecognized model color, \"" + modelColorRequest + "\"; model color must be one of:"); for (ModelColor mc : ModelColor.values()) { System.err.println("\t" + mc.name()); } System.exit(0); } String modelTypeRequest = line.getOptionValue("mt", modelType); modelType = ""; for (ModelType mt : ModelType.values()) { if (mt.name().toLowerCase().equals(modelTypeRequest.toLowerCase())) { modelType = mt.name(); } } if (modelType.isEmpty()) { System.err.println("Unrecognized model type, \"" + modelTypeRequest + "\"; model type must be one of:"); for (ModelType mt : ModelType.values()) { System.err.println("\t" + mt.name()); } System.exit(0); } // // Create CTwriter (for writing data to CT format) // CTwriter ctw = null; System.err.println("Model: " + modelType); // If sessionName isn't blank, it will end in a file separator String srcName = sessionName + "GamePlay" + File.separator + playerName; System.err.println("Game source: " + srcName); System.err.println(" write out JSON data"); try { ctw = create_CT_source(srcName, true, zipMode); } catch (Exception e) { e.printStackTrace(); System.exit(0); } // Setup the data generator JsonGenerator jsonGenerator = new MouseDataGenerator(playerName, modelType); // Adjust sampInterval to keep the desired sample period long msec_adjust = 0; while (true) { long time_msec = System.currentTimeMillis(); // Generate updated data String unityStr = jsonGenerator.generateJson(time_msec); if ((unityStr != null) && (!unityStr.isEmpty())) { // Write to CT (note that we use auto-flush so there's no call to flush here) ctw.setTime(time_msec); try { ctw.putData("CTstates.json", unityStr); } catch (Exception e) { System.err.println("Exception putting data to CT:\n" + e); continue; } System.err.print("."); } // Automatically adjust sleep time (to try and maintain the desired delta-T) if (dt > 0) { if ((dt + msec_adjust) > 0) { try { Thread.sleep(dt + msec_adjust); } catch (Exception e) { } ; } long now_time_msec = System.currentTimeMillis(); if ((now_time_msec - time_msec) > (dt + 10)) { msec_adjust = msec_adjust - 1; } else if ((now_time_msec - time_msec) < (dt - 10)) { msec_adjust = msec_adjust + 1; } } } }
From source file:eu.stratosphere.yarn.Client.java
private void printUsage() { System.out.println("Usage:"); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(200); formatter.setLeftPadding(5);//from w w w .j a va 2 s . c om formatter.setSyntaxPrefix(" Required"); Options req = new Options(); req.addOption(CONTAINER); formatter.printHelp(" ", req); formatter.setSyntaxPrefix(" Optional"); Options opt = new Options(); opt.addOption(VERBOSE); // opt.addOption(GEN_CONF); // opt.addOption(STRATOSPHERE_CONF); // opt.addOption(STRATOSPHERE_JAR); opt.addOption(JM_MEMORY); opt.addOption(TM_MEMORY); opt.addOption(TM_CORES); opt.addOption(QUERY); opt.addOption(QUEUE); formatter.printHelp(" ", opt); }
From source file:edu.umd.windmemory.RunPersonalizedPageRankBasic.java
/** * Runs this tool.//from w w w . j a va 2 s .c o m */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(COMBINER, "use combiner")); // options.addOption(new Option(INMAPPER_COMBINER, "user in-mapper combiner")); options.addOption(new Option(RANGE, "use range partitioner")); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("base path").create(BASE)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("start iteration").create(START)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("end iteration").create(END)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES)); options.addOption( OptionBuilder.withArgName("node").hasArg().withDescription("source nodes").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(BASE) || !cmdline.hasOption(START) || !cmdline.hasOption(END) || !cmdline.hasOption(NUM_NODES)) { 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 basePath = cmdline.getOptionValue(BASE); int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int s = Integer.parseInt(cmdline.getOptionValue(START)); int e = Integer.parseInt(cmdline.getOptionValue(END)); String sources = cmdline.getOptionValue(SOURCES); // boolean useInmapCombiner = cmdline.hasOption(INMAPPER_COMBINER); boolean useRange = cmdline.hasOption(RANGE); LOG.info("Tool name: RunPageRank"); LOG.info(" - base path: " + basePath); LOG.info(" - num nodes: " + n); LOG.info(" - start iteration: " + s); LOG.info(" - end iteration: " + e); // LOG.info(" - use in-mapper combiner: " + useInmapCombiner); LOG.info(" - user range partitioner: " + useRange); LOG.info(" - source nodes: " + sources); // Iterate PageRank. for (int i = s; i < e; i++) { iteratePageRank(i, i + 1, basePath, n, sources); } return 0; }
From source file:erigo.ctserial.CTserial.java
public CTserial(String[] arg) { // Specify a shutdown hook to catch Ctrl+c Runtime.getRuntime().addShutdownHook(new Thread() { @Override//from www. jav a2s .c o m public void run() { // Signal that it is time to shut down bShutdown = true; try { if (serialReadThread != null) { System.err.println("Wait for SerialRead to stop"); serialReadThread.join(1000); if (serialReadThread.isAlive()) { // SerialRead must be waiting for more serial input; // interrupt it serialReadThread.interrupt(); serialReadThread.join(2000); } if (!serialReadThread.isAlive()) { System.err.println("SerialRead has stopped"); } else { try { serialReadThread.notifyAll(); } catch (IllegalMonitorStateException excep) { // nothing to do } } } } catch (InterruptedException ie) { System.err.println("Caught exception trying to stop SerialRead:\n" + ie); } } }); String[] chanNames = null; double dt = 0.0; // Argument processing using Apache Commons CLI // 1. Setup command line options Options options = new Options(); options.addOption("h", "help", false, "Print this message"); options.addOption(Option.builder("s").argName("source name").hasArg() .desc("name of source to write serial packets to; default = " + srcName).build()); options.addOption(Option.builder("c").argName("channel name(s)").hasArg() .desc("name of channel(s) to write data to (comma-separated list)").build()); options.addOption(Option.builder("p").argName("serial port").hasArg() .desc("port number to listen for serial packets on; default = " + defaultPortStr).build()); options.addOption(Option.builder("d").argName("delta-time").hasArg() .desc("fixed delta-time (msec) between frames; dt=0 (which is the default) to use arrival-times") .build()); options.addOption(Option.builder("f").argName("autoFlush").hasArg() .desc("flush interval (sec) (amount of data per zipfile); default = " + Double.toString(autoFlush)) .build()); options.addOption(Option.builder("t").argName("trim-Time").hasArg() .desc("trim (ring-buffer loop) time (sec); trimTime=0 (which is the default) for indefinite") .build()); options.addOption(Option.builder("b").argName("baudrate").hasArg() .desc(new String("baud rate; default = " + baudRateDefault)).build()); options.addOption(Option.builder("i").argName("input file").hasArg() .desc("read input from a file rather than a serial port").build()); options.addOption(Option.builder("bps").argName("blocks_per_seg").hasArg() .desc("Number of blocks per segment; specify 0 for no segments; default = " + Long.toString(blocksPerSegment) + ".") .build()); options.addOption("time_in_str", false, "the first entry in the received CSV string is the data time; in this case, do not include the time channel as the first entry in the specified channels list"); options.addOption("x", "debug", false, "debug mode"); options.addOption("z", "sim_mode", false, "turn on simulate mode (don't read serial port)"); // 2. Parse command line options CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, arg); } catch (ParseException exp) { System.err.println("Command line argument parsing failed: " + exp.getMessage()); return; } // // 3. Retrieve the command line values // if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp("CTserial", options); return; } srcName = line.getOptionValue("s", srcName); String chanNameL = line.getOptionValue("c", "serialchan"); chanNames = chanNameL.split(","); String portStr = line.getOptionValue("p", defaultPortStr); String dtStr = line.getOptionValue("d", "0"); dt = Double.parseDouble(dtStr); // Auto-flush time autoFlush = Double.parseDouble(line.getOptionValue("f", "" + autoFlush)); trimTime = Double.parseDouble(line.getOptionValue("t", "0")); blocksPerSegment = Long.parseLong(line.getOptionValue("bps", Long.toString(blocksPerSegment))); boolean bFirstValIsTime = line.hasOption("time_in_str"); // Can't have both bFirstValIsTime==true and dt!=0 if (bFirstValIsTime && (dt != 0)) { System.err.println("Not able to use both \"time_in_str\" and \"delta-time\" options at the same time."); return; } boolean bSimulateMode = line.hasOption("sim_mode"); if (bSimulateMode && (dt == 0)) { System.err.println("Must specify \"delta-time\" when in simulate mode."); return; } debug = line.hasOption("debug"); int baudrate = Integer.parseInt(line.getOptionValue("br", Integer.toString(baudRateDefault))); inFileName = null; if (line.hasOption("i")) { inFileName = line.getOptionValue("i"); } // setup CTwriter try { ctw = new CTwriter(srcName, trimTime); ctw.setZipMode(zipMode); ctw.autoFlush(autoFlush); CTinfo.setDebug(debug); ctw.autoSegment(blocksPerSegment); } catch (Exception e) { System.err.println("Caught exception trying to setup CTwriter:"); e.printStackTrace(); return; } if (inFileName != null) { System.err.print("Source name: " + srcName + "\nInput file: " + inFileName + "\nChannels: "); } else { System.err.print("Source name: " + srcName + "\nSerial port: " + portStr + "\nBaud rate: " + baudrate + "\nChannels: "); } for (int i = 0; i < (chanNames.length - 1); ++i) { System.err.print(chanNames[i] + ","); } System.err.println(chanNames[chanNames.length - 1]); if (bSimulateMode) { System.err.println("IN SIMULATE MODE"); } try { serialRead = new SerialRead(inFileName, portStr, chanNames, dt, bFirstValIsTime, baudrate, bSimulateMode); serialReadThread = new Thread(serialRead); serialReadThread.start(); } catch (Exception e) { System.err.println("Caught exception:\n" + e); return; } }
From source file:model.AutoCoder.java
/** * Runs this tool.//from w ww . jav 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("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) + "/part*"; String outputPath = cmdline.getOptionValue(OUTPUT); //String inputPath = "mingled_v2/part*"; //String outputPath = "output"; String dataPath = cmdline.getOptionValue(INPUT) + "/common"; int reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS)) : 1; LOG.info("Tool: " + AutoCoder.class.getSimpleName()); LOG.info(" - input path: " + inputPath); LOG.info(" - output path: " + outputPath); LOG.info(" - number of reducers: " + reduceTasks); Configuration conf = getConf(); initialParameters(conf); conf.set("dataPath", dataPath); conf.set("mapreduce.map.memory.mb", "2048"); conf.set("mapreduce.map.java.opts", "-Xmx2048m"); conf.set("mapreduce.reduce.memory.mb", "2048"); conf.set("mapreduce.reduce.java.opts", "-Xmx2048m"); Job job = Job.getInstance(conf); job.setJobName(AutoCoder.class.getSimpleName()); job.setJarByClass(AutoCoder.class); // set the path of the information of k clusters in this iteration job.getConfiguration().set("sidepath", inputPath + "/side_output"); job.setNumReduceTasks(reduceTasks); dataShuffle(); FileInputFormat.setInputPaths(job, new Path(inputPath)); FileOutputFormat.setOutputPath(job, new Path(outputPath)); FileInputFormat.setMaxInputSplitSize(job, 1000 * 1024 * 1024); FileInputFormat.setMinInputSplitSize(job, 1000 * 1024 * 1024); job.setInputFormatClass(TextInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(ModelNode.class); job.setOutputKeyClass(NullWritable.class); job.setOutputValueClass(SuperModel.class); job.setMapperClass(MyMapper.class); job.setReducerClass(MyReducer.class); job.setPartitionerClass(MyPartitioner.class); // Delete the output directory if it exists already. Path outputDir = new Path(outputPath); FileSystem.get(getConf()).delete(outputDir, true); long startTime = System.currentTimeMillis(); job.waitForCompletion(true); LOG.info("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds"); //prepareNextIteration(inputPath0, outputPath,iterations,conf,reduceTasks); return 0; }
From source file:RunPageRankBasic.java
/** * Runs this tool.//from w ww .ja v a 2 s. com */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(COMBINER, "use combiner")); options.addOption(new Option(INMAPPER_COMBINER, "user in-mapper combiner")); options.addOption(new Option(RANGE, "use range partitioner")); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("base path").create(BASE)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("start iteration").create(START)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("end iteration").create(END)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES)); 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(BASE) || !cmdline.hasOption(START) || !cmdline.hasOption(END) || !cmdline.hasOption(NUM_NODES)) { 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 basePath = cmdline.getOptionValue(BASE); int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int s = Integer.parseInt(cmdline.getOptionValue(START)); int e = Integer.parseInt(cmdline.getOptionValue(END)); boolean useCombiner = cmdline.hasOption(COMBINER); boolean useInmapCombiner = cmdline.hasOption(INMAPPER_COMBINER); boolean useRange = cmdline.hasOption(RANGE); LOG.info("Tool name: RunPageRank"); LOG.info(" - base path: " + basePath); LOG.info(" - num nodes: " + n); LOG.info(" - start iteration: " + s); LOG.info(" - end iteration: " + e); LOG.info(" - use combiner: " + useCombiner); LOG.info(" - use in-mapper combiner: " + useInmapCombiner); LOG.info(" - user range partitioner: " + useRange); // Iterate PageRank. for (int i = s; i < e; i++) { iteratePageRank(i, i + 1, basePath, n, useCombiner, useInmapCombiner); } return 0; }
From source file:RunPersonalizedPageRankBasic.java
/** * Runs this tool./* w w w .ja v a2 s . c o m*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(COMBINER, "use combiner")); options.addOption(new Option(RANGE, "use range partitioner")); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("base path").create(BASE)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("start iteration").create(START)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("end iteration").create(END)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES)); options.addOption( OptionBuilder.withArgName("sources").hasArg().withDescription("source nodes").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(BASE) || !cmdline.hasOption(START) || !cmdline.hasOption(END) || !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 basePath = cmdline.getOptionValue(BASE); int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int s = Integer.parseInt(cmdline.getOptionValue(START)); int e = Integer.parseInt(cmdline.getOptionValue(END)); boolean useCombiner = cmdline.hasOption(COMBINER); boolean useRange = cmdline.hasOption(RANGE); String sourcesString = cmdline.getOptionValue(SOURCES); LOG.info("Tool name: RunPageRank"); LOG.info(" - base path: " + basePath); LOG.info(" - num nodes: " + n); LOG.info(" - start iteration: " + s); LOG.info(" - end iteration: " + e); LOG.info(" - use combiner: " + useCombiner); LOG.info(" - user range partitioner: " + useRange); LOG.info(" - sources: " + sourcesString); // Iterate PageRank. for (int i = s; i < e; i++) { iteratePageRank(i, i + 1, basePath, n, useCombiner, sourcesString); } return 0; }
From source file:com.delcyon.capo.Configuration.java
public void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(200); formatter.printHelp("CapoServer", options); }