<p>2.Run task</p>
<p>When received offer from Mesos,we can choose to accept it or decline.Accept the offer to run task, or decline it.</p>
<pre><code>func (s *Scheduler) ReceivedOffers(offers []*mesos.Offer) {
for _, offer := range offers {
cpus, mem, disk := OfferedResources(offer)
var tasks []*mesos.TaskInfo
for taskLaunched < tasksCount &&
cpus >= NeededCpus &&
mem >= NeededMem &&
disk >= NeededDisk {
task, err := BuildTask(offer)
if err != nil {
return fmt.Errorf("Build task failed: %s", err.Error())
}
taskInfo := BuildTaskInfo(offer, task)
tasks = append(tasks, taskInfo)
taskLaunched++
cpus -= version.Cpus
mem -= version.Mem
disk -= version.Disk
}
LaunchTasks(offer, tasks)
}
}
</code></pre>
<p>OfferedResources(offer) is used to compute the resource this offer provided,including cpu,memory and disk. BuildTaskInfo is used to build a TaskInfo structure that Mesos recognized.LaunchTasks is used to send Mesos instruction to build task. The process of LauchTasks is process of accepting Mesos offer.</p>
<pre><code>func (s *Scheduler) LaunchTasks(offer *mesos.Offer, tasks []*mesos.TaskInfo) {
logrus.Infof("Launch %d tasks with offer %s", len(tasks), *offer.GetId().Value)
call := &sched.Call{
FrameworkId: s.framework.GetId(),
Type: sched.Call_ACCEPT.Enum(),
Accept: &sched.Call_Accept{
OfferIds: []*mesos.OfferID{
offer.GetId(),
},
Operations: []*mesos.Offer_Operation{
&mesos.Offer_Operation{
Type: mesos.Offer_Operation_LAUNCH.Enum(),
Launch: &mesos.Offer_Operation_Launch{
TaskInfos: tasks,
},
},
},
Filters: &mesos.Filters{RefuseSeconds: proto.Float64(1)},
},
}
return s.send(call)
}
</code></pre>
<p>Then,if task building is seccessful, we could see this task on Mesos UI.</p>
<p>Mesos Framework:<a href="https://github.com/Dataman-Cloud/swan" rel="nofollow">https://github.com/Dataman-Cloud/swan</a></p>
<p>How to write a mesos framework (1):<a href="https://www.reddit.com/r/mesos/comments/5kdb52/how_to_write_a_mesos_framework_1/" rel="nofollow">https://www.reddit.com/r/mesos/comments/5kdb52/how_to_write_a_mesos_framework_1/</a></p>
<hr/>**评论:**<br/><br/>driusan: <pre><p>Did this get posted to the wrong sub? (Your part 1 is on a different sub..)</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传