Search in sources :

Example 1 with TaskState

use of org.apache.mesos.Protos.TaskState in project incubator-myriad by apache.

the class StatusUpdateEventHandler method onEvent.

/**
 * Encapsulates the logic to log and respond to the incoming StatusUpdateEvent per the
 * Event TaskStatus state:
 *
 * 1. TASK_STAGING: mark task as staging wtihin SchedulerState
 * 2. TASK_STARTING: mark task as staging within SchedulerState
 * 3. TASK_RUNNING: mark task as active within SchedulerState
 * 4. TASK_FINISHED: decline outstanding offers and remove task from SchedulerState
 * 5. TASK_FAILED: decline outstanding offers, remove failed, killable tasks from SchedulerState,
 *    mark as pending non-killable, failed tasks
 * 6. TASK_KILLED: decline outstanding offers, removed killed tasks from SchedulerState
 * 7. TASK_LOST: decline outstanding offers, remove killable, lost tasks from SchedulerState,
 *    mark as pending non-killable, lost tasks
 */
@Override
public void onEvent(StatusUpdateEvent event, long sequence, boolean endOfBatch) throws Exception {
    TaskStatus status = event.getStatus();
    this.schedulerState.updateTask(status);
    TaskID taskId = status.getTaskId();
    NodeTask task = schedulerState.getTask(taskId);
    if (task == null) {
        LOGGER.warn("Task: {} not found, status: {}", taskId.getValue(), status.getState());
        schedulerState.removeTask(taskId);
        return;
    }
    LOGGER.info("Status Update for task: {} | state: {}", taskId.getValue(), status.getState());
    TaskState state = status.getState();
    switch(state) {
        case TASK_STAGING:
            schedulerState.makeTaskStaging(taskId);
            break;
        case TASK_STARTING:
            schedulerState.makeTaskStaging(taskId);
            break;
        case TASK_RUNNING:
            schedulerState.makeTaskActive(taskId);
            break;
        case TASK_FINISHED:
            cleanupTask(taskId, task, "finished");
            break;
        case TASK_FAILED:
            cleanupFailedTask(taskId, task, "failed");
            break;
        case TASK_KILLED:
            cleanupTask(taskId, task, "killed");
            break;
        case TASK_LOST:
            cleanupFailedTask(taskId, task, "lost");
            break;
        default:
            LOGGER.error("Invalid state: {}", state);
            break;
    }
}
Also used : TaskID(org.apache.mesos.Protos.TaskID) TaskStatus(org.apache.mesos.Protos.TaskStatus) NodeTask(org.apache.myriad.state.NodeTask) TaskState(org.apache.mesos.Protos.TaskState)

Aggregations

TaskID (org.apache.mesos.Protos.TaskID)1 TaskState (org.apache.mesos.Protos.TaskState)1 TaskStatus (org.apache.mesos.Protos.TaskStatus)1 NodeTask (org.apache.myriad.state.NodeTask)1