Spark is a general-purpose big data analytics engine. Spark features high performance, ease of use, and widespread use. You can use Spark to perform complex memory analysis and build large, low-latency data analysis applications. DataWorks provides Cloudera's Distribution Including Apache Hadoop (CDH) Spark nodes that you can use to develop and periodically schedule Spark tasks in DataWorks. This topic describes how to create and use a CDH Spark node.
Prerequisites
A workflow is created in DataStudio.
Development operations in different types of compute engines are performed based on workflows in DataStudio. Therefore, before you create a node, you must create a workflow. For more information, see Create a workflow.
An Alibaba Cloud CDH cluster is created and registered to DataWorks.
Before you create a CDH node and use the CDH node to develop a CDH task in DataWorks, you must register a CDH cluster to a DataWorks workspace. For more information, see Register a CDH or CDP cluster to DataWorks.
(Required if you use a RAM user to develop tasks) The RAM user is added to the DataWorks workspace as a member and is assigned the Development or Workspace Administrator role. The Workspace Administrator role has more permissions than necessary. Exercise caution when you assign the Workspace Administrator role. For more information about how to add a member, see Add workspace members and assign roles to them.
A serverless resource group is purchased and configured. The configurations include association with a workspace and network configuration. For more information, see Create and use a serverless resource group.
Limits
Tasks on this type of node can be run on serverless resource groups or old-version exclusive resource groups for scheduling. We recommend that you run tasks on serverless resource groups.
Preparations: Prepare Spark task code and obtain a JAR package
Before you use DataWorks to schedule a CDH Spark task, you must prepare Spark task code in CDH and compile the task code to generate a JAR package. For more information about the preparation of Spark task code, see Overview.
You must upload the obtained JAR package to the DataWorks console. This way, DataWorks can periodically schedule CDH Spark tasks.
Step 1: Create a CDH Spark node
Go to the DataStudio page.
Log on to the DataWorks console. In the top navigation bar, select the desired region. In the left-side navigation pane, choose . On the page that appears, select the desired workspace from the drop-down list and click Go to Data Development.
On the DataStudio page, find the desired workflow, right-click the workflow name, and then choose
.In the Create Node dialog box, configure the Engine Instance, Path, and Name parameters.
Click Confirm. Then, you can use the created node to develop and configure tasks.
Step 2: Create and reference a CDH JAR resource
You can reference a JAR package resource in the created CDH Spark node, write code for the node, and then use the spark-submit command to commit a task on the node. Perform the following operations to create and reference a CDH JAR resource:
Create a CDH JAR resource.
Find the desired workflow and click CDH. Right-click Resource and choose
. In the Create Resource dialog box, click Upload to upload a required file.Reference the CDH JAR resource.
Go to the configuration tab of the created node.
Find the resource that you want to reference under Resource in the CDH folder, right-click the resource name, and then select Insert Resource Path. In this example, a resource named
spark-examples_2.11_2.4.0.jar
is used.If the clause that is in the
##@resource_reference{""}
format appears on the configuration tab of the node, the resource is successfully referenced. Sample code:##@resource_reference{"spark_examples_2.11_2.4.0.jar"} spark_examples_2.11_2.4.0.jar
Modify the code of the CDH Spark node and add the spark-submit command. The following code shows an example.
ImportantDo not add comments when you write code for a CDH Spark node. If you add comments, an error is reported when you run a task on the CDH Spark node. You must refer to the following sample code to edit the code of a CDH Spark node.
##@resource_reference{"spark-examples_2.11-2.4.0.jar"} spark-submit --class org.apache.spark.examples.SparkPi --master yarn spark-examples_2.11-2.4.0.jar 100
Parameter description:
org.apache.spark.examples.SparkPi: the main class of the task in the compiled JAR package.
spark-examples_2.11-2.4.0.jar: the name of the JAR package that you uploaded.
Step 3: Configure task scheduling properties
If you want the system to periodically run a task on the node, you can click Properties in the right-side navigation pane on the configuration tab of the node to configure task scheduling properties based on your business requirements.
Configure basic properties for the task. For more information, see Configure basic properties.
Configure the scheduling cycle, rerun properties, and scheduling dependencies. For more information, see Configure time properties and Configure same-cycle scheduling dependencies.
NoteYou must configure the Rerun and Parent Nodes parameters on the Properties tab before you commit the task.
Configure resource properties for the node. For more information, see Configure the resource property. If the node that you created is an auto triggered node and you want the node to access the Internet or a virtual private cloud (VPC), you must select the resource group for scheduling that is connected to the node. For more information, see Network connectivity solutions.
Step 4: Debug task code
Optional. Select a resource group and assign custom parameters to variables.
Click the icon in the top toolbar of the configuration tab of the node. In the Parameters dialog box, select the resource group that you want to use to debug and run task code.
If you use scheduling parameters in your task code, assign the scheduling parameters to variables as values in the task code for debugging. For more information about the value assignment logic of scheduling parameters, see What are the differences in the value assignment logic of scheduling parameters among the Run, Run with Parameters, and Perform Smoke Testing in Development Environment modes?
Save and execute the SQL statements.
In the top toolbar, click the icon to save the SQL statements. Then, click the icon to execute the SQL statements.
Optional. Perform smoke testing.
You can perform smoke testing on the task in the development environment when you commit the task or after you commit the task. For more information, see Perform smoke testing.
What to do next
Commit and deploy the task.
Click the Save icon in the toolbar to save the task.
Click the Submit icon in the top toolbar to commit the task.
In the Submit dialog box, configure the Change description parameter.
Click Confirm.
If you use a workspace in standard mode, you must deploy the task in the production environment after you commit the task. To deploy a task on a node, click Deploy in the top navigation bar of the DataStudio page. For more information, see Deploy tasks.
View the task.
Click Operation Center in the upper-right corner of the configuration tab of the corresponding node to go to Operation Center in the production environment.
View the scheduled task. For more information, see View and manage auto triggered tasks.
To view more information about the task, click Operation Center in the top navigation bar of the DataStudio page. For more information, see Overview.
Scenarios
DataWorks provides comprehensive job scheduling and monitoring features to ensure that your Spark jobs can be successfully submitted to CDH clusters for running. This simplifies the O&M process of jobs and ensures efficient resource management. The following information shows specific use scenarios of Spark tasks:
Data analysis: Use Spark SQL, Dataset, and DataFrame APIs to aggregate, filter, and convert complex data and quickly gain insight into data.
Stream processing: Use Spark Streaming to process real-time data streams and perform instant analysis and decision making.
Machine learning: Use Spark MLlib to preprocess data, extract features, and perform model training and evaluation.
Large-scale data extract, transform, and load (ETL): Perform ETL operations on large datasets to prepare data for data warehouses or other storage systems.