SSH node
The SSH node in DataWorks allows you to specify an SSH data source to remotely access a host and run scripts on it. For example, you can use an SSH node to remotely access an Elastic Compute Service (ECS) instance from DataWorks and run scripts on the instance as a recurring task. This topic describes how to develop tasks using an SSH node.
Usage notes
-
When you use an SSH node to start a process on a remote host, if the SSH node task exits unexpectedly, for example, due to a timeout, the process on the remote host is not affected. DataWorks does not send a command to terminate the process.
-
SSH nodes support standard Shell syntax but do not support interactive syntax.
-
When you use an SSH node to remotely run a script on an ECS instance, temporary files are created on the instance. Ensure that the ECS instance has sufficient disk space and that the maximum file count limit meets your requirements.
-
Avoid having multiple tasks operate on the same file simultaneously. Otherwise, the SSH node may fail.
Prerequisites
-
The business process has been created.
Data Studio performs engine-specific development operations based on business flows. Before creating a node, create a business flow first. For more information, see Create a business flow.
-
An SSH data source is created.
Before you can develop and schedule recurring tasks with an SSH node, you must create an SSH data source to access your SSH server. To create a data source, see SSH data source.
NoteSSH nodes support only SSH data sources created with a JDBC connection string. To prevent task failures, ensure that the data source has network connectivity to the resource group.
-
(Optional; required for Resource Access Management (RAM) users) The RAM user used for task development has been added to the target workspace and assigned either the Development or Workspace Administrator role (which grants broad permissions—assign with caution). For more information about adding members and granting permissions, see Add members to a workspace.
Limitations
-
You can run SSH tasks on Serverless resource groups. For more information about how to purchase and use Serverless resource groups, see Use Serverless resource groups.
-
Supported regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Zhangjiakou), China (Ulanqab), China (Shenzhen), China (Hong Kong), Japan (Tokyo), Singapore, Malaysia (Kuala Lumpur), Indonesia (Jakarta), Germany (Frankfurt), UK (London), US (Silicon Valley), and US (Virginia).
-
The maximum code length for an SSH node is
128 KB.
Step 1: Create an SSH node
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.
-
Right-click the target workflow and choose .
-
In the Create Node dialog box, enter a Name for the node and click OK. After the node is created, you can develop and configure the task.
Step 2: Develop an SSH task
(Optional) Select an SSH data source
If your workspace has multiple SSH data sources, you must select the appropriate one in the SSH node editor. If only one SSH data source exists, it is selected by default.
SSH nodes support only SSH data sources created with a JDBC connection string. To prevent task failures, ensure that the data source has network connectivity to the resource group.
Simple example
Write your code in the code editor of the SSH node. The following code is an example.
# 1. Prepare the environment.
# On the remote host, find the file that you want to run. For example, a file named nihao.sh exists in the /tmp directory of the remote host.
# For testing purposes, you can run the following command in the SSH node to create the nihao.sh file.
echo "echo nihao,dataworks" >/tmp/nihao.sh
# 2. Use the SSH node to run the file on the remote host.
# Use the DataWorks SSH node to run the /tmp/nihao.sh file.
sh /tmp/nihao.sh
Use scheduling parameters
DataWorks provides Scheduling Parameter to pass dynamic values for recurring tasks. You can define variables in your code in the ${variable_name} format and then assign values to the variables in the Scheduling configuration > Scheduling Parameter section in the right-side pane. For more information about supported formats and configuration details, see Supported formats of scheduling parameters and Configure and use scheduling parameters.
The following example shows how to use scheduling parameters in an SSH node.
# Goal: Write the SSH node execution time to the /tmp/sshnode.log file every day.
# Implementation: Use the ${myDate} variable and assign it the value $[yyyy-mm-dd hh24:mi:ss]. This writes the execution time of the SSH node to the file.
echo ${myDate} >/tmp/sshnode.log
cat /tmp/sshnode.log
Step 3: Configure task scheduling
To periodically run the node task, click Scheduling on the right side of the node editing page and configure scheduling settings based on your needs. For more information, see Overview of task scheduling properties.
You must configure the node’s Rerun attribute and Parent Nodes before you can submit the node.
Step 4: Test task code
Perform the following test operations as needed to verify that the task behaves as expected.
-
(Optional) Select a resource group and assign custom parameter values.
-
Click the
icon in the toolbar. In the Parameter dialog box, select the schedule resource group for testing. -
If your task code uses scheduling parameter variables, assign values to them here for testing. For more information about parameter assignment logic, see Task debugging process.
-
-
Save and run the task code.
Click the
icon in the toolbar to save your task code. Then click the
icon to run the task. -
(Optional) Perform smoke testing.
To run smoke testing in the development environment and verify that the scheduled node task executes as expected, perform smoke testing either during or after node submission. For more information, see Perform smoke testing.
Step 5: Submit and publish the task
After configuring the node task, submit and publish it. Once published, the node runs periodically based on its scheduling configuration.
-
Click the
icon in the toolbar to save the node. -
Click the
icon in the toolbar to submit the node task.In the Submission dialog box, enter a Change Description. Optionally, choose whether to require code review after submission.
Note-
You must configure the node’s Rerun attribute and Parent Nodes before you can submit the node.
-
Code review helps ensure code quality and prevents errors caused by unreviewed code being published directly to production. If code review is enabled, the submitted node code must be approved by reviewers before it can be published. For more information, see Code review.
-
If you are using a workspace in standard mode, after successfully submitting the task, click Publish in the upper-right corner of the node editing page to deploy the task to the production environment. For more information, see Publish a task.
Next steps
Task operations: After a task is committed and published, it runs periodically based on the node's configuration. You can click O&M in the top-right corner of the node editing page to go to the Operation Center and view the scheduling and running status of the scheduled task. For more information, see Managing Scheduled Tasks.
Related documentation
To learn about implementing load balancing and high availability for SSH nodes, see Implement load balancing and high availability for SSH nodes.