Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG

本文将通过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对象并返回,所以从

Apache Hadoop YARN:Client<-->ResourceManager源码解析

的调用关系图中也可发现rmClient就是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 queueInfos = yarnClient.getAllQueues();
        System.out.println(queueInfos);
    }

}

二、 首先启动ResourceManager

配置ResourceManager启动设置

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_第1张图片

启动ResourceManager

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_第2张图片

三、 打上断点,DEBUG模式运行MyTestYarnClient#testYarnClientVisitRM

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_第3张图片

四、 DEBUG下一步跟踪到YarnClientImpl#getAllQueues

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_第4张图片

五、 DEBUG下一步跟踪到RetryInvocationHandler#invoke

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_第5张图片

六、 DEBUG下一步ApplicationClientProtocolPBClientImpl#getQueueInfo

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_第6张图片

七、 下一步ApplicationClientProtocolPBServiceImpl#getQueueInfo

 

正式进入ResourceManager

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_第7张图片

八、 最后一步ClientRMService#getQueueInfo

 

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_第8张图片

九、 END 打印YARN集群队列信息

[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'

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_第9张图片

 

更多第一时间内容,微信扫描下面二维码关注公众号

你可能感兴趣的:(源码阅读,hadoop,大数据)