How to use the programmatic spark submit capability

后端 未结 1 963
余生分开走
余生分开走 2021-02-04 14:56

There is a somewhat recent (Spring 2015) feature apparently intended to allow submitting a spark job programmatically.

Here is the JIRA https://issues.apache.org/jira/

相关标签:
1条回答
  • 2021-02-04 15:13

    Looking at the details of the pull request, it seems that the functionality is provided by the SparkLauncher class, described in the API docs here.

    public class SparkLauncher extends Object

    Launcher for Spark applications.

    Use this class to start Spark applications programmatically. The class uses a builder pattern to allow clients to configure the Spark application and launch it as a child process.

    The API docs are rather minimal, but I found a blog post that gives a worked example (code also available in a GitHub repo). I have copied a simplified version of the example below (untested) in case the links go stale:

    import org.apache.spark.launcher.SparkLauncher
    
    object Launcher extends App {
      val spark = new SparkLauncher()
        .setSparkHome("/home/user/spark-1.4.0-bin-hadoop2.6")
        .setAppResource("/home/user/example-assembly-1.0.jar")
        .setMainClass("MySparkApp")
        .setMaster("local[*]")
        .launch();
      spark.waitFor();
    }
    

    See also:

    • Another tutorial blog post / review of the feature
    • A book chapter on the topic
    0 讨论(0)
提交回复
热议问题