我有一个用例,我需要从Java应用程序提交python代码。我为此编写了以下代码:
String command = "spark-submit /home/hadoop/sample.py "
+ "--input_dir " + getTmpModelInputPath() + "/* " + "--output_dir " + getTmpModelOutputPath();
final String[] arr = { "/bin/sh", "-c", command};
Process p = Runtime.getRuntime().exec(arr);
try {
int exitVal = p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException("job failed");
}
命令失败,未找到"火花素"。当我直接在主节点上运行命令字符串时,它工作正常。有谁知道这里出了什么问题?
我能够从根本上导致命令找不到错误的问题。主应用程序的 Spark-submit 在群集模式下启动。因此,在java代码中完成的火花提交是在"执行节点"上执行的,而不是在主节点上执行的。执行程序节点在主机上没有可用的 Spark-submit。
如果我们在客户端模式下提交主应用程序,上面的代码将起作用。这将确保下一个 Spark-submit 在 EMR 中安装了 Spark-submit 二进制文件的主节点上进行。