Search in sources :

Example 6 with TaskID

use of org.apache.mesos.Protos.TaskID in project elastic-job by dangdangdotcom.

the class TaskExecutorTest method assertKillTask.

@Test
public void assertKillTask() {
    TaskID taskID = Protos.TaskID.newBuilder().setValue("task_id").build();
    taskExecutor.killTask(executorDriver, taskID);
    verify(executorDriver).sendStatusUpdate(Protos.TaskStatus.newBuilder().setTaskId(taskID).setState(Protos.TaskState.TASK_KILLED).build());
}
Also used : TaskID(org.apache.mesos.Protos.TaskID) Test(org.junit.Test)

Example 7 with TaskID

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

the class TaskTerminator method run.

/**
 * Encapsulates logic that retrieves the collection of killable tasks from the
 * SchedulerState object. If a task is in pending state, the task is simply
 * removed from SchedulerState. Any tasks in a running state were not successfully
 * killed by Mesos or the callback failed, so the another kill attempt is made.
 */
@Override
public void run() {
    // If there are 1..n killable tasks, proceed; otherwise, simply return
    if (CollectionUtils.isNotEmpty(schedulerState.getKillableTaskIds())) {
        /*
       * Clone the killable task collection, iterate through all tasks, and 
       * process any pending and/or non-pending tasks
       */
        Set<TaskID> killableTasks = Sets.newHashSet(schedulerState.getKillableTaskIds());
        Status driverStatus = driverManager.getDriverStatus();
        // TODO (hokiegeek2) Can the DriverManager be restarted? If not, should the ResourceManager stop?
        if (Status.DRIVER_RUNNING != driverStatus) {
            LOGGER.warn("Cannot kill tasks because Mesos Driver is not running. Status: {}", driverStatus);
            return;
        }
        for (TaskID taskIdToKill : killableTasks) {
            LOGGER.info("Received task kill request for task: {}", taskIdToKill);
            if (isPendingTask(taskIdToKill)) {
                handlePendingTask(taskIdToKill);
            } else {
                handleNonPendingTask(taskIdToKill);
            }
        }
    }
}
Also used : Status(org.apache.mesos.Protos.Status) TaskID(org.apache.mesos.Protos.TaskID)

Example 8 with TaskID

use of org.apache.mesos.Protos.TaskID 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)

Example 9 with TaskID

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

the class SchedulerStateTest method testRemoveTask.

@Test
public void testRemoveTask() throws Exception {
    SchedulerState sState = initialize();
    TaskID idOne = TaskID.newBuilder().setValue("Task1").build();
    TaskID idTwo = TaskID.newBuilder().setValue("Task2").build();
    sState.removeTask(idOne);
    assertNull(sState.getTask(idOne));
    sState.removeTask(idTwo);
    assertNull(sState.getTask(idTwo));
}
Also used : TaskID(org.apache.mesos.Protos.TaskID) Test(org.junit.Test) BaseConfigurableTest(org.apache.myriad.BaseConfigurableTest)

Example 10 with TaskID

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

the class SchedulerStateTest method testMakeTestActive.

@Test
public void testMakeTestActive() throws Exception {
    SchedulerState sState = initialize();
    TaskID idOne = TaskID.newBuilder().setValue("Task1").build();
    TaskID idTwo = TaskID.newBuilder().setValue("Task2").build();
    sState.addTask(idOne, taskOne);
    sState.addTask(idTwo, taskTwo);
    sState.makeTaskActive(idOne);
    sState.makeTaskActive(idTwo);
    assertTrue(sState.getActiveTasks().contains(taskOne));
    assertTrue(sState.getActiveTasks().contains(taskTwo));
}
Also used : TaskID(org.apache.mesos.Protos.TaskID) Test(org.junit.Test) BaseConfigurableTest(org.apache.myriad.BaseConfigurableTest)

Aggregations

TaskID (org.apache.mesos.Protos.TaskID)14 Test (org.junit.Test)8 BaseConfigurableTest (org.apache.myriad.BaseConfigurableTest)7 Protos (org.apache.mesos.Protos)2 TaskStatus (org.apache.mesos.Protos.TaskStatus)2 NodeTask (org.apache.myriad.state.NodeTask)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteString (com.google.protobuf.ByteString)1 MachineDefinition (io.mantisrx.runtime.MachineDefinition)1 ExecuteStageRequest (io.mantisrx.server.core.ExecuteStageRequest)1 LaunchTaskException (io.mantisrx.server.master.LaunchTaskException)1 ScheduleRequest (io.mantisrx.server.master.scheduler.ScheduleRequest)1 JsonProcessingException (io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Status (org.apache.mesos.Protos.Status)1 TaskInfo (org.apache.mesos.Protos.TaskInfo)1 TaskState (org.apache.mesos.Protos.TaskState)1