Airflow GUI User Guide

Updated at:

Airflow GUI is a visual orchestration tool provided by DMS that is built on the open-source Airflow. It lets you create and manage Airflow Directed Acyclic Graph (DAG) tasks using a drag-and-drop interface, which eliminates the need to write Python code. This topic describes how to access the Airflow GUI, configure global settings and nodes, and publish tasks.

Prerequisites

Quick Start

Feature Entry Points

  1. Log in to DMS 5.0.

  2. From the top menu bar, select Data+AI > Workspace, or in Simplified Mode, click the 2023-01-28_15-57-17 icon in the upper-left corner and select All Features > Data+AI > Workspace.

  3. On the workspace list page, click the ID of the target workspace to open it.

  4. In the left navigation pane, click Resource Manager. In the blank area of the CODE module, right-click and select New Airflow File.

Workflow Canvas Overview

The GUI editor provides an intuitive visual canvas.

  • Left: The node panel. You can click the image button to select and add different types of task nodes.

  • Middle: The main canvas. You can drag nodes, connect dependencies, and build your workflow on the canvas.

  • Right: The configuration panel. When you select a node or a blank area on the canvas, its corresponding configuration items appear in this panel.

https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/res/Yvenve55peLxaloy/img/ae1091fe-bcec-42bb-9cad-1362ef1609a8.png

Core Operations

  • Global Configuration: In the right-side panel, configure the global settings for the DAG, such as its name, scheduling policy, and alerts.

  • Add and Configure Nodes: Drag the required nodes from the left-side panel to the canvas and configure their basic and advanced settings in the right-side panel.

  • Set Dependencies: Drag the anchor points between nodes to establish upstream and downstream dependencies.

  • Save and Publish: After you design the workflow, save and publish it to the Airflow environment.

Core Concepts and Configuration Details

Global Configuration

In the top navigation bar, click the Global Configuration button to view the global configuration of the DAG.

  • Basic Information:

    • Name: Specifies the DAG ID in Airflow. This ID must be unique in your Airflow environment.

  • Scheduling Configuration:

    • Cron Expression: Defines the periodic scheduling policy for the DAG.

      image.png

    • Start/End Date: Defines the time range during which the DAG can be scheduled.

  • Alert Settings:

    • Configure email alerts for task failures, successes, or retries. You can separate multiple email addresses with commas.

      image.png

    • Prerequisite: You must configure email services in Airflow before you can use email alerts.

    • Template Support: Alert titles and bodies support Jinja templates. You can dynamically insert built-in variables, such as dag and ti. The email body supports the HTML format.

  • Variables:

    • Define global variables that can be used in all tasks within the DAG. Variable values also support Jinja templates.

  • Retry Settings:

    • You can configure the global default retry count and retry interval for failed tasks.

Node Configurations

Each node that you add from the left-side panel has basic and advanced configurations. The advanced configurations are common to all nodes, whereas the basic configurations vary by node type.

Advanced Configurations (General)

  • Alert Configuration: Overrides the global alert settings to define an independent alert policy for the current node.

  • Retry: Overrides the global retry settings to define an independent retry policy for the current node.

  • Resource Pool Configuration: Specifies the Airflow resource pool (Pool) in which the task runs to control task concurrency.

    image

  • Trigger Rule: Defines the execution conditions for the current task, such as "all upstream tasks successful" or "at least one upstream task successful".

    image

Basic Configurations (by Node Type)

The following section describes the basic configurations for some common nodes:

  • Single-Instance SQL

    • Function: Executes a single SQL statement on the specified database instance.

    • Configuration: Select the instance and database, and then write the SQL statement directly or select an existing .sql file in the workspace.

      image

    • Callback Code (Optional): Specifies the Python code that runs after the SQL statement is successfully executed. The main uses are as follows:

      1. Pass Data (XCom): Retrieve SQL query results using the built-in result variable, which is a dictionary that contains a data key, and pass the results to downstream tasks. For example, result['data'][0]['co'] retrieves the value of the column named co in the first row of the result set.

      2. Result Validation: Checks the SQL results. If the conditions are not met, you can throw an exception to fail the task.

        if len(result["data"]) > 10:
            raise Exception("too many data")
  • ADB Spark

    • Function: Submits jobs to the Spark engine of AnalyticDB for MySQL.

    • Configuration: Select the AnalyticDB for MySQL instance and resource group, and then configure the job based on the task type (SQL or BATCH).

      • SQL Task: Write the Spark SQL statement directly or select an .sql file.

        image

      • BATCH Task: Provide the Spark job configuration in JSON format.

        {
          "args": [
            "1000"
          ],
          "className": "org.apache.spark.examples.SparkPi",
          "comments": [
            "-- Here is just an example of SparkPi. Modify the content and run your spark program."
          ],
          "conf": {
            "spark.driver.resourceSpec": "medium",
            "spark.executor.instances": 2,
            "spark.executor.resourceSpec": "medium"
          },
          "file": "local:///tmp/spark-examples.jar",
          "name": "SparkPi"
        }
  • Notebook

    • Function: Runs Notebook files in the workspace.

    • Configuration:

      • Select a Notebook session.

      • Select the path of the Notebook file. The file must be configured in the workspace, and the path must be a workspace file path.

        image

  • Lindorm Spark

    • Function: Submits Lindorm Spark jobs.

    • Configuration:

      • Select a Lindorm instance.

      • Select the job type and configure the job parameters.

        image

  • Lock-Free Data Change

    • Function: Executes data change SQL statements in a lock-free manner on the specified instance and database. The configuration method is the same as that for the Single-Instance SQL node. This node also supports callback code to process execution results.

  • Conditional Branch

    • Function: Determines the workflow path based on different conditions.

    • Configuration: Add multiple branch conditions. Each condition is a Python expression that returns True or False. The expressions support Jinja templates and can reference Airflow variables.

      image

    • Conditional branches have multiple downstream edges. You can drag and drop the edges to set them.

      image

  • SSH Operations

    • Function: Connects to a remote server over SSH and executes commands.

    • Configuration:

      1. Pre-configure the SSH connection information in Airflow's Connections and obtain its Connection ID.

        In the Edit Connection dialog box, set Connection Id to ssh_ecs_default, select SSH for Connection Type, enter 10.0.0.252 for Host, enter root for Username, and then click Save.

      2. In the node configuration, enter the Connection ID and the shell command to be executed.

        image.png

  • Bash Task

    • Function: Executes Bash commands in the local environment.

    • Configuration:

      1. Configure the Bash command to be executed.

      2. Configure the environment variables for the command execution.

        image

  • Time Interval

    • Function: Pauses the workflow for a specified period before it continues to execute subsequent nodes.

  • Wait for Specified Time

    • Function: Waits until a specified time before it continues to execute subsequent nodes. The target time can be dynamically set using the Airflow Jinja template syntax.

  • External Task Sensor

    • Function: Configures external task dependency checks. The workflow waits for an external DAG or task in the same Airflow instance to be completed before it continues execution.

    • Configuration:

      • Upstream DAG Name: The ID of the DAG on which the current DAG depends.

        image.png

      • Upstream Node Name (Optional): The ID of the task on which the current task depends. If you leave this parameter empty, the workflow waits for the entire upstream DAG to be completed.

  • Empty Task

    • Function: A placeholder node that performs no action. You can use it to aggregate multiple upstream branches or as a logical start or end point to clarify the workflow structure.

    • Configuration: None.

  • Data Lake Integration

    • Function: Integrates data from a source database into a destination data lake.

    • Configuration:

      • Select the source database and the destination database.

        image.png

      • Configure other parameters for the data integration task.

        image

Set Dependencies

  • Add Dependencies: Hover the mouse pointer over the edge of a node to display an anchor point. Drag the anchor point from one node to another to create an edge that represents a dependency.

    https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/res/Yvenve55peLxaloy/img/c6d3be23-6d39-44a0-b485-a853e7c3170b.png

  • Delete Dependencies: Click an edge to select it and then press the Delete key.


Publish and Verify

Git Integration (Optional)

If your workspace is associated with a Git repository, you must commit the code to Git before you publish it.

  1. Commit: Commit your changes in the Git panel.

    https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/res/Yvenve55peLxaloy/img/0c49343f-9634-49a3-b3c1-2e173ad1d95d.png

  2. Push: Push the commit to the remote repository.

Deploy to Airflow

Click the Deploy button in the upper-right corner of the editor. The system converts the workflow that you designed in the GUI into Python code and publishes the code to your Airflow environment.

Verify in Airflow

After the deployment is successful, log on to the Airflow UI. A new DAG appears. The DAG ID of the new DAG is the same as the name that you configured in the GUI. The DAG also has a generated tag, which indicates that the DAG was generated by the GUI. You can trigger, monitor, and manage the execution of the DAG in the Airflow UI.