Search in sources :

Example 1 with MutuallyExclusiveGroup

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

the class AgentClient method main.

public static void main(String[] args) throws Exception {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("trogdor-agent-client").defaultHelp(true).description("The Trogdor fault injection agent client.");
    parser.addArgument("target").action(store()).required(true).type(String.class).dest("target").metavar("TARGET").help("A colon-separated host and port pair.  For example, example.com:8888");
    MutuallyExclusiveGroup actions = parser.addMutuallyExclusiveGroup();
    actions.addArgument("--status").action(storeTrue()).type(Boolean.class).dest("status").help("Get agent status.");
    actions.addArgument("--create-worker").action(store()).type(String.class).dest("create_worker").metavar("SPEC_JSON").help("Create a new fault.");
    actions.addArgument("--stop-worker").action(store()).type(String.class).dest("stop_worker").metavar("SPEC_JSON").help("Create a new fault.");
    actions.addArgument("--shutdown").action(storeTrue()).type(Boolean.class).dest("shutdown").help("Trigger agent shutdown");
    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 target = res.getString("target");
    AgentClient client = new Builder().maxTries(3).target(target).build();
    if (res.getBoolean("status")) {
        System.out.println("Got agent status: " + JsonUtil.toPrettyJsonString(client.status()));
    } else if (res.getString("create_worker") != null) {
        client.createWorker(JsonUtil.JSON_SERDE.readValue(res.getString("create_worker"), CreateWorkerRequest.class));
        System.out.println("Created fault.");
    } else if (res.getBoolean("shutdown")) {
        client.invokeShutdown();
        System.out.println("Sent shutdown request.");
    } else {
        System.out.println("You must choose an action. Type --help for help.");
        Exit.exit(1);
    }
}
Also used : MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace)

Example 2 with MutuallyExclusiveGroup

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

the class CoordinatorClient method main.

public static void main(String[] args) throws Exception {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("trogdor-coordinator-client").defaultHelp(true).description("The Trogdor fault injection coordinator client.");
    parser.addArgument("target").action(store()).required(true).type(String.class).dest("target").metavar("TARGET").help("A colon-separated host and port pair.  For example, example.com:8889");
    MutuallyExclusiveGroup actions = parser.addMutuallyExclusiveGroup();
    actions.addArgument("--status").action(storeTrue()).type(Boolean.class).dest("status").help("Get coordinator status.");
    actions.addArgument("--show-tasks").action(storeTrue()).type(Boolean.class).dest("show_tasks").help("Show coordinator tasks.");
    actions.addArgument("--create-task").action(store()).type(String.class).dest("create_task").metavar("TASK_SPEC_JSON").help("Create a new task from a task spec.");
    actions.addArgument("--stop-task").action(store()).type(String.class).dest("stop_task").metavar("TASK_ID").help("Stop a task.");
    actions.addArgument("--shutdown").action(storeTrue()).type(Boolean.class).dest("shutdown").help("Trigger coordinator shutdown");
    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 target = res.getString("target");
    CoordinatorClient client = new Builder().maxTries(3).target(target).build();
    if (res.getBoolean("status")) {
        System.out.println("Got coordinator status: " + JsonUtil.toPrettyJsonString(client.status()));
    } else if (res.getBoolean("show_tasks")) {
        System.out.println("Got coordinator tasks: " + JsonUtil.toPrettyJsonString(client.tasks()));
    } else if (res.getString("create_task") != null) {
        client.createTask(JsonUtil.JSON_SERDE.readValue(res.getString("create_task"), CreateTaskRequest.class));
        System.out.println("Created task.");
    } else if (res.getString("stop_task") != null) {
        client.stopTask(new StopTaskRequest(res.getString("stop_task")));
        System.out.println("Created task.");
    } else if (res.getBoolean("shutdown")) {
        client.shutdown();
        System.out.println("Sent shutdown request.");
    } else {
        System.out.println("You must choose an action. Type --help for help.");
        Exit.exit(1);
    }
}
Also used : StopTaskRequest(org.apache.kafka.trogdor.rest.StopTaskRequest) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace)

Example 3 with MutuallyExclusiveGroup

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

the class ProducerPerformance method argParser.

/**
 * Get the command-line argument parser.
 */
private static ArgumentParser argParser() {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("producer-performance").defaultHelp(true).description("This tool is used to verify the producer performance.");
    MutuallyExclusiveGroup payloadOptions = parser.addMutuallyExclusiveGroup().required(true).description("either --record-size or --payload-file must be specified but not both.");
    parser.addArgument("--topic").action(store()).required(true).type(String.class).metavar("TOPIC").help("produce messages to this topic");
    parser.addArgument("--num-records").action(store()).required(true).type(Long.class).metavar("NUM-RECORDS").dest("numRecords").help("number of messages to produce");
    payloadOptions.addArgument("--record-size").action(store()).required(false).type(Integer.class).metavar("RECORD-SIZE").dest("recordSize").help("message size in bytes. Note that you must provide exactly one of --record-size or --payload-file.");
    payloadOptions.addArgument("--payload-file").action(store()).required(false).type(String.class).metavar("PAYLOAD-FILE").dest("payloadFile").help("file to read the message payloads from. This works only for UTF-8 encoded text files. " + "Payloads will be read from this file and a payload will be randomly selected when sending messages. " + "Note that you must provide exactly one of --record-size or --payload-file.");
    parser.addArgument("--payload-delimiter").action(store()).required(false).type(String.class).metavar("PAYLOAD-DELIMITER").dest("payloadDelimiter").setDefault("\\n").help("provides delimiter to be used when --payload-file is provided. " + "Defaults to new line. " + "Note that this parameter will be ignored if --payload-file is not provided.");
    parser.addArgument("--throughput").action(store()).required(true).type(Integer.class).metavar("THROUGHPUT").help("throttle maximum message throughput to *approximately* THROUGHPUT messages/sec");
    parser.addArgument("--producer-props").nargs("+").required(false).metavar("PROP-NAME=PROP-VALUE").type(String.class).dest("producerConfig").help("kafka producer related configuration properties like bootstrap.servers,client.id etc. " + "These configs take precedence over those passed via --producer.config.");
    parser.addArgument("--producer.config").action(store()).required(false).type(String.class).metavar("CONFIG-FILE").dest("producerConfigFile").help("producer config properties file.");
    parser.addArgument("--print-metrics").action(storeTrue()).type(Boolean.class).metavar("PRINT-METRICS").dest("printMetrics").help("print out metrics at the end of the test.");
    parser.addArgument("--transactional-id").action(store()).required(false).type(String.class).metavar("TRANSACTIONAL-ID").dest("transactionalId").setDefault("performance-producer-default-transactional-id").help("The transactionalId to use if transaction-duration-ms is > 0. Useful when testing the performance of concurrent transactions.");
    parser.addArgument("--transaction-duration-ms").action(store()).required(false).type(Long.class).metavar("TRANSACTION-DURATION").dest("transactionDurationMs").setDefault(0L).help("The max age of each transaction. The commitTransaction will be called after this time has elapsed. Transactions are only enabled if this value is positive.");
    return parser;
}
Also used : MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser)

Example 4 with MutuallyExclusiveGroup

use of net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup in project java-docs-samples by GoogleCloudPlatform.

the class SynthesizeText method main.

// [END tts_synthesize_ssml]
public static void main(String... args) throws Exception {
    ArgumentParser parser = ArgumentParsers.newFor("SynthesizeFile").build().defaultHelp(true).description("Synthesize a text file or ssml file.");
    MutuallyExclusiveGroup group = parser.addMutuallyExclusiveGroup().required(true);
    group.addArgument("--text").help("The text file from which to synthesize speech.");
    group.addArgument("--ssml").help("The ssml file from which to synthesize speech.");
    try {
        Namespace namespace = parser.parseArgs(args);
        if (namespace.get("text") != null) {
            synthesizeText(namespace.getString("text"));
        } else {
            synthesizeSsml(namespace.getString("ssml"));
        }
    } catch (ArgumentParserException e) {
        parser.handleError(e);
    }
}
Also used : MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace)

Example 5 with MutuallyExclusiveGroup

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

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.");
    MutuallyExclusiveGroup connectionGroup = parser.addMutuallyExclusiveGroup("Connection Group").description("Group of arguments for connection to brokers").required(true);
    connectionGroup.addArgument("--bootstrap-server").action(store()).required(false).type(String.class).metavar("HOST1:PORT1[,HOST2:PORT2[...]]").dest("bootstrapServer").help("REQUIRED: The server(s) to connect to. Comma-separated list of Kafka brokers in the form HOST1:PORT1,HOST2:PORT2,...");
    connectionGroup.addArgument("--broker-list").action(store()).required(false).type(String.class).metavar("HOST1:PORT1[,HOST2:PORT2[...]]").dest("brokerList").help("DEPRECATED, use --bootstrap-server instead; ignored if --bootstrap-server is specified.  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(-1L).type(Long.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");
    parser.addArgument("--repeating-keys").action(store()).required(false).type(Integer.class).metavar("REPEATING-KEYS").dest("repeatingKeys").help("If specified, each produced record will have a key starting at 0 increment by 1 up to the number specified (exclusive), then the key is set to 0 again");
    return parser;
}
Also used : MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser)

Aggregations

ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)13 MutuallyExclusiveGroup (net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup)13 Namespace (net.sourceforge.argparse4j.inf.Namespace)7 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)6 ArgumentGroup (net.sourceforge.argparse4j.inf.ArgumentGroup)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 HelpScreenException (net.sourceforge.argparse4j.helper.HelpScreenException)2 CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)2 StopTaskRequest (org.apache.kafka.trogdor.rest.StopTaskRequest)2 FortranCompilerVendor (clawfc.Configuration.FortranCompilerVendor)1 Utils.sprintf (clawfc.Utils.sprintf)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ZoneOffset (java.time.ZoneOffset)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1