![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)## 2. YarnApplicationMasterRunner 启动流程分析
*** RM首先分配一个NM的container去启动YarnApplicationMasterRunner ,接着下来我们看下是怎么做的***
首先是进入main函数里面,构造一个YarnApplicationMasterRunner对象,直接调用其Run方法。
> run方法主要步骤
- 获取当前用户的UGI及远端UGI
- 将当前用户ugi里面的token传递到远端的UGI中,用于数据和服务访问
- 在远端的UGI里面执行runApplicationMaster启动ApplicationMaster
![](?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)> runApplicationMaster主要过程,这里注释很清楚,我只捡重要的提示下
- 1) load and parse / validate all configurations
- 2) start the actor system,try to start the actor system, JobManager and JobManager actor system
- 3) Generate the configuration for the TaskManagers,这里主要是JobManager的地址,taskManager注册的超时时间,slot个数,这里还有最重要的一步是构造TaskManager的ContainerLaunchContext,这个context里面包含了启动TaskManager的启动命令,***主类是YarnTaskManager***。
- start the actors and components in this order: 1) JobManager & Archive (in non-HA case, the leader service takes this),启动JobManagerActor,这里主类是***YarnJobManager*** 2) Web Monitor (we need its port to register) 启动WEB监控页面,创建LeaderRetrievalService对象,这个主要用于启动TaskManager的时候,告诉TaskManager JobManager得akka url,用于TaskManager向JobManager进行注册。 3) Resource Master for YARN 启动YarnFlinkResourceManager Actor,这里主要用于Flink container资源的管理包括申请与释放等。 4) Process reapers for the JobManager and Resource Master
***这里主要介绍YarnApplicationMasterRunner 是如何通过YarnFlinkResourceManager去完成container的申请与启动TaskManager的,这里相对来说,比较复杂,我跟到Yarn的代码里才算整明白***