Search in sources :

Example 1 with SubmitState

use of com.hubspot.singularity.executor.SingularityExecutorMonitor.SubmitState 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);
    }
}
Also used : ArtifactVerificationException(com.hubspot.singularity.executor.task.ArtifactVerificationException) SingularityExecutorTask(com.hubspot.singularity.executor.task.SingularityExecutorTask) SubmitState(com.hubspot.singularity.executor.SingularityExecutorMonitor.SubmitState) TaskState(org.apache.mesos.Protos.TaskState)

Aggregations

SubmitState (com.hubspot.singularity.executor.SingularityExecutorMonitor.SubmitState)1 ArtifactVerificationException (com.hubspot.singularity.executor.task.ArtifactVerificationException)1 SingularityExecutorTask (com.hubspot.singularity.executor.task.SingularityExecutorTask)1 TaskState (org.apache.mesos.Protos.TaskState)1