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());
}
}
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();
}
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();
}
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();
}
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());
}
}
Aggregations