:original_name: mrs_01_0052.html

.. _mrs_01_0052:

Running a MapReduce Job
=======================

You can submit programs developed by yourself to MRS to execute them, and obtain the results. This section describes how to submit a MapReduce job on the MRS management console. MapReduce jobs are used to submit JAR programs to quickly process massive amounts of data in parallel and create a distributed data processing and execution environment.

If the job and file management functions are not supported on the cluster details page, submit the jobs in the background.

Prerequisites
-------------

You have uploaded the program packages and data files required for running jobs to OBS or HDFS.

Before you upload the program packages and data files to OBS, you need to create an OBS agency and bind it to the MRS cluster. For details, see :ref:`Configuring a Storage-Compute Decoupled Cluster (Agency) <mrs_01_0768>`.

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 :ref:`Synchronizing IAM Users to MRS <mrs_01_0495>`.

   .. 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.

   .. note::

      If the IAM username contains spaces (for example, **admin 01**), a job cannot be created.

#. In **Type**, select **MapReduce**. Configure other job information.

   -  Configure MapReduce job information by referring to :ref:`Table 1 <mrs_01_0052__table2037463920278>`\ if the cluster version is MRS 1.9.2 or later.
   -  Configure MapReduce job information by referring to :ref:`Table 3 <mrs_01_0052__table13750103511814>` if the cluster version is earlier than MRS 1.9.2.

   .. _mrs_01_0052__table2037463920278:

   .. table:: **Table 1** Job configuration information

      +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | 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 :ref:`Importing Data <en-us_topic_0019489057__section6302178417377>`.                                                                                                   |
      |                                   |                                                                                                                                                                                                                                                                           |
      |                                   | -  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.                      |
      +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Parameters                        | (Optional) It is the key parameter for program execution. Multiple parameters are separated by space.                                                                                                                                                                     |
      |                                   |                                                                                                                                                                                                                                                                           |
      |                                   | Configuration method: *Program class name* *Data input path* *Data output path*                                                                                                                                                                                           |
      |                                   |                                                                                                                                                                                                                                                                           |
      |                                   | -  Program class name: It is specified by a function in your program. MRS is responsible for transferring parameters only.                                                                                                                                                |
      |                                   |                                                                                                                                                                                                                                                                           |
      |                                   | -  Data input path: Click **HDFS** or **OBS** to select a path or manually enter a correct path.                                                                                                                                                                          |
      |                                   |                                                                                                                                                                                                                                                                           |
      |                                   | -  Data output path: Enter a directory that does not exist.                                                                                                                                                                                                               |
      |                                   |                                                                                                                                                                                                                                                                           |
      |                                   |    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 :ref:`Configuring Service Parameters <mrs_01_0204>`. |
      |                                   |                                                                                                                                                                                                                                                                           |
      |                                   | To add multiple parameters, click |image1| on the right. To delete a parameter, click **Delete** on the right.                                                                                                                                                            |
      |                                   |                                                                                                                                                                                                                                                                           |
      |                                   | :ref:`Table 2 <mrs_01_0052__table12538926589>` lists the common service configuration parameters.                                                                                                                                                                         |
      +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Command Reference                 | Command submitted to the background for execution when a job is submitted.                                                                                                                                                                                                |
      +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

   .. _mrs_01_0052__table12538926589:

   .. table:: **Table 2** **Service Parameter** parameters

      +-------------------+----------------------------------------------------+---------------+
      | 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. | ``-``         |
      +-------------------+----------------------------------------------------+---------------+

   .. _mrs_01_0052__table13750103511814:

   .. table:: **Table 3** Job configuration information

      +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | 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 :ref:`Importing Data <en-us_topic_0019489057__section6302178417377>`.                                                                                                                                                                                                     |
      |                                   |                                                                                                                                                                                                                                                                                                                                                                             |
      |                                   | -  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 management 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 :ref:`Importing Data <en-us_topic_0019489057__section6302178417377>`.                                                                                                                                                                                                        |
      |                                   |                                                                                                                                                                                                                                                                                                                                                                             |
      |                                   | 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://**. (Supported only in MRS 1.8.10 and earlier versions)                                                                                                                                                                                                                                                                            |
      |                                   | -  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.

#. Log in to a Master node. For details, see :ref:`Logging In to an ECS <mrs_01_0083>`.

#. Run the following command to initialize environment variables:

   **source /opt/Bigdata/client/bigdata_env**

#. If the Kerberos authentication is enabled for the current cluster, run the following command to authenticate the user. If the Kerberos authentication is disabled for the current cluster, skip this step.

   **kinit** **MRS cluster user**

   Example: **kinit admin**

#. Run the following command to copy the program in the OBS file system to the Master node in the cluster:

   **hadoop fs -Dfs.obs.access.key=AK -Dfs.obs.secret.key=SK -copyToLocal source_path.jar target_path.jar**

   Example: **hadoop fs -Dfs.obs.access.key=XXXX -Dfs.obs.secret.key=XXXX -copyToLocal "obs://mrs-word/program/hadoop-mapreduce-examples-XXX.jar" "/home/omm/hadoop-mapreduce-examples-XXX.jar"**

   You can log in to OBS Console using AK/SK. To obtain AK/SK information, click the username in the upper right corner of the management console and choose **My Credentials** > **Access Keys**.

#. Run the following command to submit a wordcount job. If data needs to be read from OBS or outputted to OBS, the AK/SK parameters need to be added.

   **source /opt/Bigdata/client/bigdata_env;hadoop jar execute_jar wordcount input_path output_path**

   Example: **source /opt/Bigdata/client/bigdata_env;hadoop jar /home/omm/hadoop-mapreduce-examples-XXX.jar wordcount -Dfs.obs.access.key=XXXX -Dfs.obs.secret.key=XXXX "obs://mrs-word/input/*" "obs://mrs-word/output/"**

   In the preceding command, **input_path** indicates a path for storing job input files on OBS. **output_path** indicates a path for storing job output files on OBS and needs to be set to a directory that does not exist

.. |image1| image:: /_static/images/en-us_image_0000001349137577.png
