Search in sources :

Example 46 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project apache-kafka-on-k8s by banzaicloud.

the class VerifiableConsumer method argParser.

private static ArgumentParser argParser() {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("verifiable-consumer").defaultHelp(true).description("This tool consumes messages from a specific topic and emits consumer events (e.g. group rebalances, received messages, and offsets committed) as JSON objects to STDOUT.");
    parser.addArgument("--broker-list").action(store()).required(true).type(String.class).metavar("HOST1:PORT1[,HOST2:PORT2[...]]").dest("brokerList").help("Comma-separated list of Kafka brokers in the form HOST1:PORT1,HOST2:PORT2,...");
    parser.addArgument("--topic").action(store()).required(true).type(String.class).metavar("TOPIC").help("Consumes messages from this topic.");
    parser.addArgument("--group-id").action(store()).required(true).type(String.class).metavar("GROUP_ID").dest("groupId").help("The groupId shared among members of the consumer group");
    parser.addArgument("--max-messages").action(store()).required(false).type(Integer.class).setDefault(-1).metavar("MAX-MESSAGES").dest("maxMessages").help("Consume this many messages. If -1 (the default), the consumer will consume until the process is killed externally");
    parser.addArgument("--session-timeout").action(store()).required(false).setDefault(30000).type(Integer.class).metavar("TIMEOUT_MS").dest("sessionTimeout").help("Set the consumer's session timeout");
    parser.addArgument("--verbose").action(storeTrue()).type(Boolean.class).metavar("VERBOSE").help("Enable to log individual consumed records");
    parser.addArgument("--enable-autocommit").action(storeTrue()).type(Boolean.class).metavar("ENABLE-AUTOCOMMIT").dest("useAutoCommit").help("Enable offset auto-commit on consumer");
    parser.addArgument("--reset-policy").action(store()).required(false).setDefault("earliest").type(String.class).dest("resetPolicy").help("Set reset policy (must be either 'earliest', 'latest', or 'none'");
    parser.addArgument("--assignment-strategy").action(store()).required(false).setDefault(RangeAssignor.class.getName()).type(String.class).dest("assignmentStrategy").help("Set assignment strategy (e.g. " + RoundRobinAssignor.class.getName() + ")");
    parser.addArgument("--consumer.config").action(store()).required(false).type(String.class).metavar("CONFIG_FILE").help("Consumer config properties file (config options shared with command line parameters will be overridden).");
    return parser;
}
Also used : RoundRobinAssignor(org.apache.kafka.clients.consumer.RoundRobinAssignor) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser)

Example 47 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project apache-kafka-on-k8s by banzaicloud.

the class VerifiableProducer method argParser.

/**
 * Get the command-line argument parser.
 */
private static ArgumentParser argParser() {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("verifiable-producer").defaultHelp(true).description("This tool produces increasing integers to the specified topic and prints JSON metadata to stdout on each \"send\" request, making externally visible which messages have been acked and which have not.");
    parser.addArgument("--topic").action(store()).required(true).type(String.class).metavar("TOPIC").help("Produce messages to this topic.");
    parser.addArgument("--broker-list").action(store()).required(true).type(String.class).metavar("HOST1:PORT1[,HOST2:PORT2[...]]").dest("brokerList").help("Comma-separated list of Kafka brokers in the form HOST1:PORT1,HOST2:PORT2,...");
    parser.addArgument("--max-messages").action(store()).required(false).setDefault(-1).type(Integer.class).metavar("MAX-MESSAGES").dest("maxMessages").help("Produce this many messages. If -1, produce messages until the process is killed externally.");
    parser.addArgument("--throughput").action(store()).required(false).setDefault(-1).type(Integer.class).metavar("THROUGHPUT").help("If set >= 0, throttle maximum message throughput to *approximately* THROUGHPUT messages/sec.");
    parser.addArgument("--acks").action(store()).required(false).setDefault(-1).type(Integer.class).choices(0, 1, -1).metavar("ACKS").help("Acks required on each produced message. See Kafka docs on acks for details.");
    parser.addArgument("--producer.config").action(store()).required(false).type(String.class).metavar("CONFIG_FILE").help("Producer config properties file.");
    parser.addArgument("--message-create-time").action(store()).required(false).setDefault(-1).type(Integer.class).metavar("CREATETIME").dest("createTime").help("Send messages with creation time starting at the arguments value, in milliseconds since epoch");
    parser.addArgument("--value-prefix").action(store()).required(false).type(Integer.class).metavar("VALUE-PREFIX").dest("valuePrefix").help("If specified, each produced value will have this prefix with a dot separator");
    return parser;
}
Also used : ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser)

Example 48 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project apache-kafka-on-k8s by banzaicloud.

the class Agent method main.

public static void main(String[] args) throws Exception {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("trogdor-agent").defaultHelp(true).description("The Trogdor fault injection agent");
    parser.addArgument("--agent.config", "-c").action(store()).required(true).type(String.class).dest("config").metavar("CONFIG").help("The configuration file to use.");
    parser.addArgument("--node-name", "-n").action(store()).required(true).type(String.class).dest("node_name").metavar("NODE_NAME").help("The name of this node.");
    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);
        }
    }
    String configPath = res.getString("config");
    String nodeName = res.getString("node_name");
    Platform platform = Platform.Config.parse(nodeName, configPath);
    JsonRestServer restServer = new JsonRestServer(Node.Util.getTrogdorAgentPort(platform.curNode()));
    AgentRestResource resource = new AgentRestResource();
    log.info("Starting agent process.");
    final Agent agent = new Agent(platform, Scheduler.SYSTEM, restServer, resource);
    restServer.start(resource);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            log.warn("Running agent shutdown hook.");
            try {
                agent.beginShutdown();
                agent.waitForShutdown();
            } catch (Exception e) {
                log.error("Got exception while running agent shutdown hook.", e);
            }
        }
    });
    agent.waitForShutdown();
}
Also used : Platform(org.apache.kafka.trogdor.common.Platform) JsonRestServer(org.apache.kafka.trogdor.rest.JsonRestServer) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException)

Example 49 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project apache-kafka-on-k8s by banzaicloud.

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.");
    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 50 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project apache-kafka-on-k8s by banzaicloud.

the class Coordinator method main.

public static void main(String[] args) throws Exception {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("trogdor-coordinator").defaultHelp(true).description("The Trogdor fault injection coordinator");
    parser.addArgument("--coordinator.config", "-c").action(store()).required(true).type(String.class).dest("config").metavar("CONFIG").help("The configuration file to use.");
    parser.addArgument("--node-name", "-n").action(store()).required(true).type(String.class).dest("node_name").metavar("NODE_NAME").help("The name of this node.");
    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);
        }
    }
    String configPath = res.getString("config");
    String nodeName = res.getString("node_name");
    Platform platform = Platform.Config.parse(nodeName, configPath);
    JsonRestServer restServer = new JsonRestServer(Node.Util.getTrogdorCoordinatorPort(platform.curNode()));
    CoordinatorRestResource resource = new CoordinatorRestResource();
    log.info("Starting coordinator process.");
    final Coordinator coordinator = new Coordinator(platform, Scheduler.SYSTEM, restServer, resource);
    restServer.start(resource);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            log.warn("Running coordinator shutdown hook.");
            try {
                coordinator.beginShutdown(false);
                coordinator.waitForShutdown();
            } catch (Exception e) {
                log.error("Got exception while running coordinator shutdown hook.", e);
            }
        }
    });
    coordinator.waitForShutdown();
}
Also used : Platform(org.apache.kafka.trogdor.common.Platform) JsonRestServer(org.apache.kafka.trogdor.rest.JsonRestServer) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException)

Aggregations

ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)63 Namespace (net.sourceforge.argparse4j.inf.Namespace)35 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)32 MutuallyExclusiveGroup (net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup)13 Subparser (net.sourceforge.argparse4j.inf.Subparser)11 Properties (java.util.Properties)8 Before (org.junit.Before)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 IOException (java.io.IOException)5 ArgumentGroup (net.sourceforge.argparse4j.inf.ArgumentGroup)5 Path (java.nio.file.Path)4 Collections (java.util.Collections)4 ArgumentParsers (net.sourceforge.argparse4j.ArgumentParsers)4 Subparsers (net.sourceforge.argparse4j.inf.Subparsers)4 Platform (org.apache.kafka.trogdor.common.Platform)4 JsonRestServer (org.apache.kafka.trogdor.rest.JsonRestServer)4 File (java.io.File)3 Arrays (java.util.Arrays)3 Level (ch.qos.logback.classic.Level)2