hadoop 之源码 ResourceManager

hadoop

RM

/**
 * The ResourceManager is the main class that is a set of components.
 * "I am the ResourceManager. All your resources belong to us..."
 *
 */
@SuppressWarnings("unchecked")
public class ResourceManager extends CompositeService implements Recoverable {

源码中关于ResourceManager的注释只有寥寥几句。大概意思就是管理集群所有的资源。
仔细看了下ResourceManager的方法列表,瞅到一mian()方法。

public static void main(String argv[]) {
   Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler());
   StringUtils.startupShutdownMessage(ResourceManager.class, argv, LOG);
   try {
     Configuration conf = new YarnConfiguration();
     // If -format-state-store, then delete RMStateStore; else startup normally
     if (argv.length == 1 && argv[0].equals("-format-state-store")) {
       deleteRMStateStore(conf);
     } else {
       ResourceManager resourceManager = new ResourceManager();
       ShutdownHookManager.get().addShutdownHook(
         new CompositeServiceShutdownHook(resourceManager),
         SHUTDOWN_HOOK_PRIORITY);
       resourceManager.init(conf);
       resourceManager.start();
     }
   } catch (Throwable t) {
     LOG.fatal("Error starting ResourceManager", t);
     System.exit(-1);
   }
 }

这里有一关键点,ResourceManager在启动时,首先调用父类init()方法,然后调用start().
这里面有必要说明下继承关系ResourceManager 继承了 CompositeService,CompositeService继承了AbstractService抽象类。
这里使用了模板方法。AbstractService类中定义了init(),start(),stop(),close()等方法的实现,这里就不一一列举其源码的实现了。

在init方法中分别调用了 setConfig 、serviceInit 和notifyListeners三个方法。ResourceManager复写了serviceInit(Configuration conf)方法。
这个方法主要做以下几件事情;

  1. 加载core-site.xml 并 refresh SuperUserGroupsConfiguration
  2. 加载yarn-site.xml 并验证配置文件
  3. 设置HA配置
  4. 用户登录

    // Set UGI and do login
    // If security is enabled, use login user
    // If security is not enabled, use current user
    this.rmLoginUGI = UserGroupInformation.getCurrentUser();
    try {
      doSecureLogin();
    } catch(IOException ie) {
      throw new YarnRuntimeException("Failed to login", ie);
    }
  5. 各种服务的注册(来回翻了下,没有注释,实在不知道是干嘛用的)

下面看看 serviceStart()做了些什么。

protected void serviceStart() throws Exception {
  if (this.rmContext.isHAEnabled()) {
    transitionToStandby(true);
  } else {
    transitionToActive();
  }

  startWepApp();
  if (getConfig().getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER,
      false)) {
    int port = webApp.port();
    WebAppUtils.setRMWebAppPort(conf, port);
  }
  super.serviceStart();
}
  1. 首先设置下HAServiceState
/**
 * An HA service may be in active or standby state. During startup, it is in
 * an unknown INITIALIZING state. During shutdown, it is in the STOPPING state
 * and can no longer return to active/standby states.
 */
public enum HAServiceState {
  INITIALIZING("initializing"),
  ACTIVE("active"),
  STANDBY("standby"),
  STOPPING("stopping");
  1. 启动webAPP

以上就是ResourceManager启动过程。
这里插一段,hadoop中service的生命周期

/** Constructed but not initialized */
NOTINITED(0, "NOTINITED"),

/** Initialized but not started or stopped */
INITED(1, "INITED"),

/** started and not stopped */
STARTED(2, "STARTED"),

/** stopped. No further state transitions are permitted */
STOPPED(3, "STOPPED");

未完待续……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值