Java Code Examples for org.apache.commons.cli.CommandLine#getOptionValue()

The following examples show how to use org.apache.commons.cli.CommandLine#getOptionValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MulticlassAROWClassifierUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
protected CommandLine processOptions(ObjectInspector[] argOIs) throws UDFArgumentException {
    final CommandLine cl = super.processOptions(argOIs);

    float r = 0.1f;
    if (cl != null) {
        String r_str = cl.getOptionValue("r");
        if (r_str != null) {
            r = Float.parseFloat(r_str);
            if (!(r > 0)) {
                throw new UDFArgumentException(
                    "Regularization parameter must be greater than 0: " + r_str);
            }
        }
    }

    this.r = r;
    return cl;
}
 
Example 2
Source File: SomaticConfig.java    From hmftools with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
static SomaticConfig createSomaticConfig(@NotNull CommandLine cmd) throws ParseException {
    final Optional<File> file;
    if (cmd.hasOption(SOMATIC_VARIANTS)) {
        final String somaticFilename = cmd.getOptionValue(SOMATIC_VARIANTS);
        final File somaticFile = new File(somaticFilename);
        if (!somaticFile.exists()) {
            throw new ParseException("Unable to read somatic variants from: " + somaticFilename);
        }
        file = Optional.of(somaticFile);
    } else {
        file = Optional.empty();
        LOGGER.info("No somatic vcf supplied");
    }

    return ImmutableSomaticConfig.builder()
            .file(file)
            .minTotalVariants(defaultIntValue(cmd, SOMATIC_MIN_TOTAL, SOMATIC_MIN_TOTAL_DEFAULT))
            .minPeakVariants(defaultIntValue(cmd, SOMATIC_MIN_PEAK, SOMATIC_MIN_PEAK_DEFAULT))
            .minSomaticPurity(defaultValue(cmd, SOMATIC_MIN_PURITY, SOMATIC_MIN_PURITY_DEFAULT))
            .minSomaticPuritySpread(defaultValue(cmd, SOMATIC_MIN_PURITY_SPREAD, SOMATIC_MIN_PURITY_SPREAD_DEFAULT))
            .somaticPenaltyWeight(defaultValue(cmd, SOMATIC_PENALTY_WEIGHT, SOMATIC_PENALTY_WEIGHT_DEFAULT))
            .highlyDiploidPercentage(defaultValue(cmd, HIGHLY_DIPLOID_PERCENTAGE, HIGHLY_DIPLOID_PERCENTAGE_DEFAULT))
            .build();
}
 
Example 3
Source File: StandaloneJobClusterConfigurationParserFactory.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public StandaloneJobClusterConfiguration createResult(@Nonnull CommandLine commandLine) throws FlinkParseException {
	final String configDir = commandLine.getOptionValue(CONFIG_DIR_OPTION.getOpt());
	final Properties dynamicProperties = commandLine.getOptionProperties(DYNAMIC_PROPERTY_OPTION.getOpt());
	final int restPort = getRestPort(commandLine);
	final String hostname = commandLine.getOptionValue(HOST_OPTION.getOpt());
	final SavepointRestoreSettings savepointRestoreSettings = CliFrontendParser.createSavepointRestoreSettings(commandLine);
	final JobID jobId = getJobId(commandLine);
	final String jobClassName = commandLine.getOptionValue(JOB_CLASS_NAME_OPTION.getOpt());

	return new StandaloneJobClusterConfiguration(
		configDir,
		dynamicProperties,
		commandLine.getArgs(),
		hostname,
		restPort,
		savepointRestoreSettings,
		jobId,
		jobClassName);
}
 
Example 4
Source File: IntegrationJobValidity.java    From datasync with MIT License 6 votes vote down vote up
private static boolean validatePathToControlFileArg(CommandLine cmd, CommandLineOptions options) {
    String controlFilePath = cmd.getOptionValue(options.PATH_TO_CONTROL_FILE_FLAG);
    if (controlFilePath == null) controlFilePath = cmd.getOptionValue(options.PATH_TO_FTP_CONTROL_FILE_FLAG);

    if(controlFilePath != null) {
        String publishingWithFtp = cmd.getOptionValue(options.PUBLISH_VIA_FTP_FLAG);
        String publishingWithDi2 = cmd.getOptionValue(options.PUBLISH_VIA_DI2_FLAG);
        if (isNullOrFalse(publishingWithFtp) && isNullOrFalse(publishingWithDi2)) {
            System.err.println("Invalid argument: Neither -sc,--" + options.PATH_TO_FTP_CONTROL_FILE_FLAG +
                    " -cf,--" + options.PATH_TO_CONTROL_FILE_FLAG + " can be supplied " +
                    "unless -pf,--" + options.PUBLISH_VIA_FTP_FLAG + " is 'true' or " +
                    "unless -ph,--" + options.PUBLISH_VIA_DI2_FLAG + " is 'true'");
            return false;
        }
    }

    if(controlFilePath != null) {
        if(cmd.getOptionValue(options.HAS_HEADER_ROW_FLAG) != null) {
            System.out.println("WARNING: -h,--" + options.HAS_HEADER_ROW_FLAG + " is being ignored because " +
                    "-sc,--" + options.PATH_TO_FTP_CONTROL_FILE_FLAG +  " or " +
                    "-cf,--" + options.PATH_TO_CONTROL_FILE_FLAG +  " was supplied");
        }
    }
    return true;
}
 
Example 5
Source File: HamletGen.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  CommandLine cmd = new GnuParser().parse(opts, args);
  if (cmd.hasOption("help")) {
    new HelpFormatter().printHelp("Usage: hbgen [OPTIONS]", opts);
    return;
  }
  // defaults
  Class<?> specClass = HamletSpec.class;
  Class<?> implClass = HamletImpl.class;
  String outputClass = "HamletTmp";
  String outputPackage = implClass.getPackage().getName();
  if (cmd.hasOption("spec-class")) {
    specClass = Class.forName(cmd.getOptionValue("spec-class"));
  }
  if (cmd.hasOption("impl-class")) {
    implClass = Class.forName(cmd.getOptionValue("impl-class"));
  }
  if (cmd.hasOption("output-class")) {
    outputClass = cmd.getOptionValue("output-class");
  }
  if (cmd.hasOption("output-package")) {
    outputPackage = cmd.getOptionValue("output-package");
  }
  new HamletGen().generate(specClass, implClass, outputClass, outputPackage);
}
 
Example 6
Source File: BamSlicerApplication.java    From hmftools with GNU General Public License v3.0 6 votes vote down vote up
public static void main(final String... args) throws ParseException, IOException {
    CommandLine cmd = createCommandLine(args);

    // Disable default samtools buffering
    System.setProperty("samjdk.buffer_size", "0");
    if (cmd.hasOption(INPUT_MODE_FILE)) {
        sliceFromVCF(cmd);
    } else if (cmd.hasOption(INPUT_MODE_S3)) {
        Pair<URL, URL> urls = generateURLs(cmd);
        sliceFromURLs(urls.getValue(), urls.getKey(), cmd);
    } else if (cmd.hasOption(INPUT_MODE_URL)) {
        URL bamURL = new URL(cmd.getOptionValue(INPUT));
        URL indexURL = new URL(cmd.getOptionValue(INDEX));
        sliceFromURLs(indexURL, bamURL, cmd);
    }

    LOGGER.info("Done.");
}
 
Example 7
Source File: Producer.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
    CommandLine commandLine = buildCommandline(args);
    if (commandLine != null) {
        String group = commandLine.getOptionValue('g');
        String topic = commandLine.getOptionValue('t');
        String tags = commandLine.getOptionValue('a');
        String keys = commandLine.getOptionValue('k');
        String msgCount = commandLine.getOptionValue('c');

        DefaultMQProducer producer = new DefaultMQProducer(group);
        producer.setInstanceName(Long.toString(System.currentTimeMillis()));

        producer.start();

        for (int i = 0; i < Integer.parseInt(msgCount); i++) {
            try {
                Message msg = new Message(
                    topic,
                    tags,
                    keys,
                    ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
                SendResult sendResult = producer.send(msg);
                System.out.printf("%-8d %s%n", i, sendResult);
            } catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }

        producer.shutdown();
    }
}
 
Example 8
Source File: GISJobValidity.java    From datasync with MIT License 5 votes vote down vote up
private static boolean validatePublishMethodArg(CommandLine cmd) {
    String method = cmd.getOptionValue("m");
    String publishingWithDi2 = cmd.getOptionValue(CommandLineOptions.PUBLISH_VIA_DI2_FLAG);
    String publishingWithFtp = cmd.getOptionValue(CommandLineOptions.PUBLISH_VIA_FTP_FLAG);
    String controlFilePath = cmd.getOptionValue(CommandLineOptions.PATH_TO_CONTROL_FILE_FLAG);

    if (method == null && controlFilePath == null
        && isNullOrFalse(publishingWithFtp) && isNullOrFalse(publishingWithDi2)) {

        System.err.println("Missing required argument: -m,--" +
                CommandLineOptions.PUBLISH_METHOD_FLAG + " is required");

        return false;
    } else if (method == null && controlFilePath == null
               && (!isNullOrFalse(publishingWithFtp) || !isNullOrFalse(publishingWithDi2))) {
        // if publishing via ftp or di2/http, we want to err about the control file, not the method arg

        return true;
    } else if (method == null && controlFilePath != null) {
        // have a control file, don't need the method arg (and would ignore it anyway)

        return true;
    } else { // method != null
        boolean publishMethodValid = false;

        for (PublishMethod m : PublishMethod.values()) {
            if (m.name().equalsIgnoreCase(method))
                publishMethodValid = true;
        }

        if (!publishMethodValid) {
            System.err.println("Invalid argument: -m,--" + CommandLineOptions.PUBLISH_METHOD_FLAG + " must be " +
                               Arrays.toString(PublishMethod.values()));
            return false;
        }

        return true;
    }
}
 
Example 9
Source File: LoadPgxData.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
public static void main(@NotNull String[] args) throws ParseException, SQLException, IOException {
    Options options = createOptions();
    CommandLine cmd = new DefaultParser().parse(options, args);

    String userName = cmd.getOptionValue(DB_USER);
    String password = cmd.getOptionValue(DB_PASS);
    String databaseUrl = cmd.getOptionValue(DB_URL);

    String sample = cmd.getOptionValue(SAMPLE);

    String pgxCallsFileName = cmd.getOptionValue(PGX_CALLS_TXT);
    String pgxGenotypeFileName = cmd.getOptionValue(PGX_GENOTYPE_TXT);

    if (Utils.anyNull(userName, password, databaseUrl, sample, pgxCallsFileName, pgxGenotypeFileName)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("patient-db - load metrics data", options);
    } else {
         String jdbcUrl = "jdbc:" + databaseUrl;
         DatabaseAccess dbWriter = new DatabaseAccess(userName, password, jdbcUrl);

        LOGGER.info("Reading pgx calls file {}", pgxCallsFileName);
        List<PGXCalls> pgxCalls = PGXCallsFile.read(pgxCallsFileName);

        LOGGER.info("Reading pgx genotype file {}", pgxGenotypeFileName);
        List<PGXGenotype> pgxGenotype = PGXGenotypeFile.read(pgxGenotypeFileName);

        LOGGER.info("Writing pgx into database");
        dbWriter.writePGX(sample, pgxGenotype, pgxCalls);

        LOGGER.info("Pgx data is written into database for sample {}", sample);
    }

}
 
Example 10
Source File: IntegrationJobValidity.java    From datasync with MIT License 5 votes vote down vote up
private static boolean validateDatasetIdArg(CommandLine cmd, CommandLineOptions options) {
    if(cmd.getOptionValue(options.DATASET_ID_FLAG) == null) {
        System.err.println("Missing required argument: -i,--" + options.DATASET_ID_FLAG + " is required");
        return false;
    }
    return true;
}
 
Example 11
Source File: ProxyTool.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
    super.parseCommandLine(cmdline);
    if (!cmdline.hasOption("d")) {
        throw new ParseException("No DLSN provided");
    }
    String[] dlsnStrs = cmdline.getOptionValue("d").split(",");
    if (dlsnStrs.length != 3) {
        throw new ParseException("Invalid DLSN : " + cmdline.getOptionValue("d"));
    }
    dlsn = new DLSN(Long.parseLong(dlsnStrs[0]), Long.parseLong(dlsnStrs[1]), Long.parseLong(dlsnStrs[2]));
}
 
Example 12
Source File: ZabbixMain.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
public static void disableExecute(CommandLine commandLine) {
    String username = commandLine.getOptionValue("username");

    try {
        ZabbixScriptService zabbixScriptService = new ZabbixScriptService();
        List<Usergroup> usergroups = zabbixScriptService.getUserGroup(username);
        zabbixScriptService.updateUserGroup(usergroups.get(0).getUsrgrpid(), false);
        log.info(username + "を無効化しました。");
    } catch (Exception e) {
        log.error(e.getMessage(), e);

    }
}
 
Example 13
Source File: ColumnIndexCommand.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(CommandLine options) throws Exception {
  super.execute(options);

  String[] args = options.getArgs();
  InputFile in = HadoopInputFile.fromPath(new Path(args[0]), new Configuration());
  PrintWriter out = new PrintWriter(Main.out, true);
  String rowGroupValue = options.getOptionValue("r");
  Set<String> indexes = new HashSet<>();
  if (rowGroupValue != null) {
    indexes.addAll(Arrays.asList(rowGroupValue.split("\\s*,\\s*")));
  }
  boolean showColumnIndex = options.hasOption("i");
  boolean showOffsetIndex = options.hasOption("o");
  if (!showColumnIndex && !showOffsetIndex) {
    showColumnIndex = true;
    showOffsetIndex = true;
  }

  try (ParquetFileReader reader = ParquetFileReader.open(in)) {
    boolean firstBlock = true;
    int rowGroupIndex = 0;
    for (BlockMetaData block : reader.getFooter().getBlocks()) {
      if (!indexes.isEmpty() && !indexes.contains(Integer.toString(rowGroupIndex))) {
        ++rowGroupIndex;
        continue;
      }
      if (!firstBlock) {
        out.println();
        firstBlock = false;
      }
      out.format("row group %d:%n", rowGroupIndex);
      for (ColumnChunkMetaData column : getColumns(block, options)) {
        String path = column.getPath().toDotString();
        if (showColumnIndex) {
          out.format("column index for column %s:%n", path);
          ColumnIndex columnIndex = reader.readColumnIndex(column);
          if (columnIndex == null) {
            out.println("NONE");
          } else {
            out.println(columnIndex);
          }
        }
        if (showOffsetIndex) {
          out.format("offset index for column %s:%n", path);
          OffsetIndex offsetIndex = reader.readOffsetIndex(column);
          if (offsetIndex == null) {
            out.println("NONE");
          } else {
            out.println(offsetIndex);
          }
        }
      }
      ++rowGroupIndex;
    }
  }
}
 
Example 14
Source File: Runtime.java    From incubator-heron with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"IllegalCatch", "RegexpSinglelineJava"})
public static void main(String[] args) throws Exception {
  final Options options = createOptions();
  final Options helpOptions = constructHelpOptions();

  CommandLineParser parser = new DefaultParser();

  // parse the help options first.
  CommandLine cmd = parser.parse(helpOptions, args, true);
  if (cmd.hasOption(Flag.Help.name)) {
    usage(options);
    return;
  }

  try {
    cmd = parser.parse(options, args);
  } catch (ParseException pe) {
    System.err.println(pe.getMessage());
    usage(options);
    return;
  }

  final boolean verbose = isVerbose(cmd);
  // set and configure logging level
  Logging.setVerbose(verbose);
  Logging.configure(verbose);

  LOG.debug("API server overrides:\n {}", cmd.getOptionProperties(Flag.Property.name));

  final String toolsHome = getToolsHome();

  // read command line flags
  final String cluster = cmd.getOptionValue(Flag.Cluster.name);
  final String heronConfigurationDirectory = getConfigurationDirectory(toolsHome, cmd);
  final String heronDirectory = getHeronDirectory(cmd);
  final String releaseFile = getReleaseFile(toolsHome, cmd);
  final String configurationOverrides = loadOverrides(cmd);
  final int port = getPort(cmd);
  final String downloadHostName = getDownloadHostName(cmd);
  final String heronCorePackagePath = getHeronCorePackagePath(cmd);

  final Config baseConfiguration =
      ConfigUtils.getBaseConfiguration(heronDirectory,
          heronConfigurationDirectory,
          releaseFile,
          configurationOverrides);

  final ResourceConfig config = new ResourceConfig(Resources.get());
  final Server server = new Server(port);

  final ServletContextHandler contextHandler =
      new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  contextHandler.setContextPath("/");

  LOG.info("using configuration path: {}", heronConfigurationDirectory);

  contextHandler.setAttribute(HeronResource.ATTRIBUTE_CLUSTER, cluster);
  contextHandler.setAttribute(HeronResource.ATTRIBUTE_CONFIGURATION, baseConfiguration);
  contextHandler.setAttribute(HeronResource.ATTRIBUTE_CONFIGURATION_DIRECTORY,
      heronConfigurationDirectory);
  contextHandler.setAttribute(HeronResource.ATTRIBUTE_CONFIGURATION_OVERRIDE_PATH,
      configurationOverrides);
  contextHandler.setAttribute(HeronResource.ATTRIBUTE_PORT,
      String.valueOf(port));
  contextHandler.setAttribute(HeronResource.ATTRIBUTE_DOWNLOAD_HOSTNAME,
      Utils.isNotEmpty(downloadHostName)
          ? String.valueOf(downloadHostName) : null);
  contextHandler.setAttribute(HeronResource.ATTRIBUTE_HERON_CORE_PACKAGE_PATH,
      Utils.isNotEmpty(heronCorePackagePath)
          ? String.valueOf(heronCorePackagePath) : null);

  server.setHandler(contextHandler);

  final ServletHolder apiServlet =
      new ServletHolder(new ServletContainer(config));

  contextHandler.addServlet(apiServlet, API_BASE_PATH);

  try {
    server.start();

    LOG.info("Heron API server started at {}", server.getURI());

    server.join();
  } catch (Exception ex) {
    final String message = getErrorMessage(server, port, ex);
    LOG.error(message);
    System.err.println(message);
    System.exit(1);
  } finally {
    server.destroy();
  }
}
 
Example 15
Source File: HealthManager.java    From incubator-heron with Apache License 2.0 4 votes vote down vote up
private static String getOptionValue(CommandLine cmd, CliArgs argName) {
  return cmd.getOptionValue(argName.text, null);
}
 
Example 16
Source File: PatentScorer.java    From act with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  System.out.println("Starting up...");
  System.out.flush();
  Options opts = new Options();
  opts.addOption(Option.builder("i").
      longOpt("input").hasArg().required().desc("Input file or directory to score").build());
  opts.addOption(Option.builder("o").
      longOpt("output").hasArg().required().desc("Output file to which to write score JSON").build());
  opts.addOption(Option.builder("h").longOpt("help").desc("Print this help message and exit").build());
  opts.addOption(Option.builder("v").longOpt("verbose").desc("Print verbose log output").build());

  HelpFormatter helpFormatter = new HelpFormatter();
  CommandLineParser cmdLineParser = new DefaultParser();
  CommandLine cmdLine = null;
  try {
    cmdLine = cmdLineParser.parse(opts, args);
  } catch (ParseException e) {
    System.out.println("Caught exception when parsing command line: " + e.getMessage());
    helpFormatter.printHelp("DocumentIndexer", opts);
    System.exit(1);
  }

  if (cmdLine.hasOption("help")) {
    helpFormatter.printHelp("DocumentIndexer", opts);
    System.exit(0);
  }

  if (cmdLine.hasOption("verbose")) {
    // With help from http://stackoverflow.com/questions/23434252/programmatically-change-log-level-in-log4j2
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration ctxConfig = ctx.getConfiguration();
    LoggerConfig logConfig = ctxConfig.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    logConfig.setLevel(Level.DEBUG);

    ctx.updateLoggers();
    LOGGER.debug("Verbose logging enabled");
  }

  String inputFileOrDir = cmdLine.getOptionValue("input");
  File splitFileOrDir = new File(inputFileOrDir);
  if (!(splitFileOrDir.exists())) {
    LOGGER.error("Unable to find directory at " + inputFileOrDir);
    System.exit(1);
  }

  try (FileWriter writer = new FileWriter(cmdLine.getOptionValue("output"))) {
    PatentScorer scorer = new PatentScorer(PatentModel.getModel(), writer);
    PatentCorpusReader corpusReader = new PatentCorpusReader(scorer, splitFileOrDir);
    corpusReader.readPatentCorpus();
  }
}
 
Example 17
Source File: UptimeSample.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static void main(String... args) throws IOException {
  CommandLine cl;
  try {
    cl = PARSER.parse(OPTIONS, args);
  } catch (ParseException pe) {
    usage("Exception parsing command line arguments.");
    throw new RuntimeException("Exception parsing command line arguments.", pe);
  }

  String projectId =
      cl.getOptionValue(PROJECT_ID_OPTION.getOpt(), System.getenv("GOOGLE_CLOUD_PROJECT"));

  String command =
      Optional.of(cl.getArgList())
          .filter(l -> l.size() > 0)
          .map(l -> Strings.emptyToNull(l.get(0)))
          .orElse(null);
  if (command == null) {
    usage(null);
    return;
  }

  switch (command.toLowerCase()) {
    case "create":
      createUptimeCheck(
          projectId,
          cl.getOptionValue(DISPLAY_NAME_OPTION.getOpt(), "new uptime check"),
          cl.getOptionValue(HOST_NAME_OPTION.getOpt(), "example.com"),
          cl.getOptionValue(PATH_NAME_OPTION.getOpt(), "/"));
      break;
    case "update":
      updateUptimeCheck(
          projectId,
          cl.getOptionValue(DISPLAY_NAME_OPTION.getOpt(), "new uptime check"),
          cl.getOptionValue(HOST_NAME_OPTION.getOpt(), "example.com"),
          cl.getOptionValue(PATH_NAME_OPTION.getOpt(), "/"));
      break;
    case "list":
      listUptimeChecks(projectId);
      break;
    case "listips":
      listUptimeCheckIPs();
      break;
    case "get":
      getUptimeCheckConfig(
          projectId, cl.getOptionValue(DISPLAY_NAME_OPTION.getOpt(), "new uptime check"));
      break;
    case "delete":
      deleteUptimeCheckConfig(
          projectId, cl.getOptionValue(DISPLAY_NAME_OPTION.getOpt(), "new uptime check"));
      break;
    default:
      usage(null);
  }
}
 
Example 18
Source File: StateStoreBasedWatermarkStorageCli.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@Override
public void run(String[] args) {
  Options options = new Options();
  options.addOption(HELP);
  options.addOption(ZK);
  options.addOption(JOB_NAME);
  options.addOption(ROOT_DIR);
  options.addOption(WATCH);

  CommandLine cli;
  try {
    CommandLineParser parser = new DefaultParser();
    cli = parser.parse(options, Arrays.copyOfRange(args, 1, args.length));
  } catch (ParseException pe) {
    System.out.println( "Command line parse exception: " + pe.getMessage() );
    return;
  }


  if (cli.hasOption(HELP.getOpt())) {
    printUsage(options);
    return;
  }



  TaskState taskState = new TaskState();

  String jobName;
  if (!cli.hasOption(JOB_NAME.getOpt())) {
    log.error("Need Job Name to be specified --", JOB_NAME.getLongOpt());
    throw new RuntimeException("Need Job Name to be specified");
  } else {
    jobName = cli.getOptionValue(JOB_NAME.getOpt());
    log.info("Using job name: {}", jobName);
  }
  taskState.setProp(ConfigurationKeys.JOB_NAME_KEY, jobName);


  String zkAddress = "locahost:2181";
  if (cli.hasOption(ZK.getOpt())) {
    zkAddress = cli.getOptionValue(ZK.getOpt());
  }

  log.info("Using zk address : {}", zkAddress);

  taskState.setProp(StateStoreBasedWatermarkStorage.WATERMARK_STORAGE_TYPE_KEY, "zk");
  taskState.setProp("state.store.zk.connectString", zkAddress);

  if (cli.hasOption(ROOT_DIR.getOpt())) {
    String rootDir = cli.getOptionValue(ROOT_DIR.getOpt());
    taskState.setProp(StateStoreBasedWatermarkStorage.WATERMARK_STORAGE_CONFIG_PREFIX
        + ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, rootDir);
    log.info("Setting root dir to {}", rootDir);
  } else {
    log.error("Need root directory specified");
    printUsage(options);
    return;
  }

  StateStoreBasedWatermarkStorage stateStoreBasedWatermarkStorage = new StateStoreBasedWatermarkStorage(taskState);

  final AtomicBoolean stop = new AtomicBoolean(true);

  if (cli.hasOption(WATCH.getOpt())) {
    stop.set(false);
  }
  try {


    if (!stop.get()) {
      Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
          stop.set(true);
        }
      });
    }
    do {
      boolean foundWatermark = false;
      try {
        for (CheckpointableWatermarkState wmState : stateStoreBasedWatermarkStorage.getAllCommittedWatermarks()) {
          foundWatermark = true;
          System.out.println(wmState.getProperties());
        }
      } catch (IOException ie) {
        Throwables.propagate(ie);
      }

      if (!foundWatermark) {
        System.out.println("No watermarks found.");
      }
      if (!stop.get()) {
        Thread.sleep(1000);
      }
    } while (!stop.get());
  } catch (Exception e) {
    Throwables.propagate(e);
  }
}
 
Example 19
Source File: CommandContext.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
public CommandContext(CommandLine commandLine) {
    this.commandLine = commandLine;
    this.region = commandLine.hasOption('r') ? commandLine.getOptionValue('r') : "us-east-1";
    this.host = commandLine.getOptionValue('H');
    this.port = resolvePort();
}
 
Example 20
Source File: BPRMatrixFactorizationUDTF.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Override
protected CommandLine processOptions(ObjectInspector[] argOIs) throws UDFArgumentException {
    CommandLine cl = null;

    String lossFuncName = null;
    String rankInitOpt = null;
    float maxInitValue = 1.f;
    double initStdDev = 0.1d;
    boolean conversionCheck = true;
    double convergenceRate = 0.005d;

    if (argOIs.length >= 4) {
        String rawArgs = HiveUtils.getConstString(argOIs, 3);
        cl = parseOptions(rawArgs);

        if (cl.hasOption("factor")) {
            this.factor = Primitives.parseInt(cl.getOptionValue("factor"), factor);
        } else {
            this.factor = Primitives.parseInt(cl.getOptionValue("factors"), factor);
        }
        if (cl.hasOption("iter")) {
            this.iterations = Primitives.parseInt(cl.getOptionValue("iter"), iterations);
        } else {
            this.iterations = Primitives.parseInt(cl.getOptionValue("iterations"), iterations);
        }
        if (iterations < 1) {
            throw new UDFArgumentException(
                "'-iterations' must be greater than or equals to 1: " + iterations);
        }
        lossFuncName = cl.getOptionValue("loss_function");

        float reg = Primitives.parseFloat(cl.getOptionValue("reg"), 0.0025f);
        this.regU = Primitives.parseFloat(cl.getOptionValue("reg_u"), reg);
        this.regI = Primitives.parseFloat(cl.getOptionValue("reg_i"), reg);
        this.regJ = Primitives.parseFloat(cl.getOptionValue("reg_j"), regI / 2.f);
        this.regBias = Primitives.parseFloat(cl.getOptionValue("reg_bias"), regBias);

        rankInitOpt = cl.getOptionValue("rankinit");
        maxInitValue = Primitives.parseFloat(cl.getOptionValue("max_init_value"), 1.f);
        initStdDev = Primitives.parseDouble(cl.getOptionValue("min_init_stddev"), 0.1d);

        conversionCheck = !cl.hasOption("disable_cvtest");
        convergenceRate = Primitives.parseDouble(cl.getOptionValue("cv_rate"), convergenceRate);
        this.useBiasClause = !cl.hasOption("no_bias");
    }

    this.lossFunction = LossFunction.resolve(lossFuncName);
    this.rankInit = RankInitScheme.resolve(rankInitOpt);
    rankInit.setMaxInitValue(maxInitValue);
    initStdDev = Math.max(initStdDev, 1.0d / factor);
    rankInit.setInitStdDev(initStdDev);
    this.etaEstimator = EtaEstimator.get(cl);
    this.cvState = new ConversionState(conversionCheck, convergenceRate);
    return cl;
}