List of usage examples for org.apache.commons.cli Option getId
public int getId()
From source file:is.landsbokasafn.deduplicator.indexer.IndexingLauncher.java
public static void main(String[] args) throws Exception { loadConfiguration();//from w w w. j a v a 2 s . c o m // Set default values for all settings boolean verbose = readBooleanConfig(VERBOSE_CONF_KEY, true); boolean etag = readBooleanConfig(ETAG_CONF_KEY, false); boolean canonical = readBooleanConfig(CANONICAL_CONF_KEY, true); boolean indexURL = readBooleanConfig(INDEX_URL_KEY, true); boolean addToIndex = readBooleanConfig(ADD_TO_INDEX_CONF_KEY, false); String mimefilter = readStringConfig(MIME_CONF_KEY, "^text/.*"); boolean whitelist = readBooleanConfig(WHITELIST_CONF_KEY, false); String iteratorClassName = readStringConfig(ITERATOR_CONF_KEY, WarcIterator.class.getName()); // Parse command line options CommandLineParser clp = new CommandLineParser(args, new PrintWriter(System.out)); Option[] opts = clp.getCommandLineOptions(); for (int i = 0; i < opts.length; i++) { Option opt = opts[i]; switch (opt.getId()) { case 'w': whitelist = true; break; case 'a': addToIndex = true; break; case 'e': etag = true; break; case 'h': clp.usage(0); break; case 'i': iteratorClassName = opt.getValue(); break; case 'm': mimefilter = opt.getValue(); break; case 'u': indexURL = false; break; case 's': canonical = false; break; case 'v': verbose = true; break; } } if (!indexURL && canonical) { canonical = false; } List<String> cargs = clp.getCommandLineArguments(); if (cargs.size() != 2) { // Should be exactly two arguments. Source and target! clp.usage(0); } String source = cargs.get(0); String target = cargs.get(1); // Load the CrawlDataIterator CrawlDataIterator iterator = (CrawlDataIterator) Class.forName(iteratorClassName).newInstance(); // Print initial stuff System.out.println("Indexing: " + source); System.out.println(" - Index URL: " + indexURL); System.out.println(" - Mime filter: " + mimefilter + " (" + (whitelist ? "whitelist" : "blacklist") + ")"); System.out.println(" - Includes" + (canonical ? " <canonical URL>" : "") + (etag ? " <etag>" : "")); System.out.println(" - Iterator: " + iteratorClassName); System.out.println(" - " + iterator.getSourceType()); System.out.println("Target: " + target); if (addToIndex) { System.out.println(" - Add to existing index (if any)"); } else { System.out.println(" - New index (erases any existing index at " + "that location)"); } iterator.initialize(source); // Create the index long start = System.currentTimeMillis(); IndexBuilder di = new IndexBuilder(target, indexURL, canonical, etag, addToIndex); di.writeToIndex(iterator, mimefilter, !whitelist, verbose); // Clean-up di.close(); System.out.println("Total run time: " + DateUtils.formatMillisecondsToConventional(System.currentTimeMillis() - start)); }
From source file:is.hi.bok.deduplicator.DigestIndexer.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void main(String[] args) throws Exception { CommandLineParser clp = new CommandLineParser(args, new PrintWriter(System.out)); long start = System.currentTimeMillis(); // Set default values for all settings. boolean etag = false; boolean equivalent = false; boolean timestamp = false; String indexMode = MODE_BOTH; boolean addToIndex = false; String mimefilter = "^text/.*"; boolean blacklist = true; String iteratorClassName = CrawlLogIterator.class.getName(); String origin = null;/*from w w w . j a va2 s .c o m*/ boolean skipDuplicates = false; // Process the options Option[] opts = clp.getCommandLineOptions(); for (int i = 0; i < opts.length; i++) { Option opt = opts[i]; switch (opt.getId()) { case 'w': blacklist = false; break; case 'a': addToIndex = true; break; case 'e': etag = true; break; case 'h': clp.usage(0); break; case 'i': iteratorClassName = opt.getValue(); break; case 'm': mimefilter = opt.getValue(); break; case 'o': indexMode = opt.getValue(); break; case 's': equivalent = true; break; case 't': timestamp = true; break; case 'r': origin = opt.getValue(); break; case 'd': skipDuplicates = true; break; default: System.err.println("Unhandled option id: " + opt.getId()); } } List cargs = clp.getCommandLineArguments(); if (cargs.size() != 2) { // Should be exactly two arguments. Source and target! clp.usage(0); } // Get the CrawlDataIterator // Get the iterator classname or load default. Class cl = Class.forName(iteratorClassName); Constructor co = cl.getConstructor(new Class[] { String.class }); CrawlDataIterator iterator = (CrawlDataIterator) co.newInstance(new Object[] { (String) cargs.get(0) }); // Print initial stuff System.out.println("Indexing: " + cargs.get(0)); System.out.println(" - Mode: " + indexMode); System.out.println(" - Mime filter: " + mimefilter + " (" + (blacklist ? "blacklist" : "whitelist") + ")"); System.out.println(" - Includes" + (equivalent ? " <equivalent URL>" : "") + (timestamp ? " <timestamp>" : "") + (etag ? " <etag>" : "")); System.out.println(" - Skip duplicates: " + (skipDuplicates ? "yes" : "no")); System.out.println(" - Iterator: " + iteratorClassName); System.out.println(" - " + iterator.getSourceType()); System.out.println("Target: " + cargs.get(1)); if (addToIndex) { System.out.println(" - Add to existing index (if any)"); } else { System.out.println(" - New index (erases any existing index at " + "that location)"); } DigestIndexer di = new DigestIndexer((String) cargs.get(1), indexMode, equivalent, timestamp, etag, addToIndex); // Create the index di.writeToIndex(iterator, mimefilter, blacklist, origin, true, skipDuplicates); // Clean-up di.close(); System.out.println("Total run time: " + ArchiveUtils.formatMillisecondsToConventional(System.currentTimeMillis() - start)); }
From source file:com.stumbleupon.hbaseadmin.HBaseCompact.java
/** * Main entry point//from w w w . j av a 2 s . co m * @param args command line arguments * @throws Exception */ public static void main(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); CommandLine cmd = null; String hbaseSite = null; String jmxRemotePasswordFile = null; String jmxPort = null; Date startDate = null; Date endDate = null; int throttleFactor = 1; int numCycles = 1; int pauseInterval = DEFAULT_PAUSE_INTERVAL; int waitInterval = DEFAULT_WAIT_INTERVAL; int filesKeep = DEFAULT_FILES_KEEP; long regionCompactWaitTime = DEFAULT_REGION_COMPACT_WAIT_TIME; long maxStoreFileAge = 0; boolean excludeTables = false; String tableNamesString = ""; List<String> tableNames = new ArrayList<String>(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); // Parse command line options try { cmd = parser.parse(getOptions(), args); } catch (org.apache.commons.cli.ParseException e) { System.out.println(e.getMessage()); printOptions(); System.exit(-1); } for (Option option : cmd.getOptions()) { switch (option.getId()) { case 'c': hbaseSite = option.getValue(); break; case 'j': jmxRemotePasswordFile = option.getValue(); break; case 't': throttleFactor = Integer.parseInt(option.getValue()); break; case 'n': numCycles = Integer.parseInt(option.getValue()); break; case 'p': pauseInterval = Integer.parseInt(option.getValue()); break; case 'w': waitInterval = Integer.parseInt(option.getValue()); break; case 's': startDate = sdf.parse(option.getValue()); break; case 'e': endDate = sdf.parse(option.getValue()); break; case 'b': tableNamesString = option.getValue(); tableNames = Arrays.asList(option.getValue().split(",")); break; case 'f': filesKeep = Integer.parseInt(option.getValue()); break; case 'r': jmxPort = option.getValue(); break; case 'x': excludeTables = true; break; case 'm': regionCompactWaitTime = Long.parseLong(option.getValue()); break; case 'a': maxStoreFileAge = Long.parseLong(option.getValue()); break; default: throw new IllegalArgumentException("unexpected option " + option); } } LOG.info("Starting compactor"); LOG.info("--------------------------------------------------"); LOG.info("HBase site : {}", hbaseSite); LOG.info("RegionServer Jmx port : {}", jmxPort); LOG.info("Jmx password file : {}", jmxRemotePasswordFile); LOG.info("Compact interval : {}", pauseInterval); LOG.info("Check interval : {}", waitInterval); LOG.info("Throttle factor : {}", throttleFactor); LOG.info("Number of cycles : {}", numCycles); LOG.info("Off-peak start time : {}", Utils.dateString(startDate, "HH:mm")); LOG.info("Off-peak end time : {}", Utils.dateString(endDate, "HH:mm")); LOG.info("Minimum store files : {}", filesKeep); LOG.info("Table names : {}", tableNamesString); LOG.info("Exclude tables : {}", excludeTables); LOG.info("Region compact wait time: {}", regionCompactWaitTime); LOG.info("Max store file age : {}", maxStoreFileAge); LOG.info("--------------------------------------------------"); // Get command line options final Configuration conf = HBaseConfiguration.create(); conf.addResource(new Path(hbaseSite)); HBaseCompact compact = new HBaseCompact(); ClusterUtils clusterUtils = new ClusterUtils(compact, regionCompactWaitTime); compact.setClusterUtils(clusterUtils); compact.setAdmin(new HBaseAdmin(conf)); compact.setSleepBetweenCompacts(pauseInterval); compact.setSleepBetweenChecks(waitInterval); compact.setThrottleFactor(throttleFactor); compact.setNumCycles(numCycles); compact.setStartDate(startDate); compact.setEndDate(endDate); compact.setNumStoreFiles(filesKeep); compact.setTableNames(tableNames); compact.setExcludeTables(excludeTables); compact.setMaxStoreFileAge(maxStoreFileAge); clusterUtils.setJmxPort(jmxPort); clusterUtils.setJmxPasswordFile(jmxRemotePasswordFile); compact.runCompactions(); }
From source file:com.imgur.backup.SnapshotS3Util.java
/** * Get args //from w w w . j a v a 2 s .c o m * @param args * @throws Exception */ private void getAndCheckArgs(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); CommandLine cmd = null; cmd = parser.parse(getOptions(), args); for (Option option : cmd.getOptions()) { switch (option.getId()) { case 'c': createSnapshot = true; break; case 'x': createSnapshot = true; exportSnapshot = true; break; case 'e': exportSnapshot = true; break; case 'i': importSnapshot = true; break; case 't': tableName = option.getValue(); break; case 'n': snapshotName = option.getValue(); break; case 'k': accessKey = option.getValue(); break; case 's': accessSecret = option.getValue(); break; case 'b': bucketName = option.getValue(); break; case 'p': s3Path = option.getValue(); break; case 'd': hdfsPath = option.getValue(); break; case 'm': mappers = Long.parseLong(option.getValue()); break; case 'a': s3protocol = S3N_PROTOCOL; break; case 'l': snapshotTtl = Long.parseLong(option.getValue()); break; default: throw new IllegalArgumentException("unexpected option " + option); } } if (createSnapshot && StringUtils.isEmpty(tableName)) { throw new IllegalArgumentException("Need a table name"); } if ((importSnapshot || (exportSnapshot && !createSnapshot)) && StringUtils.isEmpty(snapshotName)) { throw new IllegalArgumentException("Need a snapshot name"); } }
From source file:org.blue.star.plugins.check_base.java
/** * Handle the flow for processing command line arguments, as well as processing the common set. * TODO if needed to move this to a in process, must remove the System.exit calls. * @param args Command line arguments/*from ww w . j a va 2 s . c o m*/ * @return true/false depending on processing results. */ private final void process_arguments(String[] args) throws IllegalArgumentException { options = utils_h.getStandardOptions(); // call super to add it's command arguments. add_command_arguments(options); CommandLine cmd = null; try { cmd = new PosixParser().parse(options, args); } catch (Exception e) { throw new IllegalArgumentException(programName + ": Could not parse arguments."); } java.util.Iterator iter = cmd.iterator(); while (iter.hasNext()) { Option o = (Option) iter.next(); String optarg = o.getValue(); if (verbose > 0) System.out.println("processing " + o + "(" + o.getId() + ") " + o.getValue()); /* Process the basic command line agruments, default sends this to child for processing */ switch (o.getId()) { case 'h': /* help */ print_help(); System.exit(common_h.STATE_UNKNOWN); break; case 'V': /* version */ utils.print_revision(programName, revision); System.exit(common_h.STATE_UNKNOWN); break; case 't': /* timeout period */ utils_h.timeout_interval = Integer.parseInt(optarg); break; case 'v': /* verbose mode */ verbose++; break; } /* Allow extension to process all options, even if we already processed */ process_command_option(o); } String[] argv = cmd.getArgs(); if (argv != null && argv.length > 0) process_command_arguments(argv); validate_command_arguments(); }
From source file:org.blue.star.plugins.check_ftp.java
public void process_command_option(Option o) throws IllegalArgumentException { String argValue = o.getValue(); switch (o.getId()) { case 'H': hostname = argValue.trim();//from w w w . jav a2 s . c o m break; case 'f': file = argValue.trim(); break; case 'd': directory = argValue.trim(); break; case 'u': username = argValue.trim(); break; case 'p': password = argValue.trim(); break; case 'P': if (utils.is_intnonneg(argValue)) port = Integer.valueOf(argValue); else throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<Port> (%P) must be a non-negative number\n", argValue)); break; case 'm': passive = true; break; } }
From source file:org.blue.star.plugins.check_jmx.java
public void process_command_option(Option o) throws IllegalArgumentException { String argValue = o.getValue(); switch (o.getId()) { case 'H': if (!netutils.is_host(argValue)) throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<Hostname> (%H) must be a valid Host\n", argValue)); else/*from ww w .j av a 2 s. c om*/ hostname = argValue.trim(); break; case 'P': if (!utils.is_intnonneg(argValue)) throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<Port> (%P) must be a positive Integer\n", argValue)); else port = Integer.valueOf(argValue); break; case 'J': jndiAdaptorName = argValue.trim(); break; case 'M': mbeanName = argValue.trim(); break; case 'A': attribute = argValue.trim(); break; case 'e': expectString = argValue.trim(); break; case 'D': domain = argValue.trim(); break; case 'w': if (!utils.is_intnonneg(argValue)) throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<warning> (%w) must be a positive Integer\n", argValue)); else { warningThreshold = Long.valueOf(argValue); compareThresholds = true; } break; case 'c': if (!utils.is_intnonneg(argValue)) throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<critical> (%c) must be a positive Integer\n", argValue)); else { criticalThreshold = Long.valueOf(argValue); compareThresholds = true; } break; case 'C': if (!utils.is_intnonneg(argValue)) throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<Count> (%C) must be a positive Integer", argValue)); else count = Integer.valueOf(argValue); break; } }
From source file:org.blue.star.plugins.check_local_time.java
public void process_command_option(Option o) throws IllegalArgumentException { String argValue = o.getValue(); int version;/*from w ww. ja va 2 s . com*/ switch (o.getId()) { case 'H': hostname = argValue.trim(); break; case 'w': if (utils.is_intnonneg(argValue)) warningThreshold = Long.valueOf(argValue) * 1000; else throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<Warning> (%w) must be a non-negative number\n", argValue)); break; case 'c': if (utils.is_intnonneg(argValue)) criticalThreshold = Long.valueOf(argValue) * 1000; else throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<Critical> (%c) must be a non-negative number\n", argValue)); break; case 'P': if (utils.is_intnonneg(argValue)) port = Integer.valueOf(argValue); else throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<Port> (%P) must be a non-negative number\n", argValue)); break; case 'n': if (utils.is_intnonneg(argValue)) { version = Integer.valueOf(argValue); if (version == 3) ntpVersion = NtpV3Impl.VERSION_3; else if (version == 4) ntpVersion = NtpV3Impl.VERSION_4; else throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<NTP Version> (%n) must be either V3 or V4\n", argValue)); } else throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<NTP Version> (%n) must be a non-negative number\n", argValue)); break; } }
From source file:org.blue.star.plugins.check_nt.java
/** * process command-line arguments /*from w ww. j a v a2 s .co m*/ */ public void process_command_option(Option o) throws IllegalArgumentException { String optarg = o.getValue(); switch (o.getId()) { case 'H': /* hostname */ server_address = optarg; break; case 's': /* password */ req_password = optarg; break; case 'S': /* password file */ password_file = optarg; break; case 'p': /* port */ try { server_port = Integer.parseInt(optarg); } catch (NumberFormatException nfE) { throw new IllegalArgumentException("Port must be a valid integer."); } case 'v': if (optarg.equals("CLIENTVERSION")) vars_to_check = CHECK_CLIENTVERSION; else if (optarg.equals("CPULOAD")) vars_to_check = CHECK_CPULOAD; else if (optarg.equals("UPTIME")) vars_to_check = CHECK_UPTIME; else if (optarg.equals("USEDDISKSPACE")) vars_to_check = CHECK_USEDDISKSPACE; else if (optarg.equals("SERVICESTATE")) vars_to_check = CHECK_SERVICESTATE; else if (optarg.equals("PROCSTATE")) vars_to_check = CHECK_PROCSTATE; else if (optarg.equals("MEMUSE")) vars_to_check = CHECK_MEMUSE; else if (optarg.equals("COUNTER")) vars_to_check = CHECK_COUNTER; else if (optarg.equals("FILEAGE")) vars_to_check = CHECK_FILEAGE; else { throw new IllegalArgumentException("Unknown variable."); } break; case 'l': /* value list */ value_list = optarg; break; case 'w': /* warning threshold */ warning_value = Integer.parseInt(optarg); check_warning_value = true; break; case 'c': /* critical threshold */ critical_value = Integer.parseInt(optarg); check_critical_value = true; break; case 'd': /* Display select for services */ if (optarg.equals("SHOWALL")) show_all = true; break; case 't': /* timeout */ socket_timeout = Integer.parseInt(optarg); if (socket_timeout <= 0) { throw new IllegalArgumentException("Socket timeout must be greater than 0."); } } }
From source file:org.blue.star.plugins.check_ping.java
public void process_command_option(Option o) throws IllegalArgumentException { String optarg = o.getValue(); switch (o.getId()) { case '4': /* IPv4 only */ address_family = common_h.AF_INET; break;//from w ww. ja v a 2 s .co m case '6': /* IPv6 only */ address_family = common_h.AF_INET6; // TODO Determine if IPv6 is even available. break; case 'H': /* hostname */ String[] hostnames = optarg.split(","); for (String hostname : hostnames) addresses.add(hostname); n_addresses = addresses.size(); break; case 'p': /* number of packets to send */ if (utils.is_intnonneg(optarg)) max_packets = Integer.parseInt(optarg); else throw new IllegalArgumentException(utils.formatArgumentError(this.getClass().getName(), "<max_packets> (%s) must be a non-negative number\n", optarg)); break; case 'n': /* no HTML */ display_html = false; break; case 'L': /* show HTML */ display_html = true; break; case 'c': crta = get_threshold_rta(optarg); cpl = get_threshold_pl(optarg); break; case 'w': wrta = get_threshold_rta(optarg); wpl = get_threshold_pl(optarg); break; case 'i': interface_name = optarg; try { network_interface = NetworkInterface.getByName(interface_name); } catch (Exception e) { throw new IllegalArgumentException("Error acquiring acces to interface " + e.getMessage()); } if (network_interface == null) { throw new IllegalArgumentException("Interface name " + interface_name + " is not available."); } break; } }