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/
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: