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. 笔记,ajax,事件绑定,序列化

    1. Python序列化 字符串 = json.dumps(对象) 对象->字符串 对象 = json.loads(字符串) 字符串->对象 JavaScript: 字符串 = JSON. ...

  2. 初学python之路-day09

    今天的主要内容为内存管理. 1.引用计数:垃圾回收机制的依据 # 1.变量的值被引用,该值的引用计数 +1 # 2.变量的值被解绑,该值的引用计数 -1 # 3.引用计数为0时就会被垃圾回收机制回收 ...

  3. 【玩转开源】BananaPi R2 —— 第三篇 基于Openwrt开发一个简单的路由器

    上一篇讲解了R2的网口配置,这一篇我们以BananaPi R2为例子来实现一个简单的路由器:那么一个简单的路由器应该具备什么样的功能呢?最简单的说就是wan+lan+ap这三个功能. 首先wan+la ...

  4. .Net 操作Excel表格

    一..从NuGet中,引用 Microsoft.Office.Interop.Excel类库. 方法一.先打开一个execl表然后进行保存 Application xApp = null; Workb ...

  5. jdbc crud

    最近在做一个mybatis的sql审计,所有需要原生的使用一下jdbc,基于次,复习一下自己的基础知识 github 地址: https://github.com/warriorg/nodes/tre ...

  6. 一起学爬虫——使用selenium和pyquery爬取京东商品列表

    layout: article title: 一起学爬虫--使用selenium和pyquery爬取京东商品列表 mathjax: true --- 今天一起学起使用selenium和pyquery爬 ...

  7. eclipse乱码解决

    设置utf-8 1.点击window>preferences>content types 2.点击右侧Text 3.点击Java Source File 4.下面输入UTF-8 5.点击u ...

  8. jsonp实现跨域资源共享原理

  9. python默认参数陷阱

    对于学习python的人都有这样的困惑 def foo(a=[]): a.append(5) return a Python新手希望这个函数总是返回一个只包含一个元素的列表:[5].结果却非常不同,而 ...

  10. 从BAT这种公司平薪跳槽头条,是否值得?

    有一个朋友之前就职于阿里,之前交流关于跳槽的问题,具体是这样的:阿里工作3年,拿到了头条的offer.但是非常纠结要不要接的问题.于是几个朋友聚在了一起讨论了这个问题 而且最近好多读者也在参加面试,接 ...