Lindorm Spark node

更新时间:
复制 MD 格式

In DataWorks, you can use a Lindorm Spark node to develop and periodically schedule Lindorm Spark tasks. This topic describes the workflow for developing tasks on a Lindorm Spark node.

Background information

Lindorm is a distributed computing service based on a cloud native architecture. It supports Community Edition computing models, is compatible with Spark APIs, and is deeply integrated with the Lindorm storage engine. It leverages the features and indexing capabilities of the underlying data storage to complete distributed jobs efficiently, making it suitable for scenarios such as massive data processing, interactive analysis, machine learning, and graph computing.

Prerequisites

  • (Optional, for RAM users) The RAM user for task development has been added to the corresponding workspace and granted the Development or Workspace Administrator role. The Workspace Administrator role grants extensive permissions, so assign it with caution. For more information, see Add members to a workspace.

    Note

    If you are using an Alibaba Cloud account, you can skip this step.

  • A Lindorm instance has been created and bound to your DataWorks workspace. For more information, see Bind a Lindorm computing resource.

Create a Lindorm Spark node

For instructions on how to create a node, see Create a Lindorm Spark node.

Develop a Lindorm Spark node

Depending on the language (Java/Scala or Python), you can configure the node to reference the corresponding JAR package or .py file.

Node content (Java/Scala)

This section uses the SparkPi sample program as an example to demonstrate how to configure and use a Lindorm Spark node in DataWorks.

Upload a JAR package

Upload the sample JAR package to LindormDFS and copy its storage path. This path is required later to configure the node.

  1. Prepare the sample JAR package.

    Download the sample spark-examples_2.12-3.3.0.jar package to your computer.

  2. Upload the JAR package to LindormDFS.

    1. Log on to the Lindorm console. In the Instances list for the corresponding region, find the Lindorm instance that you created.

    2. Click the instance Name to open the Instance Details page.

    3. In the left navigation bar, click Compute Engines to go to the Compute Engines page.

    4. On the Job Management tab, click Upload resources to open the Upload resources page.

    5. Click the dotted-line box, find the JAR package that you downloaded, and then click Open.

    6. Click Upload to upload the JAR package.

  3. Copy the storage path of the sample JAR package.

    On the Job Management tab, find the JAR package that you uploaded. It appears under the Upload Resource button. Click the image icon to the left of the file name to copy the storage path of the JAR package in LindormDFS.

Configure node content

Configure the Lindorm Spark node with the following parameters.

Language

Parameter

Description

Java/Scala

Main JAR Resource

Enter the storage path of the sample JAR package that you copied in the Upload a JAR package step.

Main Class

The main class of the task in the compiled JAR package. For the sample code, the main class is org.apache.spark.examples.SparkPi.

Parameter

Enter the parameters to pass to the code. You can configure a dynamic parameter by using the ${var} format.

Configuration Item

Configure Spark runtime parameters in this section. For more information about Spark properties, see Job configuration instructions.

Note

You can set global Spark parameters when you bind a Lindorm computing resource.

Node content (Python)

This section uses a sample Spark program that calculates pi as an example to demonstrate how to configure and use a Lindorm Spark node in DataWorks.

Upload a Python resource

Upload the sample Python file to LindormDFS and copy its storage path. This path is required later to configure the node.

  1. Create a Python file.

    Save the following Python script as a local file named pi.py.

    import sys
    from random import random
    from operator import add
    
    from pyspark.sql import SparkSession
    
    if __name__ == "__main__":
        """
            Usage: pi [partitions]
        """
        spark = SparkSession\
            .builder\
            .appName("PythonPi")\
            .getOrCreate()
    
        partitions = int(sys.argv[1]) if len(sys.argv) > 1 else 2
        n = 100000 * partitions
    
        def f(_: int) -> float:
            x = random() * 2 - 1
            y = random() * 2 - 1
            return 1 if x ** 2 + y ** 2 <= 1 else 0
    
        count = spark.sparkContext.parallelize(range(1, n + 1), partitions).map(f).reduce(add)
        print("Pi is roughly %f" % (4.0 * count / n))
    
        spark.stop()
    
  2. Upload the Python file to LindormDFS.

    1. Log on to the Lindorm console. In the Instances list for the corresponding region, find the Lindorm instance that you created.

    2. Click the instance Name to open the Instance Details page.

    3. In the left navigation bar, click Compute Engines to go to the Compute Engines page.

    4. On the Job Management tab, click the Upload resources button to open the Upload resources page.

    5. Click the dotted-line box, find the Python file that you created, and then click Open.

    6. Click Upload to upload the Python file.

  3. Copy the storage path of the sample Python file.

    On the Job Management tab, find the Python file that you uploaded. It appears under the Upload Resource button. Click the image icon to the left of the file name to copy the storage path of the Python file in LindormDFS.

Configure node content

Configure the Lindorm Spark node with the following parameters.

Language

Parameter

Description

Python

Main Package

Enter the storage path of the sample Python file that you copied in the Upload a Python resource step.

Parameter

Enter the parameters to pass to the code. You can configure a dynamic parameter by using the ${var} format.

Configuration Item

You can configure Spark runtime parameters in this section. For more information about Spark properties, see Job configuration instructions.

Debug the Lindorm Spark node

  1. Configure debugging properties.

    In the Run Configuration pane on the right, configure the Compute Resource, Lindorm Resource Group, and Resource Group. The following table describes these parameters.

    Parameter

    Description

    Compute Resource

    Select the Lindorm computing resource that is bound to your workspace.

    Lindorm Resource Group

    Select the Lindorm resource group that you specified when you bound the Lindorm computing resource.

    Resource Group

    Select the resource group for which the connectivity test was passed when you bound the Lindorm Spark computing resource.

    Script Parameters

    If you define dynamic parameters in the ${ParameterName} format, specify the corresponding Script Parameters and Parameter name in the Parameter Value section. When the task runs, the variables are dynamically replaced with their actual values. For more information, see Sources and expressions of scheduling parameters.

  2. Debug and run the node.

    To run the node, click Save and then Run.

What to do next

  • Configure scheduling for a node: To run a node on a periodic schedule, go to the Scheduling Settings pane to set the Scheduling Policy and configure related properties.

  • Deploy a node: To run the task in the production environment, click the image icon to deploy it. A node is periodically scheduled only after it is deployed to the production environment.

  • Data Map (Lindorm table data): Use Data Map to collect Lindorm metadata.