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. jquery +ajax 上传加预览

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. Shell常用快捷键

    编辑命令 ctr+u 删除光标到行首(unix-line-discard) ctrl+k 删除此处至末尾(kill-line) ctr+e 光标移到末尾(end) ctr+a 光标移到行首(ahead ...

  3. python的学习之路(二)

    1.字符串内置功能练习#!/usr/bin/env python# *_*coding:utf-8 *_*# Author: harsonname = 'harson'name =str('harso ...

  4. (转载)C# 枚举 FlagsAttribute用法

    这是读过几篇文章后发现整理的最完整的一篇文章 转载地址:枚举特性FlagsAttribute的用法 先看官方的解释:指示可以将枚举作为位域(即一组标志)处理. 看起来并不好理解,到底什么是作为位域处理 ...

  5. labview下载地址

    ftp://ftp.ni.com/evaluation/labview/ekit/other/downloader

  6. Windows 运行命令大全,装逼必备哦!

    以下已整理,以字母先后排序: appwiz.cpl:程序和功能 cliconfg:SQL SERVER 客户端网络实用工具 cmd:CMD命令提示符 comexp.msc或者dcomcnfg:组件服务 ...

  7. 2019年5月1日起安卓应用应基于API 26开发,那么API等级是啥?

    2019年5月1日起安卓应用应基于API 26开发,那么API等级是啥? 转 https://www.ithome.com/html/android/372234.htm   据泰尔终端实验室公众微信 ...

  8. Pytorch: cuda runtime error (59) : device-side assert triggered at /pytorch/aten/src/THC/generic/THCTensorMa

    更换了数据集, 在计算交叉熵损失时出现错误 : cuda runtime error (59) : device-side assert triggered at /pytorch/aten/src/ ...

  9. 【Vue-Cli3.0】【1】创建一个Vue-Cli3.0的项目

    最近在做爬虫,然后要爬好多数据,代码写完了,就让它在爬了.不想闲着就复习一下Vue吧! 开始开始! ***正式讲解之前 先下载一个node.js吧! 一.首先检查一下 版本 PS D:\徐孟林\D D ...

  10. [R]R包版本更迭【持续更新】

    由于R版本更迭,网上或旧的教材上的包可能没有在维护,或者被其他包替代. 做一个表记录碰到的一些替代方案.个人向,非完整指南. * mvpart 2014年之后不再更新,R 3.0版本后无法安装, 提示 ...