Search in sources :

Example 36 with ArgumentParserException

use of net.sourceforge.argparse4j.inf.ArgumentParserException in project kafka by apache.

the class ClientCompatibilityTest method main.

public static void main(String[] args) throws Exception {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("client-compatibility-test").defaultHelp(true).description("This tool is used to verify client compatibility guarantees.");
    parser.addArgument("--topic").action(store()).required(true).type(String.class).dest("topic").metavar("TOPIC").help("the compatibility test will produce messages to this topic");
    parser.addArgument("--bootstrap-server").action(store()).required(true).type(String.class).dest("bootstrapServer").metavar("BOOTSTRAP_SERVER").help("The server(s) to use for bootstrapping");
    parser.addArgument("--offsets-for-times-supported").action(store()).required(true).type(Boolean.class).dest("offsetsForTimesSupported").metavar("OFFSETS_FOR_TIMES_SUPPORTED").help("True if KafkaConsumer#offsetsForTimes is supported by the current broker version");
    parser.addArgument("--cluster-id-supported").action(store()).required(true).type(Boolean.class).dest("clusterIdSupported").metavar("CLUSTER_ID_SUPPORTED").help("True if cluster IDs are supported.  False if cluster ID always appears as null.");
    parser.addArgument("--expect-record-too-large-exception").action(store()).required(true).type(Boolean.class).dest("expectRecordTooLargeException").metavar("EXPECT_RECORD_TOO_LARGE_EXCEPTION").help("True if we should expect a RecordTooLargeException when trying to read from a topic " + "that contains a message that is bigger than " + ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG + ".  This is pre-KIP-74 behavior.");
    parser.addArgument("--num-cluster-nodes").action(store()).required(true).type(Integer.class).dest("numClusterNodes").metavar("NUM_CLUSTER_NODES").help("The number of cluster nodes we should expect to see from the AdminClient.");
    parser.addArgument("--create-topics-supported").action(store()).required(true).type(Boolean.class).dest("createTopicsSupported").metavar("CREATE_TOPICS_SUPPORTED").help("Whether we should be able to create topics via the AdminClient.");
    parser.addArgument("--describe-acls-supported").action(store()).required(true).type(Boolean.class).dest("describeAclsSupported").metavar("DESCRIBE_ACLS_SUPPORTED").help("Whether describeAcls is supported in the AdminClient.");
    parser.addArgument("--describe-configs-supported").action(store()).required(true).type(Boolean.class).dest("describeConfigsSupported").metavar("DESCRIBE_CONFIGS_SUPPORTED").help("Whether describeConfigs is supported in the AdminClient.");
    Namespace res = null;
    try {
        res = parser.parseArgs(args);
    } catch (ArgumentParserException e) {
        if (args.length == 0) {
            parser.printHelp();
            Exit.exit(0);
        } else {
            parser.handleError(e);
            Exit.exit(1);
        }
    }
    TestConfig testConfig = new TestConfig(res);
    ClientCompatibilityTest test = new ClientCompatibilityTest(testConfig);
    try {
        test.run();
    } catch (Throwable t) {
        System.out.printf("FAILED: Caught exception %s%n%n", t.getMessage());
        t.printStackTrace();
        Exit.exit(1);
    }
    System.out.println("SUCCESS.");
    Exit.exit(0);
}
Also used : ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace)

Example 37 with ArgumentParserException

use of net.sourceforge.argparse4j.inf.ArgumentParserException in project kafka by apache.

the class VerifiableConsumer method main.

public static void main(String[] args) {
    ArgumentParser parser = argParser();
    if (args.length == 0) {
        parser.printHelp();
        // Can't use `Exit.exit` here because it didn't exist until 0.11.0.0.
        System.exit(0);
    }
    try {
        final VerifiableConsumer consumer = createFromArgs(parser, args);
        // Can't use `Exit.addShutdownHook` here because it didn't exist until 2.5.0.
        Runtime.getRuntime().addShutdownHook(new Thread(consumer::close, "verifiable-consumer-shutdown-hook"));
        consumer.run();
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        // Can't use `Exit.exit` here because it didn't exist until 0.11.0.0.
        System.exit(1);
    }
}
Also used : ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser)

Example 38 with ArgumentParserException

use of net.sourceforge.argparse4j.inf.ArgumentParserException in project kafka by apache.

the class VerifiableProducer method createFromArgs.

/**
 * Construct a VerifiableProducer object from command-line arguments.
 */
public static VerifiableProducer createFromArgs(ArgumentParser parser, String[] args) throws ArgumentParserException {
    Namespace res = parser.parseArgs(args);
    int maxMessages = res.getInt("maxMessages");
    String topic = res.getString("topic");
    int throughput = res.getInt("throughput");
    String configFile = res.getString("producer.config");
    Integer valuePrefix = res.getInt("valuePrefix");
    Long createTime = res.getLong("createTime");
    Integer repeatingKeys = res.getInt("repeatingKeys");
    if (createTime == -1L)
        createTime = null;
    Properties producerProps = new Properties();
    if (res.get("bootstrapServer") != null) {
        producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, res.getString("bootstrapServer"));
    } else if (res.getString("brokerList") != null) {
        producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, res.getString("brokerList"));
    } else {
        parser.printHelp();
        // Can't use `Exit.exit` here because it didn't exist until 0.11.0.0.
        System.exit(0);
    }
    producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
    producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
    producerProps.put(ProducerConfig.ACKS_CONFIG, Integer.toString(res.getInt("acks")));
    // No producer retries
    producerProps.put(ProducerConfig.RETRIES_CONFIG, "0");
    if (configFile != null) {
        try {
            producerProps.putAll(loadProps(configFile));
        } catch (IOException e) {
            throw new ArgumentParserException(e.getMessage(), parser);
        }
    }
    StringSerializer serializer = new StringSerializer();
    KafkaProducer<String, String> producer = new KafkaProducer<>(producerProps, serializer, serializer);
    return new VerifiableProducer(producer, topic, throughput, maxMessages, valuePrefix, createTime, repeatingKeys);
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) IOException(java.io.IOException) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) Properties(java.util.Properties) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) Namespace(net.sourceforge.argparse4j.inf.Namespace)

Example 39 with ArgumentParserException

use of net.sourceforge.argparse4j.inf.ArgumentParserException in project kafka by apache.

the class VerifiableProducer method main.

public static void main(String[] args) {
    ArgumentParser parser = argParser();
    if (args.length == 0) {
        parser.printHelp();
        // Can't use `Exit.exit` here because it didn't exist until 0.11.0.0.
        System.exit(0);
    }
    try {
        final VerifiableProducer producer = createFromArgs(parser, args);
        final long startMs = System.currentTimeMillis();
        ThroughputThrottler throttler = new ThroughputThrottler(producer.throughput, startMs);
        // Can't use `Exit.addShutdownHook` here because it didn't exist until 2.5.0.
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            // Trigger main thread to stop producing messages
            producer.stopProducing = true;
            // Flush any remaining messages
            producer.close();
            // Print a summary
            long stopMs = System.currentTimeMillis();
            double avgThroughput = 1000 * ((producer.numAcked) / (double) (stopMs - startMs));
            producer.printJson(new ToolData(producer.numSent, producer.numAcked, producer.throughput, avgThroughput));
        }, "verifiable-producer-shutdown-hook"));
        producer.run(throttler);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        // Can't use `Exit.exit` here because it didn't exist until 0.11.0.0.
        System.exit(1);
    }
}
Also used : ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser)

Example 40 with ArgumentParserException

use of net.sourceforge.argparse4j.inf.ArgumentParserException in project claw-compiler by C2SM-RCM.

the class CLIOptions method parseArguments.

public static CLIOptions parseArguments(String[] args) throws Exception {
    ArgumentParser parser = ArgumentParsers.newFor("claw-cx2t").build().description("The CLAW Compiler is a " + "source-to-source translator working on the XcodeML intermediate representation");
    Namespace parsedArgs = null;
    try {
        parser.addArgument("input-xast-file").nargs("?").help("Input XCodeML file");
        MutuallyExclusiveGroup qOpts = parser.addMutuallyExclusiveGroup("Query options");
        qOpts.addArgument("--print-opts").action(Arguments.storeTrue()).help("Print processed cmdline options");
        qOpts.addArgument("--version").action(Arguments.storeTrue()).help("Print version");
        qOpts.addArgument("-tl", "--target-list").action(Arguments.storeTrue()).help("List all targets supported by code transformation");
        qOpts.addArgument("-dl", "--directive-list").action(Arguments.storeTrue()).help("List all directive languages supported by code generation");
        qOpts.addArgument("-sc", "--show-config").action(Arguments.storeTrue()).help("Display the current configuration");
        ArgumentGroup cOpts = parser.addArgumentGroup("Translator options");
        cOpts.addArgument("-l", "--suppress-pp-line-directives").action(Arguments.storeTrue()).help("Suppress line directive in decompiled code");
        cOpts.addArgument("-cp", "--config-path").help("Path to configuration directory");
        cOpts.addArgument("-c", "--config").help("Path to translator configuration file");
        cOpts.addArgument("-t", "--target").help("Code transformation target platform");
        cOpts.addArgument("-dir", "--directive").help("Target directive language to be used in code generation");
        cOpts.addArgument("-d", "--debug").action(Arguments.storeTrue()).help("Enable output debug message");
        cOpts.addArgument("-f", "--out-ftn-file").help("Output file for decompiled FORTRAN source");
        cOpts.addArgument("-o", "--out-xast-file").help("Output file for transformed XcodeML");
        cOpts.addArgument("-r", "--report").help("Output file for the transformation report");
        cOpts.addArgument("-M", "--mod-include-dir").nargs("*").action(Arguments.append()).help("Search directory for .xmod files");
        cOpts.addArgument("-w", "--max-fortran-line-length").type(Integer.class).help("Number of character per line in decompiled code");
        cOpts.addArgument("-fp", "--force-pure").action(Arguments.storeTrue()).help("Exit the translator if a PURE subroutine/function has to be transformed");
        cOpts.addArgument("-m", "--model-config").help("Model configuration file for SCA transformation");
        cOpts.addArgument("-x", "--override-cfg-key").nargs("*").action(Arguments.append()).help("Override configuration option. Has higher priority than base and user configuration");
        cOpts.addArgument("-ap", "--add-paren").action(Arguments.storeTrue()).help("Force backend to add parentheses around binary mathematical operations");
        cOpts.addArgument("-td", "--trans-path-dir").nargs("*").action(Arguments.append()).help("Search directory for external transformation set");
        parsedArgs = parser.parseArgs(args);
    } catch (HelpScreenException hse) {
        return null;
    } catch (ArgumentParserException ape) {
        parser.handleError(ape);
        throw ape;
    }
    CLIOptions opts = new CLIOptions(parsedArgs);
    return opts;
}
Also used : HelpScreenException(net.sourceforge.argparse4j.helper.HelpScreenException) MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace) ArgumentGroup(net.sourceforge.argparse4j.inf.ArgumentGroup)

Aggregations

ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)42 Namespace (net.sourceforge.argparse4j.inf.Namespace)34 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)30 Properties (java.util.Properties)13 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)6 MutuallyExclusiveGroup (net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup)6 ArgumentGroup (net.sourceforge.argparse4j.inf.ArgumentGroup)4 Platform (org.apache.kafka.trogdor.common.Platform)4 JsonRestServer (org.apache.kafka.trogdor.rest.JsonRestServer)4 AnnotatorService (edu.illinois.cs.cogcomp.annotation.AnnotatorService)3 File (java.io.File)3 Path (java.nio.file.Path)3 List (java.util.List)3 Random (java.util.Random)3 HelpScreenException (net.sourceforge.argparse4j.internal.HelpScreenException)3 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2