func (k *KubernetesScheduler) handleTaskLost(taskStatus *mesos.TaskStatus) { log.Errorf("Task lost: '%v'", taskStatus) taskId := taskStatus.GetTaskId().GetValue() if _, exists := k.pendingTasks[taskId]; exists { delete(k.pendingTasks, taskId) } if _, exists := k.runningTasks[taskId]; exists { delete(k.runningTasks, taskId) } }
func (k *KubernetesScheduler) handleTaskRunning(taskStatus *mesos.TaskStatus) { taskId, slaveId := taskStatus.GetTaskId().GetValue(), taskStatus.GetSlaveId().GetValue() slave, exists := k.slaves[slaveId] if !exists { log.Warningf("Ignore status TASK_RUNNING because the slave does not exist\n") return } task, exists := k.pendingTasks[taskId] if !exists { log.Warningf("Ignore status TASK_RUNNING (%s) because the the task is discarded: '%v'", taskId, k.pendingTasks) return } if _, exists = k.runningTasks[taskId]; exists { log.Warningf("Ignore status TASK_RUNNING because the the task is already running") return } if containsTask(k.finishedTasks, taskId) { log.Warningf("Ignore status TASK_RUNNING because the the task is already finished") return } log.Infof("Received running status: '%v'", taskStatus) task.Pod.CurrentState.Status = api.PodRunning task.Pod.CurrentState.Manifest = task.Pod.DesiredState.Manifest task.Pod.CurrentState.Host = slave.HostName if taskStatus.Data != nil { var target api.PodInfo err := json.Unmarshal(taskStatus.Data, &target) if err == nil { task.Pod.CurrentState.Info = target } } k.runningTasks[taskId] = task slave.tasks[taskId] = task delete(k.pendingTasks, taskId) }
func (k *KubernetesScheduler) handleTaskFinished(taskStatus *mesos.TaskStatus) { taskId, slaveId := taskStatus.GetTaskId().GetValue(), taskStatus.GetSlaveId().GetValue() slave, exists := k.slaves[slaveId] if !exists { log.Warningf("Ignore status TASK_FINISHED because the slave does not exist\n") return } if _, exists := k.pendingTasks[taskId]; exists { panic("Pending task finished, this couldn't happen") } if _, exists := k.runningTasks[taskId]; exists { log.Warningf("Ignore status TASK_FINISHED because the the task is not running") return } if containsTask(k.finishedTasks, taskId) { log.Warningf("Ignore status TASK_FINISHED because the the task is already finished") return } k.finishedTasks.Next().Value = taskId delete(k.runningTasks, taskId) delete(slave.tasks, taskId) }
// StatusUpdate is called when a status update message is sent to the scheduler. func (k *KubernetesScheduler) StatusUpdate(driver mesos.SchedulerDriver, taskStatus *mesos.TaskStatus) { log.Infof("Received status update %v\n", taskStatus) k.Lock() defer k.Unlock() switch taskStatus.GetState() { case mesos.TaskState_TASK_STAGING: k.handleTaskStaging(taskStatus) case mesos.TaskState_TASK_STARTING: k.handleTaskStarting(taskStatus) case mesos.TaskState_TASK_RUNNING: k.handleTaskRunning(taskStatus) case mesos.TaskState_TASK_FINISHED: k.handleTaskFinished(taskStatus) case mesos.TaskState_TASK_FAILED: k.handleTaskFailed(taskStatus) case mesos.TaskState_TASK_KILLED: k.handleTaskKilled(taskStatus) case mesos.TaskState_TASK_LOST: k.handleTaskLost(taskStatus) } }