Ejemplo n.º 1
0
func (self *ResMan) handleMesosStatusUpdate(t *cmdMesosStatusUpdate) {
	status := t.status

	defer func() {
		t.wait <- struct{}{}
	}()

	taskId := status.TaskId.GetValue()
	log.Debugf("Received task %+v status: %+v", taskId, status)
	currentTask := self.running.Get(taskId)
	if currentTask == nil {
		task, err := scheduler.GetTaskByTaskId(taskId)
		if err != nil {
			return
		}
		job, err := scheduler.GetJobByName(task.JobName)
		if err != nil {
			return
		}
		currentTask = &Task{Tid: task.TaskId, job: job, SlaveId: status.SlaveId.GetValue(), state: taskRuning}
		self.running.Add(currentTask.Tid, currentTask) //add this alone task to runing queue
	}

	pwd := string(status.Data)
	if len(pwd) > 0 && len(currentTask.Pwd) == 0 {
		currentTask.Pwd = pwd
	}

	currentTask.LastUpdate = time.Now()

	switch *status.State {
	case mesos.TaskState_TASK_FINISHED:
		currentTask.job.LastSuccessTs = time.Now().Unix()
		self.removeRunningTask(taskId)
	case mesos.TaskState_TASK_FAILED, mesos.TaskState_TASK_KILLED, mesos.TaskState_TASK_LOST:
		currentTask.job.LastErrTs = time.Now().Unix()
		self.removeRunningTask(taskId)
	case mesos.TaskState_TASK_STAGING:
		//todo: update something
	case mesos.TaskState_TASK_STARTING:
		//todo:update something
	case mesos.TaskState_TASK_RUNNING:
		//todo:update something
	default:
		log.Fatalf("should never happend %+v", status.State)
	}

	persistentTask, err := scheduler.GetTaskByTaskId(taskId)
	if err != nil {
		log.Error(err)
	}

	self.saveTaskStatus(persistentTask, status, currentTask)
}
Ejemplo n.º 2
0
func (self *ResMan) handleMesosStatusUpdate(t *cmdMesosStatusUpdate) {
	status := t.status

	defer func() {
		t.wait <- struct{}{}
	}()

	pwd := string(status.Data)
	taskId := *status.TaskId
	id := *taskId.Value
	log.Debugf("Received task %+v status: %+v", id, status)
	tk := self.running.Get(id)
	if tk == nil {
		return
	}

	//todo:check database and add this task to running queue

	if len(pwd) > 0 && len(tk.Pwd) == 0 {
		tk.Pwd = pwd
	}

	tk.LastUpdate = time.Now()

	persistentTask, err := scheduler.GetTaskByTaskId(id)
	if err != nil {
		log.Error(err)
	}

	//todo: update in storage
	switch *status.State {
	case mesos.TaskState_TASK_FINISHED:
		tk.job.LastSuccessTs = time.Now().Unix()
		self.removeRunningTask(id)
	case mesos.TaskState_TASK_FAILED, mesos.TaskState_TASK_KILLED, mesos.TaskState_TASK_LOST:
		tk.job.LastErrTs = time.Now().Unix()
		self.removeRunningTask(id)
	case mesos.TaskState_TASK_STAGING:
		//todo: update something
	case mesos.TaskState_TASK_STARTING:
		//todo:update something
	case mesos.TaskState_TASK_RUNNING:
		//todo:update something
	default:
		log.Fatalf("should never happend %+v", status.State)
	}

	if persistentTask != nil {
		var url string
		if len(tk.Pwd) > 0 {
			url = fmt.Sprintf("http://%v:%v/#/slaves/%s/browse?path=%s",
				Inet_itoa(self.masterInfo.GetIp()), self.masterInfo.GetPort(), tk.SalveId, tk.Pwd)
		} else {
			url = fmt.Sprintf("http://%v:%v/#/frameworks/%s", Inet_itoa(self.masterInfo.GetIp()),
				self.masterInfo.GetPort(), self.frameworkId)
		}
		persistentTask.Status = (*status.State).String()
		if len(status.GetMessage()) > 0 {
			persistentTask.Message = status.GetMessage()
		}
		persistentTask.Url = url
		tk.job.LastStatus = persistentTask.Status
		tk.job.Save()
		persistentTask.UpdateTs = time.Now().Unix()
		persistentTask.Save()
		tk.job.SendNotify(persistentTask)
		log.Debugf("persistentTask:%+v", persistentTask)
	}
}