func (self *ResMan) Run(master string) { frameworkIdStr := FRAMEWORK_ID frameworkId := &mesos.FrameworkID{Value: &frameworkIdStr} driver := mesos.SchedulerDriver{ Master: master, Framework: mesos.FrameworkInfo{ Name: proto.String("TyrantFramework"), User: proto.String(""), FailoverTimeout: failoverTimeout, Id: frameworkId, }, Scheduler: &mesos.Scheduler{ ResourceOffers: self.OnResourceOffers, StatusUpdate: self.OnStatusUpdate, Error: self.OnError, Disconnected: self.OnDisconnected, Registered: self.OnRegister, Reregistered: self.OnReregister, }, } driver.Init() defer driver.Destroy() go self.EventLoop() driver.Start() <-self.exit log.Debug("exit") driver.Stop(false) }
func (self *ResMan) Run() { master := flag.String("master", "localhost:5050", "Location of leading Mesos master") flag.Parse() frameworkIdStr := "tyrant" frameworkId := &mesos.FrameworkID{Value: &frameworkIdStr} failoverTimeout := flag.Float64("failoverTimeout", 60, "failover timeout") driver := mesos.SchedulerDriver{ Master: *master, Framework: mesos.FrameworkInfo{ Name: proto.String("GoFramework"), User: proto.String(""), FailoverTimeout: failoverTimeout, Id: frameworkId, }, Scheduler: &mesos.Scheduler{ ResourceOffers: self.OnResourceOffers, StatusUpdate: self.OnStatusUpdate, Error: self.OnError, Disconnected: self.OnDisconnected, Registered: self.OnRegister, Reregistered: self.OnReregister, }, } driver.Init() defer driver.Destroy() go self.EventLoop() driver.Start() <-self.exit log.Debug("exit") driver.Stop(false) }
func main() { finishedLocales := 0 runningLocales := 0 taskId := 0 exit := make(chan bool) agents := make(map[string]uint64) saturated := false master := flag.String("master", "localhost:5050", "Location of leading Mesos master") namenode := flag.String("name-node", "localhost", "Location of bootstrap package and executables") locales := flag.Int("locales", 1, "Number of Chapel locales i.e. number of nodes") flag.Parse() chapel_program := flag.Args() args := len(chapel_program) if args == 0 { fmt.Println("No Chapel program found") fmt.Println("Syntax: ./chapel (<options>) <chapel-program>") os.Exit(1) } chapel_program = append(chapel_program, "-nl "+strconv.Itoa(*locales)) driver := mesos.SchedulerDriver{ Master: *master, Framework: mesos.FrameworkInfo{ Name: proto.String("Chapel: " + strings.Join(chapel_program, " ")), User: proto.String(""), }, Scheduler: &mesos.Scheduler{ ResourceOffers: func(driver *mesos.SchedulerDriver, offers []mesos.Offer) { for _, offer := range offers { if saturated { driver.DeclineOffer(offer.Id) continue } var port uint64 = 0 var cpus float64 = 0 var mem float64 = 0 for _, resource := range offer.Resources { if resource.GetName() == "cpus" { cpus = *resource.GetScalar().Value } if resource.GetName() == "mem" { mem = *resource.GetScalar().Value } if resource.GetName() == "ports" { r := (*resource).GetRanges().Range[0] port = r.GetBegin() } } agents[*offer.Hostname] = port bootstrap := *namenode + "/chapel/chapel-bootstrap.tgz" target := *namenode + "/chapel/" + chapel_program[0] + "_real" command := &mesos.CommandInfo{ Uris: []*mesos.CommandInfo_URI{ &mesos.CommandInfo_URI{Value: &bootstrap}, &mesos.CommandInfo_URI{Value: &target}, }, Value: proto.String("./bin/chapel-agent -port=" + strconv.FormatUint(port, 10)), } taskId++ tasks := []mesos.TaskInfo{ mesos.TaskInfo{ Name: proto.String("Chapel-agent"), TaskId: &mesos.TaskID{ Value: proto.String("Chapel-agent-" + strconv.Itoa(taskId)), }, SlaveId: offer.SlaveId, Command: command, Resources: []*mesos.Resource{ mesos.ScalarResource("cpus", cpus), mesos.ScalarResource("mem", mem), mesos.RangeResource("ports", port, port), }, }, } driver.LaunchTasks(offer.Id, tasks) } }, StatusUpdate: func(driver *mesos.SchedulerDriver, status mesos.TaskStatus) { if *status.State == mesos.TaskState_TASK_FINISHED { finishedLocales++ if finishedLocales >= *locales { exit <- true } } else if *status.State == mesos.TaskState_TASK_RUNNING { runningLocales++ if !saturated { fmt.Println("[", runningLocales, "/", *locales, "] Setting up locale..") if runningLocales >= *locales { saturated = true triggerAgents(chapel_program, agents) } } } else { fmt.Println("Received task status: " + mesos.TaskState_name[int32(*status.State)]) if status.Message != nil { fmt.Println("Message: " + *status.Message) } } }, }, } driver.Init() defer driver.Destroy() driver.Start() <-exit driver.Stop(false) }
func (self *ResMan) runTaskUsingOffer(driver *mesos.SchedulerDriver, offer mesos.Offer, ts []*Task) (launchCount int) { cpus, mem := extraCpuMem(offer) var tasks []mesos.TaskInfo for i := 0; i < len(ts) && cpus > 0 && mem > 512; i++ { t := ts[i] log.Debugf("Launching task: %s\n", t.Tid) job := t.job executor := &mesos.ExecutorInfo{ Command: &mesos.CommandInfo{ Value: proto.String(job.Executor + ` "` + job.ExecutorFlags + `"`), }, Name: proto.String("shell executor (Go)"), Source: proto.String("go_test"), } executorId := self.genExtorId(t.Tid) executor.ExecutorId = &mesos.ExecutorID{Value: proto.String(executorId)} log.Debug(*executor.Command.Value) urls := splitTrim(job.Uris) taskUris := make([]*mesos.CommandInfo_URI, len(urls)) for i, _ := range urls { taskUris[i] = &mesos.CommandInfo_URI{Value: &urls[i]} } executor.Command.Uris = taskUris task := mesos.TaskInfo{ Name: proto.String("go-task"), TaskId: &mesos.TaskID{ Value: proto.String(t.Tid), }, SlaveId: offer.SlaveId, Executor: executor, Resources: []*mesos.Resource{ mesos.ScalarResource("cpus", 1), mesos.ScalarResource("mem", 512), }, } tasks = append(tasks, task) t.state = taskRuning t.LastUpdate = time.Now() t.SlaveId = offer.GetSlaveId().GetValue() self.running.Add(t.Tid, t) log.Debugf("remove %+v from ready queue", t.Tid) self.ready.Del(t.Tid) cpus -= CPU_UNIT mem -= MEM_UNIT } if len(tasks) == 0 { return 0 } log.Debugf("%+v", tasks) driver.LaunchTasks(offer.Id, tasks) return len(tasks) }
func main() { taskLimit := 5 taskId := 0 exit := make(chan bool) localExecutor, _ := executorPath() master := flag.String("master", "localhost:5050", "Location of leading Mesos master") executorUri := flag.String("executor-uri", localExecutor, "URI of executor executable") flag.Parse() executor := &mesos.ExecutorInfo{ ExecutorId: &mesos.ExecutorID{Value: proto.String("default")}, Command: &mesos.CommandInfo{ Value: proto.String("./example_executor"), Uris: []*mesos.CommandInfo_URI{ &mesos.CommandInfo_URI{Value: executorUri}, }, }, Name: proto.String("Test Executor (Go)"), Source: proto.String("go_test"), } driver := mesos.SchedulerDriver{ Master: *master, Framework: mesos.FrameworkInfo{ Name: proto.String("GoFramework"), User: proto.String(""), }, Scheduler: &mesos.Scheduler{ ResourceOffers: func(driver *mesos.SchedulerDriver, offers []mesos.Offer) { for _, offer := range offers { taskId++ fmt.Printf("Launching task: %d\n", taskId) tasks := []mesos.TaskInfo{ mesos.TaskInfo{ Name: proto.String("go-task"), TaskId: &mesos.TaskID{ Value: proto.String("go-task-" + strconv.Itoa(taskId)), }, SlaveId: offer.SlaveId, Executor: executor, Resources: []*mesos.Resource{ mesos.ScalarResource("cpus", 1), mesos.ScalarResource("mem", 512), }, }, } driver.LaunchTasks(offer.Id, tasks) } }, StatusUpdate: func(driver *mesos.SchedulerDriver, status mesos.TaskStatus) { fmt.Println("Received task status: " + *status.Message) if *status.State == mesos.TaskState_TASK_FINISHED { taskLimit-- if taskLimit <= 0 { exit <- true } } }, }, } driver.Init() defer driver.Destroy() driver.Start() <-exit driver.Stop(false) }