func (ctx *RunOnceApplicationContext) StatusUpdate(driver scheduler.SchedulerDriver, status *mesos.TaskStatus) bool {
	ctx.lock.Lock()
	defer ctx.lock.Unlock()

	hostname := hostnameFromTaskID(status.GetTaskId().GetValue())
	ctx.updateTaskState(status)
	switch status.GetState() {
	case mesos.TaskState_TASK_RUNNING:
		log.Infof("Task %s received status update in state %s", status.GetTaskId().GetValue(), status.GetState().String())
	case mesos.TaskState_TASK_LOST, mesos.TaskState_TASK_FAILED, mesos.TaskState_TASK_ERROR:
		//TODO also kill all other running tasks sometime?
		ctx.StatusChan <- framework.NewApplicationRunStatus(ctx.Application, fmt.Errorf("Application %s failed to run on host %s with status %s: %s", ctx.Application.ID, hostname, status.GetState().String(), status.GetMessage()))
		return true
	case mesos.TaskState_TASK_FINISHED, mesos.TaskState_TASK_KILLED:
		if ctx.allTasksFinished() {
			ctx.StatusChan <- framework.NewApplicationRunStatus(ctx.Application, nil)
			return true
		}
	default:
		log.Warningf("Got unexpected task state %s", pretty.Status(status))
	}

	return false
}
示例#2
0
func (r *RunOnceRunner) ScheduleApplication(application *framework.Application, state framework.MesosState, cronScheduler framework.CronScheduler) (int64, <-chan *framework.ApplicationRunStatus) {
	var id int64
	if application.StartTime != "" && application.TimeSchedule != "" {
		id = r.StartWithSchedule(application, state, cronScheduler)
	}
	if application.StartTime != "" && application.TimeSchedule == "" {
		id = r.StartOnly(application, state, cronScheduler)
	}
	if application.StartTime == "" && application.TimeSchedule != "" {
		id = r.ScheduleOnly(application, state, cronScheduler)
	}

	ch := make(chan *framework.ApplicationRunStatus, 1)
	ch <- framework.NewApplicationRunStatus(application, nil)
	return id, ch
}
示例#3
0
func (r *RunOnceRunner) StageApplication(application *framework.Application, state framework.MesosState) <-chan *framework.ApplicationRunStatus {
	r.applicationLock.Lock()
	defer r.applicationLock.Unlock()

	instances := application.GetInstances(state)
	if instances == 0 {
		statusChan := make(chan *framework.ApplicationRunStatus, 1)
		statusChan <- framework.NewApplicationRunStatus(application, nil)
		return statusChan
	}

	ctx := NewRunOnceApplicationContext()
	ctx.Application = application
	ctx.InstancesLeftToRun = instances
	r.applications[application.ID] = ctx

	return ctx.StatusChan
}