Java connection HDFs ha and call MapReduce jar sample _java

Source: Internet
Author: User
Tags failover

Java API Connection HDFS HA

Copy Code code as follows:

public static void Main (string[] args) {
Configuration conf = new Configuration ();
Conf.set ("Fs.defaultfs", "Hdfs://hadoop2cluster");
Conf.set ("Dfs.nameservices", "Hadoop2cluster");
Conf.set ("Dfs.ha.namenodes.hadoop2cluster", "nn1,nn2");
Conf.set ("Dfs.namenode.rpc-address.hadoop2cluster.nn1", "10.0.1.165:8020");
Conf.set ("Dfs.namenode.rpc-address.hadoop2cluster.nn2", "10.0.1.166:8020");
Conf.set ("Dfs.client.failover.proxy.provider.hadoop2cluster", " Org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider ");
FileSystem fs = null;
try {
FS = Filesystem.get (conf);
filestatus[] List = Fs.liststatus (new Path ("/"));
for (Filestatus file:list) {
System.out.println (File.getpath (). GetName ());
}
catch (IOException e) {
E.printstacktrace ();
} finally{
try {
Fs.close ();
catch (IOException e) {
E.printstacktrace ();
}
}
}

Java API Invoke MapReduce program

Copy Code code as follows:

string[] args = new string[24];
Args[0] = "/usr/hadoop-2.2.0/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.2.0.jar";
ARGS[1] = "WordCount";
ARGS[2] = "-D";
ARGS[3] = "yarn.resourcemanager.address=10.0.1.165:8032";
ARGS[4] = "-D";
ARGS[5] = "yarn.resourcemanager.scheduler.address=10.0.1.165:8030";
ARGS[6] = "-D";
ARGS[7] = "fs.defaultfs=hdfs://hadoop2cluster/";
ARGS[8] = "-D";
ARGS[9] = "Dfs.nameservices=hadoop2cluster";
ARGS[10] = "-D";
ARGS[11] = "DFS.HA.NAMENODES.HADOOP2CLUSTER=NN1,NN2";
ARGS[12] = "-D";
ARGS[13] = "dfs.namenode.rpc-address.hadoop2cluster.nn1=10.0.1.165:8020";
ARGS[14] = "-D";
ARGS[15] = "dfs.namenode.rpc-address.hadoop2cluster.nn2=10.0.1.166:8020";
ARGS[16] = "-D";
ARGS[17] = "dfs.client.failover.proxy.provider.hadoop2cluster= Org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider ";
ARGS[18] = "-D";
ARGS[19] = "Fs.hdfs.impl=org.apache.hadoop.hdfs.distributedfilesystem";
ARGS[20] = "-D";
ARGS[21] = "Mapreduce.framework.name=yarn";
ARGS[22] = "/input";
ARGS[23] = "/out01";
Runjar.main (args);

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.