in genie-agent/src/main/java/com/netflix/genie/agent/cli/ExecCommand.java [89:158]
public ExitCode run() {
// Lock-free since the only other thread accessing this has not been registered yet
this.isRunning = true;
// Before execution starts, add shutdown hooks
Runtime.getRuntime().addShutdownHook(this.threadFactory.newThread(this::waitForCleanShutdown));
Runtime.getRuntime().addShutdownHook(this.threadFactory.newThread(this::handleSystemSignal));
log.info("Starting job execution");
try {
this.stateMachine.run();
} catch (final Exception e) {
log.error("Job state machine execution failed: {}", e.getMessage());
throw e;
}
final ExecutionContext executionContext = this.stateMachine.getExecutionContext();
final JobStatus finalJobStatus = executionContext.getCurrentJobStatus();
final boolean jobLaunched = executionContext.isJobLaunched();
final FatalJobExecutionException fatalException = executionContext.getExecutionAbortedFatalException();
if (fatalException != null) {
ConsoleLog.getLogger().error(
"Job execution fatal error in state {}: {}",
fatalException.getSourceState(),
fatalException.getCause().getMessage()
);
}
final ExitCode exitCode;
switch (finalJobStatus) {
case SUCCEEDED:
log.info("Job executed successfully");
exitCode = ExitCode.SUCCESS;
break;
case KILLED:
log.info("Job killed during execution");
exitCode = ExitCode.EXEC_ABORTED;
break;
case FAILED:
if (jobLaunched) {
log.info("Job execution failed");
exitCode = ExitCode.EXEC_FAIL;
} else {
log.info("Job setup failed");
exitCode = ExitCode.COMMAND_INIT_FAIL;
}
break;
case INVALID:
log.info("Job execution initialization failed");
exitCode = ExitCode.INIT_FAIL;
break;
default:
throw new RuntimeException("Unexpected final job status: " + finalJobStatus.name());
}
this.isRunningLock.lock();
try {
this.isRunning = false;
this.isRunningCondition.signalAll();
} finally {
this.isRunningLock.unlock();
}
return exitCode;
}