Quick start

Updated at:

This guide shows you how to use the Alibaba Cloud E-MapReduce (EMR) console to create an EMR Studio cluster, interactively develop jobs, and schedule workflows.

Background information

For more information about Zeppelin, Jupyter, and Airflow, see the following topics:

Prerequisites

  • You have access to the EMR Studio trial.
  • You have created an EMR Studio cluster. For more information, see Create an EMR Studio cluster.
    Note If this is the first time you create an EMR Studio cluster, the console prompts you to authorize a system role. Use your primary account to authorize the system role AliyunECSInstanceForEMRStudioRole. For more information, see Role authorization.
  • Your security group rules allow inbound traffic on ports 8000, 8081, and 8443.

    For more information about how to add a security group rule, see Add a security group rule.

  • You have added a user. For more information, see Add a user.

Limitations

EMR Studio can be associated only with EMR compute clusters that are in the same Virtual Private Cloud (VPC).

Procedure

  1. Step 1: Go to the data development workbench
  2. Step 2: Associate a compute cluster
  3. Step 3: Develop jobs in Zeppelin
  4. Step 4: Write an Airflow Python script
  5. Step 5: Schedule a notebook job

Step 1: Go to the data development workbench

  1. Go to the details page.
    1. Log on to the Alibaba Cloud E-MapReduce console.
    2. In the top navigation bar, select a region and a resource group.
    3. Click the Clusters tab.
    4. On the Clusters page, click Details for the desired cluster.
  2. Add a Linux user.
    For more information about adding a user, see Add a user.
  3. In the left-side navigation pane, choose Access Links and Ports.
  4. Click the link in the Studio Workspace UI row.
    Enter the username and password for the user you added to access the web UI.
    Note Wait a few seconds for the Studio Workspace UI information to appear.

Step 2: Associate a compute cluster

Important EMR Studio can be associated only with EMR compute clusters that are in the same VPC.

After you associate a compute cluster, EMR Studio can access its resources and submit jobs to it.

  1. On the Associate Cluster page, click the Available Clusters tab.
    Note The list shows only EMR clusters in the same VPC. You can associate three types of clusters: Hadoop, Dataflow, and DataScience.
  2. Select the type of cluster to associate.
  3. Find the cluster that you want to associate and click Associate Cluster in the Actions column.
  4. In the Associate Cluster dialog box, click Bind.
    The association is successful when the associated cluster information appears on the Associated Clusters tab.
    Note The binding process takes 1 to 2 minutes.

Step 3: Develop jobs in Zeppelin

Once a cluster is associated, you can interactively develop jobs in Zeppelin notebooks. To demonstrate this, the guide uses the built-in "Airflow Scheduling Tutorial 1" as an example.

  1. In the left-side navigation pane, click Zeppelin.
  2. On the Zeppelin page, select Alibaba Cloud EMR Data Development Tutorial > Airflow Tutorial > Airflow Scheduling Tutorial 1.
    The following page appears:
    Area Description
    ① The %md interpreter renders Markdown text for notes and explanations.
    ② The %sh interpreter runs shell scripts to perform tasks like generating data.
    ③ The %hive interpreter runs Hive SQL statements.
    ④ Click the icon to switch the associated cluster.
    ⑤ Click the icon to run the current paragraph.
    Note Some interpreters download dependencies the first time you use them. If you see a message like Interpreter Setting 'hive' is not ready, the download is still in progress. Wait a moment and try again.

Step 4: Write an Airflow Python script

Airflow scheduling requires you to manually write Python scripts to build DAGs. EMR Studio automatically synchronizes Python scripts from a specified OSS path to Airflow. Therefore, after you edit and upload a DAG script, you can go to the data development workbench. In the left-side navigation pane, click Airflow to open the DAGs page and view the DAGs that you created.

EMR Studio includes a built-in scheduling tutorial. On the Zeppelin page, select Alibaba Cloud EMR Data Development Tutorial > Airflow Tutorial > Airflow Scheduling Tutorial 1 to view it. For basic Airflow usage, see Apache Airflow.
Note EMR Studio provides a built-in Operator, ZeppelinOperator, for scheduling Zeppelin notebooks. It supports scheduling at both the note and paragraph levels. For more information, see Schedule recurring jobs in Zeppelin.
This script creates a task for each paragraph and links them to form a chain-like DAG. The following code provides an example.
from airflow import DAG
from datetime import datetime, timedelta
from airflow.providers.apache.zeppelin.operators.zeppelin_operator import ZeppelinOperator

default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime(2018, 1, 1),
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 0,
    'retry_delay': timedelta(minutes=5),
}


with DAG('zeppelin_example_paragraph_dag',
         max_active_runs=5,
         schedule_interval='0 0 * * *',
         default_args=default_args) as dag:

    execution_date = "{{ ds }}"

    raw_data_task = ZeppelinOperator(
        task_id='raw_data_task',
        conn_id='zeppelin_default',
        note_id='2FXADMCY9',
        paragraph_id='paragraph_1613703810025_1489985581',
        params= {'dt' : execution_date}
    )

    csv_data_task = ZeppelinOperator(
        task_id='csv_data_task',
        conn_id='zeppelin_default',
        note_id='2FXADMCY9',
        paragraph_id='paragraph_1613705325984_828524031',
        params= {'dt' : execution_date}
    )

    parquet_data_task = ZeppelinOperator(
        task_id='parquet_data_task',
        conn_id='zeppelin_default',
        note_id='2FXADMCY9',
        paragraph_id='paragraph_1613709950691_1420422787',
        params= {'dt' : execution_date}
    )

    query_task = ZeppelinOperator(
        task_id='query_task',
        conn_id='zeppelin_default',
        note_id='2FXADMCY9',
        paragraph_id='paragraph_1613703819960_454383326',
        params= {'dt' : execution_date}
    )

    raw_data_task >> csv_data_task >> parquet_data_task >> query_task
 

Step 5: Schedule a notebook job

  • Enable DAG scheduling
    On the DAGs page, toggle the switch from Off to On to enable DAG scheduling.
  • View the details of a scheduled task

    On the DAGs page, click a DAG name to open its Tree View.

    On the Tree View page, you can view the details of the scheduled tasks for the DAG.
  • View task run status

    On the Tree View page, click the icon for a task to view its run status.

    Task Log Details