List of usage examples for org.apache.commons.cli Option getValues
public String[] getValues()
From source file:de.bmw.yamaica.common.console.CommandExecuter.java
/** * Converts an instance the CommandLine Object into an array of strings. * * @param commandLine/*from ww w .j a v a2 s. c om*/ * instance * @param keepIdOption * if true the returned array will contain the ID option if available * @return Arguments split into string array */ public static String[] getArguments(CommandLine commandLine, boolean keepIdOption) { Assert.isNotNull(commandLine); List<String> argumentsList = new ArrayList<String>(); Option[] options = commandLine.getOptions(); if (null != options) { for (Option option : options) { String optionString = option.getOpt(); if (keepIdOption == false && SHORT_ID_OPTION.equals(optionString)) { continue; } argumentsList.add("-" + optionString); String[] values = option.getValues(); if (null != values) { for (String value : values) { argumentsList.add(value); } } } } return argumentsList.toArray(new String[argumentsList.size()]); }
From source file:lcmc.LCMC.java
/** Parse cluster options and create cluster button. */ private static void parseClusterOptions(final CommandLine cmd) throws ParseException { String clusterName = null;//from w w w. j a va2 s . com List<HostOptions> hostsOptions = null; final Map<String, List<HostOptions>> clusters = new LinkedHashMap<String, List<HostOptions>>(); for (final Option option : cmd.getOptions()) { final String op = option.getLongOpt(); if (CLUSTER_OP.equals(op)) { clusterName = option.getValue(); if (clusterName == null) { throw new ParseException("could not parse " + CLUSTER_OP + " option"); } clusters.put(clusterName, new ArrayList<HostOptions>()); } else if (HOST_OP.equals(op)) { final String[] hostNames = option.getValues(); if (clusterName == null) { clusterName = "default"; clusters.put(clusterName, new ArrayList<HostOptions>()); } if (hostNames == null) { throw new ParseException("could not parse " + HOST_OP + " option"); } hostsOptions = new ArrayList<HostOptions>(); for (final String hostNameEntered : hostNames) { String hostName; String port = null; if (hostNameEntered.indexOf(':') > 0) { final String[] he = hostNameEntered.split(":"); hostName = he[0]; port = he[1]; if ("".equals(port) || !Tools.isNumber(port)) { throw new ParseException("could not parse " + HOST_OP + " option"); } } else { hostName = hostNameEntered; } final HostOptions ho = new HostOptions(hostName); if (port != null) { ho.setPort(port); } hostsOptions.add(ho); clusters.get(clusterName).add(ho); } } else if (SUDO_OP.equals(op)) { if (hostsOptions == null) { throw new ParseException(SUDO_OP + " must be defined after " + HOST_OP); } for (final HostOptions ho : hostsOptions) { ho.setSudo(true); } } else if (USER_OP.equals(op)) { if (hostsOptions == null) { throw new ParseException(USER_OP + " must be defined after " + HOST_OP); } final String userName = option.getValue(); if (userName == null) { throw new ParseException("could not parse " + USER_OP + " option"); } for (final HostOptions ho : hostsOptions) { ho.setUser(userName); } } else if (PORT_OP.equals(op)) { if (hostsOptions == null) { throw new ParseException(PORT_OP + " must be defined after " + HOST_OP); } final String port = option.getValue(); if (port == null) { throw new ParseException("could not parse " + PORT_OP + " option"); } for (final HostOptions ho : hostsOptions) { ho.setPort(port); } } } for (final String cn : clusters.keySet()) { for (final HostOptions hostOptions : clusters.get(cn)) { if (hostsOptions.size() < 1 || (hostsOptions.size() == 1 && !Tools.getConfigData().isOneHostCluster())) { throw new ParseException("not enough hosts for cluster: " + cn); } } } final String failedHost = Tools.setUserConfigFromOptions(clusters); if (failedHost != null) { Tools.appWarning("could not resolve host \"" + failedHost + "\" skipping"); } }
From source file:com.dal.a.ui.DalAppConsole.java
public void config(CommandLine cli) { for (Option opt : cli.getOptions()) { config.addProperty(opt.getOpt(), opt.getValues()); }/*from w ww .j a v a 2s . c o m*/ }
From source file:de.nrw.hbz.regal.sync.MyConfiguration.java
/** * /* www .j av a 2 s. c o m*/ * generates the configuration in terms of arguments and options * * @param args * Command line arguments * @param options * Command line options * @throws ParseException * When the configuration cannot be parsed */ MyConfiguration(String[] args, Options options) { try { CommandLineParser parser = new BasicParser(); CommandLine commandLine = parser.parse(options, args); for (Option option : commandLine.getOptions()) { String key = option.getLongOpt(); // System.out.println(key); if (key.compareTo("set") == 0) { String[] vals = option.getValues(); if (vals == null || vals.length == 0) { this.addProperty(key, "N/A"); } else { StringBuffer val = new StringBuffer(); for (int i = 0; i < vals.length; i++) { val.append(vals[i]); val.append(","); } val.delete(val.length(), val.length()); this.addProperty(key, val.toString()); } } else { String val = option.getValue(); if (val == null) { this.addProperty(key, "N/A"); } else { this.addProperty(key, val); } } } } catch (ParseException e) { throw new ConfigurationParseException(e); } }
From source file:com.aliyun.odps.mapred.bridge.streaming.StreamJob.java
void parseArgv() { CommandLine cmdLine = null;/* w w w . j ava2s . co m*/ try { cmdLine = parser.parse(allOptions, argv_); } catch (Exception oe) { LOG.error(oe.getMessage()); exitUsage(argv_.length > 0 && "-info".equals(argv_[0])); } if (cmdLine == null) { exitUsage(argv_.length > 0 && "-info".equals(argv_[0])); return; } @SuppressWarnings("unchecked") List<String> args = cmdLine.getArgList(); if (args != null && args.size() > 0) { fail("Found " + args.size() + " unexpected arguments on the " + "command line " + args); } detailedUsage_ = cmdLine.hasOption("info"); if (cmdLine.hasOption("help") || detailedUsage_) { printUsage = true; return; } verbose_ = cmdLine.hasOption("verbose"); background_ = cmdLine.hasOption("background"); debug_ = cmdLine.hasOption("debug") ? debug_ + 1 : debug_; output_ = cmdLine.getOptionValue("output"); comCmd_ = cmdLine.getOptionValue("combiner"); redCmd_ = cmdLine.getOptionValue("reducer"); lazyOutput_ = cmdLine.hasOption("lazyOutput"); String[] values = cmdLine.getOptionValues("file"); SessionState ss = SessionState.get(); MetaExplorer metaExplorer = new MetaExplorerImpl(ss.getOdps()); Map<String, String> aliasToTempResource = new HashMap<String, String>(); String padding = "_" + UUID.randomUUID().toString(); if (values != null && values.length > 0) { for (int i = 0; i < values.length; i++) { String file = values[i]; packageFiles_.add(file); try { aliasToTempResource.put(FilenameUtils.getName(file), metaExplorer.addFileResourceWithRetry(file, Resource.Type.FILE, padding, true)); } catch (OdpsException e) { throw new RuntimeException(e); } } config_.set("stream.temp.resource.alias", JSON.toJSONString(aliasToTempResource)); String[] res = config_.getResources(); Set<String> resources = aliasToTempResource.keySet(); if (res != null) { config_.setResources(StringUtils.join(res, ",") + "," + StringUtils.join(resources, ",")); } else { config_.setResources(StringUtils.join(resources, ",")); } } additionalConfSpec_ = cmdLine.getOptionValue("additionalconfspec"); numReduceTasksSpec_ = cmdLine.getOptionValue("numReduceTasks"); partitionerSpec_ = cmdLine.getOptionValue("partitioner"); mapDebugSpec_ = cmdLine.getOptionValue("mapdebug"); reduceDebugSpec_ = cmdLine.getOptionValue("reducedebug"); ioSpec_ = cmdLine.getOptionValue("io"); String[] car = cmdLine.getOptionValues("cacheArchive"); if (null != car) { fail("no -cacheArchive option any more, please use -resources instead."); } String[] caf = cmdLine.getOptionValues("cacheFile"); if (null != caf) { fail("no -cacheFile option any more, please use -resources instead."); } mapCmd_ = cmdLine.getOptionValue("mapper"); String[] cmd = cmdLine.getOptionValues("cmdenv"); if (null != cmd && cmd.length > 0) { for (String s : cmd) { if (addTaskEnvironment_.length() > 0) { addTaskEnvironment_ += " "; } addTaskEnvironment_ += s; } } // per table input config Map<String, Map<String, String>> inputConfigs = new HashMap<String, Map<String, String>>(); String[] columns = null; for (Option opt : cmdLine.getOptions()) { if ("jobconf".equals(opt.getOpt())) { String[] jobconf = opt.getValues(); if (null != jobconf && jobconf.length > 0) { for (String s : jobconf) { String[] parts = s.split("=", 2); config_.set(parts[0], parts[1]); } } } else if ("columns".equals(opt.getOpt())) { String columnsValue = opt.getValue(); if (columnsValue.equals("ALL")) { columns = null; } else { columns = columnsValue.split(","); } } else if ("input".equals(opt.getOpt())) { values = opt.getValues(); if (values != null && values.length > 0) { for (String input : values) { TableInfo ti = parseTableInfo(input); if (columns != null) { ti.setCols(columns); } inputSpecs_.add(ti); String inputKey = (ti.getProjectName() + "." + ti.getTableName()).toLowerCase(); // XXX only apply once per table if (inputConfigs.get(inputKey) != null) { continue; } Map<String, String> inputConfig = new HashMap<String, String>(); inputConfig.put("stream.map.input.field.separator", config_.get("stream.map.input.field.separator", "\t")); // TODO other per table input config: cols, etc. inputConfigs.put(inputKey, inputConfig); } } } } try { config_.set("stream.map.input.configs", JSON.toJSONString(inputConfigs)); } catch (Exception e) { throw new RuntimeException("fail to set input configs"); } }
From source file:lcmc.ArgumentParser.java
public void parseClusterOptionsAndCreateClusterButton(final CommandLine cmd) throws ParseException { String clusterName = null;/*from w w w .j ava2s .c om*/ List<HostOptions> hostsOptions = null; final Map<String, List<HostOptions>> clusters = new LinkedHashMap<String, List<HostOptions>>(); for (final Option option : cmd.getOptions()) { final String op = option.getLongOpt(); if (CLUSTER_OP.equals(op)) { clusterName = option.getValue(); if (clusterName == null) { throw new ParseException("could not parse " + CLUSTER_OP + " option"); } clusters.put(clusterName, new ArrayList<HostOptions>()); } else if (HOST_OP.equals(op)) { final String[] hostNames = option.getValues(); if (clusterName == null) { clusterName = "default"; clusters.put(clusterName, new ArrayList<HostOptions>()); } if (hostNames == null) { throw new ParseException("could not parse " + HOST_OP + " option"); } hostsOptions = new ArrayList<HostOptions>(); for (final String hostNameEntered : hostNames) { final String hostName; String port = null; if (hostNameEntered.indexOf(':') > 0) { final String[] he = hostNameEntered.split(":"); hostName = he[0]; port = he[1]; if (port != null && port.isEmpty() || !lcmc.common.domain.util.Tools.isNumber(port)) { throw new ParseException("could not parse " + HOST_OP + " option"); } } else { hostName = hostNameEntered; } final HostOptions ho = new HostOptions(hostName); if (port != null) { ho.setPort(port); } hostsOptions.add(ho); clusters.get(clusterName).add(ho); } } else if (SUDO_OP.equals(op)) { if (hostsOptions == null) { throw new ParseException(SUDO_OP + " must be defined after " + HOST_OP); } for (final HostOptions ho : hostsOptions) { ho.setUseSudo(true); } } else if (USER_OP.equals(op)) { if (hostsOptions == null) { throw new ParseException(USER_OP + " must be defined after " + HOST_OP); } final String userName = option.getValue(); if (userName == null) { throw new ParseException("could not parse " + USER_OP + " option"); } for (final HostOptions ho : hostsOptions) { ho.setLoginUser(userName); } } else if (PORT_OP.equals(op)) { if (hostsOptions == null) { throw new ParseException(PORT_OP + " must be defined after " + HOST_OP); } final String port = option.getValue(); if (port == null) { throw new ParseException("could not parse " + PORT_OP + " option"); } for (final HostOptions ho : hostsOptions) { ho.setPort(port); } } else if (PCMKTEST_OP.equals(op)) { final String index = option.getValue(); if (index != null && !index.isEmpty()) { application.setAutoTest(new Test(StartTests.Type.PCMK, index.charAt(0))); } } else if (DRBDTEST_OP.equals(op)) { final String index = option.getValue(); if (index != null && !index.isEmpty()) { application.setAutoTest(new Test(StartTests.Type.DRBD, index.charAt(0))); } } else if (VMTEST_OP.equals(op)) { final String index = option.getValue(); if (index != null && !index.isEmpty()) { application.setAutoTest(new Test(StartTests.Type.VM, index.charAt(0))); } } else if (GUITEST_OP.equals(op)) { final String index = option.getValue(); if (index != null && !index.isEmpty()) { application.setAutoTest(new Test(StartTests.Type.GUI, index.charAt(0))); } } } for (final Map.Entry<String, List<HostOptions>> clusterEntry : clusters.entrySet()) { final List<HostOptions> hostOptions = clusterEntry.getValue(); if (hostOptions.size() < 1 || (hostOptions.size() == 1 && !application.isOneHostCluster())) { throw new ParseException("not enough hosts for cluster: " + clusterEntry.getKey()); } } final String failedHost = setUserConfigFromOptions(clusters); if (failedHost != null) { LOG.appWarning("parseClusterOptions: could not resolve host \"" + failedHost + "\" skipping"); } }
From source file:com.cloudera.sqoop.cli.SqoopParser.java
@Override /**//from www.j a v a 2 s. c o m * Processes arguments to options but only strips matched quotes. */ public void processArgs(Option opt, ListIterator iter) throws ParseException { // Loop until an option is found. while (iter.hasNext()) { String str = (String) iter.next(); if (getOptions().hasOption(str) && str.startsWith("-")) { // found an Option, not an argument. iter.previous(); break; } // Otherwise, this is a value. try { // Note that we only strip matched quotes here. addValForProcessing.invoke(opt, stripMatchedQuotes(str)); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (java.lang.reflect.InvocationTargetException ite) { // Any runtime exception thrown within addValForProcessing() // will be wrapped in an InvocationTargetException. iter.previous(); break; } catch (RuntimeException re) { iter.previous(); break; } } if (opt.getValues() == null && !opt.hasOptionalArg()) { throw new MissingArgumentException(opt); } }
From source file:edu.usc.scrc.PriorityPruner.CommandLineOptions.java
/** * Parses command line arguments, evaluates them, and stores values if * they're correct.//from ww w.j a v a 2 s .c o m * * @param options * collection of Option-objects * @param args * command line arguments * @throws PriorityPrunerException * if error occurs during parsing */ private void parse(Options options, String[] args) throws PriorityPrunerException { try { CommandLineParser cmdLineParser = new GnuParser(); CommandLine commandLine = cmdLineParser.parse(options, args); setParsedOptions(commandLine.getOptions()); // gets set to true if -tfile option is entered through the command // line //boolean tFlag = false; // counts --tped & --tfam options entered through the command line //int tpedCount = 0; //int tfamCount = 0; // loops through all options to save the ones in effect as a String // for printing String tmp = "Options in effect:"; for (Option opt : commandLine.getOptions()) { tmp += ("\r\n -" + opt.getOpt()); if (opt.getValues() != null) { for (int i = 0; i < opt.getValues().length; i++) { tmp += (" " + opt.getValues()[i]); } } } // saves options in effect for printing this.setOptionsInEffect(tmp + "\r\n"); // parse max_distance if (commandLine.hasOption("max_distance")) { this.maxDistance(getLongArgument("max_distance", commandLine.getOptionValue("max_distance"), 0, Long.MAX_VALUE)); checkInput(1, "max_distance", commandLine); } // parse min_maf if (commandLine.hasOption("min_maf")) { this.setMinMaf(getDoubleArgument("min_maf", commandLine.getOptionValue("min_maf"), 0, 0.5)); checkInput(1, "min_maf", commandLine); } // parse min_hwe // if (commandLine.hasOption("min_hwe")) { // this.setMinHwe(getDoubleArgument("min_hwe", // commandLine.getOptionValue("min_hwe"), 0, 1)); // checkInput(1, "min_hwe", commandLine); // } // parses min_snp_callrate if (commandLine.hasOption("min_snp_callrate")) { this.setMinSnpCallRate(getDoubleArgument("min_snp_callrate", commandLine.getOptionValue("min_snp_callrate"), 0, 1)); checkInput(1, "min_snp_callrate", commandLine); } // parses min_design_score if (commandLine.hasOption("min_design_score")) { this.setMinDesignScore(getDoubleArgument("min_design_score", commandLine.getOptionValue("min_design_score"), 0, Double.MAX_VALUE)); checkInput(1, "min_design_score", commandLine); } // // parses option that sets the absolute minimum design score // // value, allowed arguments are doubles between 0.0 and // // Double.MAX_VALUE // if (commandLine.hasOption("amds")) { // this.setAbsoluteMinDesignScore(getDoubleArgument( // "absmindesignscore", // commandLine.getOptionValue("amds"), 0, Double.MAX_VALUE)); // checkInput(1, "amds", commandLine); // } // parse metric if (commandLine.hasOption("metric")) { String[] str = commandLine.getOptionValues("metric"); if (str.length % 2 == 1) { throw new PriorityPrunerException( "Only one argument specified for option \"metric\", a column name (text string) and a weight (decimal number) are required."); } else { for (int i = 0; i < str.length; i++) { if (str[i].equals("design_score")) { throw new PriorityPrunerException("Invalid metric: \"" + str[i] + "\". To filter on design score, simply add correct column in the SNP input file, no metric is needed."); } addMetric(str[i], this.getDoubleArgument("metric", str[i + 1], 0, Double.MAX_VALUE)); i++; } } } // parse st if (commandLine.hasOption("st")) { String[] str = commandLine.getOptionValues("st"); if (str.length % 2 == 1) { throw new PriorityPrunerException( "Only one argument specified for option: \"st\", a p-value (decimal number) and a number of surrogates (integer) are are required."); } else { for (int i = 0; i < str.length; i++) { addSurrogateThreshold(this.getDoubleArgument("st", str[i], 0, 1), this.getIntegerArgument("st", str[i + 1], 0, Integer.MAX_VALUE)); i++; } } } // parse r2t if (commandLine.hasOption("r2t")) { String[] str = commandLine.getOptionValues("r2t"); if (str.length % 2 == 1) { throw new PriorityPrunerException( "Only one argument specified for option: \"r2t\", a p-value and a threshold (decimal numbers between 0 and 1) are required."); } else { for (int i = 0; i < str.length; i++) { addR2Threshold(this.getDoubleArgument("r2t", str[i], 0, 1), this.getDoubleArgument("r2t", str[i + 1], 0, 1)); i++; } } } // parse r2 if (commandLine.hasOption("r2")) { String value = commandLine.getOptionValue("r2"); this.addR2Threshold(1, this.getDoubleArgument("r2", value, 0, 1)); checkInput(1, "r2", commandLine); } // parse chr if (commandLine.hasOption("chr")) { String value = commandLine.getOptionValue("chr"); // recoding chromosome X-representations to "23" if (value.toUpperCase().equals("X") || value.toUpperCase().equals("CHRX")) { //value = "23"; } // if chromosome Y or mitochondrial DNA is encountered, an // exception is thrown else if (value.toUpperCase().equals("M") || value.toUpperCase().equals("MT") || value.toUpperCase().equals("CHRM") || value.toUpperCase().equals("CHRMT") || value.toUpperCase().equals("Y") || value.toUpperCase().equals("CHRY") || value.toUpperCase().equals("24")) { throw new PriorityPrunerException("Chromosome \"" + value + "\" specified in the command line, is not supported. Please update input files and rerun program."); } this.setChr(value); checkInput(1, "chr", commandLine); } // parse out if (commandLine.hasOption("out")) { String value = commandLine.getOptionValue("out"); if (value.endsWith("/")) { value = new StringBuilder(value).append("prioritypruner").toString(); } this.setOutputPrefix(value); checkInput(1, "out", commandLine); } // // parse forceInclude // if (commandLine.hasOption("force_include")) { // String value = commandLine.getOptionValue("force_include"); // this.setForceIncludeFilePath(value); // checkInput(1, "force_include", commandLine); // } // parse do_not_pick_force_included_snps_first if (commandLine.hasOption("do_not_pick_force_included_snps_first")) { this.setSortByForceIncludeAndPValue(false); } // parse snp_table if (commandLine.hasOption("snp_table")) { String[] str = commandLine.getOptionValues("snp_table"); this.setSnpTablePath(str[0]); // counts number of metrics added to command line int metrics = 0; for (int i = 0; i < getParsedOptions().length; i++) { if (getParsedOptions()[i].getOpt().equals("metric")) { metrics++; } } this.setNumMetrics(metrics); checkInput(1, "snp_table", commandLine); } // parse tped if (commandLine.hasOption("tped")) { String value = commandLine.getOptionValue("tped"); checkInput(1, "tped", commandLine); this.setTped(value); } // parse tfam if (commandLine.hasOption("tfam")) { String value = commandLine.getOptionValue("tfam"); checkInput(1, "tfam", commandLine); this.setTfam(value); } // parse tfile if (commandLine.hasOption("tfile")) { String value = commandLine.getOptionValue("tfile"); checkInput(1, "tfile", commandLine); this.setTped(value + ".tped"); this.setTfam(value + ".tfam"); this.setTfile(value); } // parse use_surrogate_for_non_passing_index_snps // if (commandLine.hasOption("use_surrogate_for_non_passing_index_snps")) { // this.setUseSurrogateForNonPassingIndexSnp(true); // } // parses verbose if (commandLine.hasOption("verbose")) { this.setVerbose(true); } // parse outputLDTable if (commandLine.hasOption("ld")) { this.setOutputLDTable(true); } // parse remove if (commandLine.hasOption("remove")) { String value = commandLine.getOptionValue("remove"); checkInput(1, "remove", commandLine); this.setRemove(value); } // parse keep if (commandLine.hasOption("keep")) { String value = commandLine.getOptionValue("keep"); checkInput(1, "keep", commandLine); this.setKeep(value); } // parse keep_random if (commandLine.hasOption("keep_random")) { String value = commandLine.getOptionValue("keep_random"); this.setKeepPercentage(this.getDoubleArgument("keep_random", value, 0, 1)); checkInput(1, "keep_random", commandLine); } // parse no_surrogates_for_force_included_snps if (commandLine.hasOption("no_surrogates_for_force_included_snps")) { this.setAddSurrogatesForForceIncludedSnps(false); } // parse seed if (commandLine.hasOption("seed")) { String value = commandLine.getOptionValue("seed"); this.seed = new Long(this.getLongArgument("seed", value, Long.MIN_VALUE, Long.MAX_VALUE)); } // check that we have all required arguments checkRequiredArguments(commandLine); // checks if any unrecognized arguments been entered checkLeftArguments(commandLine); // if several options from the same options group been entered, // an AlreadySelectedException gets thrown. A custom message is // generated since we wanted another design than the one provided in // the library gave } catch (AlreadySelectedException e) { String message = ""; for (int i = 0; i < e.getOptionGroup().getNames().toArray().length; i++) { message += "\"" + e.getOptionGroup().getNames().toArray()[i] + "\" "; } throw new PriorityPrunerException( "The options: " + message + " may not both be defined. Type --help for help."); // if an undefined option is entered an UnrecognizedOptionException // gets thrown } catch (UnrecognizedOptionException e) { throw new PriorityPrunerException(e.getOption() + " is not a valid option. Type --help for help."); // if an option that is supposed to have arguments is missing, // a MissingArgumentException gets thrown } catch (MissingArgumentException e) { throw new PriorityPrunerException("Missing argument for option \"" + e.getOption().getOpt() + "\". Expected: " + e.getOption().getArgName() + ". Type --help for help."); // if a required option is missing, a MissingOptionException gets // thrown } catch (MissingOptionException e) { // if any other problem occurs while parsing, a general // ParseException gets thrown } catch (ParseException parseException) { throw new PriorityPrunerException("Invalid command line options. Type --help for help."); } }
From source file:org.apache.activemq.apollo.util.cli.CommonsCLISupport.java
/** *//*from ww w . j a v a2s. com*/ static public String[] setOptions(Object target, CommandLine cli) { Option[] options = cli.getOptions(); for (Option option : options) { String name = option.getLongOpt(); if (name == null) continue; String propName = convertOptionToPropertyName(name); String value = option.getValue(); if (value != null) { Class<?> type = IntrospectionSupport.getPropertyType(target, propName); if (type.isArray()) { IntrospectionSupport.setProperty(target, propName, option.getValues()); } else if (type.isAssignableFrom(ArrayList.class)) { IntrospectionSupport.setProperty(target, propName, new ArrayList(option.getValuesList())); } else if (type.isAssignableFrom(HashSet.class)) { IntrospectionSupport.setProperty(target, propName, new HashSet(option.getValuesList())); } else { IntrospectionSupport.setProperty(target, propName, value); } } else { IntrospectionSupport.setProperty(target, propName, true); } } return cli.getArgs(); }
From source file:org.apache.blur.mapreduce.lib.CsvBlurDriver.java
public static Job setupJob(Configuration configuration, ControllerPool controllerPool, AtomicReference<Callable<Void>> ref, String... otherArgs) throws Exception { CommandLine cmd = parse(otherArgs);/*ww w . ja v a 2 s .c o m*/ if (cmd == null) { return null; } final String controllerConnectionStr = cmd.getOptionValue("c"); final String tableName = cmd.getOptionValue("t"); final Iface client = controllerPool.getClient(controllerConnectionStr); TableDescriptor tableDescriptor = client.describe(tableName); Job job = Job.getInstance(configuration, "Blur indexer [" + tableName + "]"); job.setJarByClass(CsvBlurDriver.class); job.setMapperClass(CsvBlurMapper.class); if (cmd.hasOption("p")) { job.getConfiguration().set(MAPRED_COMPRESS_MAP_OUTPUT, "true"); String codecStr = cmd.getOptionValue("p"); COMPRESSION compression; try { compression = COMPRESSION.valueOf(codecStr.trim().toUpperCase()); } catch (IllegalArgumentException e) { compression = null; } if (compression == null) { job.getConfiguration().set(MAPRED_MAP_OUTPUT_COMPRESSION_CODEC, codecStr.trim()); } else { job.getConfiguration().set(MAPRED_MAP_OUTPUT_COMPRESSION_CODEC, compression.getClassName()); } } if (cmd.hasOption("a")) { CsvBlurMapper.setAutoGenerateRecordIdAsHashOfData(job, true); } if (cmd.hasOption("A")) { CsvBlurMapper.setAutoGenerateRowIdAsHashOfData(job, true); } if (cmd.hasOption("S")) { job.setInputFormatClass(SequenceFileInputFormat.class); } else { job.setInputFormatClass(TextInputFormat.class); } if (cmd.hasOption("C")) { if (cmd.hasOption("S")) { String[] optionValues = cmd.getOptionValues("C"); job.setInputFormatClass(CsvBlurCombineSequenceFileInputFormat.class); CombineFileInputFormat.setMinInputSplitSize(job, Long.parseLong(optionValues[0])); CombineFileInputFormat.setMaxInputSplitSize(job, Long.parseLong(optionValues[1])); } else { System.err.println("'C' can only be used with option 'S'"); return null; } } if (cmd.hasOption("i")) { for (String input : cmd.getOptionValues("i")) { Path path = new Path(input); Set<Path> pathSet = recurisvelyGetPathesContainingFiles(path, job.getConfiguration()); if (pathSet.isEmpty()) { FileInputFormat.addInputPath(job, path); } else { for (Path p : pathSet) { FileInputFormat.addInputPath(job, p); } } } } // processing the 'I' option if (cmd.hasOption("I")) { if (cmd.hasOption("C")) { System.err.println("'I' and 'C' both parameters can not be used together."); return null; } Option[] options = cmd.getOptions(); for (Option option : options) { if (option.getOpt().equals("I")) { String[] values = option.getValues(); if (values.length < 2) { System.err.println("'I' parameter missing minimum args of (family path*)"); return null; } for (String p : getSubArray(values, 1)) { Path path = new Path(p); CsvBlurMapper.addFamilyPath(job, values[0], path); FileInputFormat.addInputPath(job, path); } } } } if (cmd.hasOption("s")) { CsvBlurMapper.setSeparator(job, StringEscapeUtils.unescapeJava(cmd.getOptionValue("s"))); } if (cmd.hasOption("o")) { BlurOutputFormat.setOptimizeInFlight(job, false); } if (cmd.hasOption("l")) { BlurOutputFormat.setIndexLocally(job, false); } if (cmd.hasOption("b")) { int maxDocumentBufferSize = Integer.parseInt(cmd.getOptionValue("b")); BlurOutputFormat.setMaxDocumentBufferSize(job, maxDocumentBufferSize); } // processing the 'd' option Option[] options = cmd.getOptions(); for (Option option : options) { if (option.getOpt().equals("d")) { String[] values = option.getValues(); if (values.length < 2) { System.err.println("'d' parameter missing minimum args of (family columname*)"); return null; } CsvBlurMapper.addColumns(job, values[0], getSubArray(values, 1)); } } BlurOutputFormat.setupJob(job, tableDescriptor); BlurMapReduceUtil.addDependencyJars(job.getConfiguration(), Splitter.class); if (cmd.hasOption("r")) { int reducerMultiplier = Integer.parseInt(cmd.getOptionValue("r")); BlurOutputFormat.setReducerMultiplier(job, reducerMultiplier); } final Path output; if (cmd.hasOption("out")) { output = new Path(cmd.getOptionValue("out")); } else { UserGroupInformation currentUser = UserGroupInformation.getCurrentUser(); String userName = currentUser.getUserName(); output = new Path("/user/" + userName + "/.blur-" + System.currentTimeMillis()); } BlurOutputFormat.setOutputPath(job, output); if (cmd.hasOption("import")) { ref.set(new Callable<Void>() { @Override public Void call() throws Exception { client.loadData(tableName, output.toUri().toString()); return null; } }); } return job; }