• 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);
    }
    
    1. 各种服务的注册(来回翻了下,没有注释,实在不知道是干嘛用的)

    下面看看 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");
    
    

    未完待续……

    用放荡不羁的心态过随遇而安的生活
  • 相关阅读:
    Android导包导致java.lang.NoClassDefFoundError
    canvas
    [java]OutOfMemoryError 原因及解决办法
    [转]加速Android Studio/Gradle构建
    本地Tomcat配置ssl 实现https访问
    机器学习中的无监督学习
    SQL 创建数据库、表以及索引
    海马玩模拟器共享文件夹导入导出图文教程
    Java-SDK-图像识别实现身份证照片获取信息
    Java中的平方
  • 原文地址:https://www.cnblogs.com/re-myself/p/5528860.html
Copyright © 2020-2023  润新知