func (s *rancherScheduler) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) { task := tasks.GetNextTask() if task == nil { for _, of := range offers { driver.DeclineOffer(of.Id, defaultFilter) } return } if task.RegistrationUrl == "" { tasks.AddTask(task) for _, of := range offers { driver.DeclineOffer(of.Id, defaultFilter) } return } taskBytes, err := task.Marshal() if err != nil { log.WithFields(log.Fields{ "err": err, }).Error("Error Marshalling task") for _, of := range offers { driver.DeclineOffer(of.Id, defaultFilter) } return } for _, offer := range offers { inadequate := false for _, res := range offer.GetResources() { if res.GetName() == "cpus" && *res.GetScalar().Value < taskCPUs { driver.DeclineOffer(offer.Id, defaultFilter) inadequate = true continue } if res.GetName() == "mem" && *res.GetScalar().Value < taskMem { driver.DeclineOffer(offer.Id, defaultFilter) inadequate = true continue } } if inadequate { continue } mesosTask := &mesos.TaskInfo{ TaskId: &mesos.TaskID{ Value: proto.String(task.HostUuid), }, SlaveId: offer.SlaveId, Resources: []*mesos.Resource{ mesosutil.NewScalarResource("cpus", taskCPUs), mesosutil.NewScalarResource("mem", taskMem), }, Data: taskBytes, Name: &task.Name, Executor: s.rancherExecutor, } driver.LaunchTasks([]*mesos.OfferID{offer.Id}, []*mesos.TaskInfo{mesosTask}, defaultFilter) } }
func MesosScheduleCreate(event *events.Event, apiClient *client.RancherClient) (err error) { log.WithFields(log.Fields{ "resourceId": event.ResourceId, "eventId": event.Id, }).Info("Creating Machine") task := &tasks.Task{ Id: event.Id, Name: event.ResourceId, CPU: 1, Mem: 1024, } tasks.AddTask(task) reply := newReply(event) return publishReply(reply, apiClient) }