Example usage for org.apache.commons.cli Option getId

List of usage examples for org.apache.commons.cli Option getId

Introduction

In this page you can find the example usage for org.apache.commons.cli Option getId.

Prototype

public int getId() 

Source Link

Document

Returns the id of this Option.

Usage

From source file:org.blue.star.plugins.check_salesforce_api.java

public void process_command_option(Option o) throws IllegalArgumentException {
    String argValue = o.getValue();

    switch (o.getId()) {
    case 'u':
        this.user = argValue;
        break;/*from w w  w  .j  ava 2  s .  co  m*/
    case 'p':
        this.pass = argValue;
        break;
    case 'w':
        this.url = argValue;
        break;
    }
}

From source file:org.blue.star.plugins.check_salesforce_schema.java

public void process_command_option(Option o) throws IllegalArgumentException {
    String argValue = o.getValue();

    switch (o.getId()) {
    case 'u':
        this.user = argValue;
        break;/*from w  w w  .j a va2 s  .c om*/
    case 'p':
        this.pass = argValue;
        break;
    case 'w':
        this.url = argValue;
        break;
    case 'k':
        this.keepBase = true;
        break;
    }
}

From source file:org.blue.star.plugins.send_mail.java

public void process_command_option(Option o) throws IllegalArgumentException {
    String optarg = o.getValue();

    switch (o.getId()) {
    case 'M':
        this.message = optarg;
        break;/*from ww  w. jav a2s.co  m*/
    case 'S':
        this.subject = optarg;
        break;
    case 'F':
        this.from = optarg;
        break;
    case 'T':
        this.to = optarg;
        break;
    case 's':
        this.smtpServer = optarg;
        break;
    case 'U':
        this.smtpUser = optarg;
        break;
    case 'P':
        this.smtpPass = optarg;
        break;
    case 'A':
        this.smtpAuth = true;
        break;
    case 'L':
        this.ssl = true;
        break;
    }

}

From source file:org.oclc.firefly.hadoop.backup.Backup.java

/**
 * Entry point//w  ww.  ja  v a 2 s.  c  o  m
 * @param args Command line arguments
 * @throws Exception exception
 */
public static void main(String[] args) throws Exception {
    int initialReplication = 1;
    int finalReplication = 0;
    int numMaps = 2;
    int tries = 0;
    String tbl = null;
    String dest = null;
    String user = System.getProperty("user.name");
    Path destPath = null;
    CommandLineParser parser = new PosixParser();
    CommandLine cmdline = null;

    // Parse command line options
    try {
        cmdline = parser.parse(getOptions(), args);
    } catch (org.apache.commons.cli.ParseException e) {
        System.out.println(e.getMessage());
        printOptions();
        System.exit(-1);
    }

    // Get command line options
    for (Option option : cmdline.getOptions()) {
        switch (option.getId()) {
        case 'd':
            dest = option.getValue();
            destPath = new Path(dest);
            if (!destPath.isAbsolute()) {
                throw new IllegalArgumentException("Destination path must be an absolute path");
            }

            break;
        case 'm':
            numMaps = Integer.parseInt(option.getValue());
            if (numMaps <= 0) {
                throw new IllegalArgumentException("Number of map tasks must be greater than zero.");
            }
            break;
        case 'n':
            tries = Integer.parseInt(option.getValue());
            if (tries < 0) {
                throw new IllegalArgumentException(
                        "Maximum number of tries must be greater than or equal to zero.");
            }
            break;
        case 'f':
            finalReplication = Integer.parseInt(option.getValue());
            if (finalReplication <= 0) {
                throw new IllegalArgumentException("Initial replication must be greater than zero.");
            }
            break;
        case 'r':
            initialReplication = Integer.parseInt(option.getValue());
            if (initialReplication <= 0) {
                throw new IllegalArgumentException("Initial replication must be greater than zero.");
            }
            break;
        case 't':
            tbl = option.getValue();
            break;
        case 'u':
            user = option.getValue();
            break;
        default:
            throw new IllegalArgumentException("unexpected option " + option);
        }
    }

    String[] tables = null;
    if (tbl != null) {
        tables = tbl.split(",");
    }

    Configuration srcConf = HBaseConfiguration.create();
    Configuration dstConf = HBaseConfiguration.create();

    // This allows us to copy to a separate HDFS instance
    String destDir = null;
    if (dest != null) {
        destDir = destPath.toUri().getPath();
        String fsName = null;

        if (destDir != null && destDir.length() > 0) {
            LOG.debug("destination dfs: " + dest.substring(0, dest.length() - destDir.length()));
            fsName = dest.substring(0, dest.length() - destDir.length());
        } else {
            fsName = dest;
            destDir = null;
        }

        if (fsName != null && fsName.length() > 0) {
            dstConf.set("fs.default.name", fsName);
        }
    }

    Backup backup = new Backup(srcConf, dstConf);
    backup.setInitialReplication(initialReplication);
    backup.setFinalReplication(finalReplication);
    backup.setUsername(user);
    backup.setNumMapTasks(numMaps);
    if (destDir != null) {
        backup.setBackupStoreDirectory(destDir);
    }

    LOG.info("HBase backup tool");
    LOG.info("--------------------------------------------------");
    //LOG.info("Destination fs     : " + dstConf.get("fs.default.name"));
    LOG.info("Initial replication: " + backup.getInitialReplication());
    LOG.info("Final replication  : " + backup.getFinalReplication());
    LOG.info("Number of attempts : " + ((tries == 0) ? "Until nothing left to copy" : tries));
    LOG.info("Username           : " + backup.getUsername());
    LOG.info("Number map tasks   : " + backup.getNumMapTasks());
    LOG.info("Backup store path  : " + backup.getBackupStoreDirectory());
    LOG.info("--------------------------------------------------");

    boolean success = backup.doMajorCopy(tables, tries);

    LOG.info("--------------------------------------------------");
    if (success) {
        LOG.info("Backup located at: " + backup.getBackupDirectoryPath());
        LOG.info("Backup complete");
    } else {
        LOG.info("Files located at: " + backup.getBackupDirectoryPath());
        LOG.info("Backup failed");
    }

    System.exit(success ? 0 : -1);
}

From source file:org.oclc.firefly.hadoop.backup.Import.java

/**
 * Import table entry point/* ww  w  .j  a  va2s . c o  m*/
 * @param args Command line arguments
 * @throws Exception If failed to read from file system
 */
public static void main(String[] args) throws Exception {
    boolean copy = false;
    boolean ignoreBadName = false;
    String inputDir = null;
    String tbl = null;
    CommandLineParser parser = new PosixParser();
    CommandLine cmdline = null;

    // Parse command line options
    try {
        cmdline = parser.parse(getOptions(), args);
    } catch (org.apache.commons.cli.ParseException e) {
        System.out.println(e.getMessage());
        printOptions();
        System.exit(-1);
    }

    // Get command line options
    for (Option option : cmdline.getOptions()) {
        switch (option.getId()) {
        case 'b':
            ignoreBadName = true;
            break;
        case 'i':
            inputDir = option.getValue();
            break;
        case 'c':
            copy = true;
            break;
        case 't':
            tbl = option.getValue();
            break;
        default:
            throw new IllegalArgumentException("unexpected option " + option);
        }
    }

    String[] tables = null;
    Configuration conf = HBaseConfiguration.create();
    Path backupDirPath = new Path(inputDir);

    Import importer = new Import(conf, backupDirPath, ignoreBadName);
    importer.setRetainOriginal(copy);

    if (tbl == null) {
        tables = importer.getTableNames();
    } else {
        tables = tbl.split(",");
    }

    LOG.info("HBase import tool");
    LOG.info("--------------------------------------------------");
    LOG.info("Backup start time   : " + importer.getStartDate());
    LOG.info("Backup end time     : " + importer.getEndDate());
    LOG.info("Retain original copy: " + importer.getRetainOriginal());
    LOG.info("HBase location      : " + conf.get(HConstants.HBASE_DIR));
    LOG.info("Backup location     : " + backupDirPath);
    LOG.info("--------------------------------------------------");

    importer.importAll(tables);
    int totalSuccess = importer.getNumTablesImported();
    int totalFailed = importer.getNumFailedImports();

    LOG.info("Import results");
    LOG.info("--------------------------------------------------");
    LOG.info("Number of tables: " + tables.length);
    LOG.info("Imported tables : " + totalSuccess);
    LOG.info("Failed          : " + totalFailed);
    LOG.info("--------------------------------------------------");

    if (totalFailed == 0) {
        LOG.info("Import completed successfully.");
    } else if (totalSuccess > 0) {
        LOG.warn("Import completed but with errors. Please inspect manually.");
    } else {
        LOG.error("Import failed. Please inspect manually.");
        System.exit(1);
    }

    System.exit(0);
}

From source file:org.oclc.firefly.hadoop.backup.LogCopier.java

/**
 * Main/*from w w w  .j ava  2s  .c om*/
 * @param args Command line arguments
 * @throws Exception If failed to read from file system
 */
public static void main(String[] args) throws Exception {
    String destDirectory = null;
    long frequency = DEFAULT_FREQUENCY;
    long threads = DEFAULT_NUM_THREADS;
    long dtl = 0L;
    CommandLineParser parser = new PosixParser();
    CommandLine cmdline = null;

    // Parse command line options
    try {
        cmdline = parser.parse(getOptions(), args);
    } catch (org.apache.commons.cli.ParseException e) {
        System.out.println(e.getMessage());
        printOptions();
        System.exit(-1);
    }

    // Get command line options
    for (Option option : cmdline.getOptions()) {
        switch (option.getId()) {
        case 'd':
            destDirectory = option.getValue();
            break;
        case 'm':
            frequency = Long.parseLong(option.getValue());
            if (frequency <= 0) {
                throw new IllegalArgumentException("Minutes must be greater than 0");
            }
            break;
        case 'l':
            dtl = Long.parseLong(option.getValue());
            if (dtl < 0) {
                throw new IllegalArgumentException("Log days-to-live Must be non-negative");
            }
            break;
        case 't':
            threads = Long.parseLong(option.getValue());
            if (threads < 0) {
                throw new IllegalArgumentException("Number of threads must be greater than 0");
            }
            break;
        default:
            throw new IllegalArgumentException("unexpected option " + option);
        }
    }

    LogCopier copier = new LogCopier(destDirectory, frequency);
    copier.setLogDaysToLive(dtl);
    copier.setNumberThreads(threads);

    LOG.info("--------------------------------------------------");
    LOG.info("Copy frequency    : " + copier.getCopyFrequency() + " minutes");
    LOG.info("Archive directory : " + copier.getArchiveDirectory());
    LOG.info("Log days to live  : " + copier.getLogDaysToLive() + " days");
    LOG.info("Copy threads      : " + copier.getNumberThreads());
    LOG.info("--------------------------------------------------");

    copier.run();
}

From source file:org.scidb.iquery.Config.java

/**
 * Parse command-line parameters into the Config object.
 *
 * @note (For developers:) Please do not use a number as either a short option name or a long option name.
 *       This will ensure that DefaultParser::isArgument() returns true if and only if the token is not an option.
 *///from   ww  w .  j a va 2 s.  c  o  m
public void parse(String[] args) throws ParseException {
    Options options = new Options();
    options.addOption(Option.builder("w").required(false).hasArg(true).longOpt("precision").build());
    options.addOption(Option.builder("c").required(false).hasArg(true).longOpt("host").build());
    options.addOption(Option.builder("p").required(false).hasArg(true).longOpt("port").build());
    options.addOption(Option.builder("q").required(false).hasArg(true).longOpt("query").build());
    options.addOption(Option.builder("f").required(false).hasArg(true).longOpt("query_file").build());
    options.addOption(Option.builder("r").required(false).hasArg(true).longOpt("result").build());
    options.addOption(Option.builder("o").required(false).hasArg(true).longOpt("format").build());
    options.addOption(Option.builder("A").required(false).hasArg(true).longOpt("auth-file").build());
    //options.addOption(Option.builder("U").required(false).hasArg(true).longOpt("user-name").build());
    //options.addOption(Option.builder("P").required(false).hasArg(true).longOpt("user-password").build());
    options.addOption(Option.builder("v").required(false).hasArg(false).longOpt("verbose").build());
    options.addOption(Option.builder("t").required(false).hasArg(false).longOpt("timer").build());
    options.addOption(Option.builder("n").required(false).hasArg(false).longOpt("no_fetch").build());
    options.addOption(Option.builder("a").required(false).hasArg(false).longOpt("afl").build());
    options.addOption(Option.builder("h").required(false).hasArg(false).longOpt("help").build());
    options.addOption(Option.builder("V").required(false).hasArg(false).longOpt("version").build());
    options.addOption(Option.builder("i").required(false).hasArg(false).longOpt("ignore_errors").build());
    options.addOption(
            Option.builder("b").required(false).hasArg(false).longOpt("bypass_usr_cfg_perms_chk").build());

    CommandLineParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, args);
    Option[] processedOptions = line.getOptions();

    for (Option o : processedOptions) {
        switch (o.getId()) {
        case 'w':
            setPrecision(Integer.parseInt(o.getValue()));
            break;
        case 'c':
            setHost(o.getValue());
            break;
        case 'p':
            setPort(Integer.parseInt(o.getValue()));
            break;
        case 'q':
            setQuery(o.getValue());
            break;
        case 'f':
            setQueryFile(o.getValue());
            break;
        case 'r':
            setResult(o.getValue());
            break;
        case 'o':
            setFormat(o.getValue());
            break;
        case 'A':
            setAuthFile(o.getValue());
            break;
        case 'v':
            setVerbose(true);
            break;
        case 't':
            setTimer(true);
            break;
        case 'n':
            setNoFetch(true);
            break;
        case 'a':
            setAfl(true);
            break;
        case 'i':
            setIgnoreErrors(true);
            break;
        case 'b':
            setBypassUsrCfgPermsChk(true);
            break;
        case 'h':
            printHelp();
            System.exit(0);
        case 'V':
            printVersion();
            System.exit(0);
        case '?':
            System.exit(1);
        }
    }
}