我正在使用SparkLauncher从代码中提交spark应用程序。
Map<String, String> env = new HashMap<String, String>();
env.put("SPARK_PRINT_LAUNCH_COMMAND", "1");
System.out.println("Creating SparkLauncher");
SparkLauncher launcher = new SparkLauncher(env);
launcher.setSparkHome(sparkHome);
launcher.setAppResource(appResource);
launcher.setMaster(sparkMaster);
launcher.setMainClass(mainClass);
launcher.setAppName("TestFromJersey")
.setVerbose(true)
.setConf("spark.cores.max", "20")
.setConf("spark.executor.memory", "30G")
.setConf("spark.executor.extraJavaOptions", "-XX:+UseG1GC -XX:+PrintFlagsFinal -XX:+PrintReferenceGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintAdaptiveSizePolicy -XX:+UnlockDiagnosticVMOptions -XX:+G1SummarizeConcMark -XX:ConcGCThreads=13 -XX:NewRatio=1 -XX:+PrintTenuringDistribution");
for(File f : new File("/home/user/jars").listFiles()){
launcher.addJar(f.getAbsolutePath());
}
try {
System.out.println("Launching Spark Job from SparkLauncher");
launcher.addAppArgs("--jobName myJobName",
"--time "+System.currentTimeMillis()+"",
"--authUser admin",
"--savePage true");
launcher.startApplication(new SparkAppHandle.Listener() {
@Override public void stateChanged(SparkAppHandle h) {
System.out.println("App State:" + h.getState());
}
@Override public void infoChanged(SparkAppHandle h) { }
});
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("error in launching Spark Application");
e.printStackTrace();
}
现在,作业根本没有运行,并且没有调用处理函数,我认为这是因为作业配置错误。在输出日志中,我可以看到以下错误:
org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -jobName myJobName
所以,在我看来,代码无法从sparkArguments中单独识别appArgs。
任何指针?是我用于添加AppArgs正确的格式吗?
答案 0 :(得分:0)
好的,通过一些命中和试验,指定参数的正确方法是:
launcher.addAppArgs("--jobName","myJobName",
"--authUser","admin",
"--savePage","true");