public class SparkLauncher
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DRIVER_EXTRA_CLASSPATH
Configuration key for the driver class path.
|
static java.lang.String |
DRIVER_EXTRA_JAVA_OPTIONS
Configuration key for the driver VM options.
|
static java.lang.String |
DRIVER_EXTRA_LIBRARY_PATH
Configuration key for the driver native library path.
|
static java.lang.String |
DRIVER_MEMORY
Configuration key for the driver memory.
|
static java.lang.String |
EXECUTOR_CORES
Configuration key for the number of executor CPU cores.
|
static java.lang.String |
EXECUTOR_EXTRA_CLASSPATH
Configuration key for the executor class path.
|
static java.lang.String |
EXECUTOR_EXTRA_JAVA_OPTIONS
Configuration key for the executor VM options.
|
static java.lang.String |
EXECUTOR_EXTRA_LIBRARY_PATH
Configuration key for the executor native library path.
|
static java.lang.String |
EXECUTOR_MEMORY
Configuration key for the executor memory.
|
static java.lang.String |
SPARK_MASTER
The Spark master.
|
Constructor and Description |
---|
SparkLauncher() |
SparkLauncher(java.util.Map<java.lang.String,java.lang.String> env)
Creates a launcher that will set the given environment variables in the child.
|
Modifier and Type | Method and Description |
---|---|
SparkLauncher |
addAppArgs(java.lang.String... args)
Adds command line arguments for the application.
|
SparkLauncher |
addFile(java.lang.String file)
Adds a file to be submitted with the application.
|
SparkLauncher |
addJar(java.lang.String jar)
Adds a jar file to be submitted with the application.
|
SparkLauncher |
addPyFile(java.lang.String file)
Adds a python file / zip / egg to be submitted with the application.
|
SparkLauncher |
addSparkArg(java.lang.String arg)
Adds a no-value argument to the Spark invocation.
|
SparkLauncher |
addSparkArg(java.lang.String name,
java.lang.String value)
Adds an argument with a value to the Spark invocation.
|
java.lang.Process |
launch()
Launches a sub-process that will start the configured Spark application.
|
SparkLauncher |
setAppName(java.lang.String appName)
Set the application name.
|
SparkLauncher |
setAppResource(java.lang.String resource)
Set the main application resource.
|
SparkLauncher |
setConf(java.lang.String key,
java.lang.String value)
Set a single configuration value for the application.
|
SparkLauncher |
setDeployMode(java.lang.String mode)
Set the deploy mode for the application.
|
SparkLauncher |
setJavaHome(java.lang.String javaHome)
Set a custom JAVA_HOME for launching the Spark application.
|
SparkLauncher |
setMainClass(java.lang.String mainClass)
Sets the application class name for Java/Scala applications.
|
SparkLauncher |
setMaster(java.lang.String master)
Set the Spark master for the application.
|
SparkLauncher |
setPropertiesFile(java.lang.String path)
Set a custom properties file with Spark configuration for the application.
|
SparkLauncher |
setSparkHome(java.lang.String sparkHome)
Set a custom Spark installation location for the application.
|
SparkLauncher |
setVerbose(boolean verbose)
Enables verbose reporting for SparkSubmit.
|
public static final java.lang.String SPARK_MASTER
public static final java.lang.String DRIVER_MEMORY
public static final java.lang.String DRIVER_EXTRA_CLASSPATH
public static final java.lang.String DRIVER_EXTRA_JAVA_OPTIONS
public static final java.lang.String DRIVER_EXTRA_LIBRARY_PATH
public static final java.lang.String EXECUTOR_MEMORY
public static final java.lang.String EXECUTOR_EXTRA_CLASSPATH
public static final java.lang.String EXECUTOR_EXTRA_JAVA_OPTIONS
public static final java.lang.String EXECUTOR_EXTRA_LIBRARY_PATH
public static final java.lang.String EXECUTOR_CORES
public SparkLauncher()
public SparkLauncher(java.util.Map<java.lang.String,java.lang.String> env)
env
- Environment variables to set.public SparkLauncher setJavaHome(java.lang.String javaHome)
javaHome
- Path to the JAVA_HOME to use.public SparkLauncher setSparkHome(java.lang.String sparkHome)
sparkHome
- Path to the Spark installation to use.public SparkLauncher setPropertiesFile(java.lang.String path)
path
- Path to custom properties file to use.public SparkLauncher setConf(java.lang.String key, java.lang.String value)
key
- Configuration key.value
- The value to use.public SparkLauncher setAppName(java.lang.String appName)
appName
- Application name.public SparkLauncher setMaster(java.lang.String master)
master
- Spark master.public SparkLauncher setDeployMode(java.lang.String mode)
mode
- Deploy mode.public SparkLauncher setAppResource(java.lang.String resource)
resource
- Path to the main application resource.public SparkLauncher setMainClass(java.lang.String mainClass)
mainClass
- Application's main class.public SparkLauncher addSparkArg(java.lang.String arg)
Use this method with caution. It is possible to create an invalid Spark command by passing unknown arguments to this method, since those are allowed for forward compatibility.
arg
- Argument to add.public SparkLauncher addSparkArg(java.lang.String name, java.lang.String value)
It is safe to add arguments modified by other methods in this class (such as
setMaster(String)
- the last invocation will be the one to take effect.
Use this method with caution. It is possible to create an invalid Spark command by passing unknown arguments to this method, since those are allowed for forward compatibility.
name
- Name of argument to add.value
- Value of the argument.public SparkLauncher addAppArgs(java.lang.String... args)
args
- Arguments to pass to the application's main class.public SparkLauncher addJar(java.lang.String jar)
jar
- Path to the jar file.public SparkLauncher addFile(java.lang.String file)
file
- Path to the file.public SparkLauncher addPyFile(java.lang.String file)
file
- Path to the file.public SparkLauncher setVerbose(boolean verbose)
verbose
- Whether to enable verbose output.public java.lang.Process launch() throws java.io.IOException
java.io.IOException