use of com.hubspot.singularity.executor.task.ArtifactVerificationException in project Singularity by HubSpot.
the class SingularityExecutorMonitor method watchProcessBuilder.
private void watchProcessBuilder(final SingularityExecutorTask task, final ListenableFuture<ProcessBuilder> processBuildFuture) {
Futures.addCallback(processBuildFuture, new FutureCallback<ProcessBuilder>() {
private void onSuccessThrows(ProcessBuilder processBuilder) {
task.getLog().debug("Process builder finished succesfully... ");
boolean wasKilled = false;
final Lock taskLock = task.getLock();
taskLock.lock();
try {
processBuildingTasks.remove(task.getTaskId());
wasKilled = task.wasKilled();
if (!wasKilled) {
processRunningTasks.put(task.getTaskId(), submitProcessMonitor(task, processBuilder));
startCgroupWatcher(task);
}
} finally {
taskLock.unlock();
}
if (wasKilled) {
finishTask(task, TaskState.TASK_KILLED, "Task killed before service process started", Optional.<String>empty());
}
}
// these code blocks must not throw exceptions since they are executed inside an executor. (or must be caught)
@Override
public void onSuccess(ProcessBuilder processBuilder) {
try {
onSuccessThrows(processBuilder);
} catch (Throwable t) {
TaskState state = t instanceof ArtifactVerificationException ? TaskState.TASK_FAILED : TaskState.TASK_LOST;
finishTask(task, state, String.format("%s while transitioning due to: %s", state, t.getClass().getSimpleName()), Optional.of("While submitting process task"), t);
}
}
@Override
public void onFailure(Throwable t) {
TaskState state = TaskState.TASK_LOST;
String message = String.format("%s while initializing task: %s", t.getClass().getSimpleName(), t.getMessage());
try {
if (task.wasKilled()) {
state = TaskState.TASK_KILLED;
message = String.format("Task killed, caught expected %s", t.getClass().getSimpleName());
}
} finally {
finishTask(task, state, message, Optional.of("Task {} failed before starting process"), task, t);
}
}
}, getShellCommandExecutorServiceForTask(task.getTaskId()));
}
use of com.hubspot.singularity.executor.task.ArtifactVerificationException in project Singularity by HubSpot.
the class SingularityExecutor method launchTask.
/**
* Invoked when a task has been launched on this executor (initiated
* via Scheduler::launchTasks). Note that this task can be realized
* with a thread, a process, or some simple computation, however, no
* other callbacks will be invoked on this executor until this
* callback has returned.
*/
@Override
public void launchTask(final ExecutorDriver executorDriver, final Protos.TaskInfo taskInfo) {
final String taskId = taskInfo.getTaskId().getValue();
LOG.info("Asked to launch task {}", taskId);
try {
final ch.qos.logback.classic.Logger taskLog = taskBuilder.buildTaskLogger(taskId, taskInfo.getExecutor().getExecutorId().getValue());
final SingularityExecutorTask task = taskBuilder.buildTask(taskId, executorDriver, taskInfo, taskLog);
SubmitState submitState = monitor.submit(task);
switch(submitState) {
case REJECTED:
LOG.warn("Can't launch task {}, it was rejected (probably due to shutdown)", taskInfo);
break;
case TASK_ALREADY_EXISTED:
LOG.error("Can't launch task {}, already had a task with that ID", taskInfo);
break;
case SUBMITTED:
task.getLog().info("Launched task {} with data {}", taskId, task.getExecutorData());
break;
}
} catch (Throwable t) {
LOG.error("Unexpected exception starting task {}", taskId, t);
TaskState state = t instanceof ArtifactVerificationException ? TaskState.TASK_FAILED : TaskState.TASK_LOST;
executorUtils.sendStatusUpdate(executorDriver, taskInfo.getTaskId(), state, String.format("Unexpected exception while launching task %s - %s", taskId, t.getMessage()), LOG);
}
}
Aggregations