List of usage examples for org.apache.commons.cli ParseException toString
public String toString()
From source file:org.apache.helix.tools.ZkCopy.java
public static void main(String[] args) throws Exception { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCmdLineOpt(); CommandLine cmd = null;//from w ww . j ava2 s .co m try { cmd = cliParser.parse(cliOptions, args); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } URI srcUri = new URI(cmd.getOptionValue(src)); URI dstUri = new URI(cmd.getOptionValue(dst)); ZkCopyScheme srcScheme = ZkCopyScheme.valueOf(srcUri.getScheme()); ZkCopyScheme dstScheme = ZkCopyScheme.valueOf(dstUri.getScheme()); if (srcScheme == ZkCopyScheme.zk && dstScheme == ZkCopyScheme.zk) { String srcZkAddr = srcUri.getAuthority(); String dstZkAddr = dstUri.getAuthority(); ZkClient srcClient = null; ZkClient dstClient = null; try { if (srcZkAddr.equals(dstZkAddr)) { srcClient = dstClient = new ZkClient(srcZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer()); } else { srcClient = new ZkClient(srcZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer()); dstClient = new ZkClient(dstZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer()); } String srcPath = srcUri.getPath(); String dstPath = dstUri.getPath(); zkCopy(srcClient, srcPath, dstClient, dstPath); } finally { if (srcClient != null) { srcClient.close(); } if (dstClient != null) { dstClient.close(); } } } else { System.err.println("Unsupported scheme. srcScheme: " + srcScheme + ", dstScheme: " + dstScheme); System.exit(1); } }
From source file:org.apache.sqoop.manager.sqlserver.SQLServerMultiMapsManualTest.java
public void runMultiMapTest(String splitByCol, int expectedSum) throws IOException { String[] columns = MSSQLTestUtils.getColumns(); ClassLoader prevClassLoader = null; SequenceFile.Reader reader = null; String[] argv = getArgv(true, columns, splitByCol); runImport(argv);/*from w w w . j a v a 2 s. c o m*/ try { ImportTool importTool = new ImportTool(); SqoopOptions opts = importTool.parseArguments(getArgv(false, columns, splitByCol), null, null, true); String username = MSSQLTestUtils.getDBUserName(); String password = MSSQLTestUtils.getDBPassWord(); opts.setUsername(username); opts.setPassword(password); CompilationManager compileMgr = new CompilationManager(opts); String jarFileName = compileMgr.getJarFilename(); prevClassLoader = ClassLoaderStack.addJarFile(jarFileName, getTableName()); List<Path> paths = getDataFilePaths(); Configuration conf = new Configuration(); int curSum = 0; // We expect multiple files. We need to open all the files and sum // up the // first column across all of them. for (Path p : paths) { reader = SeqFileReader.getSeqFileReader(p.toString()); // here we can actually instantiate (k, v) pairs. Object key = ReflectionUtils.newInstance(reader.getKeyClass(), conf); Object val = ReflectionUtils.newInstance(reader.getValueClass(), conf); // We know that these values are two ints separated by a ',' // character. Since this is all dynamic, though, we don't want // to // actually link against the class and use its methods. So we // just // parse this back into int fields manually. Sum them up and // ensure // that we get the expected total for the first column, to // verify that // we got all the results from the db into the file. // now sum up everything in the file. while (reader.next(key) != null) { reader.getCurrentValue(val); curSum += getFirstInt(val.toString()); } IOUtils.closeStream(reader); reader = null; } assertEquals("Total sum of first db column mismatch", expectedSum, curSum); } catch (InvalidOptionsException ioe) { LOG.error(StringUtils.stringifyException(ioe)); fail(ioe.toString()); } catch (ParseException pe) { LOG.error(StringUtils.stringifyException(pe)); fail(pe.toString()); } finally { IOUtils.closeStream(reader); if (null != prevClassLoader) { ClassLoaderStack.setCurrentClassLoader(prevClassLoader); } } }
From source file:org.apache.sqoop.manager.sqlserver.SQLServerParseMethodsManualTest.java
public void runParseTest(String fieldTerminator, String lineTerminator, String encloser, String escape, boolean encloseRequired) throws IOException { ClassLoader prevClassLoader = null; String[] argv = getArgv(true, fieldTerminator, lineTerminator, encloser, escape, encloseRequired); runImport(argv);// ww w .j av a 2s .co m try { String tableClassName = getTableName(); argv = getArgv(false, fieldTerminator, lineTerminator, encloser, escape, encloseRequired); SqoopOptions opts = new ImportTool().parseArguments(argv, null, null, true); CompilationManager compileMgr = new CompilationManager(opts); String jarFileName = compileMgr.getJarFilename(); // Make sure the user's class is loaded into our address space. prevClassLoader = ClassLoaderStack.addJarFile(jarFileName, tableClassName); JobConf job = new JobConf(); job.setJar(jarFileName); // Tell the job what class we're testing. job.set(ReparseMapper.USER_TYPE_NAME_KEY, tableClassName); // use local mode in the same JVM. ConfigurationHelper.setJobtrackerAddr(job, "local"); job.set("fs.default.name", "file:///"); String warehouseDir = getWarehouseDir(); Path warehousePath = new Path(warehouseDir); Path inputPath = new Path(warehousePath, getTableName()); Path outputPath = new Path(warehousePath, getTableName() + "-out"); job.setMapperClass(ReparseMapper.class); job.setNumReduceTasks(0); FileInputFormat.addInputPath(job, inputPath); FileOutputFormat.setOutputPath(job, outputPath); job.setOutputKeyClass(Text.class); job.setOutputValueClass(NullWritable.class); JobClient.runJob(job); } catch (InvalidOptionsException ioe) { LOG.error(StringUtils.stringifyException(ioe)); fail(ioe.toString()); } catch (ParseException pe) { LOG.error(StringUtils.stringifyException(pe)); fail(pe.toString()); } finally { if (null != prevClassLoader) { ClassLoaderStack.setCurrentClassLoader(prevClassLoader); } } }
From source file:org.apache.sqoop.manager.sqlserver.SQLServerQueryManualTest.java
public void runQueryTest(String query, String firstValStr, int numExpectedResults, int expectedSum, String targetDir) throws IOException { ClassLoader prevClassLoader = null; SequenceFile.Reader reader = null; String[] argv = getArgv(true, query, targetDir, false); runImport(argv);//from www . j a v a2 s.c o m try { SqoopOptions opts = new ImportTool().parseArguments(getArgv(false, query, targetDir, false), null, null, true); CompilationManager compileMgr = new CompilationManager(opts); String jarFileName = compileMgr.getJarFilename(); prevClassLoader = ClassLoaderStack.addJarFile(jarFileName, getTableName()); reader = SeqFileReader.getSeqFileReader(getDataFilePath().toString()); // here we can actually instantiate (k, v) pairs. Configuration conf = new Configuration(); Object key = ReflectionUtils.newInstance(reader.getKeyClass(), conf); Object val = ReflectionUtils.newInstance(reader.getValueClass(), conf); if (reader.next(key) == null) { fail("Empty SequenceFile during import"); } // make sure that the value we think should be at the top, is. reader.getCurrentValue(val); assertEquals("Invalid ordering within sorted SeqFile", firstValStr, val.toString()); // We know that these values are two ints separated by a ',' // character. // Since this is all dynamic, though, we don't want to actually link // against the class and use its methods. So we just parse this back // into int fields manually. Sum them up and ensure that we get the // expected total for the first column, to verify that we got all // the // results from the db into the file. int curSum = getFirstInt(val.toString()); int totalResults = 1; // now sum up everything else in the file. while (reader.next(key) != null) { reader.getCurrentValue(val); curSum += getFirstInt(val.toString()); totalResults++; } assertEquals("Total sum of first db column mismatch", expectedSum, curSum); assertEquals("Incorrect number of results for query", numExpectedResults, totalResults); } catch (InvalidOptionsException ioe) { LOG.error(StringUtils.stringifyException(ioe)); fail(ioe.toString()); } catch (ParseException pe) { LOG.error(StringUtils.stringifyException(pe)); fail(pe.toString()); } finally { IOUtils.closeStream(reader); if (null != prevClassLoader) { ClassLoaderStack.setCurrentClassLoader(prevClassLoader); } } }
From source file:org.apache.sqoop.manager.sqlserver.SQLServerSplitByManualTest.java
public void runSplitByTest(String splitByCol, int expectedSum) throws IOException { String[] columns = new String[] { "L_ORDERKEY", "L_PARTKEY", "L_SUPPKEY", "L_LINENUMBER", "L_QUANTITY", "L_EXTENDEDPRICE", "L_DISCOUNT", "L_TAX", "L_RETURNFLAG", "L_LINESTATUS", "L_SHIPDATE", "L_COMMITDATE", "L_RECEIPTDATE", "L_SHIPINSTRUCT", "L_SHIPMODE", "L_COMMENT", }; ClassLoader prevClassLoader = null; SequenceFile.Reader reader = null; String[] argv = getArgv(true, columns, splitByCol); runImport(argv);//w ww. j a v a 2 s.c o m try { SqoopOptions opts = new ImportTool().parseArguments(getArgv(false, columns, splitByCol), null, null, true); CompilationManager compileMgr = new CompilationManager(opts); String jarFileName = compileMgr.getJarFilename(); LOG.debug("Got jar from import job: " + jarFileName); prevClassLoader = ClassLoaderStack.addJarFile(jarFileName, getTableName()); reader = SeqFileReader.getSeqFileReader(getDataFilePath().toString()); // here we can actually instantiate (k, v) pairs. Configuration conf = new Configuration(); Object key = ReflectionUtils.newInstance(reader.getKeyClass(), conf); Object val = ReflectionUtils.newInstance(reader.getValueClass(), conf); // We know that these values are two ints separated by a ',' // character. // Since this is all dynamic, though, we don't want to actually link // against the class and use its methods. So we just parse this back // into int fields manually. Sum them up and ensure that we get the // expected total for the first column, to verify that we got all // the // results from the db into the file. // Sum up everything in the file. int curSum = 0; while (reader.next(key) != null) { reader.getCurrentValue(val); curSum += getFirstInt(val.toString()); } System.out.println("Sum : e,c" + expectedSum + " : " + curSum); assertEquals("Total sum of first db column mismatch", expectedSum, curSum); } catch (InvalidOptionsException ioe) { LOG.error(StringUtils.stringifyException(ioe)); fail(ioe.toString()); } catch (ParseException pe) { LOG.error(StringUtils.stringifyException(pe)); fail(pe.toString()); } finally { IOUtils.closeStream(reader); if (null != prevClassLoader) { ClassLoaderStack.setCurrentClassLoader(prevClassLoader); } } }
From source file:org.apache.sqoop.manager.sqlserver.SQLServerWhereManualTest.java
public void runWhereTest(String whereClause, String firstValStr, int numExpectedResults, int expectedSum) throws IOException { String[] columns = MSSQLTestUtils.getColumns(); ClassLoader prevClassLoader = null; SequenceFile.Reader reader = null; String[] argv = getArgv(true, columns, whereClause); runImport(argv);//from www .j av a 2 s.co m try { String username = MSSQLTestUtils.getDBUserName(); String password = MSSQLTestUtils.getDBPassWord(); SqoopOptions opts = new ImportTool().parseArguments(getArgv(false, columns, whereClause), null, null, true); opts.setUsername(username); opts.setPassword(password); CompilationManager compileMgr = new CompilationManager(opts); String jarFileName = compileMgr.getJarFilename(); prevClassLoader = ClassLoaderStack.addJarFile(jarFileName, getTableName()); reader = SeqFileReader.getSeqFileReader(getDataFilePath().toString()); // here we can actually instantiate (k, v) pairs. Configuration conf = new Configuration(); Object key = ReflectionUtils.newInstance(reader.getKeyClass(), conf); Object val = ReflectionUtils.newInstance(reader.getValueClass(), conf); if (reader.next(key) == null) { fail("Empty SequenceFile during import"); } // make sure that the value we think should be at the top, is. reader.getCurrentValue(val); assertEquals("Invalid ordering within sorted SeqFile", firstValStr, val.toString()); // We know that these values are two ints separated by a ',' // character. // Since this is all dynamic, though, we don't want to actually link // against the class and use its methods. So we just parse this back // into int fields manually. Sum them up and ensure that we get the // expected total for the first column, to verify that we got all // the // results from the db into the file. int curSum = getFirstInt(val.toString()); int totalResults = 1; // now sum up everything else in the file. while (reader.next(key) != null) { reader.getCurrentValue(val); curSum += getFirstInt(val.toString()); totalResults++; } assertEquals("Total sum of first db column mismatch", expectedSum, curSum); assertEquals("Incorrect number of results for query", numExpectedResults, totalResults); } catch (InvalidOptionsException ioe) { fail(ioe.toString()); } catch (ParseException pe) { fail(pe.toString()); } finally { IOUtils.closeStream(reader); if (null != prevClassLoader) { ClassLoaderStack.setCurrentClassLoader(prevClassLoader); } } }
From source file:org.apache.storm.loadgen.CaptureLoad.java
static Map<String, Double> parseResources(String input) { Map<String, Double> topologyResources = new HashMap<>(); JSONParser parser = new JSONParser(); LOG.debug("Input to parseResources {}", input); try {/*from ww w . j av a 2 s . co m*/ if (input != null) { Object obj = parser.parse(input); JSONObject jsonObject = (JSONObject) obj; if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB)) { Double topoMemOnHeap = ObjectReader .getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB), null); topologyResources.put(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB, topoMemOnHeap); } if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB)) { Double topoMemOffHeap = ObjectReader .getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB), null); topologyResources.put(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB, topoMemOffHeap); } if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT)) { Double topoCpu = ObjectReader .getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT), null); topologyResources.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT, topoCpu); } LOG.debug("Topology Resources {}", topologyResources); } } catch (org.json.simple.parser.ParseException e) { LOG.error("Failed to parse component resources is:" + e.toString(), e); return null; } return topologyResources; }
From source file:org.dspace.health.Report.java
public static void main(String[] args) { log.info("Starting healthcheck report..."); final String option_help = "h"; final String option_email = "e"; final String option_check = "c"; final String option_last_n = "f"; final String option_verbose = "v"; // command line options Options options = new Options(); options.addOption(option_help, "help", false, "Show available checks and their index."); options.addOption(option_email, "email", true, "Send report to this email address."); options.addOption(option_check, "check", true, "Perform only specific check (use index starting from 0)."); options.addOption(option_last_n, "for", true, "For last N days."); options.addOption(option_verbose, "verbose", false, "Verbose report."); CommandLine cmdline = null;/*from w w w . j av a 2 s.c o m*/ try { cmdline = new PosixParser().parse(options, args); } catch (ParseException e) { log.fatal("Invalid command line " + e.toString(), e); System.exit(1); } if (cmdline.hasOption(option_help)) { String checks_summary = ""; int pos = 0; for (String check_name : checks().keySet()) { checks_summary += String.format("%d. %s\n", pos++, check_name); } HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("dspace healthcheck", options); System.out.println("\nAvailable checks:\n" + checks_summary); return; } // what to perform List<Integer> to_perform = null; if (null != cmdline.getOptionValues(option_check)) { to_perform = new ArrayList<>(); for (String s : cmdline.getOptionValues('c')) { to_perform.add(Integer.valueOf(s)); } } try { // last n days int for_last_n_days = ConfigurationManager.getIntProperty("healthcheck", "last_n_days"); if (cmdline.hasOption(option_last_n)) { for_last_n_days = Integer.getInteger(cmdline.getOptionValue(option_last_n)); } ReportInfo ri = new ReportInfo(for_last_n_days); if (cmdline.hasOption(option_verbose)) { ri.verbose(true); } // run report Report r = new Report(); r.run(to_perform, ri); log.info("reports generated..."); // send/output the report if (cmdline.hasOption(option_email)) { String to = cmdline.getOptionValue(option_email); if (!to.contains("@")) { to = ConfigurationManager.getProperty(to); } try { String dspace_dir = ConfigurationManager.getProperty("dspace.dir"); String email_path = dspace_dir.endsWith("/") ? dspace_dir : dspace_dir + "/"; email_path += Report.EMAIL_PATH; log.info(String.format("Looking for email template at [%s]", email_path)); Email email = Email.getEmail(email_path); email.addRecipient(to); email.addArgument(r.toString()); email.send(); } catch (Exception e) { log.fatal("Error sending email:", e); System.err.println("Error sending email:\n" + e.getMessage()); System.exit(1); } } } catch (Exception e) { log.fatal(e); e.printStackTrace(); } }
From source file:org.jreversepro.cmd.CommandLineInterface.java
public void parse(String[] args) { try {/*from w ww . jav a2 s . c om*/ cmd = parser.parse(options, args); if (cmd.hasOption(OPTION_GUI)) { if (cmd.hasOption(OPTION_INPUT) || cmd.hasOption(OPTION_DECOMPILE) || cmd.hasOption(OPTION_DISASSEMBLE)) { LOGGER.severe( OPTION_GUI + " needs to be specified alone and should not accompany other arguments"); throw new IllegalArgumentException("Invalid argument specified"); } guiEnabled = true; return; } if (!cmd.hasOption(OPTION_INPUT)) { LOGGER.severe("Option -" + OPTION_INPUT + " mandatory"); } outputType = OutputType.NONE; if (cmd.hasOption(OPTION_DISASSEMBLE)) { outputType = OutputType.DISASSEMBLER; } if (cmd.hasOption(OPTION_DECOMPILE)) { outputType = OutputType.DECOMPILER; } if (cmd.hasOption(OPTION_GUI)) { if (cmd.hasOption(OPTION_INPUT) || cmd.hasOption(OPTION_DECOMPILE)) { LOGGER.severe( OPTION_GUI + " needs to be specified alone and should not accompany other arguments"); throw new UnsupportedOperationException("Invalid argument specified"); } guiEnabled = true; } if (outputType == OutputType.NONE) { LOGGER.severe("Need to specify either " + OPTION_DISASSEMBLE + " or " + OPTION_DECOMPILE); } if (cmd.hasOption(DECOMPILE_VERSION)) { javaVersionToDecompile = cmd.getOptionValue(DECOMPILE_VERSION); } } catch (ParseException ex) { LOGGER.severe(ex.toString()); } }
From source file:org.lsc.connectors.xmlrpc.AbstractLscXmlRpcClient.java
protected int parseOptions(final String[] args) throws MalformedURLException { CommandLineParser parser = new GnuParser(); try {/*from w w w . j av a 2 s .c o m*/ cmdLine = parser.parse(options, args); if (cmdLine.hasOption("h")) { url = new URL(cmdLine.getOptionValue("h")); } if (cmdLine.hasOption("u")) { username = cmdLine.getOptionValue("u"); } if (cmdLine.hasOption("p")) { password = cmdLine.getOptionValue("p"); } if (url == null) { printHelp(options); return -1; } } catch (ParseException e) { LOGGER.error("Unable to parse the options ({})", e.toString()); LOGGER.debug(e.toString(), e); return 1; } return 0; }