代码在spark-launcher工程下面:
package-info.java是入口,看完豁然开朗,向spark submit application。
主要InProcessLauncher和SparkLauncher两个类。
一.InProcessLauncher: spark application与caller在同一进程。
pb启动程序 org.apache.spark.deploy.InProcessSparkSubmit或者org.apache.spark.deploy.SparkSubmit 相关main方法。
二.SparkLauncher:通过ProcessBuilder submit spark application进程,与caller在俩进程。
pb启动程序:spark_home/bin/spark-submit ...
SparkLauncher 又分俩种情况
1.startApplication()方法,通过hander可以控制application,同时submit时会监听application pb。
2.通过launch()方法,直接启动ProcessBuilder ,变返回pb。
* import org.apache.spark.launcher.SparkAppHandle;
* import org.apache.spark.launcher.SparkLauncher;
*
* public class MyLauncher {
* public static void main(String[] args) throws Exception {
* SparkAppHandle handle = new SparkLauncher()
* .setAppResource("/my/app.jar")
* .setMainClass("my.spark.app.Main")
* .setMaster("local")
* .setConf(SparkLauncher.DRIVER_MEMORY, "2g")
* .startApplication(...可以加Listeners,监听Application变化);
* // Use handle API to monitor / control application.
* }
* }
* }
* import org.apache.spark.launcher.SparkLauncher;
*
* public class MyLauncher {
* public static void main(String[] args) throws Exception {
* Process spark = new SparkLauncher()
* .setAppResource("/my/app.jar")
* .setMainClass("my.spark.app.Main")
* .setMaster("local")
* .setConf(SparkLauncher.DRIVER_MEMORY, "2g")
* .launch();
* spark.waitFor();
* }
* }
* }
网友评论