Search in sources :

Example 1 with Platform

use of org.apache.kafka.trogdor.common.Platform in project apache-kafka-on-k8s by banzaicloud.

the class BasicPlatformTest method testCreateBasicPlatform.

@Test
public void testCreateBasicPlatform() throws Exception {
    File configFile = TestUtils.tempFile();
    try {
        try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8)) {
            writer.write("{\n");
            writer.write("  \"platform\": \"org.apache.kafka.trogdor.basic.BasicPlatform\",\n");
            writer.write("  \"nodes\": {\n");
            writer.write("    \"bob01\": {\n");
            writer.write("      \"hostname\": \"localhost\",\n");
            writer.write("      \"trogdor.agent.port\": 8888\n");
            writer.write("    },\n");
            writer.write("    \"bob02\": {\n");
            writer.write("      \"hostname\": \"localhost\",\n");
            writer.write("      \"trogdor.agent.port\": 8889\n");
            writer.write("    }\n");
            writer.write("  }\n");
            writer.write("}\n");
        }
        Platform platform = Platform.Config.parse("bob01", configFile.getPath());
        assertEquals("BasicPlatform", platform.name());
        assertEquals(2, platform.topology().nodes().size());
        assertEquals("bob01, bob02", Utils.join(platform.topology().nodes().keySet(), ", "));
    } finally {
        Files.delete(configFile.toPath());
    }
}
Also used : Platform(org.apache.kafka.trogdor.common.Platform) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Test(org.junit.Test)

Example 2 with Platform

use of org.apache.kafka.trogdor.common.Platform 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 3 with Platform

use of org.apache.kafka.trogdor.common.Platform 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 Platform

use of org.apache.kafka.trogdor.common.Platform 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 Platform

use of org.apache.kafka.trogdor.common.Platform in project kafka by apache.

the class BasicPlatformTest method testCreateBasicPlatform.

@Test
public void testCreateBasicPlatform() throws Exception {
    File configFile = TestUtils.tempFile();
    try {
        try (OutputStreamWriter writer = new OutputStreamWriter(Files.newOutputStream(configFile.toPath()), StandardCharsets.UTF_8)) {
            writer.write("{\n");
            writer.write("  \"platform\": \"org.apache.kafka.trogdor.basic.BasicPlatform\",\n");
            writer.write("  \"nodes\": {\n");
            writer.write("    \"bob01\": {\n");
            writer.write("      \"hostname\": \"localhost\",\n");
            writer.write("      \"trogdor.agent.port\": 8888\n");
            writer.write("    },\n");
            writer.write("    \"bob02\": {\n");
            writer.write("      \"hostname\": \"localhost\",\n");
            writer.write("      \"trogdor.agent.port\": 8889\n");
            writer.write("    }\n");
            writer.write("  }\n");
            writer.write("}\n");
        }
        Platform platform = Platform.Config.parse("bob01", configFile.getPath());
        assertEquals("BasicPlatform", platform.name());
        assertEquals(2, platform.topology().nodes().size());
        assertEquals("bob01, bob02", Utils.join(platform.topology().nodes().keySet(), ", "));
    } finally {
        Files.delete(configFile.toPath());
    }
}
Also used : Platform(org.apache.kafka.trogdor.common.Platform) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

Platform (org.apache.kafka.trogdor.common.Platform)7 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)4 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)4 Namespace (net.sourceforge.argparse4j.inf.Namespace)4 JsonRestServer (org.apache.kafka.trogdor.rest.JsonRestServer)4 File (java.io.File)2 OutputStreamWriter (java.io.OutputStreamWriter)2 TaskSpec (org.apache.kafka.trogdor.task.TaskSpec)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1