Get a new application ID from Resource Manager

Source: Internet
Author: User

Premise: There is a Hadoop cluster, and copy Core-site.xml,hdfs-site.xml,mapred-site.xml,yarn-site.xml to Classpath, you can make src/main/resources

1. Get a getnewapplicationrequest, an instance of Protobuf class Getnewapplicationrequestpbimpl, which will support other serialization methods in the future. The serialization method determines which serializable class the RPC factory produces.

Records.newrecord, is to instantiate a Protobuf class, note that if you write code, the suffix of protobuf has some rules, must be "Pbimpl" end, the package name must be "IMPL.PB"; Otherwise, the corresponding Protobuf class cannot be found

Getnewapplicationrequest request = Records                . NewRecord (getnewapplicationrequest. class);
Configuration conf = new configuration ();

2. Get the IP and port where the Resoucemanager resides

Inetsocketaddress rmaddress = conf.getsocketaddr (                yarnconfiguration.rm_address,                Yarnconfiguration.default_rm_address,                yarnconfiguration.default_rm_port);

3. Create a new YARNRPC instance, which is the default class: Org.apache.hadoop.yarn.ipc.HadoopYarnProtoRPC, and gets

Applicationclientprotocol instance, the default class is Applicationclientprotocolpbclientimpl

Immediately after the call gets a new AppID

//Get Yarn RPCYARNRPC RPC =yarnrpc.create (conf); //get a proxy from yarn RPC, yarn RPC is a factory, can produce some protocolRmclientprotocol =( Applicationclientprotocol) (Rpc.getproxy (Applicationclientprotocol.class, rmaddress, conf)); //get response from yarn RPC proxies with sending the Getnewapplicationrequest//which contains a Protobuf object.Getnewapplicationresponse Newapp =Rmclientprotocol. getnewapplication (Request); System.err.println ("Get a new Application ID:" + newapp.getapplicationid ());

The specific proxy has done how to initialize which classes, but also need further research.

The summary is that currently Hadoop supports PROTOBUF as the default serialization framework, and currently yarn RPC is using the Protobuf factory.

Here is the complete code

 PackageCom.jarvis.yarnapp;Importjava.io.IOException;Importjava.net.InetSocketAddress;Importorg.apache.hadoop.conf.Configuration;ImportOrg.apache.hadoop.yarn.api.ApplicationClientProtocol;Importorg.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest;ImportOrg.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse;Importorg.apache.hadoop.yarn.conf.YarnConfiguration;Importorg.apache.hadoop.yarn.exceptions.YarnException;ImportOrg.apache.hadoop.yarn.ipc.YarnRPC;Importorg.apache.hadoop.yarn.util.Records; Public classzjxclient {PrivateApplicationclientprotocol Rmclientprotocol;  Public voidRun ()throwsyarnexception, IOException {//get a request for communicate with yarnGetnewapplicationrequest request =Records. NewRecord (getnewapplicationrequest.class); Configuration conf=NewConfiguration (); //get Resouce Manager addressInetsocketaddress rmaddress =conf.getsocketaddr (yarnconfiguration.rm_address, Yarnconfiguration.default_rm_address,        Yarnconfiguration.default_rm_port); //Get Yarn RPCYARNRPC RPC =yarnrpc.create (conf); //get a proxy from yarn RPC, yarn RPC is a factory, can produce some protocolRmclientprotocol =( Applicationclientprotocol) (Rpc.getproxy (Applicationclientprotocol.class, rmaddress, conf)); //get response from yarn RPC proxies with sending the Getnewapplicationrequest//which contains a Protobuf object.Getnewapplicationresponse Newapp =Rmclientprotocol. getnewapplication (Request); System.err.println ("Get a new Application ID:" +Newapp.getapplicationid ()); }     Public Static voidMain (string[] args)throwsyarnexception, IOException {zjxclient zjxclient=Newzjxclient ();    Zjxclient.run (); }}

Get a new application ID from Resource Manager

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.