尝试从http://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/WritingYarnApplications.html复制纱线教程。
实际上需要在CDH4.3上运行一些修改。它崩溃如下:
13/12/02 17:09:36 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchFieldException: versionID
at org.apache.hadoop.ipc.RPC.getProtocolVersion(RPC.java:171)
at org.apache.hadoop.ipc.WritableRpcEngine$Invocation.<init>(WritableRpcEngine.java:111)
at org.apache.hadoop.ipc.WritableRpcEngine$Invoker.invoke(WritableRpcEngine.java:225)
at com.sun.proxy.$Proxy6.getNewApplication(Unknown Source)
at ch.unibe.scg.yarn.ApplicationMaster.launch(ApplicationMaster.java:58)
at ch.unibe.scg.yarn.ApplicationMaster.main(ApplicationMaster.java:112)
Caused by: java.lang.NoSuchFieldException: versionID
at java.lang.Class.getField(Class.java:1579)
at org.apache.hadoop.ipc.RPC.getProtocolVersion(RPC.java:167)
... 5 more
这是我们的代码,直至崩溃。
// mostly stolen from http://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/WritingYarnApplications.html
Configuration conf = new Configuration();
conf.addResource(new Path(CONF_FILE_PATH));
YarnConfiguration yarnConf = new YarnConfiguration(conf);
InetSocketAddress rmAddress = NetUtils.createSocketAddr(
yarnConf.get(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS));
Configuration appsManagerServerConf = new Configuration(conf);
ClientRMProtocol applicationsManager = RPC.getProxy(ClientRMProtocol.class, 1L, rmAddress, appsManagerServerConf);
GetNewApplicationRequest request = Records.newRecord(GetNewApplicationRequest.class);
GetNewApplicationResponse response = applicationsManager.getNewApplication(request);
最后一行触发上述异常。