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.
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.
-
Prepare the sample JAR package.
Download the sample spark-examples_2.12-3.3.0.jar package to your computer.
-
Upload the JAR package to LindormDFS.
-
Log on to the Lindorm console. In the Instances list for the corresponding region, find the Lindorm instance that you created.
-
Click the instance Name to open the Instance Details page.
-
In the left navigation bar, click Compute Engines to go to the Compute Engines page.
-
On the Job Management tab, click Upload resources to open the Upload resources page.
-
Click the dotted-line box, find the JAR package that you downloaded, and then click Open.
-
Click Upload to upload the JAR package.
-
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
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.
|
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.
-
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()
-
Upload the Python file to LindormDFS.
-
Log on to the Lindorm console. In the Instances list for the corresponding region, find the Lindorm instance that you created.
-
Click the instance Name to open the Instance Details page.
-
In the left navigation bar, click Compute Engines to go to the Compute Engines page.
-
On the Job Management tab, click the Upload resources button to open the Upload resources page.
-
Click the dotted-line box, find the Python file that you created, and then click Open.
-
Click Upload to upload the Python file.
-
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
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
-
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.
|
-
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
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.