Search in sources :

Example 1 with JsonRestServer

use of org.apache.kafka.trogdor.rest.JsonRestServer 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 2 with JsonRestServer

use of org.apache.kafka.trogdor.rest.JsonRestServer in project apache-kafka-on-k8s by banzaicloud.

the class AgentTest method createAgent.

private Agent createAgent(Scheduler scheduler) {
    JsonRestServer restServer = new JsonRestServer(0);
    AgentRestResource resource = new AgentRestResource();
    restServer.start(resource);
    return new Agent(createBasicPlatform(scheduler), scheduler, restServer, resource);
}
Also used : JsonRestServer(org.apache.kafka.trogdor.rest.JsonRestServer)

Example 3 with JsonRestServer

use of org.apache.kafka.trogdor.rest.JsonRestServer 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)

Example 4 with JsonRestServer

use of org.apache.kafka.trogdor.rest.JsonRestServer 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();
}
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 5 with JsonRestServer

use of org.apache.kafka.trogdor.rest.JsonRestServer in project kafka by apache.

the class AgentTest method createAgent.

private Agent createAgent(Scheduler scheduler) {
    JsonRestServer restServer = new JsonRestServer(0);
    AgentRestResource resource = new AgentRestResource();
    restServer.start(resource);
    return new Agent(createBasicPlatform(scheduler), scheduler, restServer, resource);
}
Also used : JsonRestServer(org.apache.kafka.trogdor.rest.JsonRestServer)

Aggregations

JsonRestServer (org.apache.kafka.trogdor.rest.JsonRestServer)6 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)4 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)4 Namespace (net.sourceforge.argparse4j.inf.Namespace)4 Platform (org.apache.kafka.trogdor.common.Platform)4 TaskSpec (org.apache.kafka.trogdor.task.TaskSpec)1