Java API Conecte -se ao HDFS HA
A cópia do código é a seguinte:
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;
tentar {
fs = filesystem.get (conf);
Filestatus [] list = fs.listStatus (novo caminho ("/"));
para (arquivo filestatus: list) {
System.out.println (file.getPath (). GetName ());
}
} catch (ioexception e) {
E.PrintStackTrace ();
} finalmente{
tentar {
fs.close ();
} catch (ioexception e) {
E.PrintStackTrace ();
}
}
}
Java API Chamadas MapReduce Program
A cópia do código é a seguinte:
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.distribedfilesystem";
args [20] = "-d";
args [21] = "mapReduce.framework.name = yarn";
args [22] = "/entrada";
args [23] = "/out01";
Runjar.main (args);