Java Code Examples for org.apache.commons.cli.ParseException

The following examples show how to use org.apache.commons.cli.ParseException. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: djl   Source File: LoadModel.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException, ModelException, TranslateException {
    Options options = Arguments.getOptions();
    try {
        DefaultParser parser = new DefaultParser();
        CommandLine cmd = parser.parse(options, args, null, false);
        Arguments arguments = new Arguments(cmd);

        Classifications classifications = predict(arguments);
        logger.info("{}", classifications);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setLeftPadding(1);
        formatter.setWidth(120);
        formatter.printHelp(e.getMessage(), options);
    }
}
 
Example 2
Source Project: localization_nifi   Source File: BaseCommandLine.java    License: Apache License 2.0 6 votes vote down vote up
protected CommandLine doParse(String[] args) throws CommandLineParseException {
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption(HELP_ARG)) {
            return printUsageAndThrow(null, ExitCode.HELP);
        }
        certificateAuthorityHostname = commandLine.getOptionValue(CERTIFICATE_AUTHORITY_HOSTNAME_ARG, TlsConfig.DEFAULT_HOSTNAME);
        days = getIntValue(commandLine, DAYS_ARG, TlsConfig.DEFAULT_DAYS);
        keySize = getIntValue(commandLine, KEY_SIZE_ARG, TlsConfig.DEFAULT_KEY_SIZE);
        keyAlgorithm = commandLine.getOptionValue(KEY_ALGORITHM_ARG, TlsConfig.DEFAULT_KEY_PAIR_ALGORITHM);
        keyStoreType = commandLine.getOptionValue(KEY_STORE_TYPE_ARG, getKeyStoreTypeDefault());
        if (KeystoreType.PKCS12.toString().equalsIgnoreCase(keyStoreType)) {
            logger.info("Command line argument --" + KEY_STORE_TYPE_ARG + "=" + keyStoreType + " only applies to keystore, recommended truststore type of " + KeystoreType.JKS.toString() +
                    " unaffected.");
        }
        signingAlgorithm = commandLine.getOptionValue(SIGNING_ALGORITHM_ARG, TlsConfig.DEFAULT_SIGNING_ALGORITHM);
        differentPasswordForKeyAndKeystore = commandLine.hasOption(DIFFERENT_KEY_AND_KEYSTORE_PASSWORDS_ARG);
    } catch (ParseException e) {
        return printUsageAndThrow("Error parsing command line. (" + e.getMessage() + ")", ExitCode.ERROR_PARSING_COMMAND_LINE);
    }
    return commandLine;
}
 
Example 3
public SerialScoreParameters(String[] arguments) throws ParseException {
  super(arguments);

  if (cmd.hasOption("fileName"))
    fileName = cmd.getOptionValue("fileName");

  if (fileName.equals("stdout"))
    useStandardOutput = true;

  if (cmd.hasOption("limit"))
    limit = Integer.parseInt(cmd.getOptionValue("limit"));

  if (cmd.hasOption("offset"))
    offset = Integer.parseInt(cmd.getOptionValue("offset"));

  if (offset > -1 && limit > -1)
    limit += offset;
}
 
Example 4
Source Project: submarine   Source File: RunParameters.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void updateParameters(Parameter parametersHolder, ClientContext clientContext)
  throws ParseException,
    IOException, YarnException {
  String savedModelPath = parametersHolder.getOptionValue(
      CliConstants.SAVED_MODEL_PATH);
  this.setSavedModelPath(savedModelPath);

  List<String> envVars = getEnvVars((ParametersHolder)parametersHolder);
  this.setEnvars(envVars);

  String queue = parametersHolder.getOptionValue(
      CliConstants.QUEUE);
  this.setQueue(queue);

  String dockerImage = parametersHolder.getOptionValue(
      CliConstants.DOCKER_IMAGE);
  this.setDockerImageName(dockerImage);

  super.updateParameters(parametersHolder, clientContext);
}
 
Example 5
public MappingParameters(String[] arguments) throws ParseException {
  cmd = parser.parse(getOptions(), arguments);

  if (cmd.hasOption("withSubfieldCodelists"))
    exportSubfieldCodes = true;

  if (cmd.hasOption("withSelfDescriptiveCode"))
    exportSelfDescriptiveCodes = true;

  if (cmd.hasOption("solrFieldType"))
    solrFieldType = SolrFieldType.byCode(cmd.getOptionValue("solrFieldType"));

  if (cmd.hasOption("withFrbrFunctions"))
    exportFrbrFunctions = true;

  if (cmd.hasOption("withCompilanceLevel"))
    exportCompilanceLevel = true;
}
 
Example 6
private void readArguments() throws ParseException
{
    String[] arguments = parsedCommandLine.getArgs();
    if (arguments.length > 1)
    {
        // more than one unparsed argument (input file name) is always an error
        throw new ParseException("Unknown argument " + arguments[1]);
    }
    else if (arguments.length == 1)
    {
        // normalize slashes and backslashes
        inputFileName = new File(arguments[0]).getPath();
    }
    else
    {
        // don't fail yet - file name is not required for -h or -v
        inputFileName = null;
    }
}
 
Example 7
@Test
public void testDefaults() {
  String[] arguments = new String[]{"a-marc-file.mrc"};
  try {
    MarcToSolrParameters parameters = new MarcToSolrParameters(arguments);

    assertNotNull(parameters.getArgs());
    assertEquals(1, parameters.getArgs().length);
    assertEquals("a-marc-file.mrc", parameters.getArgs()[0]);

    assertFalse(parameters.doHelp());

    assertNull(parameters.getSolrUrl());
    assertFalse(parameters.doCommit());
    assertNotNull(parameters.getSolrFieldType());
    assertEquals(SolrFieldType.MARC, parameters.getSolrFieldType());
  } catch (ParseException e) {
    e.printStackTrace();
  }
}
 
Example 8
Source Project: submarine   Source File: RunJobCli.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int run(String[] args)
    throws ParseException, IOException, YarnException, SubmarineException {
  if (CliUtils.argsForHelp(args)) {
    printUsages();
    return 0;
  }

  parseCommandLineAndGetRunJobParameters(args);
  ApplicationId applicationId = jobSubmitter.submitJob(parametersHolder);
  LOG.info("Submarine job is submitted, the job id is " + applicationId);
  RunJobParameters parameters =
      (RunJobParameters) parametersHolder.getParameters();
  storeJobInformation(parameters, applicationId, args);
  if (parameters.isWaitJobFinish()) {
    this.jobMonitor.waitTrainingFinal(parameters.getName());
  }

  return 0;
}
 
Example 9
Source Project: zserio   Source File: ZserioTool.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void execute(String[] args) throws Exception
{
    commandLineArguments.parse(args);
    if (commandLineArguments.hasHelpOption())
    {
        commandLineArguments.printHelp();
        extensionManager.printExtensions();
    }
    else if (commandLineArguments.hasVersionOption())
    {
        ZserioToolPrinter.printMessage("version " + ZserioVersion.VERSION_STRING);
    }
    else if (commandLineArguments.getInputFileName() == null)
    {
        throw new ParseException("Missing input file name!");
    }
    else
    {
        process();
    }
}
 
Example 10
Source Project: doctorkafka   Source File: URPChecker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  Usage:  URPChecker  \
 *             -brokerstatszk    datazk001:2181/data07    \
 *             -brokerstatstopic brokerstats              \
 *             -clusterzk  m10nzk001:2181,...,m10nzk007:2181/m10n07
 */
private static CommandLine parseCommandLine(String[] args) {
  Option zookeeper = new Option(ZOOKEEPER, true, "cluster zookeeper");
  options.addOption(zookeeper);

  if (args.length < 2) {
    printUsageAndExit();
  }

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
Example 11
Source Project: Flink-CEPplus   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseEmbeddedModeClient(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(EMBEDDED_MODE_CLIENT_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			checkSessionId(line),
			checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT),
			checkUrl(line, CliOptionsParser.OPTION_DEFAULTS),
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt())
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 12
@Test
public void testJobWithoutName() throws Exception {
  RunJobCli runJobCli = new RunJobCli(getMockClientContext());
  String expectedErrorMessage =
      "--" + CliConstants.NAME + " is absent";
  String actualMessage = "";
  try {
    runJobCli.run(
        new String[]{"--framework", getFrameworkName(),
            "--docker_image", "tf-docker:1.1.0",
            "--num_workers", "0", "--verbose"});
  } catch (ParseException e) {
    actualMessage = e.getMessage();
    e.printStackTrace();
  }
  assertEquals(expectedErrorMessage, actualMessage);
}
 
Example 13
Source Project: submarine   Source File: RunJobCliParsingPyTorchTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNumPSCannotBeDefined() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  assertFalse(SubmarineLogs.isVerbose());

  expectedException.expect(ParseException.class);
  expectedException.expectMessage("cannot be defined for PyTorch jobs");
  runJobCli.run(
      new String[]{"--framework", "pytorch",
          "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
          "--input_path", "hdfs://input",
          "--checkpoint_path", "hdfs://output",
          "--num_workers", "3",
          "--worker_launch_cmd",
          "python run-job.py", "--worker_resources", "memory=2048M,vcores=2",
          "--num_ps", "2"});
}
 
Example 14
Source Project: submarine   Source File: RunJobCliParsingPyTorchTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPSResourcesCannotBeDefined() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  assertFalse(SubmarineLogs.isVerbose());

  expectedException.expect(ParseException.class);
  expectedException.expectMessage("cannot be defined for PyTorch jobs");
  runJobCli.run(
      new String[]{"--framework", "pytorch",
          "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
          "--input_path", "hdfs://input",
          "--checkpoint_path", "hdfs://output",
          "--num_workers", "3",
          "--worker_launch_cmd",
          "python run-job.py", "--worker_resources", "memory=2048M,vcores=2",
          "--ps_resources", "memory=2048M,vcores=2"});
}
 
Example 15
Source Project: amazon-mq-workshop   Source File: AmazonMqClient.java    License: Apache License 2.0 6 votes vote down vote up
private static CommandLine parseAndValidateCommandLineArguments(String[] args) throws ParseException {
    Options options = new Options();
    options.addOption("help", false, "Print the help message.");
    options.addOption("url", true, "The broker connection url.");
    options.addOption("user", true, "The user to connect to the broker.");
    options.addOption("password", true, "The password for the user.");
    options.addOption("mode", true, "Whether to act as 'sender' or 'receiver'");
    options.addOption("type", true, "Whether to use a queue or a topic.");
    options.addOption("destination", true, "The name of the queue or topic");
    options.addOption("name", true, "The name of the sender");
    options.addOption("interval", true, "The interval in msec at which messages are generated. Default 1000");
    options.addOption("notPersistent", false, "Send messages in non-persistent mode");
    options.addOption("ttl", true, "The time to live value for the message.");
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("help")) {
        printUsage(options);
    }

    if (!(cmd.hasOption("url") && cmd.hasOption("type") && cmd.hasOption("mode") && cmd.hasOption("destination"))) {
        printUsage(options);
    }

    return cmd;
}
 
Example 16
Source Project: submarine   Source File: RunJobCliParsingPyTorchTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTensorboardDockerImageCannotBeDefined() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  assertFalse(SubmarineLogs.isVerbose());

  expectedException.expect(ParseException.class);
  expectedException.expectMessage("cannot be defined for PyTorch jobs");
  runJobCli.run(
      new String[]{"--framework", "pytorch",
          "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
          "--input_path", "hdfs://input",
          "--checkpoint_path", "hdfs://output",
          "--num_workers", "3",
          "--worker_launch_cmd",
          "python run-job.py", "--worker_resources", "memory=2048M,vcores=2",
          "--tensorboard_docker_image", "TBDockerImage"});
}
 
Example 17
Source Project: quarkus   Source File: BootstrapMavenOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static Map<String, Object> parse(String[] args) {
    final CommandLine cmdLine;
    try {
        cmdLine = new CLIManager().parse(args);
    } catch (ParseException e) {
        throw new IllegalStateException("Failed to parse Maven command line arguments", e);
    }

    final Map<String, Object> map = new HashMap<>();
    put(cmdLine, map, CLIManager.ALTERNATE_USER_SETTINGS);
    put(cmdLine, map, CLIManager.ALTERNATE_GLOBAL_SETTINGS);
    put(cmdLine, map, CLIManager.ALTERNATE_POM_FILE);
    put(map, String.valueOf(CLIManager.ACTIVATE_PROFILES), cmdLine.getOptionValues(CLIManager.ACTIVATE_PROFILES));

    putBoolean(cmdLine, map, CLIManager.OFFLINE);
    putBoolean(cmdLine, map, CLIManager.SUPRESS_SNAPSHOT_UPDATES);
    putBoolean(cmdLine, map, CLIManager.UPDATE_SNAPSHOTS);
    putBoolean(cmdLine, map, CLIManager.CHECKSUM_FAILURE_POLICY);
    putBoolean(cmdLine, map, CLIManager.CHECKSUM_WARNING_POLICY);

    return map;
}
 
Example 18
Source Project: SikuliX1   Source File: CommandArgs.java    License: MIT License 6 votes vote down vote up
public CommandLine getCommandLine(String[] args) {
  CommandLineParser parser = new PosixParser();
  CommandLine cmd = null;

  boolean isUserArg = false;
  for (int i = 0; i < args.length; i++) {
    if (!isUserArg && args[i].startsWith("--")) {
      isUserArg = true;
      continue;
    }
    if (isUserArg) {
      userArgs.add(args[i]);
    } else {
      sikuliArgs.add(args[i]);
    }
  }
  try {
    cmd = parser.parse(cmdArgs, sikuliArgs.toArray(new String[]{}), true);
  } catch (ParseException exp) {
    Debug.error(exp.getMessage());
  }
  return cmd;
}
 
Example 19
Source Project: submarine   Source File: RunJobCliParsingTensorFlowTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * when only run tensorboard, input_path is not needed
 * */
@Test
public void testNoInputPathOptionButOnlyRunTensorboard() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  boolean success = true;
  try {
    runJobCli.run(
        new String[]{"--framework", "tensorflow",
            "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
            "--num_workers", "0", "--tensorboard", "--verbose",
            "--tensorboard_resources", "memory=2G,vcores=2",
            "--tensorboard_docker_image", "tb_docker_image:001"});
  } catch (ParseException e) {
    success = false;
  }
  assertTrue(success);
}
 
Example 20
Source Project: submarine   Source File: RunJobCliParsingTensorFlowTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSchedulerDockerImageCannotBeDefined() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  assertFalse(SubmarineLogs.isVerbose());

  expectedException.expect(ParseException.class);
  expectedException.expectMessage("cannot be defined for TensorFlow jobs");
  runJobCli.run(
      new String[] {"--framework", "tensorflow",
          "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
          "--input_path", "hdfs://input", "--checkpoint_path", "hdfs://output",
          "--num_workers", "1", "--worker_launch_cmd", "python run-job.py",
          "--worker_resources", "memory=4g,vcores=2", "--tensorboard", "true",
          "--verbose", "--wait_job_finish",
          "--scheduler_docker_image", "schedulerDockerImage"});
}
 
Example 21
Source Project: LibScout   Source File: LibScoutConfig.java    License: Apache License 2.0 6 votes vote down vote up
private static void parseConfig(String key, Object value) throws ParseException {
    try {
        //logger.debug("Parse config key : " + key + "   value: " + value);

        if ("logging.log4j_config_file".equals(key)) {
            File f = checkIfValidFile((String) value);
            log4jConfigFileName = f.getAbsolutePath();

        } else if ("sdk.android_sdk_jar".equals(key)) {
            if (pathToAndroidJar == null)  // CLI takes precedence
                pathToAndroidJar = checkIfValidFile((String) value);

        } else if ("packageTree.ascii_rendering".equals(key)) {
            PckgTree.useAsciiRendering = (Boolean) value;

        } else if ("reporting.show_comments".equals(key)) {
            Reporting.showComments = (Boolean) value;

        } else
            logger.warn("Found unknown config key: " + key);

    } catch (ParseException e) {
       throw new ParseException("Could not parse config option " + key + " : " + e.getMessage());
    }
}
 
Example 22
Source Project: doctorkafka   Source File: ReplicaStatsRetriever.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  Usage:  ReplicaStatsRetriever  \
 *             -brokerstatszk    datazk001:2181/data07    \
 *             -brokerstatstopic brokerstats              \
 *             -clusterzk  m10nzk001:2181,...,m10nzk007:2181/m10n07 \
 *             -seconds 43200
 */
private static CommandLine parseCommandLine(String[] args) {
  Option config = new Option(CONFIG, true, "operator config");
  Option brokerStatsZookeeper =
      new Option(BROKERSTATS_ZOOKEEPER, true, "zookeeper for brokerstats topic");
  Option brokerStatsTopic = new Option(BROKERSTATS_TOPIC, true, "topic for brokerstats");
  Option clusterZookeeper = new Option(CLUSTER_ZOOKEEPER, true, "cluster zookeeper");
  Option seconds = new Option(SECONDS, true, "examined time window in seconds");
  options.addOption(config).addOption(brokerStatsZookeeper).addOption(brokerStatsTopic)
      .addOption(clusterZookeeper).addOption(seconds);

  if (args.length < 6) {
    printUsageAndExit();
  }

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
Example 23
Source Project: rocketmq   Source File: ServerUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static CommandLine parseCmdLine(final String appName, String[] args, Options options,
    CommandLineParser parser) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp(appName, options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp(appName, options, true);
    }

    return commandLine;
}
 
Example 24
@Test
public void testDefaults() {
  String[] arguments = new String[]{"a-marc-file.mrc"};
  try {
    ValidatorParameters parameters = new ValidatorParameters(arguments);

    assertNotNull(parameters.getArgs());
    assertEquals(1, parameters.getArgs().length);
    assertEquals("a-marc-file.mrc", parameters.getArgs()[0]);

    assertFalse(parameters.doHelp());

    assertNotNull(parameters.getDetailsFileName());
    assertEquals("validation-report.txt", parameters.getDetailsFileName());
    assertFalse(parameters.useStandardOutput());

    assertEquals(-1, parameters.getLimit());
    assertEquals(-1, parameters.getOffset());

    assertFalse(parameters.doSummary());

    assertEquals(ValidationErrorFormat.TEXT, parameters.getFormat());
  } catch (ParseException e) {
    e.printStackTrace();
  }
}
 
Example 25
@Test
public void withoutWriterCode() throws ParseException
{
    String[] args = { "-withoutWriterCode" };
    CommandLineArguments parsedArgs = parse(args);
    assertFalse(parsedArgs.getWithWriterCode());
    assertFalse(parsedArgs.getWithPubsubCode()); // auto-disabled
    assertFalse(parsedArgs.getWithServiceCode()); // auto-disabled
}
 
Example 26
@Test
public void withValidationCode() throws ParseException
{
    String[] args = { "-withValidationCode" };
    CommandLineArguments parsedArgs = parse(args);
    assertTrue(parsedArgs.getWithValidationCode());
}
 
Example 27
Source Project: localization_nifi   Source File: SiteToSiteCliMainTest.java    License: Apache License 2.0 5 votes vote down vote up
private void parseAndCheckExpected(String[] args) throws ParseException {
    SiteToSiteCliMain.CliParse cliParse = SiteToSiteCliMain.parseCli(new Options(), args);
    SiteToSiteClient.Builder builder = cliParse.getBuilder();
    assertEquals(expectedUrl, builder.getUrl());
    assertEquals(expectedSiteToSiteTransportProtocol, builder.getTransportProtocol());
    assertEquals(expectedPortName, builder.getPortName());
    assertEquals(expectedPortIdentifier, builder.getPortIdentifier());
    assertEquals(expectedTimeoutNs, builder.getTimeout(TimeUnit.NANOSECONDS));
    assertEquals(expectedPenalizationNs, builder.getPenalizationPeriod(TimeUnit.NANOSECONDS));
    assertEquals(expectedKeystoreFilename, builder.getKeystoreFilename());
    assertEquals(expectedKeystorePass, builder.getKeystorePass());
    assertEquals(expectedKeystoreType, builder.getKeystoreType());
    assertEquals(expectedTruststoreFilename, builder.getTruststoreFilename());
    assertEquals(expectedTruststorePass, builder.getTruststorePass());
    assertEquals(expectedTruststoreType, builder.getTruststoreType());
    assertEquals(expectedCompression, builder.isUseCompression());
    assertEquals(expectedPeerPersistenceFile, builder.getPeerPersistenceFile());
    if (expectedHttpProxy == null) {
        assertNull(builder.getHttpProxy());
    } else {
        HttpProxy httpProxy = builder.getHttpProxy();
        assertNotNull(httpProxy);
        assertEquals(expectedHttpProxy.getHttpHost(), httpProxy.getHttpHost());
        assertEquals(expectedHttpProxy.getUsername(), httpProxy.getUsername());
        assertEquals(expectedHttpProxy.getPassword(), httpProxy.getPassword());
    }
    SiteToSiteClientConfig siteToSiteClientConfig = builder.buildConfig();
    assertEquals(expectedBatchCount, siteToSiteClientConfig.getPreferredBatchCount());
    assertEquals(expectedBatchDuration, siteToSiteClientConfig.getPreferredBatchDuration(TimeUnit.NANOSECONDS));
    assertEquals(expectedBatchSize, siteToSiteClientConfig.getPreferredBatchSize());
    assertEquals(expectedTransferDirection, cliParse.getTransferDirection());
}
 
Example 28
Source Project: metanome-algorithms   Source File: CLIParserBenchmarker.java    License: Apache License 2.0 5 votes vote down vote up
public THashMap<String, String> parse(String[] input) {
	THashMap<String, String> result = new THashMap<>();
	try {
		CommandLine cmdLine = this.parse(this.getOptions(), input);
		for (Option option : cmdLine.getOptions()) {
			result.put(option.getOpt(), option.getValue());
		}
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return result;
}
 
Example 29
Source Project: submarine   Source File: TensorFlowRunJobParameters.java    License: Apache License 2.0 5 votes vote down vote up
private boolean determineIfDistributed(int nWorkers, int nPS)
    throws ParseException {
  // Check #workers and #ps.
  // When distributed training is required
  if (nWorkers >= 2 && nPS > 0) {
    return true;
  } else if (nWorkers <= 1 && nPS > 0) {
    throw new ParseException("Only specified one worker but non-zero PS, "
        + "please double check.");
  }
  return false;
}
 
Example 30
Source Project: djl   Source File: TrainPikachuTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDetection()
        throws IOException, MalformedModelException, TranslateException, ParseException {
    // this is nightly test
    if (!Boolean.getBoolean("nightly")) {
        throw new SkipException("Nightly only");
    }
    String[] args;
    float expectedLoss = 0;
    int expectedMinNumber = 0;
    int expectedMaxNumber = 0;
    if (Device.getGpuCount() > 0) {
        args = new String[] {"-e", "20", "-b", "32", "-g", "1"};
        expectedLoss = 2.5e-3f;
        expectedMaxNumber = 15;
        expectedMinNumber = 6;
    } else {
        // test train 1 epoch and predict workflow works on CPU
        args = new String[] {"-e", "1", "-m", "1", "-b", "32"};
    }
    // test train
    TrainingResult result = TrainPikachu.runExample(args);

    if (expectedLoss > 0) {
        Assert.assertTrue(result.getValidateLoss() < expectedLoss);
    }

    // test predict
    int numberOfPikachus =
            TrainPikachu.predict("build/model", "src/test/resources/pikachu.jpg");
    if (expectedMinNumber > 0) {
        Assert.assertTrue(numberOfPikachus >= expectedMinNumber);
        Assert.assertTrue(numberOfPikachus <= expectedMaxNumber);
    }
}