SSH node

更新时间:
复制 MD 格式

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

  • A workflow is created.

    You must create a workflow before you create a node. For more information, see Create a workflow.

  • 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.

    Note

    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.

  • (Optional) If you use a RAM user for task development, the RAM user must be added to the workspace and granted the Development or Workspace Administrator role. The Workspace Administrator role provides extensive permissions. Grant this role with caution. For more information about how to add members to a workspace and grant roles to the members, 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

  1. 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 Data Development and O&M > Data Development. On the page that appears, select the desired workspace from the drop-down list and click Go to Data Development.

  2. Right-click the target workflow and choose Create Node > SSH.

  3. 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.

Note

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

If you need to run the node task periodically, click the scheduling properties tab in the right-side navigation pane of the node editor page and configure scheduling properties for the task based on your business requirements. For more information, see Overview of task scheduling properties.

Note

Before you can commit the node, you must specify the Rerun attribute property and Parent Nodes for the node.

Step 4: Debug the task

To debug the task and check whether it runs as expected:

  1. (Optional) Select a resource group for scheduling and specify values for custom parameters.

    • Click the 高级运行 icon in the toolbar. In the Parameter dialog box, select the resource group for scheduling that you want to use for debugging.

    • If your task code uses scheduling parameters, you can specify values for them for debugging. For more information about how to specify parameter values, see Debug a task.

  2. Save and run the task code.

    Click the 保存 icon in the toolbar to save the task code and click the 运行 icon to run the task.

  3. (Optional) Perform smoke testing.

    To check if the scheduled task runs as expected in the development environment, you can perform smoke testing when you commit the node or after it is committed. For more information, see Perform smoke testing.

Step 5: Commit and deploy the task

After you configure the node task, you must commit and deploy it. Once deployed, the node runs on a schedule based on its scheduling properties.

  1. Click the 保存 icon in the toolbar to save the node.

  2. Click the 提交 icon in the toolbar to commit the node task.

    In the Submission dialog box, enter a Change Description. You can also select whether to perform a code review after you commit the node.

    Note
    • Before you can commit the node, you must specify the Rerun attribute property and Parent Nodes for the node.

    • Code review helps ensure code quality and prevents task errors that may result from deploying incorrect code to the production environment without being reviewed. If you enable code review, the submitted node code can be deployed only after reviewers approve it. For more information, see Code review.

If you use a workspace in standard mode, you must click Deploy in the upper-right corner of the node editor page after you commit the task. This operation deploys the task to the production environment. For more information, see Deploy tasks.

What's next

After the task is published, it runs on a recurring schedule based on the node's configuration. Click O&M in the upper-right corner of the node configuration tab to go to Operation Center, where you can view the scheduling and running status of the task. For more information, see Manage recurring 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.