Running a SparkSubmit Job¶
You can submit programs developed by yourself to MRS to execute them, and obtain the results. This section describes how to submit a Spark job on the MRS console.
Prerequisites¶
You have uploaded the program packages and data files required for running jobs to OBS or HDFS.
Submitting a Job on the GUI¶
Log in to the MRS console.
Choose Clusters > Active Clusters, select a running cluster, and click its name to switch to the cluster details page.
If Kerberos authentication is enabled for the cluster, perform the following steps. If Kerberos authentication is not enabled for the cluster, skip this step.
In the Basic Information area on the Dashboard page, click Synchronize on the right side of IAM User Sync to synchronize IAM users. For details, see Synchronizing IAM Users to MRS.
Note
In MRS 1.7.2 or earlier, the job management function is unavailable in a cluster with Kerberos authentication enabled. You need to submit a job in the background.
When the policy of the user group to which the IAM user belongs changes from MRS ReadOnlyAccess to MRS CommonOperations, MRS FullAccess, or MRS Administrator, wait for 5 minutes until the new policy takes effect after the synchronization is complete because the SSSD (System Security Services Daemon) cache of cluster nodes needs time to be updated. Then, submit a job. Otherwise, the job may fail to be submitted.
When the policy of the user group to which the IAM user belongs changes from MRS CommonOperations, MRS FullAccess, or MRS Administrator to MRS ReadOnlyAccess, wait for 5 minutes until the new policy takes effect after the synchronization is complete because the SSSD cache of cluster nodes needs time to be updated.
Click the Jobs tab.
Click Create. The Create Job page is displayed.
Configure job information.
Set Type to SparkSubmit if the cluster version is MRS 1.9.2 or later. Configure other parameters of the SparkSubmit job by referring to Table 1.
Set Type to Sparkif the cluster version is earlier than MRS 1.9.2. Configure other parameters of the Spark job by referring to Table 4.
¶ Parameter
Description
Name
Job name. It contains 1 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.
Note
You are advised to set different names for different jobs.
Program Path
Path of the program package to be executed. The following requirements must be met:
Contains a maximum of 1,023 characters, excluding special characters such as
;|&><'$.
The parameter value cannot be empty or full of spaces.The path of the program to be executed can be stored in HDFS or OBS. The path varies depending on the file system.
OBS: The path must start with obs://. Example: obs://wordcount/program/xxx.jar
HDFS: The path must start with /user. For details about how to import data to HDFS, see Importing Data.
For SparkScript and HiveScript, the path must end with .sql. For MapReduce, the path must end with .jar. For Flink and SparkSubmit, the path must end with .jar or .py. The .sql, .jar, and .py are case-insensitive.
Program Parameter
(Optional) Used to configure optimization parameters such as threads, memory, and vCPUs for the job to optimize resource usage and improve job execution performance.
Table 2 describes the common parameters of a running program.
Parameters
(Optional) Key parameter for program execution. The parameter is specified by the function of the user's program. MRS is only responsible for loading the parameter. Multiple parameters are separated by space.
The parameter contains a maximum of 150,000 characters. It cannot contain special characters
;|&><'$,
but can be left blank.Caution
CAUTION: If you enter a parameter with sensitive information (such as the login password), the parameter may be exposed in the job details display and log printing. Exercise caution when performing this operation.
Service Parameter
(Optional) It is used to modify service parameters for the job. The parameter modification applies only to the current job. To make the modification take effect permanently for the cluster, follow instructions in Configuring Service Parameters.
To add multiple parameters, click on the right. To delete a parameter, click Delete on the right.
Table 3 lists the common service configuration parameters.
Note
If you need to run a long-term job, such as SparkStreaming, and access OBS, you need to use Service Parameter to import the AK/SK for accessing OBS.
Command Reference
Command submitted to the background for execution when a job is submitted.
¶ Parameter
Description
Example Value
--conf
Add the task configuration items.
spark.executor.memory=2G
--driver-memory
Set the running memory of driver.
2G
--num-executors
Set the number of executors to be started.
5
--executor-cores
Set the number of executor cores.
2
--class
Set the main class of a task.
org.apache.spark.examples.SparkPi
--files
Upload files to a task. The files can be custom configuration files or some data files from OBS or HDFS.
-
--jars
Upload additional dependency packages of a task to add the external dependency packages to the task.
-
--executor-memory
Set executor memory.
2G
--conf spark-yarn.maxAppAttempts
Control the number of AM retries.
If this parameter is set to 0, retry is not allowed. If this parameter is set to 1, one retry is allowed.
¶ Parameter
Description
Example Value
fs.obs.access.key
Key ID for accessing OBS.
-
fs.obs.secret.key
Key corresponding to the key ID for accessing OBS.
-
¶ Parameter
Description
Name
Job name. It contains 1 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.
Note
You are advised to set different names for different jobs.
Program Path
Path of the program package to be executed. The following requirements must be met:
Contains a maximum of 1,023 characters, excluding special characters such as
;|&><'$.
The parameter value cannot be empty or full of spaces.The path of the program to be executed can be stored in HDFS or OBS. The path varies depending on the file system.
OBS: The path must start with s3a://. Example: s3a://wordcount/program/xxx.jar
HDFS: The path must start with /user. For details about how to import data to HDFS, see Importing Data.
For SparkScript, the path must end with .sql. For MapReduce and Spark, the path must end with .jar. The .sql and .jar are case-insensitive.
Parameters
Key parameter for program execution. The parameter is specified by the function of the user's program. MRS is only responsible for loading the parameter. Multiple parameters are separated by space.
Configuration method: Package name.Class name
The parameter contains a maximum of 150,000 characters. It cannot contain special characters
;|&><'$,
but can be left blank.Note
When entering a parameter containing sensitive information (for example, login password), you can add an at sign (@) before the parameter name to encrypt the parameter value. This prevents the sensitive information from being persisted in plaintext. When you view job information on the MRS console, the sensitive information is displayed as *.
Example: username=admin @password=admin_123
Import From
Path for inputting data
Data can be stored in HDFS or OBS. The path varies depending on the file system.
OBS: The path must start with s3a://.
HDFS: The path must start with /user. For details about how to import data to HDFS, see Importing Data.
The parameter contains a maximum of 1,023 characters, excluding special characters such as
;|&>,<'$,
and can be left blank.Export To
Path for outputting data
Note
When setting this parameter, select OBS or HDFS. Select a file directory or manually enter a file directory, and click OK.
If you add the hadoop-mapreduce-examples-x.x.x.jar sample program or a program similar to hadoop-mapreduce-examples-x.x.x.jar, enter a directory that does not exist.
Data can be stored in HDFS or OBS. The path varies depending on the file system.
OBS: The path must start with s3a://.
HDFS: The path must start with /user.
The parameter contains a maximum of 1,023 characters, excluding special characters such as
;|&>,<'$,
and can be left blank.Log Path
Path for storing job logs that record job running status.
Data can be stored in HDFS or OBS. The path varies depending on the file system.
OBS: The path must start with s3a://.
HDFS: The path must start with /user.
The parameter contains a maximum of 1,023 characters, excluding special characters such as
;|&>,<'$,
and can be left blank.Confirm job configuration information and click OK.
After the job is created, you can manage it.
Submitting a Job in the Background¶
In MRS 3.x and later versions, the default installation path of the client is /opt/Bigdata/client. In MRS 3.x and earlier versions, the default installation path is /opt/client. For details, see the actual situation.
Create a user for submitting jobs. For details, see Creating a User.
In this example, a machine-machine user used in the user development scenario has been created, and user groups (hadoop and supergroup), the primary group (supergroup), and role permissions (System_administrator and default) have been correctly assigned to the user.
Download the authentication credential.
For clusters of MRS 3.x or later, log in to MRS Manager and choose System > Permission > User. In the Operation column of the newly created user, choose More > Download Authentication Credential.
For clusters whose version is earlier than MRS 3.x, log in to MRS Manager and choose System > Manage User. In the Operation column of the newly created user, choose More > Download Authentication Credential.
Upload JAR files related to the job to the cluster. In this example, the sample JAR file built in Spark is used. It is stored in $SPARK_HOME/examples/jars.
Upload the authentication credential of the user created in 2 to the /opt directory of the cluster and run the following command to decompress the credential:
tar -xvf MRSTest _xxxxxx_keytab.tar
You will obtain two files: user.keytab and krb5.conf.
Before performing operations on the cluster, run the following commands:
source /opt/Bigdata/client/bigdata_env
cd $SPARK_HOME
Run the following command to submit the Spark job:
./bin/spark-submit --master yarn --deploy-mode client --conf spark.yarn.principal=MRSTest --conf spark.yarn.keytab=/opt/user.keytab --class org.apache.spark.examples.SparkPi examples/jars/spark-examples_2.11-2.3.2-mrs-2.0.jar 10
Parameter description:
Computing capability of Yarn, which specifies that the job is submitted in client mode.
Configuration item of the Spark job. The authentication file and username are transferred here.
spark.yarn.principal: user created in step 1
spark.yarn.keytab: keytab file used for authentication
xx.jar: JAR file used by the job