List of usage examples for org.apache.commons.cli ParseException printStackTrace
public void printStackTrace()
From source file:org.schreibubi.JCombinationsTools.templateEngine.TemplateEngine.java
/** * TemplateEngine//from w w w . j a v a2s. c o m * * @param args * assignments template */ @SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); try { CommandLineParser CLparser = new PosixParser(); // create the Options options.addOption(OptionBuilder.isRequired().withLongOpt("output-filename") .withDescription("[out] which variable is used for nameing the files").hasArg() .withArgName("variable name").create('o')); options.addOption(OptionBuilder.withLongOpt("multifile") .withDescription( "output template to multiple files, -o contains variable name to use for filename") .create('m')); options.addOption(OptionBuilder.withLongOpt("multitemplate") .withDescription("use multiple templates, -t contains variable name to use for template") .create('u')); options.addOption(OptionBuilder.isRequired().withLongOpt("template") .withDescription("[in] the file containing the template to process").hasArg() .withArgName("file").create('t')); options.addOption(OptionBuilder.isRequired().withLongOpt("variables").withDescription( "[in] a file containing the values of the variables which should be replaced in the template") .hasArg().withArgName("file").create('v')); options.addOption(OptionBuilder.withLongOpt("outputDir") .withDescription("output directory to write the generated files to.").hasArg() .withArgName("file").create('d')); options.addOption(OptionBuilder.withLongOpt("header").withDescription("header to insert in each file") .hasArg().withArgName("file").create('h')); options.addOption(OptionBuilder.withLongOpt("footer").withDescription("footer to insert in each file") .hasArg().withArgName("file").create('f')); options.addOption(OptionBuilder.withLongOpt("version").withDescription("version").create('v')); CommandLine line = CLparser.parse(options, args); if (line.hasOption("v")) { Info.printVersion("TemplateEngine"); Runtime.getRuntime().exit(0); } boolean generateSeparateFilesSwitch = false; if (line.hasOption("m")) { generateSeparateFilesSwitch = true; } boolean multiTemplateSwitch = false; if (line.hasOption("u")) { multiTemplateSwitch = true; } String outputFilenameOrVariable = ""; if (line.hasOption("o")) { outputFilenameOrVariable = line.getOptionValue("o"); } String templateFilenameOrVariable = ""; if (line.hasOption("t")) { templateFilenameOrVariable = line.getOptionValue("t"); } String variablesFilename = ""; if (line.hasOption("v")) { variablesFilename = line.getOptionValue("v"); } String outputDir = null; if (line.hasOption("d")) { outputDir = line.getOptionValue("d", null); } String header = null; if (line.hasOption("h")) { header = line.getOptionValue("h", null); } String footer = null; if (line.hasOption("f")) { outputDir = line.getOptionValue("f", null); } File variablesFile = new File(variablesFilename); File headerFile = new File(header); File footerFile = new File(footer); File inputDirFile = new File("."); File outputDirFile = new File(outputDir); exec(variablesFile, generateSeparateFilesSwitch, outputFilenameOrVariable, multiTemplateSwitch, templateFilenameOrVariable, inputDirFile, outputDirFile, headerFile, footerFile); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(Info.getVersionString("TemplateEngine"), options); } catch (Exception e) { System.out.println("TemplateEngine error: " + e.getMessage()); e.printStackTrace(); System.exit(1); } }
From source file:org.semanticscience.narf.graphs.main.CycleExtractor.java
public static void main(String[] args) { Options options = createOptions();// w ww. jav a 2s. c o m CommandLineParser p = createCliParser(); String inputPDBDirStr = null; String inputSeqFileStr = null; File inputSeqFile = null; File inputPDBDir = null; String outputdirStr = null; File outputDir = null; String format = null; try { CommandLine c = p.parse(options, args); if (c.hasOption("help")) { printUsage(); System.exit(1); } if (c.hasOption("inputPDBDir")) { inputPDBDirStr = c.getOptionValue("inputPDBDir"); inputPDBDir = new File(inputPDBDirStr); } if (c.hasOption("inputSeqFile")) { inputSeqFileStr = c.getOptionValue("inputSeqFile"); inputSeqFile = new File(inputSeqFileStr); } // check that either the input sequence file or the input PDB // directory are specified if (inputSeqFile == null && inputPDBDir == null) { System.out.println("Either an input PDB directory or an input sequence file must be specified!"); printUsage(); System.exit(1); } if (c.hasOption("outputDir")) { outputdirStr = c.getOptionValue("outputDir"); outputDir = new File(outputdirStr); } else { System.out.println("You must specify an output directory!"); printUsage(); System.exit(1); } if (c.hasOption("outputFormat")) { format = c.getOptionValue("outputFormat"); } else { System.out.println("You must specify an output format!"); printUsage(); System.exit(1); } if (inputPDBDir != null) { //TODO: be able to change default parser for pdb structures CycleSerializer cs = new CycleSerializer("x3dna-dssr", "beta-r21-on-20130903"); // from the input directory get a list of input files<String> List<String> inputFiles = CycleExtractor.getFilePathsFromDir(inputPDBDir, "pdb"); for (String aFilePath : inputFiles) { Set<NucleicAcid> nucs = CycleExtractor.runX3DNADSSR(aFilePath); if (nucs == null || nucs.size() == 0) { throw new CycleException("Could not extract cycles from :" + aFilePath); } else { // only one model if (nucs.size() == 1) { for (NucleicAcid aNuc : nucs) { List<Cycle<Nucleotide, InteractionEdge>> ccb = aNuc.getMinimumCycleBasis(); //see if cycle basis is empty if (ccb.size() == 0) { System.out.println("PDBID:" + aFilePath + " has an empty cycle basis!"); continue; } // the pdbid String aPdbId = CycleExtractor.getPdbIdFromFilePath(aFilePath); if (format.equals("RDF")) { Model m = cs.createNarfModelFromPDB(aPdbId, aNuc, ccb, false); // make an output file File outputFile = new File( outputDir.getAbsolutePath() + "/" + aPdbId + "_cycles.rdf"); // create a fop FileOutputStream fop = new FileOutputStream(outputFile); m.write(fop); fop.close(); } else if (format.equals("tsv")) { String tsv = cs.createNarfTsv(aPdbId, aNuc, ccb, null, -1, false); File outputFile = new File( outputDir.getAbsolutePath() + "/" + aPdbId + "_cycles.tsv"); FileUtils.writeStringToFile(outputFile, tsv); } } } } } //now write a report in a separate output file //print a summary file String summary = cs.makeSummary(); File readme_out = new File(outputDir.getAbsolutePath() + "/cycle_summary.txt"); FileUtils.writeStringToFile(readme_out, summary); } else if (inputSeqFile != null) { //create a cycle serializer object CycleSerializer cs = new CycleSerializer("x3dna-dssr", "beta-r21-on-20130903"); // open the file List<String> lines = FileUtils.readLines(inputSeqFile); // foreach line in the file int c3 = 1; for (String aLine : lines) { c3++; // get a sequence List<String> sl = Arrays.asList(aLine.split(",")); // skip the first line //if (sl.get(0).equals("sequence")) { // continue; //} String aSeq = aLine; //String aSeq = sl.get(0).replace("\"", ""); // call runMfold Set<NucleicAcid> nas = CycleExtractor.runMfold(aSeq); if (nas == null || nas.size() == 0) { throw new CycleException("Could not extract cycles from :" + sl); } else { if (nas.size() == 1) { for (NucleicAcid aNuc : nas) { Random r = new Random(); int rand = Math.abs((r.nextInt(65536) - 32768)); String rd = Integer.toString(rand); // get the MCB of each prediction List<Cycle<Nucleotide, InteractionEdge>> ccb = aNuc.getMinimumCycleBasis(); //get the aptamer type //String apt_type = sl.get(5).replace("\"", ""); //get the selex experiment mid //String se_mid = sl.get(4).replace("\"", ""); //se_mid = se_mid.replace("\\/", ""); //se_mid += rand; if (format.equals("RDF")) { Model m = cs.createNarfModelFromAB(rd, aNuc, ccb); // make an output file File outputFile = new File(outputDir.getAbsolutePath() + "/" + Math.abs(c3 + rand) + rd + "_cycles.rdf"); // create a fop FileOutputStream fop = new FileOutputStream(outputFile); m.write(fop); fop.close(); } else if (format.equals("tsv")) { /*String tsv = cs.createNarfTsv(se_mid, aNuc, ccb,apt_type,rand, true); File outputFile = new File( outputDir.getAbsolutePath() + "/" + se_mid+"-"+rand + "_cycles.tsv"); FileUtils .writeStringToFile(outputFile, tsv);*/ } } } } } String summary = cs.makeSummary(); File readme_out = new File(outputDir.getAbsolutePath() + "/cycle_summary.txt"); FileUtils.writeStringToFile(readme_out, summary); } } catch (ParseException e) { System.out.println("Unable to parse specified options."); printUsage(); System.exit(1); } catch (CycleException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.stubby.Stubby4J.java
public static void main(final String[] args) { try {/* ww w . j a v a2s .c o m*/ CommandLineIntepreter.parseCommandLine(args); } catch (ParseException e) { e.printStackTrace(); System.exit(1); } if (CommandLineIntepreter.isHelp()) { CommandLineIntepreter.printHelp(Stubby4J.class); } else if (!CommandLineIntepreter.isYamlProvided()) { System.err.println( "\n\nYAML configuration was not provided using command line option '-f' or '--config'.\nPlease run again with option '--help'\n\n"); System.exit(1); } else { try { final Map<String, String> commandLineArgs = CommandLineIntepreter.getCommandlineParams(); final String yamlConfigFilename = commandLineArgs.get(CommandLineIntepreter.OPTION_CONFIG); JettyOrchestratorFactory.getInstance(yamlConfigFilename, commandLineArgs).startJetty(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }
From source file:org.teavm.cli.TeaVMRunner.java
@SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("target").hasArg() .withDescription("target type (javascript/js, webassembly/wasm)").create('t')); options.addOption(OptionBuilder.withArgName("directory").hasArg() .withDescription("a directory where to put generated files (current directory by default)") .withLongOpt("targetdir").create('d')); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("a file where to put decompiled classes (classes.js by default)") .withLongOpt("targetfile").create('f')); options.addOption(OptionBuilder.withDescription("causes TeaVM to generate minimized JavaScript file") .withLongOpt("minify").create("m")); options.addOption(OptionBuilder.withDescription("optimization level (1-3)").hasArg().withArgName("number") .create("O")); options.addOption(OptionBuilder.withArgName("separate|merge|none").hasArg() .withDescription("how to attach runtime. Possible values are: separate|merge|none") .withLongOpt("runtime").create("r")); options.addOption(OptionBuilder.withDescription("causes TeaVM to include default main page") .withLongOpt("mainpage").create()); options.addOption(//w ww.ja va 2s .co m OptionBuilder.withDescription("Generate debug information").withLongOpt("debug").create('g')); options.addOption( OptionBuilder.withDescription("Generate source maps").withLongOpt("sourcemaps").create('G')); options.addOption( OptionBuilder.withDescription("Incremental build").withLongOpt("incremental").create('i')); options.addOption(OptionBuilder.withArgName("directory").hasArg() .withDescription("Incremental build cache directory").withLongOpt("cachedir").create('c')); options.addOption(OptionBuilder .withDescription("Wait for command after compilation, in order to enable hot recompilation") .withLongOpt("wait").create('w')); options.addOption(OptionBuilder.withArgName("classpath").hasArgs() .withDescription("Additional classpath that will be reloaded by TeaVM each time in wait mode") .withLongOpt("classpath").create('p')); options.addOption(OptionBuilder.withLongOpt("classalias").withArgName("alias").hasArgs() .withDescription("Alias names for classes. Specify as fully.qualified.Name:AliasName").create()); options.addOption(OptionBuilder.withLongOpt("wasm-version").withArgName("version").hasArg() .withDescription("WebAssembly binary version (11, 12, 13)").create()); if (args.length == 0) { printUsage(options); return; } CommandLineParser parser = new PosixParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException e) { printUsage(options); return; } TeaVMTool tool = new TeaVMTool(); if (commandLine.hasOption("t")) { switch (commandLine.getOptionValue('t').toLowerCase()) { case "javascript": case "js": tool.setTargetType(TeaVMTargetType.JAVASCRIPT); break; case "webassembly": case "wasm": tool.setTargetType(TeaVMTargetType.WEBASSEMBLY); break; } } if (commandLine.hasOption("d")) { tool.setTargetDirectory(new File(commandLine.getOptionValue("d"))); } if (commandLine.hasOption("f")) { tool.setTargetFileName(commandLine.getOptionValue("f")); } if (commandLine.hasOption("m")) { tool.setMinifying(true); } else { tool.setMinifying(false); } if (commandLine.hasOption("r")) { switch (commandLine.getOptionValue("r")) { case "separate": tool.setRuntime(RuntimeCopyOperation.SEPARATE); break; case "merge": tool.setRuntime(RuntimeCopyOperation.MERGED); break; case "none": tool.setRuntime(RuntimeCopyOperation.NONE); break; default: System.err.println("Wrong parameter for -r option specified"); printUsage(options); return; } } if (commandLine.hasOption("mainpage")) { tool.setMainPageIncluded(true); } if (commandLine.hasOption('g')) { tool.setDebugInformationGenerated(true); } if (commandLine.hasOption("O")) { int level; try { level = Integer.parseInt(commandLine.getOptionValue("O")); } catch (NumberFormatException e) { System.err.print("Wrong optimization level"); printUsage(options); return; } switch (level) { case 1: tool.setOptimizationLevel(TeaVMOptimizationLevel.SIMPLE); break; case 2: tool.setOptimizationLevel(TeaVMOptimizationLevel.ADVANCED); break; case 3: tool.setOptimizationLevel(TeaVMOptimizationLevel.FULL); break; default: System.err.print("Wrong optimization level"); printUsage(options); return; } } if (commandLine.hasOption('S')) { tool.setSourceMapsFileGenerated(true); } if (commandLine.hasOption('i')) { tool.setIncremental(true); } if (commandLine.hasOption('c')) { tool.setCacheDirectory(new File(commandLine.getOptionValue('c'))); } else { tool.setCacheDirectory(new File(tool.getTargetDirectory(), "teavm-cache")); } if (commandLine.hasOption('p')) { classPath = commandLine.getOptionValues('p'); } if (commandLine.hasOption("classalias")) { String[] aliasStrings = commandLine.getOptionValues("classalias"); for (String aliasString : aliasStrings) { int i = aliasString.indexOf(':'); if (i == -1) { System.err.print("Wrong alias specification"); printUsage(options); return; } ClassAlias alias = new ClassAlias(); alias.setClassName(aliasString.substring(0, i)); alias.setAlias(aliasString.substring(i + 1)); tool.getClassAliases().add(alias); } } boolean interactive = commandLine.hasOption('w'); setupWasm(tool, commandLine, options); args = commandLine.getArgs(); if (args.length > 1) { System.err.println("Unexpected arguments"); printUsage(options); return; } else if (args.length == 1) { tool.setMainClass(args[0]); } tool.setLog(new ConsoleTeaVMToolLog()); tool.getProperties().putAll(System.getProperties()); tool.setProgressListener(progressListener); if (interactive) { boolean quit = false; BufferedReader reader; try { reader = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); System.exit(-2); return; } do { try { build(tool); } catch (Exception e) { e.printStackTrace(System.err); } System.out.println("Press enter to repeat or enter 'q' to quit"); try { String line = reader.readLine().trim(); if (!line.isEmpty()) { if (line.equals("q")) { quit = true; } else { System.out.println("Unrecognized command"); } } } catch (IOException e) { e.printStackTrace(); System.exit(-2); } } while (!quit); } else { try { build(tool); } catch (Exception e) { e.printStackTrace(System.err); System.exit(-2); } if (!tool.getProblemProvider().getSevereProblems().isEmpty()) { System.exit(-2); } } }
From source file:org.timconrad.fakecarbon.Main.java
public static void main(String[] args) { Logger logger = LoggerFactory.getLogger(Main.class); Hashtable<String, String> appConfig = new Hashtable<String, String>(); CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("p", "port", true, "Port to run on (default:2003)"); options.addOption("D", "displayAll", false, "Log all incoming packets"); options.addOption("d", "displayBad", false, "Log only incoming malformed packets"); options.addOption("h", "help", false, "show this help"); int somePort = 2003; try {/*from ww w . ja va 2s . com*/ CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("FakeCarbon.jar", options); System.exit(0); } if (line.hasOption("port")) { System.out.println("Say nothing, act casual"); somePort = Integer.parseInt(line.getOptionValue("port")); } if (line.hasOption("displayAll")) { appConfig.put("displayAll", "true"); } else { appConfig.put("displayAll", "false"); } if (line.hasOption("displayBad")) { appConfig.put("displayBad", "true"); } else { appConfig.put("displayBad", "false"); } } catch (ParseException e) { System.out.println("CLI options exception: " + e.getMessage()); e.printStackTrace(); System.exit(-1); } System.out.println("Fake Carbon listener starting up on TCP@" + somePort); new Main(somePort).run(appConfig); }
From source file:org.timconrad.vmstats.Main.java
public static void main(String[] args) { Logger logger = LoggerFactory.getLogger(Main.class); Properties config = new Properties(); Boolean showPerfMgr = false;//from www. j av a2 s . c om Boolean showEstimate = false; Boolean noThreads = false; Boolean noGraphite = false; File configFile = new File("vmstats.properties"); Hashtable<String, String> appConfig = new Hashtable<String, String>(); CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("P", "perfMgr", false, "Display Performance Manager Counters and exit"); options.addOption("E", "estimate", false, "Estimate the # of counters written to graphite and exit"); options.addOption("N", "noThreads", false, "Don't start any threads, just run the main part (helpful for troubleshooting initial issues"); options.addOption("g", "noGraphite", false, "Don't send anything to graphite"); options.addOption("c", "configFile", true, "Configuration file for vmstats - defaults to 'vmstats.properties' in the .jar directory"); options.addOption("O", "runOnce", false, "Run the stats gatherer one time - useful for debugging"); options.addOption("D", "debugOutput", false, "Dump the output to a thread-named file."); options.addOption("h", "help", false, "show help"); try { CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { System.out.println("vmstats.jar -Dlog4j.configuration=file:/path/to/log4j.properties [options]"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("vmstats.jar", options); System.exit(0); } if (line.hasOption("perfMgr")) { showPerfMgr = true; } if (line.hasOption("estimate")) { showEstimate = true; } if (line.hasOption("noThreads")) { noThreads = true; } if (line.hasOption("noGraphite")) { noGraphite = true; } if (line.hasOption("runOnce")) { appConfig.put("runOnce", "true"); } else { appConfig.put("runOnce", "false"); } if (line.hasOption("debugOutput")) { appConfig.put("debugOutput", "true"); } else { appConfig.put("debugOutput", "false"); } if (line.hasOption("configFile")) { // if the user adds a custom config flag, use it. Otherwise they'll get the default. String file = line.getOptionValue("configFile"); File optFile = new File(file); boolean exists = optFile.exists(); // check to make sure the file exists. if (!exists) { System.out.println("The configuration file doesn't seem to exist in path: " + file); System.exit(0); } else { configFile = optFile; } } } catch (org.apache.commons.cli.ParseException e) { System.out.println("CLI options exception: " + e.getMessage()); e.printStackTrace(); } try { config.load(new FileInputStream(configFile)); } catch (FileNotFoundException e) { logger.info("Configuration file not found!\n\tException: " + e); System.exit(-1); } catch (IOException e) { logger.info("Configuration file not found!\n\tException: " + e); System.exit(-1); } Enumeration configOpts = config.propertyNames(); // this will have to be manually updated. String[] expectedOptions = { "VCS_TAG", "VCS_USER", "GRAPHITE_PORT", "GRAPHITE_TAG", "VCS_HOST", "VCS_PASS", "MAX_VMSTAT_THREADS", "GRAPHITE_HOST", "ESX_STATS", "USE_FQDN", "SLEEP_TIME", "SEND_ALL_ABSOLUTE", "SEND_ALL_DELTA", "SEND_ALL_PERIODS" }; ArrayList<String> matchedOptions = new ArrayList<String>(); while (configOpts.hasMoreElements()) { String optTmp = (String) configOpts.nextElement(); for (int i = 0; i < expectedOptions.length; i++) { if (optTmp.equals(expectedOptions[i])) { matchedOptions.add(optTmp); } } } if (expectedOptions.length != matchedOptions.size()) { // this kinda blows, but better than throwing a null pointer exception // or doing try/catch for each possible option below. System.out.println("Configuration file options are missing"); System.exit(-1); } // Get settings from config file String vcsHostRaw = config.getProperty("VCS_HOST"); String vcsUser = config.getProperty("VCS_USER"); String vcsPass = config.getProperty("VCS_PASS"); String vcsTag = config.getProperty("VCS_TAG"); String vcsFilter = config.getProperty("FILTERFILE"); if (vcsFilter != null) { String filterfile = vcsFilter; File FilterFile = new File(filterfile); List<String> FilterList = null; try { FilterList = FileUtils.readLines(FilterFile); } catch (IOException e) { e.printStackTrace(); } FilterArrays = FilterList.toArray(new String[] {}); } appConfig.put("vcsTag", vcsTag); // vcs information // this needs to be https://host/sdk String vcsHost = "https://" + vcsHostRaw + "/sdk"; String graphEsx = config.getProperty("ESX_STATS"); appConfig.put("USE_FQDN", config.getProperty("USE_FQDN")); appConfig.put("graphEsx", graphEsx); // graphite information String graphiteHost = config.getProperty("GRAPHITE_HOST"); int graphitePort = Integer.parseInt(config.getProperty("GRAPHITE_PORT")); String graphiteTag = config.getProperty("GRAPHITE_TAG"); try { appConfig.put("graphiteTag", graphiteTag); } catch (NullPointerException e) { System.out.println("Issue with configuration file - Missing GRAPHITE_TAG"); System.exit(-1); } // TODO: make this dynamic. maybe. int MAX_VMSTAT_THREADS = Integer.parseInt(config.getProperty("MAX_VMSTAT_THREADS")); int MAX_ESXSTAT_THREADS = Integer.parseInt(config.getProperty("MAX_ESXSTAT_THREADS")); int MAX_GRAPHITE_THREADS = Integer.parseInt(config.getProperty("MAX_GRAPHITE_THREADS")); appConfig.put("MAX_VMSTAT_THREADS", String.valueOf(MAX_VMSTAT_THREADS)); appConfig.put("MAX_ESXSTAT_THREADS", String.valueOf(MAX_ESXSTAT_THREADS)); String SLEEP_TIME = config.getProperty("SLEEP_TIME"); appConfig.put("SLEEP_TIME", SLEEP_TIME); String SEND_ALL_PERIODS = config.getProperty("SEND_ALL_PERIODS"); appConfig.put("SEND_ALL_PERIODS", SEND_ALL_PERIODS); int sleep_time = Integer.parseInt(SLEEP_TIME); if ((sleep_time % 20) == 0) { int periods = sleep_time / 20; appConfig.put("PERIODS", String.valueOf(periods)); } else { System.out.println("SLEEP_TIME needs to be divisible by 20, please fix"); System.exit(-1); } appConfig.put("SEND_ALL_ABSOLUTE", config.getProperty("SEND_ALL_ABSOLUTE")); appConfig.put("SEND_ALL_DELTA", config.getProperty("SEND_ALL_DELTA")); // Build internal data structures. // use a hashtable to store performance id information Hashtable<String, Hashtable<String, String>> perfKeys = new Hashtable<String, Hashtable<String, String>>(); // BlockingQueue to store managed objects - basically anything that vmware knows about BlockingQueue<Object> vm_mob_queue = new ArrayBlockingQueue<Object>(10000); BlockingQueue<Object> esx_mob_queue = new ArrayBlockingQueue<Object>(10000); // BlockingQueue to store arrays of stats - each managed object generates a bunch of strings that are stored in BlockingQueue<Object> sender = new ArrayBlockingQueue<Object>(60000); // Initialize these vmware types as nulls so we can see if things work properly ServiceInstance si = null; PerformanceManager perfMgr = null; try { // TODO: this doesn't handle some ASCII characters well, not sure why. si = new ServiceInstance(new URL(vcsHost), vcsUser, vcsPass, true); } catch (InvalidLogin e) { logger.info("Invalid login vCenter: " + vcsHost + " User: " + vcsUser); System.exit(-1); } catch (RemoteException e) { logger.info("Remote exception: " + e); e.printStackTrace(); } catch (MalformedURLException e) { logger.info("MalformedURLexception: " + e); e.printStackTrace(); } if (si != null) { perfMgr = si.getPerformanceManager(); PerfCounterInfo[] counters = perfMgr.getPerfCounter(); // build a hash lookup to turn the counter 23 into 'disk.this.that.the.other' // These are not sequential. for (int i = 0; i < counters.length; i++) { // create a temp hash to push onto the big hash Hashtable<String, String> temp_hash = new Hashtable<String, String>(); String path = counters[i].getGroupInfo().getKey() + "." + counters[i].getNameInfo().getKey(); // this is a key like cpu.run.0.summation temp_hash.put("key", path); // one of average, latest, maximum, minimum, none, summation temp_hash.put("rollup", counters[i].getRollupType().toString()); // one of absolute, delta, rate temp_hash.put("statstype", counters[i].getStatsType().toString()); // it's important to understand that the counters aren't sequential, so they have their own id. perfKeys.put("" + counters[i].getKey(), temp_hash); } } else { logger.info("Issues with the service instance that wasn't properly handled"); System.exit(-1); } if (showPerfMgr) { // show the performance keys that are available to the user System.out.println("Showing Performance Counter Entities available:"); System.out.println("Read the following link for more information:"); System.out.println( "http://vijava.sourceforge.net/vSphereAPIDoc/ver5/ReferenceGuide/vim.PerformanceManager.html"); Enumeration<String> keys = perfKeys.keys(); System.out.println("ID|Tag|Rollup"); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); System.out .println(key + "|" + perfKeys.get(key).get("key") + "|" + perfKeys.get(key).get("rollup")); } System.exit(0); } if (showEstimate) { // estimate the number of keys that will be updated/written to Graphite per minute System.out.println("Currently Disabled"); } // this gets the lists of vm's from vCenter if (!noThreads) { if (si != null && perfMgr != null) { logger.info("ServiceInstance: " + si); logger.info("PerformanceManager: " + perfMgr); meGrabber me_grabber = new meGrabber(si, vm_mob_queue, esx_mob_queue, appConfig, sender); ExecutorService grab_exe = Executors.newCachedThreadPool(); grab_exe.execute(me_grabber); // it's easier sometimes to debug things without stats being sent to graphite. make noGraphite = true; to // change this. if (!noGraphite) { for (int i = 1; i <= MAX_GRAPHITE_THREADS; i++) { GraphiteWriter graphite = new GraphiteWriter(graphiteHost, graphitePort, sender, appConfig); ExecutorService graph_exe = Executors.newCachedThreadPool(); graph_exe.execute(graphite); } } else { System.out.println("Graphite output has been disabled via the -g flag."); } for (int i = 1; i <= MAX_VMSTAT_THREADS; i++) { statsGrabber vm_stats_grabber = new statsGrabber(perfMgr, perfKeys, vm_mob_queue, sender, appConfig, "vm", FilterArrays); ExecutorService vm_stat_exe = Executors.newCachedThreadPool(); vm_stat_exe.execute(vm_stats_grabber); } if (graphEsx.contains("true")) { for (int i = 1; i <= MAX_ESXSTAT_THREADS; i++) { statsGrabber esx_stats_grabber = new statsGrabber(perfMgr, perfKeys, esx_mob_queue, sender, appConfig, "ESX", FilterArrays); ExecutorService esx_stat_exe = Executors.newCachedThreadPool(); esx_stat_exe.execute(esx_stats_grabber); } } } else { logger.info("Either ServiceInstance or PerformanceManager is null, bailing."); } } else { System.out.println("Not running any of the main threads"); System.exit(0); } }
From source file:org.transitime.applications.Core.java
/** * The main program that runs the entire Transitime application.! * //from w w w .ja va 2 s.c o m * @param args */ public static void main(String[] args) { try { try { processCommandLineOptions(args); } catch (ParseException e1) { e1.printStackTrace(); System.exit(-1); } // Write pid file so that monit can automatically start // or restart this application PidFile.createPidFile(CoreConfig.getPidFileDirectory() + AgencyConfig.getAgencyId() + ".pid"); // For making sure logger configured properly outputLoggerStatus(); // Initialize the core now createCore(); // Start any optional modules. List<String> optionalModuleNames = CoreConfig.getOptionalModules(); if (optionalModuleNames.size() > 0) logger.info("Starting up optional modules specified via " + "transitime.modules.optionalModulesList param:"); else logger.info("No optional modules to start up."); for (String moduleName : optionalModuleNames) { logger.info("Starting up optional module " + moduleName); Module.start(moduleName); } // Start the RMI Servers so that clients can obtain data // on predictions, vehicles locations, etc. String agencyId = AgencyConfig.getAgencyId(); startRmiServers(agencyId); } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:org.wattdepot.client.http.api.collector.EGaugeCollector.java
/** * Processes the command line arguments and starts the eGauge Collector. * /*w w w . j av a 2 s . c om*/ * @param args * command line arguments. */ public static void main(String[] args) { Options options = new Options(); options.addOption("h", "help", false, "Usage: EGaugeCollector <server uri> <username> <password> <collectorid>"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("c", "collector", true, "Collector Process Definition Id"); options.addOption("d", "debug", false, "Displays sensor data as it is sent to the server."); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; String collectorId = null; boolean debug = false; CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("EGaugeCollector", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://localhost:8119/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = UserInfo.ROOT.getUid(); } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = Organization.ADMIN_GROUP.getId(); } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("c")) { collectorId = cmd.getOptionValue("c"); } else { collectorId = "ilima_6th_power"; } debug = cmd.hasOption("d"); if (debug) { System.out.println("WattDepot Server: " + serverUri); System.out.println("Username: " + username); System.out.println("OrganizationID: " + organizationId); System.out.println("Password: " + password); System.out.println("Collector Process Definition Id: " + collectorId); System.out.println("debug: " + debug); System.out.println(); } try { if (!MultiThreadedCollector.start(serverUri, username, organizationId, password, collectorId, debug)) { System.exit(1); } } catch (InterruptedException e) { e.printStackTrace(); System.exit(1); } catch (BadCredentialException e) { e.printStackTrace(); System.exit(1); } }
From source file:org.wattdepot.client.http.api.collector.MeasurementSummaryClient.java
/** * @param args command line arguments.//from w w w .ja va2s. c o m */ public static void main(String[] args) { Options options = new Options(); options.addOption("h", false, "Usage: MeasurementSummaryClient -s <server uri> -u <username>" + " -p <password> -o <orgId> -c <collectorId> -m <millisecond sleep> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("c", "collector", true, "Collector Process Definition Id"); options.addOption("m", "milliseconds", true, "Number of milliseconds to sleep between polls."); options.addOption("d", "debug", false, "Displays sensor data as it is sent to the server."); options.addOption("w", "windowing", false, "Use a window instead of getting all the measurements."); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; String collectorId = null; Integer milliSeconds = null; boolean debug = false; boolean windowP = false; CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("StressTestCollector", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://server.wattdepot.org/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = "user"; } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = "organization"; } if (cmd.hasOption("c")) { collectorId = cmd.getOptionValue("c"); } else { collectorId = "stress_test"; } if (cmd.hasOption("m")) { milliSeconds = Integer.parseInt(cmd.getOptionValue("m")); } else { milliSeconds = 1000; } debug = cmd.hasOption("d"); windowP = cmd.hasOption("w"); if (debug) { System.out.println("Measurement Summary Client:"); System.out.println(" WattDepotServer: " + serverUri); System.out.println(" Username: " + username); System.out.println(" OrganizationId: " + organizationId); System.out.println(" Password :" + password); System.out.println(" CPD Id: " + collectorId); System.out.println(" MilliSeconds: " + milliSeconds); System.out.println(" Windowing: " + windowP); } Timer t = new Timer(); try { MeasurementSummaryClient c = new MeasurementSummaryClient(serverUri, username, organizationId, password, collectorId, debug); c.windowP = windowP; System.out.format("Started MeasurementSummaryClient at %s%n", Tstamp.makeTimestamp()); t.schedule(c, 0, milliSeconds); } catch (BadCredentialException e) { e.printStackTrace(); } catch (IdNotFoundException e) { e.printStackTrace(); } catch (BadSensorUriException e) { e.printStackTrace(); } }
From source file:org.wattdepot.client.http.api.collector.NOAAWeatherCollector.java
/** * Processes the command line arguments and starts the NOAA Weather Collector. * /*from w ww.j a va2 s . c o m*/ * @param args command line arguments. */ public static void main(String[] args) { Options options = new Options(); options.addOption("h", "help", false, "Usage: NOAAWeatherCollector -s <server uri> -u <username> -p <password> -c <collectorid> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("c", "collector", true, "Collector Process Definition Id"); options.addOption("d", "debug", false, "Displays sensor data as it is sent to the server."); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; String collectorId = null; boolean debug = false; CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("NOAAWeatherCollector", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://localhost:8119/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = UserInfo.ROOT.getUid(); } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = Organization.ADMIN_GROUP.getId(); } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("c")) { collectorId = cmd.getOptionValue("c"); } else { collectorId = "ilima_6th_power"; } debug = cmd.hasOption("d"); if (debug) { System.out.println("WattDepot Server: " + serverUri); System.out.println("Username: " + username); System.out.println("OrganizationID: " + organizationId); System.out.println("Password: " + password); System.out.println("Collector Process Definition Id: " + collectorId); System.out.println("debug: " + debug); System.out.println(); } try { if (!MultiThreadedCollector.start(serverUri, username, organizationId, password, collectorId, debug)) { System.exit(1); } } catch (InterruptedException e) { e.printStackTrace(); System.exit(1); } catch (BadCredentialException e) { e.printStackTrace(); System.exit(1); } }