赞
踩
本文将通过DEBUG的方式进行源码跟踪,
探查YARN客户端与ResourceManager之间简单的交互过程,
以yarnClient.getAllQueues()获取YARN集群所有队列信息为例进行演示。
Hadoop版本3.2.1
DEBUG环境:IntelliJ IDEA
这里直接调用YarnClient的静态方法createYarnClient()
创建一个YarnClient实例new YarnClientImpl();。
yarnClient.init(conf)初始化主要是设置配置参数(处理配置文件)和通知监听器(服务状态变更),其中初始化会调用serviceInit(config)【详见YarnClientImpl中具体实现】。
yarnClient.start()首先判断如果已经处于已启动状态则直接返回,否则给stateChangeLock加上synchronized锁,然后调用serviceStart()
【详见YarnClientImpl中具体实现,在serviceStart方法中首先会去初始化rmClient,过程涉及多个Proxy和Handler,
底层会用到Java的java.lang.reflect.Proxy#newProxyInstance;
另外重点:初始化rmClient的过程中,
在RMProxy#newProxyInstance方法中有这样两行行代码
- T proxy = instance.getProxy(conf, protocol, rmAddress);
- return (T) RetryProxy.create(protocol, proxy, retryPolicy);
会去初始化ApplicationClientProtocolPBClientImpl对象并返回,所以从
yarnClient.getAllQueues()从ResourceManager获取YARN集群所有队列信息,从此处DEBUG下去。
ApplicationClientProtocolPBServiceImpl见名知意,这是ResourceManager服务端实现的。
- package yarn.client.test;
-
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.yarn.api.records.QueueInfo;
- import org.apache.hadoop.yarn.client.api.YarnClient;
- import org.junit.Test;
-
- import java.util.List;
-
- public class MyTestYarnClient {
-
- @Test
- public void testYarnClientVisitRM() throws Exception {
- YarnClient yarnClient = YarnClient.createYarnClient();
- Configuration conf = new Configuration();
- yarnClient.init(conf);
- yarnClient.start();
-
- List<QueueInfo> queueInfos = yarnClient.getAllQueues();
- System.out.println(queueInfos);
- }
-
- }
配置ResourceManager启动设置
启动ResourceManager
正式进入ResourceManager
- [queueName: "default" capacity: 1.0 maximumCapacity: 1.0 currentCapacity: 0.0 state: Q_RUNNING accessibleNodeLabels: "*" queueStatistics { numAppsSubmitted: 0 numAppsRunning: 0 numAppsPending: 0 numAppsCompleted: 0 numAppsKilled: 0 numAppsFailed: 0 numActiveUsers: 0 availableMemoryMB: 0 allocatedMemoryMB: 0 pendingMemoryMB: 0 reservedMemoryMB: 0 availableVCores: 0 allocatedVCores: 0 pendingVCores: 0 reservedVCores: 0 allocatedContainers: 0 pendingContainers: 0 reservedContainers: 0 } preemptionDisabled: true queueConfigurationsMap { partitionName: "" queueConfigurations { capacity: 1.0 absoluteCapacity: 1.0 maxCapacity: 1.0 absoluteMaxCapacity: 1.0 maxAMPercentage: 0.1 effectiveMinCapacity { memory: 0 virtual_cores: 0 resource_value_map { key: "memory-mb" value: 0 units: "Mi" type: COUNTABLE } resource_value_map { key: "vcores" value: 0 units: "" type: COUNTABLE } } effectiveMaxCapacity { memory: 0 virtual_cores: 0 resource_value_map { key: "memory-mb" value: 0 units: "Mi" type: COUNTABLE } resource_value_map { key: "vcores" value: 0 units: "" type: COUNTABLE } } } } intraQueuePreemptionDisabled: true]
- Disconnected from the target VM, address: '127.0.0.1:63224', transport: 'socket'
更多第一时间内容,微信扫描下面二维码关注公众号
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。