Java API Connect و HDFS HA
نسخة الكود كما يلي:
الفراغ الثابت العام الرئيسي (سلسلة [] args) {
التكوين conf = تكوين جديد () ؛
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") ؛
نظام الملفات fs = null ؛
يحاول {
fs = fileystem.get (conf) ؛
filestatus [] list = fs.liststatus (مسار جديد ("/")) ؛
لـ (ملف filestatus: قائمة) {
System.out.println (file.getPath (). getName ()) ؛
}
} catch (ioException e) {
E.PrintStackTrace () ؛
} أخيراً{
يحاول {
fs.close () ؛
} catch (ioException e) {
E.PrintStackTrace () ؛
}
}
}
مكالمات Java API برنامج MapReduce
نسخة الكود كما يلي:
سلسلة [] args = سلسلة جديدة [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 = الغزل" ؛
args [22] = "/input" ؛
args [23] = "/out01" ؛
Runjar.main (args) ؛