// LaunchTask with specific offer and resources func (core *Core) LaunchTask(task *registry.Task, offer *mesosproto.Offer, offers []*mesosproto.Offer) error { core.generateResource(task) resources := resource.BuildResources(task) log.Infof("Launch task %v, on node %v", task.ID, offer.GetHostname()) taskInfo := &mesosproto.TaskInfo{} var err error if task.Type == registry.TaskTypeTest { taskInfo, err = core.CreateSingleTaskInfo(offer, resources, task) log.Debug(taskInfo) } else if task.Type == registry.TaskTypeBuild { taskInfo, err = core.CreateBuildImageTaskInfo(offer, resources, task) } else { return errors.New("Unknown task type received.") } if err != nil { return err } for _, value := range offers { if offer.GetSlaveId() == value.GetSlaveId() { if err := core.AcceptOffer(value, resources, taskInfo); err != nil { return err } core.deleteOffer(value) task.State = "TASK_STAGING" } } return nil }
// CollectResult collect result for task func (core *Core) CollectResult(job *registry.Job, task *registry.Task) { taskInstance := ®istry.Task{ Cpus: CollectCPU, Mem: CollectMem, ID: "collect-" + job.ID + "-" + task.ID, Name: job.Name, Type: registry.TaskTypeBuild, CreateTime: time.Now().UnixNano(), JobID: job.ID, State: "TASK_WAITING", SLA: registry.SLAOnePerNode, Directory: task.Directory, } err := core.AddTask(taskInstance.ID, taskInstance) job.PushTask(taskInstance) if err != nil { log.Errorf("Error when add %d result collector: %v", err) task.State = "TASK_FAILED" job.PopLastTask() } }