How to write a mesos framework (2)

xuanbao · · 383 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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 &lt; tasksCount &amp;&amp; cpus &gt;= NeededCpus &amp;&amp; mem &gt;= NeededMem &amp;&amp; disk &gt;= NeededDisk { task, err := BuildTask(offer) if err != nil { return fmt.Errorf(&#34;Build task failed: %s&#34;, 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(&#34;Launch %d tasks with offer %s&#34;, len(tasks), *offer.GetId().Value) call := &amp;sched.Call{ FrameworkId: s.framework.GetId(), Type: sched.Call_ACCEPT.Enum(), Accept: &amp;sched.Call_Accept{ OfferIds: []*mesos.OfferID{ offer.GetId(), }, Operations: []*mesos.Offer_Operation{ &amp;mesos.Offer_Operation{ Type: mesos.Offer_Operation_LAUNCH.Enum(), Launch: &amp;mesos.Offer_Operation_Launch{ TaskInfos: tasks, }, }, }, Filters: &amp;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

383 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传