Mesos Master的初始化在src/master/master.cpp中

 

 

在Mesos Master的log中,是能看到这一行的。

 

1.初始化role,并设置weight权重

 

 

 

2. 初始化Allocator

 

 

注意,Allocator的initialize函数中,传入的OfferCallback是Master::offer。

 

如果前面所述,没过allocation_interval,Allocator都会计算每个framework的offer,然后依次调用Master::offer,将资源offer给相应的framework。

 

 

在Master::offer函数中,生成如下的ResourceOffersMessage,并且发送给Framework

 

  1.   // Create an offer for each slave and add it to the message.
  2.   ResourceOffersMessage message;
  3.  
  4.   Framework* framework = CHECK_NOTNULL(frameworks.registered[frameworkId]);
  5.   foreachpair (const SlaveID& slaveId, const Resources& offered, resources) {
  6. ……
  7.     Slave* slave = slaves.registered.get(slaveId);
  8.     CHECK_NOTNULL(slave);
  9. ……
  10.     // TODO(bmahler): Set "https" if only "https" is supported.
  11.     mesos::URL url;
  12.     url.set_scheme("http");
  13.     url.mutable_address()->set_hostname(slave->info.hostname());
  14.     url.mutable_address()->set_ip(stringify(slave->pid.address.ip));
  15.     url.mutable_address()->set_port(slave->pid.address.port);
  16.     url.set_path("/" + slave->pid.id);
  17.  
  18.     Offer* offer = new Offer();
  19.     offer->mutable_id()->MergeFrom(newOfferId());
  20.     offer->mutable_framework_id()->MergeFrom(framework->id());
  21.     offer->mutable_slave_id()->MergeFrom(slave->id);
  22.     offer->set_hostname(slave->info.hostname());
  23.     offer->mutable_url()->MergeFrom(url);
  24.     offer->mutable_resources()->MergeFrom(offered);
  25.     offer->mutable_attributes()->MergeFrom(slave->info.attributes());
  26.  
  27.     // Add all framework's executors running on this slave.
  28.     if (slave->executors.contains(framework->id())) {
  29.       const hashmap<ExecutorID, ExecutorInfo>& executors =
  30.         slave->executors[framework->id()];
  31.       foreachkey (const ExecutorID& executorId, executors) {
  32.         offer->add_executor_ids()->MergeFrom(executorId);
  33.       }
  34.     }
  35. ……
  36.     offers[offer->id()] = offer;
  37.  
  38.     framework->addOffer(offer);
  39.     slave->addOffer(offer);
  40.  
  41.     if (flags.offer_timeout.isSome()) {
  42.       // Rescind the offer after the timeout elapses.
  43.       offerTimers[offer->id()] =
  44.         delay(flags.offer_timeout.get(),
  45.               self(),
  46.               &Self::offerTimeout,
  47.               offer->id());
  48.     }
  49.  
  50.     // TODO(jieyu): For now, we strip 'ephemeral_ports' resource from
  51.     // offers so that frameworks do not see this resource. This is a
  52.     // short term workaround. Revisit this once we resolve MESOS-1654.
  53.     Offer offer_ = *offer;
  54.     offer_.clear_resources();
  55.  
  56.     foreach (const Resource& resource, offered) {
  57.       if (resource.name() != "ephemeral_ports") {
  58.         offer_.add_resources()->CopyFrom(resource);
  59.       }
  60.     }
  61.  
  62.     // Add the offer *AND* the corresponding slave's PID.
  63.     message.add_offers()->MergeFrom(offer_);
  64.     message.add_pids(slave->pid);
  65.   }
  66.  
  67.   if (message.offers().size() == 0) {
  68.     return;
  69.   }
  70.  
  71.   LOG(INFO) << "Sending " << message.offers().size()
  72.             << " offers to framework " << *framework;
  73.  
  74.   framework->send(message);
  75. }

 

3. 监听消息,注册处理函数

 

最后注册一些处理函数,当收到相应的消息的时候,调用相应的函数。

 

下面仅仅列举比较重要的几个函数。

 

第一个是Framework注册的时候调用的函数。

 

第二个是收到Framework发送来的运行Task的消息。

 

第三个是Slave发送来的注册时候调用的函数。

 

第四个是更新Status时候的Message

 

4. 竞争成为Master中的Leader,或者检测当前的Leader

 

Mesos源码分析(6): Mesos Master的初始化的更多相关文章

  1. Mesos源码分析(5): Mesos Master的启动之四

      5. Create an instance of allocator.   代码如下   Mesos源码中默认的Allocator,即HierarchicalDRFAllocator的位置在$ME ...

  2. Mesos源码分析(4) Mesos Master的启动之三

    3. ModuleManager::load(flags.modules.get())如果有参数--modules或者--modules_dir=dirpath,则会将路径中的so文件load进来   ...

  3. Mesos源码分析(2): Mesos Master的启动之一

    Mesos Master的启动参数如下: /usr/sbin/mesos-master --zk=zk://127.0.0.1:2181/mesos --port=5050 --log_dir=/va ...

  4. Mesos源码分析(3): Mesos Master的启动之二

    2. process::firewall::install(move(rules));如果有参数--firewall_rules则会添加规则   对应的代码如下: // Initialize fire ...

  5. Mesos源码分析(1): Mesos的启动过程总论

  6. Mesos源码分析

    Mesos源码分析(1): Mesos的启动过程总论 Mesos源码分析(2): Mesos Master的启动之一 Mesos源码分析(3): Mesos Master的启动之二 Mesos源码分析 ...

  7. Mesos源码分析(11): Mesos-Master接收到launchTasks消息

    根据Mesos源码分析(6): Mesos Master的初始化中的代码分析,当Mesos-Master接收到launchTask消息的时候,会调用Master::launchTasks函数.   v ...

  8. Mesos源码分析(10): MesosSchedulerDriver的启动及运行一个Task

      MesosSchedulerDriver的代码在src/sched/sched.cpp里面实现.     Driver->run()调用start()     首先检测Mesos-Maste ...

  9. Mesos源码分析(12): Mesos-Slave接收到RunTask消息

    在前文Mesos源码分析(8): Mesos-Slave的初始化中,Mesos-Slave接收到RunTaskMessage消息,会调用Slave::runTask.   void Slave::ru ...

随机推荐

  1. 修改Maven仓库路径

    我自己新建的地址:D:\apache-maven-3.6.0\repository 找到:localRepository,修改为自定义的位置 在IDEA里面进行配置 这样项目的maven仓库地址就修改 ...

  2. 《剑指offer》二叉树的深度

    本题来自<剑指offer> 反转链表 题目: 思路: C++ Code: Python Code: 总结:

  3. Scyther 论文相关资料整理

    1.Scyther 的特点使用方法 Scyther可以提供轨迹的简单描述,方便分析协议可能出现的攻击和表现,使用Athena算法,该软件表现如下特点: 该软件有明确的终止,能工提供无限会话协议安全性的 ...

  4. 【转载】如何直观的理解 O(logn) 时间复杂度的神奇之处

    转自 https://blog.csdn.net/u012814856/article/details/83010082 一.引言最近在极客时间上订阅了<数据结构与算法>的课程,其中王争老 ...

  5. 路漫漫其修远兮,吾将上下而求索--2019OKR规划

    一.前言 加入博客园半年多,认识了很多优秀上进,乐于分享的人,我的男神:EdisonZhou,还有张队长,叶伟民,腾飞,梁桐铭 等等. 半年来写了26篇随笔,我的第一篇随笔 C# DynamicObj ...

  6. Ubuntu16.04安装编译caffe以及一些问题记录

    前期准备: 最好是python虚拟环境 [anaconda的创建虚拟环境] 创建 conda create -n caffeEnv(虚拟环境名字) python=3.6 激活环境 source act ...

  7. get_k_data 接口文档 全新的免费行情数据接口

    get_k_data 接口文档 全新的免费行情数据接口 原创: Jimmy 挖地兔 2016-11-06 前言在tushareAPI里,曾经被用户喜欢和作为典范使用的API get_hist_data ...

  8. SQL Server 数据库中的异常信息与编号

    SQL Server 数据库中的系统表提供了强大的元数据信息,其中 dbo.sysmessages 表中存储了数据库执行命令过程中的所有消息. SELECT * FROM master.dbo.sys ...

  9. 腾讯AI开放平台的使用

    一.腾讯AI开放平台 https://ai.qq.com/ 二.腾讯AI平台支持的功能 三.签名机制 1.计算步骤 用于计算签名的参数在不同接口之间会有差异,但算法过程固定如下4个步骤. 1.将< ...

  10. linux下mysql修改字符集

    # 编辑/etc/my.cnfvim /etc/my.cnf # 在[mysqld]标签下添加下面内容default-storage-engine = innodbinnodb_file_per_ta ...