Search in sources :

Example 1 with ArtifactVerificationException

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()));
}
Also used : ArtifactVerificationException(com.hubspot.singularity.executor.task.ArtifactVerificationException) TaskState(org.apache.mesos.Protos.TaskState) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 2 with ArtifactVerificationException

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

ArtifactVerificationException (com.hubspot.singularity.executor.task.ArtifactVerificationException)2 TaskState (org.apache.mesos.Protos.TaskState)2 SubmitState (com.hubspot.singularity.executor.SingularityExecutorMonitor.SubmitState)1 SingularityExecutorTask (com.hubspot.singularity.executor.task.SingularityExecutorTask)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1