Help Center> Cloud Stream Service> User Guide> Operation Guide> Job Management> Creating a Flink Streaming SQL Edge Job

Creating a Flink Streaming SQL Edge Job

This section describes how to create a Flink streaming SQL edge job. The Flink streaming SQL edge job analyzes and processes data near where data is generated when a large amount of data is generated on edge devices, which reduces the amount of data to be migrated to the cloud and improves real-time data processing.

Such a job is a combination of CS and IEF. Stream computing applications are deployed on edge nodes to realize real-time data processing at the edge, not on the cloud. CS then edits and delivers the stream processing job to edge nodes for execution. This helps you quickly and accurately analyze and process streaming data at the edge in real time.

Prerequisites

  • IEF has been enabled.
  • An ECS has been created. The recommended configuration is 4 vCPUs and 8 GB or higher memory. For details about how to create an ECS, see Purchasing and Logging In to a Linux ECS in the Elastic Cloud Server Getting Started Guide.
  • Edge nodes have been created and successfully managed. For details, see section "Edge Node" in the Intelligent EdgeFabric User Guide.
  • The edge stream computing application edge-cs has been deployed. For details, see section "Application Deployment" in the Intelligent EdgeFabric User Guide.

    If you deploy an application using a system template, ensure that the container specification is not less than the default value. Otherwise, the instance deployment fails.

Creating a Flink Streaming SQL Edge Job

  1. You can create a Flink streaming SQL job on any of the three pages: Overview, Job Management and Edit.

    • Overview
      1. In the navigation tree on the left pane of the CS management console, click Overview to switch to the Overview page.
        Figure 1 Creating a job on the Overview page
      2. Click Create Job to switch to the Create Job dialog box.
    • Job Management
      1. In the navigation tree on the left pane of the CS management console, choose Job Management to switch to the Job Management page.
        Figure 2 Creating a job on the Job Management page
      2. Click Create Job to switch to the Create Job dialog box.
    • Edit
      1. In the navigation tree on the left pane of the CS management console, choose Job Management to switch to the Job Management page.
      2. In the row where a created Flink streaming SQL edge job is located, click Edit under Operation to enter the Edit page.
        Figure 3 Creating a Flink streaming SQL edge job on the Edit page
      3. Click More > Save As. The Save Job As dialog box is displayed.

  2. Specify job parameters.

    Figure 4 Creating a Flink streaming SQL edge job
    Table 1 Job parameters

    Parameter

    Description

    Type

    Set Type to Flink Streaming SQL Edge Job. You will need to start jobs by compiling SQL statements.

    Name

    Name of a job. Enter 1 to 57 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

    NOTE:

    The job name must be globally unique.

    Description

    Description of a job. It can be up to 512 characters long.

    Template

    You can select a sample template or a custom job template. For details about templates, see Job Template.

  3. For Enterprise Project, select an enterprise project that you created on the Enterprise Management console.

    For details about how to create an enterprise project on the Enterprise Management console, see Creating an Enterprise Project in the Enterprise Management User Guide.

    The system also has a built-in enterprise project, default. If you do not select an enterprise project for the job, the default project is used instead.

    During job creation, if the job is successfully bound to an enterprise project, the job has been created. If the binding fails, the system sends an alarm and the job fails to be created.

    When you delete a job, the association between the job and its enterprise project is automatically deleted as well.

  4. (Optional) Add tags for the job. In this step, configure the parameters in the following table as required. The tags are optional. If you do not need tags, skip this step.

    Table 2 Tag parameters

    Parameter

    Description

    Tag key

    You can perform the following operations:

    • Click the text box and select a predefined tag key from the drop-down list.
      NOTE:

      To add a predefined tag, you need to create one on TMS and select it from the Tag key drop-down list. You can click View Predefined Tag to enter the Predefined Tag page of TMS. Then, click Create Tag to create a predefined tag. For details, see section Creating Predefined Tags in the Tag Management Service User Guide.

    • Enter a tag key in the text box.
      NOTE:

      A tag key contains a maximum of 36 characters. The first and last characters cannot be spaces. The following characters are not allowed: =*,<>\|/

    Tag value

    You can perform the following operations:

    • Click the text box and select a predefined tag value from the drop-down list.
    • Enter a tag value in the text box.
      NOTE:

      A tag value contains a maximum of 43 characters. The first and last characters cannot be spaces. The following characters are not allowed: =*,<>\|/

    • A maximum of 10 tags can be added.
    • Only one tag value can be added to a tag key.
    • The key name must be unique in the same resource.

  5. Click OK to enter the Edit page.
  6. Edit a job.

    Edit the Flink streaming SQL edge job as required to process data generated on edge devices. Currently, type can be set to edgehub, and encode can be set to json or csv. For details about the SQL syntax, see the Cloud Stream Service SQL Syntax Reference.

    Example: Export the names and scores of students whose scores are greater than or equal to 80.

    create source stream student_scores(name string, score int) with ( 
        type = "edgehub", 
        topic = "abc",    
        encode = "json", 
        json_config = "score = student.score; name=student.name" 
      ); 
      create sink stream excellent_students(name string, score int) with ( 
        type = "edgehub", 
        topic = "abcd", 
        encode = "csv", 
        field_delimiter = "," 
      ); 
      insert into excellent_students select name, score from student_scores where score >= 80;

  7. Click Check Semantics.

    • You can only debug, submit, or start a job after semantic verification succeeds.
    • If verification is successful, the message "The SQL semantic verification is complete. No error." will be displayed.
    • If verification fails, a red "X" mark will be displayed in front of each SQL statement that produced an error. You can move the cursor to the "X" mark to view error details and change the SQL statement as prompted.

  8. Set job running parameters.

    Figure 5 Setting running parameters of the Flink streaming SQL edge job
    Table 3 Job running parameter description

    Parameter

    Description

    Parallelism

    Number of tasks where CS jobs can simultaneously run

    NOTE:

    The value of Parallelism must not exceed four times of (Number of SPUs – 1).

    Edge node to which the job belongs

    Select the edge node that the job belongs to.

    • Your own edge computing devices serve as the edge nodes run edge applications, process your data, and work with cloud applications securely and conveniently. An edge application is a functional module that runs on an edge node.
    • CS jobs can be deployed on multiple edge nodes so that it can work with IEF.

  9. Click Save.
  10. Click Submit. On the displayed Job Configurations page, click OK to submit and start the job.

    After you click OK to submit a job, the system automatically switches to the Job Management page, and the created job is displayed in the job list. You can view the job status in the Status column. After a job is successfully submitted, the job status will change from Submitting to Running.

    If the job status is Submission failed or Running exception, the job submission failed or the job did not execute successfully. In this case, you can move the cursor over the status icon in the Status column of the job list to view the error details. You can click to copy these details. After handling the fault based on the provided information, resubmit the job.

    Other buttons are as follows:

    • Debug: indicates to perform job debugging. For details, see Debugging a Job.
    • Format SQL: indicates to format the SQL statement. After clicking Format SQL, you need to edit SQL statements again.
    • More > Modify Name and Description: indicates to modify the job name and description.
    • More > Save As: indicates to save the created job as a new job.
    • More > Set as Template: indicates to set the created job as a job template.
    • More > Theme Settings: indicates to set the theme related parameters, including Font Size, Wrap, and Page Style.
    • More > Help: The help center provides SQL syntax reference for users.

Verifying Job Running

  1. On IEF, log in to any node that must interwork with edge nodes and install Mosquitto.

    To download Mosquitto, visit https://mosquitto.org/download/.

  2. In the example, the following command is used to send data to edge nodes.

    mosquitto_pub -h Edge node IP address -t abc -m '{"student":{"score":90,"name":"1bc2"}}';

    In the command, abc refers to the topic name defined in the job.

  3. Open a new window and run related commands to monitor the output. Enter the following command to query the names and scores of students whose scores are greater than or equal to 80.

    mosquitto_sub -h Edge node IP address -t abcd

    In the command, abcd refers to the topic name defined in the job.