Writing YARN Applications
Link:http://hadoop.apache.org/docs/r2.7.2/hadoop-yarn/hadoop-yarn-site/WritingYarnApplications.html
Application submission client向Yarn ResourceManager提交一个Application,RM、NM、AM处理流程。
首先,创建一个YarnClient对象并start它,然后Client可以设置ApplicationContext。为app准备第一个container来containeApplicationMaster,然后提交Application。
RM在已经指定的Container中启动ApplicationMaster。AM与YARN集群通信,处理Application的执行。在app启动的过程中(app的启动个AM与RM的通信是异步的),AM的主要工作包括:
(1)与RM通信,协商为之后的Containers分配资源(通过AMRMClientAsync对象,AMRMClientAsync.CallbackHandler指定事件的处理方法);
(2)Container分配之后,与NodeManagers通信,启动它们所在节点的app的Containers(启动一个Runnable对象,当为Containers分配资源之后,启动containers。作为启动Container的一部分,AM需要指定带有启动信息的ContainerLaunchContext)。
在Application执行的过程中,ApplicationMaster通过NMClientAsync对象与NodeManagers通信。所有Containers的事件由NMClientAsync.CallbackHandler处理。
一个callback handler处理Client的start,stop,status update以及error。
原文:
The general concept is that an application submission client submits an application to the YARN ResourceManager (RM). This can be done through setting up a YarnClient object. After YarnClient is started, the client can then set up application context, prepare the very first container of the application that contains the ApplicationMaster (AM), and then submit the application. You need to provide information such as the details about the local files/jars that need to be available for your application to run, the actual command that needs to be executed (with the necessary command line arguments), any OS environment settings (optional), etc. Effectively, you need to describe the Unix process(es) that needs to be launched for your ApplicationMaster.
The YARN ResourceManager will then launch the ApplicationMaster (as specified) on an allocated container. The ApplicationMaster communicates with YARN cluster, and handles application execution. It performs operations in an asynchronous fashion. During application launch time, the main tasks of the ApplicationMaster are: a) communicating with the ResourceManager to negotiate and allocate resources for future containers, and b) after container allocation, communicating YARN *NodeManager*s (NMs) to launch application containers on them. Task a) can be performed asynchronously through an AMRMClientAsync object, with event handling methods specified in a AMRMClientAsync.CallbackHandler type of event handler. The event handler needs to be set to the client explicitly. Task b) can be performed by launching a runnable object that then launches containers when there are containers allocated. As part of launching this container, the AM has to specify the ContainerLaunchContext that has the launch information such as command line specification, environment, etc.