use of net.sourceforge.argparse4j.inf.ArgumentParser in project kafka by apache.
the class MessageGenerator method main.
public static void main(String[] args) throws Exception {
ArgumentParser parser = ArgumentParsers.newArgumentParser("message-generator").defaultHelp(true).description("The Kafka message generator");
parser.addArgument("--package", "-p").action(store()).required(true).metavar("PACKAGE").help("The java package to use in generated files.");
parser.addArgument("--output", "-o").action(store()).required(true).metavar("OUTPUT").help("The output directory to create.");
parser.addArgument("--input", "-i").action(store()).required(true).metavar("INPUT").help("The input directory to use.");
parser.addArgument("--typeclass-generators", "-t").nargs("+").action(store()).metavar("TYPECLASS_GENERATORS").help("The type class generators to use, if any.");
parser.addArgument("--message-class-generators", "-m").nargs("+").action(store()).metavar("MESSAGE_CLASS_GENERATORS").help("The message class generators to use.");
Namespace res = parser.parseArgsOrFail(args);
processDirectories(res.getString("package"), res.getString("output"), res.getString("input"), res.getList("typeclass_generators"), res.getList("message_class_generators"));
}
use of net.sourceforge.argparse4j.inf.ArgumentParser in project kafka by apache.
the class ManCommandHandler method run.
@Override
public void run(Optional<InteractiveShell> shell, PrintWriter writer, MetadataNodeManager manager) {
Commands.Type type = Commands.TYPES.get(cmd);
if (type == null) {
writer.println("man: unknown command " + cmd + ". Type help to get a list of commands.");
} else {
ArgumentParser parser = ArgumentParsers.newArgumentParser(type.name(), false);
type.addArguments(parser);
writer.printf("%s: %s%n%n", cmd, type.description());
parser.printHelp(writer);
}
}
use of net.sourceforge.argparse4j.inf.ArgumentParser in project kafka by apache.
the class MetadataShell method main.
public static void main(String[] args) throws Exception {
ArgumentParser parser = ArgumentParsers.newArgumentParser("metadata-tool").defaultHelp(true).description("The Apache Kafka metadata tool");
parser.addArgument("--snapshot", "-s").type(String.class).help("The snapshot file to read.");
parser.addArgument("command").nargs("*").help("The command to run.");
Namespace res = parser.parseArgsOrFail(args);
try {
Builder builder = new Builder();
builder.setSnapshotPath(res.getString("snapshot"));
Path tempDir = Files.createTempDirectory("MetadataShell");
Exit.addShutdownHook("agent-shutdown-hook", () -> {
log.debug("Removing temporary directory " + tempDir.toAbsolutePath().toString());
try {
Utils.delete(tempDir.toFile());
} catch (Exception e) {
log.error("Got exception while removing temporary directory " + tempDir.toAbsolutePath().toString());
}
});
MetadataShell shell = builder.build();
try {
shell.run(res.getList("command"));
} finally {
shell.close();
}
Exit.exit(0);
} catch (TerseFailure e) {
System.err.println("Error: " + e.getMessage());
Exit.exit(1);
} catch (Throwable e) {
System.err.println("Unexpected error: " + (e.getMessage() == null ? "" : e.getMessage()));
e.printStackTrace(System.err);
Exit.exit(1);
}
}
use of net.sourceforge.argparse4j.inf.ArgumentParser in project kafka by apache.
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, ThreadLocalRandom.current().nextLong(0, Long.MAX_VALUE / 2));
restServer.start(resource);
Exit.addShutdownHook("coordinator-shutdown-hook", () -> {
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();
}
use of net.sourceforge.argparse4j.inf.ArgumentParser in project kafka by apache.
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.");
parser.addArgument("--exec", "-e").action(store()).type(String.class).dest("task_spec").metavar("TASK_SPEC").help("Execute a single task spec and then exit. The argument is the task spec to load when starting up, or a path to it.");
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");
String taskSpec = res.getString("task_spec");
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);
Exit.addShutdownHook("agent-shutdown-hook", () -> {
log.warn("Running agent shutdown hook.");
try {
agent.beginShutdown();
agent.waitForShutdown();
} catch (Exception e) {
log.error("Got exception while running agent shutdown hook.", e);
}
});
if (taskSpec != null) {
TaskSpec spec = null;
try {
spec = JsonUtil.objectFromCommandLineArgument(taskSpec, TaskSpec.class);
} catch (Exception e) {
System.out.println("Unable to parse the supplied task spec.");
e.printStackTrace();
Exit.exit(1);
}
TaskSpec effectiveSpec = agent.rebaseTaskSpecTime(spec);
Exit.exit(agent.exec(effectiveSpec, System.out) ? 0 : 1);
}
agent.waitForShutdown();
}
Aggregations