use of org.apache.kafka.trogdor.common.Platform 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();
}
use of org.apache.kafka.trogdor.common.Platform in project kafka by apache.
the class WorkerManager method createWorker.
public KafkaFuture<String> createWorker(long workerId, String taskId, TaskSpec spec) throws Throwable {
try (ShutdownManager.Reference ref = shutdownManager.takeReference()) {
final Worker worker = stateChangeExecutor.submit(new CreateWorker(workerId, taskId, spec, time.milliseconds())).get();
if (worker.doneFuture != null) {
log.info("{}: Ignoring request to create worker {}, because there is already " + "a worker with that id.", nodeName, workerId);
return worker.doneFuture;
}
worker.doneFuture = new KafkaFutureImpl<>();
if (worker.spec.endMs() <= time.milliseconds()) {
log.info("{}: Will not run worker {} as it has expired.", nodeName, worker);
stateChangeExecutor.submit(new HandleWorkerHalting(worker, "worker expired", true));
return worker.doneFuture;
}
KafkaFutureImpl<String> haltFuture = new KafkaFutureImpl<>();
haltFuture.thenApply((KafkaFuture.BaseFunction<String, Void>) errorString -> {
if (errorString == null)
errorString = "";
if (errorString.isEmpty()) {
log.info("{}: Worker {} is halting.", nodeName, worker);
} else {
log.info("{}: Worker {} is halting with error {}", nodeName, worker, errorString);
}
stateChangeExecutor.submit(new HandleWorkerHalting(worker, errorString, false));
return null;
});
try {
worker.taskWorker.start(platform, worker.status, haltFuture);
} catch (Exception e) {
log.info("{}: Worker {} start() exception", nodeName, worker, e);
stateChangeExecutor.submit(new HandleWorkerHalting(worker, "worker.start() exception: " + Utils.stackTrace(e), true));
}
stateChangeExecutor.submit(new FinishCreatingWorker(worker));
return worker.doneFuture;
} catch (ExecutionException e) {
if (e.getCause() instanceof RequestConflictException) {
log.info("{}: request conflict while creating worker {} for task {} with spec {}.", nodeName, workerId, taskId, spec);
} else {
log.info("{}: Error creating worker {} for task {} with spec {}", nodeName, workerId, taskId, spec, e);
}
throw e.getCause();
}
}
Aggregations