Search in sources :

Example 1 with TerseFailure

use of kafka.tools.TerseFailure 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);
    }
}
Also used : Path(java.nio.file.Path) TerseFailure(kafka.tools.TerseFailure) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Path (java.nio.file.Path)1 ExecutionException (java.util.concurrent.ExecutionException)1 TerseFailure (kafka.tools.TerseFailure)1 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)1 Namespace (net.sourceforge.argparse4j.inf.Namespace)1