Example usage for org.apache.commons.cli OptionBuilder withLongOpt

List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder withLongOpt.

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:com.linkedin.databus.bootstrap.utils.BootstrapAddSource.java

@SuppressWarnings("static-access")
public static Config parseArgs(String[] args) throws Exception {
    CommandLineParser cliParser = new GnuParser();

    Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen")
            .create(HELP_OPT_CHAR);//from  ww w .  j  ava2  s . co  m

    Option sourceIdOption = OptionBuilder.withLongOpt(SOURCE_ID_OPT_LONG_NAME)
            .withDescription("Source ID for which tables need to be added").hasArg().withArgName("Source ID")
            .create(SOURCE_ID_OPT_CHAR);

    Option sourceNameOption = OptionBuilder.withLongOpt(SOURCE_NAME_OPT_LONG_NAME)
            .withDescription("Source Name for which tables need to be added").hasArg().withArgName("Source ID")
            .create(SOURCE_NAME_OPT_CHAR);

    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME)
            .withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file")
            .create(BOOTSTRAP_DB_PROP_OPT_CHAR);

    Option cmdLinePropsOption = OptionBuilder.withLongOpt(CMD_LINE_PROPS_OPT_LONG_NAME)
            .withDescription("Cmd line override of config properties. Semicolon separated.").hasArg()
            .withArgName("Semicolon_separated_properties").create(CMD_LINE_PROPS_OPT_CHAR);

    Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME)
            .withDescription("Log4j properties to use").hasArg().withArgName("property_file")
            .create(LOG4J_PROPS_OPT_CHAR);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(sourceIdOption);
    options.addOption(sourceNameOption);
    options.addOption(dbOption);
    options.addOption(cmdLinePropsOption);
    options.addOption(log4jPropsOption);

    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        LOG.error("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
    }

    if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
    } else {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);

        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);

        LOG.info("Using default logging settings");
    }

    if (cmd.hasOption(HELP_OPT_CHAR)) {
        printCliHelp(options);
        System.exit(0);
    }

    if (!cmd.hasOption(SOURCE_ID_OPT_CHAR))
        throw new RuntimeException("Source ID is not provided");

    if (!cmd.hasOption(SOURCE_NAME_OPT_CHAR))
        throw new RuntimeException("Source Name is not provided");

    if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
        throw new RuntimeException("Bootstrap config is not provided");

    String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
    LOG.info("Loading bootstrap DB config from properties file " + propFile);

    _sBootstrapConfigProps = new Properties();
    FileInputStream f = new FileInputStream(propFile);
    try {
        _sBootstrapConfigProps.load(f);
    } finally {
        f.close();
    }
    if (cmd.hasOption(CMD_LINE_PROPS_OPT_CHAR)) {
        String cmdLinePropString = cmd.getOptionValue(CMD_LINE_PROPS_OPT_CHAR);
        updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString);
    }

    int srcId = Integer.parseInt(cmd.getOptionValue(SOURCE_ID_OPT_CHAR));
    String srcName = cmd.getOptionValue(SOURCE_NAME_OPT_CHAR);

    BootstrapConfig config = new BootstrapConfig();

    ConfigLoader<BootstrapReadOnlyConfig> configLoader = new ConfigLoader<BootstrapReadOnlyConfig>("bootstrap.",
            config);

    BootstrapReadOnlyConfig staticConfig = configLoader.loadConfig(_sBootstrapConfigProps);
    Config cfg = new Config();
    cfg.setDbConfig(staticConfig);
    cfg.setSrcId(srcId);
    cfg.setSrcName(srcName);
    return cfg;
}

From source file:com.metadave.eql.EQLConsole.java

@SuppressWarnings("static-access")
public static CommandLine processArgs(String[] args) {
    Options options = new Options();

    Option help = OptionBuilder.withLongOpt("help").withDescription("Print this list of commands").create();

    Option nocolor = OptionBuilder.withLongOpt("nocolor").withDescription("Don't use color output").create();

    Option noconfig = OptionBuilder.withLongOpt("noconfig").withDescription("Don't read ~/.EQL.config")
            .create();//from  ww  w. j  a v  a  2s  .  c  om

    Option infile = OptionBuilder.withLongOpt("infile").withDescription("Read input from file and exit")
            .hasArg().withArgName("filename").create();

    Option nosignals = OptionBuilder.withLongOpt("nosignals")
            .withDescription("Don't catch the Ctrl-C (INT) signal").create();

    options.addOption(help);
    options.addOption(nocolor);
    options.addOption(noconfig);
    options.addOption(infile);
    options.addOption(nosignals);
    CommandLineParser parser = new org.apache.commons.cli.GnuParser();
    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("EQL", options);
            System.exit(0);
        }
        return line;
    } catch (ParseException exp) {
        System.err.println("Error processing command line args: " + exp.getMessage());
        System.exit(-1);
    }
    return null;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.ExtractData.java

@SuppressWarnings("static-access")
@Override/*from w  w w.ja v a2 s .com*/
public Options getOptions() {
    Options options = super.getOptions();

    OptionGroup group = new OptionGroup();
    group.setRequired(true);
    group.addOption(OptionBuilder.withLongOpt("problem").hasArg().withArgName("name").create('b'));
    group.addOption(OptionBuilder.withLongOpt("dimension").hasArg().withArgName("number").create('d'));
    options.addOptionGroup(group);

    options.addOption(OptionBuilder.withLongOpt("input").hasArg().withArgName("file").isRequired().create('i'));
    options.addOption(OptionBuilder.withLongOpt("output").hasArg().withArgName("file").create('o'));
    options.addOption(OptionBuilder.withLongOpt("separator").hasArg().withArgName("value").create('s'));
    options.addOption(OptionBuilder.withLongOpt("reference").hasArg().withArgName("file").create('r'));
    options.addOption(OptionBuilder.withLongOpt("epsilon").hasArg().withArgName("e1,e2,...").create('e'));
    options.addOption(OptionBuilder.withLongOpt("noheader").create('n'));

    return options;
}

From source file:eu.crydee.alignment.aligner.BritannicaP.java

static private void parseArguments(String[] args) {
    Options shortCircuitOptions = new Options();
    shortCircuitOptions// ww  w.ja va 2s. co  m
            .addOption(OptionBuilder.withLongOpt("help").withDescription("Print this message.").create('h'));
    shortCircuitOptions
            .addOption(OptionBuilder.withLongOpt("version").withDescription("Print the version.").create('v'));
    Options options = new Options();
    options.addOption(OptionBuilder.isRequired().withLongOpt("corpus-path").hasArg().withArgName("folder-path")
            .withDescription("Path to the Britannica corpus.").create('c'));
    options.addOption(
            OptionBuilder.isRequired().withLongOpt("annotations-path").hasArg().withArgName("folder-path")
                    .withDescription("Path to the test folder of the annotations.").create('a'));
    try {
        CommandLineParser parser = new PosixParser();
        CommandLine cmd = parser.parse(shortCircuitOptions, args, true);
        if (cmd.hasOption('h')) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("britannica", options, true);
            System.exit(0);
        }
        if (cmd.hasOption('v')) {
            System.out.println("britannica-aligner v1.0.0-SNAPSHOT");
            System.exit(0);
        }
        cmd = parser.parse(options, args);
        CORPUS = cmd.getOptionValue('c');
        ANNS = cmd.getOptionValue('a');
    } catch (ParseException ex) {
        System.err.println("The CLI args could not be parsed.");
        System.err.println("The error message was:");
        System.err.println(" " + ex.getMessage());
        System.exit(1);
    }
}

From source file:ch.eiafr.cojac.Arg.java

@SuppressWarnings("static-access")
static Options createOptions() {
    Options options = new Options();

    options.addOption(Arg.HELP.shortOpt(), "help", false, "Print the help of the program and exit");
    options.addOption(Arg.VERBOSE.shortOpt(), "verbose", false, "Display some internal traces");
    options.addOption(Arg.PRINT.shortOpt(), "console", false,
            "Signal problems with console messages to stderr (default signaling policy)");
    options.addOption(Arg.EXCEPTION.shortOpt(), "exception", false,
            "Signal problems by throwing an ArithmeticException");
    options.addOption(OptionBuilder.withLongOpt("callback").withArgName("meth").hasArg()
            .withDescription("Signal problems by calling " + "a user-supplied method matching this signature:"
                    + "\n...public static void f(String msg) \n"
                    + "(Give a fully qualified identifier in the form: \n" + "pkgA/myPkg/myClass/myMethod)")
            .create(Arg.CALL_BACK.shortOpt()));
    options.addOption(OptionBuilder.withLongOpt("logfile").withArgName("path").hasOptionalArg()
            .withDescription("Signal problems by writing to a log file.\n" + "Default filename is: "
                    + Args.DEFAULT_LOG_FILE_NAME + '.')
            .create(Arg.LOG_FILE.shortOpt()));
    options.addOption(Arg.DETAILED_LOG.shortOpt(), "detailed", false,
            "Log the full stack trace (combined with -Cc or -Cl)");
    options.addOption(OptionBuilder.withLongOpt("bypass").withArgName("prefixes").hasOptionalArg()
            .withDescription("Bypass classes starting with one of these prefixes (semi-colon separated list). "
                    + "\nExample: -Xb foo;bar.util\n will skip classes with name foo* or bar.util*")
            .create(Arg.BYPASS.shortOpt()));
    options.addOption(Arg.FILTER.shortOpt(), "filter", false, "Report each problem only once per faulty line");
    options.addOption(Arg.RUNTIME_STATS.shortOpt(), "summary", false, "Print runtime statistics");
    options.addOption(Arg.INSTRUMENTATION_STATS.shortOpt(), "stats", false, "Print instrumentation statistics");

    options.addOption(Arg.JMX_ENABLE.shortOpt(), false, "Enable JMX feature");
    options.addOption(OptionBuilder.withArgName("host").hasArg()
            .withDescription("Set remote JMX connection host (default: localhost)")
            .create(JMX_HOST.shortOpt()));
    options.addOption(OptionBuilder.withArgName("port").hasArg()
            .withDescription("Set remote JMX connection port (default: 5017)").create(JMX_PORT.shortOpt()));
    options.addOption(OptionBuilder.withArgName("MBean-id").hasArg()
            .withDescription("Set remote MBean name (default: COJAC)").create(JMX_NAME.shortOpt()));

    //        options.addOption(Arg.REPLACE_FLOATS.shortOpt(),
    //            "replacefloats", false, "Replace floats by Cojac-wrapper objects ");

    options.addOption(OptionBuilder.withArgName("class").hasArg()
            .withDescription("Select the double container (don't use it!).\n"
                    + "Example: -Wd cojac.BigDecimalDouble will use ch.eiafr.cojac.models.wrappers.BigDecimalDouble")
            .create(DOUBLE_WRAPPER.shortOpt()));
    options.addOption(OptionBuilder.withArgName("class").hasArg()
            .withDescription("Select the float container. See -Wd.").create(FLOAT_WRAPPER.shortOpt()));
    options.addOption(OptionBuilder.withArgName("class").hasArg()
            .withDescription("Select the wrapper (don't use it!).\n"
                    + "Example: -W cojac.WrapperBasic will use ch.eiafr.cojac.models.wrappers.WrapperBasic")
            .create(NG_WRAPPER.shortOpt()));

    options.addOption(OptionBuilder.withLongOpt("bigdecimal").withArgName("digits").hasArg()
            .withDescription("Use BigDecimal wrapping with a certain precision (number of digits).\n"
                    + "Example: -Rb 100 will wrap with 100-significant-digit BigDecimals")
            .create(BIG_DECIMAL_PRECISION.shortOpt()));

    options.addOption(Arg.INTERVAL.shortOpt(), "interval", false, "Use interval computation wrapping");
    options.addOption(Arg.STOCHASTIC.shortOpt(), "stochastic", false,
            "Use discrete stochastic arithmetic wrapping");
    options.addOption(Arg.AUTOMATIC_DERIVATION.shortOpt(), "autodiff", false,
            "Use automatic differentiation wrapping");

    options.addOption(Arg.DISABLE_UNSTABLE_COMPARISONS_CHECK.shortOpt(), false,
            "Disable unstability checks in comparisons, for the Interval or Stochastic wrappers");
    options.addOption(OptionBuilder.withArgName("epsilon").hasArg().withDescription(
            "Relative precision considered unstable, for Interval/Stochastic wrappers (default 0.00001)")
            .create(STABILITY_THRESHOLD.shortOpt()));

    options.addOption(Arg.ALL.shortOpt(), "all", false, "Sniff everywhere (this is the default behavior)");
    options.addOption(Arg.NONE.shortOpt(), "none", false, "Don't sniff at all");
    options.addOption(Arg.OPCODES.shortOpt(), true,
            "Sniff in those (comma separated) opcodes; eg: " + allOpcodes);
    options.addOption(Arg.MATHS.shortOpt(), false, "Sniff in (Strict)Math.xyz() methods");
    options.addOption(Arg.INTS.shortOpt(), false, "Sniff in ints opcodes");
    options.addOption(Arg.LONGS.shortOpt(), false, "Sniff in longs opcodes");
    options.addOption(Arg.CASTS.shortOpt(), false, "Sniff in casts opcodes");
    options.addOption(Arg.DOUBLES.shortOpt(), false, "Sniff in doubles opcodes");
    options.addOption(Arg.FLOATS.shortOpt(), false, "Sniff in floats opcodes");

    return options;
}

From source file:edu.uchicago.lowasser.flaginjection.Flags.java

public static Injector bootstrapFlagInjector(final String[] args, String mainClassName, List<String> packages,
        Module... baseModules) {//from  ww  w.ja v  a 2s  .c  o m
    Logger logger = Logger.getLogger("org.learningu.scheduling.flags.Flags");
    AbstractModule linkingModule = new AbstractModule() {

        @Override
        protected void configure() {
        }

        @Provides
        @RuntimeArguments
        String[] commandLineArguments() {
            return args;
        }

        @Provides
        @Singleton
        Options options(Map<Flag, Type> flagsMap) {
            Options options = new Options();
            for (Flag flag : flagsMap.keySet()) {
                OptionBuilder.hasArgs();
                OptionBuilder.withLongOpt(flag.name());
                OptionBuilder.withDescription(flag.description());
                OptionBuilder.withArgName(flagsMap.get(flag).toString());
                options.addOption(OptionBuilder.create());
            }
            return options;
        }

        @Provides
        @Singleton
        CommandLine commandLine(Options options, @RuntimeArguments String[] args) {
            try {
                return new PosixParser().parse(options, args);
            } catch (ParseException e) {
                throw Throwables.propagate(e);
            }
        }
    };
    logger.fine("Built Options module");
    Injector baseInjector = Guice.createInjector(new FlagErrorModule(mainClassName),
            Modules.combine(Iterables.concat(Arrays.asList(baseModules), ImmutableList.of(linkingModule))));
    logger.fine("Bootstrapping flag injector with command line arguments");
    Injector createdInjector = baseInjector
            .createChildInjector(baseInjector.getInstance(FlagBootstrapModule.class));
    // Use reflection to instantiate the variables in FlagClass classes
    for (String packageName : packages) {
        Reflections reflections = new Reflections(packageName);
        Set<Class<? extends FlagsClass>> classes = reflections.getSubTypesOf(FlagsClass.class);
        for (Class<? extends FlagsClass> flagClass : classes) {
            createdInjector.getInstance(flagClass);
        }
    }
    return createdInjector;
}

From source file:com.github.cojac.Arg.java

@SuppressWarnings("static-access")
static Options createOptions() {
    Options options = new Options();

    options.addOption(Arg.HELP.shortOpt(), "help", false, "Print the help of the program and exit");
    options.addOption(Arg.VERBOSE.shortOpt(), "verbose", false, "Display some internal traces");
    options.addOption(Arg.PRINT.shortOpt(), "console", false,
            "Signal problems with console messages to stderr (default signaling policy)");
    options.addOption(Arg.EXCEPTION.shortOpt(), "exception", false,
            "Signal problems by throwing an ArithmeticException");
    options.addOption(OptionBuilder.withLongOpt("callback").withArgName("meth").hasArg()
            .withDescription("Signal problems by calling " + "a user-supplied method matching this signature:"
                    + "\n...public static void f(String msg) \n"
                    + "(Give a fully qualified identifier in the form: \n" + "pkgA/myPkg/myClass/myMethod)")
            .create(Arg.CALL_BACK.shortOpt()));
    options.addOption(OptionBuilder.withLongOpt("logfile").withArgName("path").hasOptionalArg()
            .withDescription("Signal problems by writing to a log file.\n" + "Default filename is: "
                    + Args.DEFAULT_LOG_FILE_NAME + '.')
            .create(Arg.LOG_FILE.shortOpt()));
    options.addOption(Arg.DETAILED_LOG.shortOpt(), "detailed", false,
            "Log the full stack trace (combined with -Cc or -Cl)");
    options.addOption(OptionBuilder.withLongOpt("bypass").withArgName("prefixes").hasOptionalArg()
            .withDescription("Bypass classes starting with one of these prefixes (semi-colon separated list). "
                    + "\nExample: -Xb foo;bar.util\n will skip classes with name foo* or bar.util*")
            .create(Arg.BYPASS.shortOpt()));
    options.addOption(Arg.FILTER.shortOpt(), "filter", false, "Report each problem only once per faulty line");
    options.addOption(Arg.RUNTIME_STATS.shortOpt(), "summary", false, "Print runtime statistics");
    options.addOption(Arg.INSTRUMENTATION_STATS.shortOpt(), "stats", false, "Print instrumentation statistics");

    options.addOption(Arg.JMX_ENABLE.shortOpt(), false, "Enable JMX feature");
    options.addOption(OptionBuilder.withArgName("host").hasArg()
            .withDescription("Set remote JMX connection host (default: localhost)")
            .create(JMX_HOST.shortOpt()));
    options.addOption(OptionBuilder.withArgName("port").hasArg()
            .withDescription("Set remote JMX connection port (default: 5017)").create(JMX_PORT.shortOpt()));
    options.addOption(OptionBuilder.withArgName("MBean-id").hasArg()
            .withDescription("Set remote MBean name (default: COJAC)").create(JMX_NAME.shortOpt()));

    //        options.addOption(Arg.REPLACE_FLOATS.shortOpt(),
    //            "replacefloats", false, "Replace floats by Cojac-wrapper objects ");

    options.addOption(OptionBuilder.withArgName("class").hasArg()
            .withDescription("Select the double container (don't use it!).\n"
                    + "Example: -Wd cojac.BigDecimalDouble will use com.github.cojac.models.wrappers.BigDecimalDouble")
            .create(DOUBLE_WRAPPER.shortOpt()));
    options.addOption(OptionBuilder.withArgName("class").hasArg()
            .withDescription("Select the float container. See -Wd.").create(FLOAT_WRAPPER.shortOpt()));
    options.addOption(OptionBuilder.withArgName("class").hasArg()
            .withDescription("Select the wrapper (don't use it!).\n"
                    + "Example: -W cojac.WrapperBasic will use com.github.cojac.models.wrappers.WrapperBasic")
            .create(NG_WRAPPER.shortOpt()));

    options.addOption(OptionBuilder.withLongOpt("bigdecimal").withArgName("digits").hasArg()
            .withDescription("Use BigDecimal wrapping with a certain precision (number of digits).\n"
                    + "Example: -Rb 100 will wrap with 100-significant-digit BigDecimals")
            .create(BIG_DECIMAL_PRECISION.shortOpt()));

    options.addOption(Arg.INTERVAL.shortOpt(), "interval", false, "Use interval computation wrapping");
    options.addOption(Arg.STOCHASTIC.shortOpt(), "stochastic", false,
            "Use discrete stochastic arithmetic wrapping");
    options.addOption(Arg.AUTOMATIC_DERIVATION.shortOpt(), "autodiff", false,
            "Use automatic differentiation wrapping");

    options.addOption(Arg.DISABLE_UNSTABLE_COMPARISONS_CHECK.shortOpt(), false,
            "Disable unstability checks in comparisons, for the Interval or Stochastic wrappers");
    options.addOption(OptionBuilder.withArgName("epsilon").hasArg().withDescription(
            "Relative precision considered unstable, for Interval/Stochastic wrappers (default 0.00001)")
            .create(STABILITY_THRESHOLD.shortOpt()));

    options.addOption(Arg.ALL.shortOpt(), "all", false, "Sniff everywhere (this is the default behavior)");
    options.addOption(Arg.NONE.shortOpt(), "none", false, "Don't sniff at all");
    options.addOption(Arg.OPCODES.shortOpt(), true,
            "Sniff in those (comma separated) opcodes; eg: " + allOpcodes);
    options.addOption(Arg.MATHS.shortOpt(), false, "Sniff in (Strict)Math.xyz() methods");
    options.addOption(Arg.INTS.shortOpt(), false, "Sniff in ints opcodes");
    options.addOption(Arg.LONGS.shortOpt(), false, "Sniff in longs opcodes");
    options.addOption(Arg.CASTS.shortOpt(), false, "Sniff in casts opcodes");
    options.addOption(Arg.DOUBLES.shortOpt(), false, "Sniff in doubles opcodes");
    options.addOption(Arg.FLOATS.shortOpt(), false, "Sniff in floats opcodes");

    return options;
}

From source file:hws.core.JobClient.java

public void run(String[] args) throws Exception {
    //final String command = args[0];
    //final int n = Integer.valueOf(args[1]);
    //final Path jarPath = new Path(args[2]);
    Options options = new Options();
    /*options.addOption(OptionBuilder.withLongOpt("jar")
                           .withDescription( "Jar path" )
                           .hasArg()//from www .j  av a 2  s  . co  m
                           .withArgName("JarPath")
                           .create());
    options.addOption(OptionBuilder.withLongOpt("scheduler")
                           .withDescription( "Scheduler class name" )
                           .hasArg()
                           .withArgName("ClassName")
                           .create());
    */options.addOption(OptionBuilder.withLongOpt("zk-servers")
            .withDescription("List of the ZooKeeper servers").hasArgs().withArgName("zkAddrs").create("zks"));
    //options.addOption("l", "list", false, "list modules");
    options.addOption(OptionBuilder.withLongOpt("load").withDescription("load new modules").hasArgs()
            .withArgName("XMLFiles").create());
    /*options.addOption(OptionBuilder.withLongOpt( "remove" )
                           .withDescription( "remove modules" )
                           .hasArgs()
                           .withArgName("ModuleNames")
                           .create("rm"));
    */CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);

    //Path jarPath = null;
    //String schedulerClassName = null;
    String[] xmlFileNames = null;
    //String []moduleNames = null;
    String zksArgs = "";
    String[] zkServers = null;
    if (cmd.hasOption("zks")) {
        zksArgs = "-zks";
        zkServers = cmd.getOptionValues("zks");
        for (String zks : zkServers) {
            zksArgs += " " + zks;
        }
    }

    //Logger setup
    //FSDataOutputStream writer = FileSystem.get(conf).create(new Path("hdfs:///hws/apps/"+appIdStr+"/logs/jobClient.log"));
    //Logger.addOutputStream(writer);

    /*if(cmd.hasOption("l")){
       LOG.warn("Argument --list (-l) is not supported yet.");
    }
    if(cmd.hasOption("jar")){
       jarPath = new Path(cmd.getOptionValue("jar")); 
    }
    if(cmd.hasOption("scheduler")){
       schedulerClassName = cmd.getOptionValue("scheduler");
    }*/
    if (cmd.hasOption("load")) {
        xmlFileNames = cmd.getOptionValues("load");
    } /*else if(cmd.hasOption("rm")){
        moduleNames = cmd.getOptionValues("rm");
      }*/

    //LOG.info("Jar-Path "+jarPath);
    if (xmlFileNames != null) {
        String paths = "";
        for (String path : xmlFileNames) {
            paths += path + "; ";
        }
        LOG.info("Load XMLs: " + paths);
    }
    /*if(moduleNames!=null){
       String modules = "";
       for(String module: moduleNames){
          modules += module+"; ";
       }
       LOG.info("remove: "+modules);
    }*/
    // Create yarnClient
    YarnConfiguration conf = new YarnConfiguration();
    YarnClient yarnClient = YarnClient.createYarnClient();
    yarnClient.init(conf);
    yarnClient.start();

    // Create application via yarnClient
    YarnClientApplication app = yarnClient.createApplication();

    System.out.println("LOG Path: " + ApplicationConstants.LOG_DIR_EXPANSION_VAR);
    // Set up the container launch context for the application master
    ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);

    ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
    ApplicationId appId = appContext.getApplicationId();

    ZkClient zk = new ZkClient(zkServers[0]); //TODO select a ZooKeeper server
    if (!zk.exists("/hadoop-watershed")) {
        zk.createPersistent("/hadoop-watershed", "");
    }
    zk.createPersistent("/hadoop-watershed/" + appId.toString(), "");

    FileSystem fs = FileSystem.get(conf);

    LOG.info("Collecting files to upload");
    fs.mkdirs(new Path("hdfs:///hws/apps/" + appId.toString()));
    fs.mkdirs(new Path("hdfs:///hws/apps/" + appId.toString() + "/logs"));

    ModulePipeline modulePipeline = ModulePipeline.fromXMLFiles(xmlFileNames);
    LOG.info("Uploading files to HDFS");
    for (String path : modulePipeline.files()) {
        uploadFile(fs, new File(path), appId);
    }
    LOG.info("Upload finished");

    String modulePipelineJson = Json.dumps(modulePipeline);
    String modulePipelineBase64 = Base64.encodeBase64String(StringUtils.getBytesUtf8(modulePipelineJson))
            .replaceAll("\\s", "");
    LOG.info("ModulePipeline: " + modulePipelineJson);
    //LOG.info("ModulePipeline: "+modulePipelineBase64);
    amContainer.setCommands(Collections.singletonList("$JAVA_HOME/bin/java" + " -Xmx256M"
            + " hws.core.JobMaster" + " -aid " + appId.toString() + " --load " + modulePipelineBase64 + " "
            + zksArgs + " 1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stdout" + " 2>"
            + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stderr"));

    // Setup jar for ApplicationMaster
    //LocalResource appMasterJar = Records.newRecord(LocalResource.class);
    //setupAppMasterJar(jarPath, appMasterJar);
    //amContainer.setLocalResources(Collections.singletonMap("hws.jar", appMasterJar));

    LOG.info("Listing files for YARN-Watershed");
    RemoteIterator<LocatedFileStatus> filesIterator = fs.listFiles(new Path("hdfs:///hws/bin/"), false);
    Map<String, LocalResource> resources = new HashMap<String, LocalResource>();
    LOG.info("Files setup as resource");
    while (filesIterator.hasNext()) {
        LocatedFileStatus fileStatus = filesIterator.next();
        // Setup jar for ApplicationMaster
        LocalResource containerJar = Records.newRecord(LocalResource.class);
        ContainerUtils.setupContainerJar(fs, fileStatus.getPath(), containerJar);
        resources.put(fileStatus.getPath().getName(), containerJar);
    }
    LOG.info("container resource setup");
    amContainer.setLocalResources(resources);

    fs.close(); //closing FileSystem interface

    // Setup CLASSPATH for ApplicationMaster
    Map<String, String> appMasterEnv = new HashMap<String, String>();
    ContainerUtils.setupContainerEnv(appMasterEnv, conf);
    amContainer.setEnvironment(appMasterEnv);

    // Set up resource type requirements for ApplicationMaster
    Resource capability = Records.newRecord(Resource.class);
    capability.setMemory(256);
    capability.setVirtualCores(1);

    // Finally, set-up ApplicationSubmissionContext for the application
    //ApplicationSubmissionContext appContext = 
    //app.getApplicationSubmissionContext();
    appContext.setApplicationName("Hadoop-Watershed"); // application name
    appContext.setAMContainerSpec(amContainer);
    appContext.setResource(capability);
    appContext.setQueue("default"); // queue 

    // Submit application
    LOG.info("Submitting application " + appId);
    yarnClient.submitApplication(appContext);

    LOG.info("Waiting for containers to finish");
    zk.waitUntilExists("/hadoop-watershed/" + appId.toString() + "/done", TimeUnit.MILLISECONDS, 250);
    ApplicationReport appReport = yarnClient.getApplicationReport(appId);
    YarnApplicationState appState = appReport.getYarnApplicationState();
    while (appState != YarnApplicationState.FINISHED && appState != YarnApplicationState.KILLED
            && appState != YarnApplicationState.FAILED) {
        Thread.sleep(100);
        appReport = yarnClient.getApplicationReport(appId);
        appState = appReport.getYarnApplicationState();
    }

    System.out.println("Application " + appId + " finished with" + " state " + appState + " at "
            + appReport.getFinishTime());

    System.out.println("deleting " + appId.toString() + " znode");
    zk.deleteRecursive("/hadoop-watershed/" + appId.toString()); //TODO remove app folder from ZooKeeper
}

From source file:fr.romainf.QRCode.java

/**
 * Creates the options object required for the program.
 *
 * @return Options//from  w w w.  j  av  a  2 s.  c o m
 */
private static Options buildOptions() {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("output").isRequired(false).hasArg(true)
            .withDescription("file to write to").withArgName("FILENAME").create("o"));
    options.addOption(OptionBuilder.withLongOpt("colour").isRequired(false).hasArg(true)
            .withDescription("pixel colour").withArgName("COLOUR").create("c"));
    options.addOption("h", "help", false, "print this message");

    return options;
}

From source file:com.linkedin.helix.MockEspressoService.java

@SuppressWarnings("static-access")
private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(HELP).withDescription("Prints command-line options info")
            .create();//from  w  w  w  .j  a  va  2s .  c  om
    helpOption.setArgs(0);
    helpOption.setRequired(false);
    helpOption.setArgName("print help message");

    Option zkServerOption = OptionBuilder.withLongOpt(ZKSERVERADDRESS)
            .withDescription("Provide zookeeper address").create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required)");

    Option clusterOption = OptionBuilder.withLongOpt(CLUSTERNAME).withDescription("Provide cluster name")
            .create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name(Required)");

    Option instanceOption = OptionBuilder.withLongOpt(INSTANCENAME)
            .withDescription("Provide name for this instance").create();
    instanceOption.setArgs(1);
    instanceOption.setRequired(false);
    instanceOption.setArgName("Instance name(Optional, defaults to localhost)");

    Option portOption = OptionBuilder.withLongOpt(PORT).withDescription("Provide web service port").create();
    portOption.setArgs(1);
    portOption.setRequired(false);
    portOption.setArgName("web service port, default: " + DEFAULT_PORT);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(zkServerOption);
    options.addOption(clusterOption);
    options.addOption(instanceOption);
    options.addOption(portOption);

    return options;
}