hadoop 之源码 ResourceManager

来源:互联网 发布:淘宝助理怎么同步手机 编辑:程序博客网 时间:2024/04/29 17:09

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 userthis.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
原创粉丝点击