概述
ResourceManager是一系列組件的集合。它會加載core-site.xml和yarn-site.xml,同時創建yarn scheduler、RMAppManager等一系列組件。
創建yarn scheduler
獲取yarn.resourcemanager.scheduler.class配置項,默認是CapacityScheduler
public static final String RM_SCHEDULER = "yarn.resourcemanager.scheduler.class";
public static final String DEFAULT_RM_SCHEDULER = "org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler";
protected ResourceScheduler createScheduler() {
//獲取yarn.resourcemanager.scheduler.class配置項,默認是CapacityScheduler
String schedulerClassName = conf.get(YarnConfiguration.RM_SCHEDULER,
YarnConfiguration.DEFAULT_RM_SCHEDULER);
LOG.info("Using Scheduler: " + schedulerClassName);
try {
Class<?> schedulerClazz = Class.forName(schedulerClassName);
if (ResourceScheduler.class.isAssignableFrom(schedulerClazz)) {
return (ResourceScheduler) ReflectionUtils.newInstance(schedulerClazz,
this.conf);
} else {
throw new YarnRuntimeException("Class: " + schedulerClassName
+ " not instance of " + ResourceScheduler.class.getCanonicalName());
}
} catch (ClassNotFoundException e) {
throw new YarnRuntimeException("Could not instantiate Scheduler: "
+ schedulerClassName, e);
}
}
Application管理模塊
protected RMAppManager createRMAppManager() {
return new RMAppManager(this.rmContext, this.scheduler, this.masterService,
this.applicationACLsManager, this.conf);
}
ApplicationMaster管理模塊
創建ApplicationMasterService
protected ApplicationMasterService createApplicationMasterService() {
Configuration config = this.rmContext.getYarnConfiguration();
if (isOpportunisticSchedulingEnabled(conf)) {
if (YarnConfiguration.isDistSchedulingEnabled(config) &&
!YarnConfiguration
.isOpportunisticContainerAllocationEnabled(config)) {
throw new YarnRuntimeException(
"Invalid parameters: opportunistic container allocation has to " +
"be enabled when distributed scheduling is enabled.");
}
OpportunisticContainerAllocatorAMService
oppContainerAllocatingAMService =
new OpportunisticContainerAllocatorAMService(this.rmContext,
scheduler);
this.rmContext.setContainerQueueLimitCalculator(
oppContainerAllocatingAMService.getNodeManagerQueueLimitCalculator());
return oppContainerAllocatingAMService;
}
return new ApplicationMasterService(this.rmContext, scheduler);
}
ApplicationMasterLauncher
protected ApplicationMasterLauncher createAMLauncher() {
return new ApplicationMasterLauncher(this.rmContext);
}
NodeManager管理模塊
protected ResourceTrackerService createResourceTrackerService() {
return new ResourceTrackerService(this.rmContext, this.nodesListManager,
this.nmLivelinessMonitor,
this.rmContext.getContainerTokenSecretManager(),
this.rmContext.getNMTokenSecretManager());
}
用戶管理模塊
創建AdminService
protected AdminService createAdminService() {
return new AdminService(this);
}
創建ClientRMService
protected ClientRMService createClientRMService() {
return new ClientRMService(this.rmContext, scheduler, this.rmAppManager,
this.applicationACLsManager, this.queueACLsManager,
this.rmContext.getRMDelegationTokenSecretManager());
}
ResourceManager的交互協議
-
ResourceTracker
NodeManager通過該協議向ResourceManager中註冊、彙報節點健康情況以及Container的運行狀態,並且領取ResourceManager下達的重新初始化、清理Container等命令。NodeManager和ResourceManager這種RPC通信採用了和MRv1類似的“pull模型”(ResourceManager充當RPC server角色,NodeManager充當RPC client角色),NodeManager週期性主動地向ResourceManager發起請求,並且領取下達給自己的命令。
-
ApplicationMasterProtocol
應用程序的ApplicationMaster同過該協議向ResourceManager註冊、申請和釋放資源。該協議和上面協議同樣也是採用了“pull模型”,其中在RPC機制中,ApplicationMaster充當RPC client角色,ResourceManager充當RPC server角色。
-
ApplicationClientProtocol
-
客戶端通過該協議向ResourceManager提交應用程序、控制應用程序(如殺死job)以及查詢應用程序的運行狀態等。在該RPC 協議中應用程序客戶端充當RPC client角色,ResourceManager充當RPC server角色。
整理一下ResourceManager與NodeManager、ApplicationMaster和客戶端RPC協議交互的信息:
上圖中的ResourceTrackeServer、ApplicationMasterService 、ClientRMServer是ResourceManager中處理上述功能的組件。