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. 写一个python脚本监控在linux中的进程

    在虚拟机中安装Linux中的CentOS7系统 https://baijiahao.baidu.com/s?id=1597320700700593557&wfr=spider&for= ...

  2. Eclipse:An error has occurred. See error log for more details. java.lang.NullPointerException

    问题描述   在使用 Eclipse Clean 项目时报错:An error has occurred. See error log for more details. java.lang.Null ...

  3. web.xml 各版本的 Schema 头部声明

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "- ...

  4. P4391 [BOI2009]Radio Transmission 无线传输(KMP)

    题目描述 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. 输入输出格式 输入格式: 第一行给出字符串的长度,1 < L ≤ 1, ...

  5. Lesson 3-2 语句:循环语句

    3.2 循环语句 3.2.1 while 循环语句 --- while 语句包含:关键字while.条件.冒号.while子句(代码块). --- 执行while 循环,首先判断条件是否为真,如果为假 ...

  6. Jenkins job之间依赖关系配置(联动构建)

    使用场景: 想要在某APP打新包之后,立即执行自动化测试的job来验证该新包.比如Job A 执行完执行Job B ,如下图所示,如何建立依赖呢? 主要有两种方法: 1.配置上游依赖: 2.配置下游依 ...

  7. 题解 P5315 【头像上传】

    本题就是按照题目模拟, 只是要注意一些细节问题. 看代码注释 #include<bits/stdc++.h> using namespace std; int n,l,g,i; int m ...

  8. python3+Robot Framework+PyCharm第一个WEB UI自动化用例

    这里只是列举一个很简单的例子,简单介绍工具的使用,编写用例之前,做好WEB UI自动化的准备工作,下载好chrome驱动(这里以chrome为例,不同浏览器有对应的驱动),注意驱动和浏览器版本要对应, ...

  9. xcode升级10

    ld: library not found for -lstdc++.6 删除 libstdc++ stackoverflow Building with libstdc++ was deprecat ...

  10. pygame学习之打印文本

    import pygame from pygame.locals import * white = 255, 255, 255 blue = 0, 0, 200 pygame.init() scree ...