Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Developing a Python Job

Updated on 2025-02-18 GMT+08:00

This section describes how to develop and execute a Python job using DataArts Factory.

Preparing the Environment

  • An ECS named ecs-dgc has been created.
    NOTE:

    In this example, the ECS uses the CentOS 8.0 64bit with ARM (40 GB) public image and the Python environment. You can log in to the ECS and run the python command to check the Python environment.

  • You have enabled the DataArts Migration incremental package and created a CDM cluster named cdm-dlfpyhthon. The cluster provides an agent for the DataArts Factory module to communicate with the ECS.
  • Ensure that the ECS can communicate with the CDM cluster, which depends on the following conditions:
    • If the CDM cluster and the ECS are in the same region, VPC, subnet, and security group, they can communicate with each other by default. If they are in the same VPC but in different subnets or security groups, you must configure routing rules and security group rules. For details about how to configure routing rules, see Configuring Routing Rules. For details about how to configure security group rules, see Configuring Security Group Rules.
    • If the CDM cluster and the ECS are in different regions, a public network or a dedicated connection is required for enabling communication between the CDM cluster and the cloud service. If the Internet is used for communication, ensure that an EIP has been bound to the CDM cluster, the host where the data source is located can access the Internet, and the port has been enabled in the firewall rules.
    • The ECS and the CDM cluster belong to the same enterprise project. If they do not, you can modify the enterprise project of the workspace.

Constraints

  • Python nodes support script parameters and job parameters.
  • This section uses Python3 as an example.

Creating an ECS Data Connection

Before developing a Python script, you need to create a connection to the ECS.

  1. Log in to the DataArts Studio console by following the instructions in Accessing the DataArts Studio Instance Console.
  2. On the DataArts Studio console, locate a workspace and click Management Center.
  3. On the displayed Manage Data Connections page, click Create Data Connection.
  4. Configure parameters by referring to Table 1 and create a data connection named ecs.

    Table 1 Host Connection parameters

    Parameter

    Mandatory

    Description

    Data Connection Type

    Yes

    Host Connection is selected by default and cannot be changed.

    Name

    Yes

    Name of the data connection to create. Data connection names can contain a maximum of 100 characters. They can contain only letters, digits, underscores (_), and hyphens (-).

    Tag

    No

    Attribute of the data connection to create. Tags make management easier.
    NOTE:

    The tag name can contain only letters, digits, and underscores (_) and cannot start with an underscore (_) or contain more than 100 characters.

    Applicable Modules

    Yes

    Select the modules for which this connection is available.

    Basic and Network Connectivity Configuration

    Host Address

    Yes

    IP address of the Linux host

    For details, see Viewing Details About an ECS.

    Agent

    Yes

    CDM cluster used as an agent. If no CDM cluster is available, create one first by referring to Creating a CDM Cluster.

    NOTE:
    • If a CDM cluster functions as the agent for a data connection in Management Center, the cluster supports a maximum of 200 concurrent active threads. If multiple data connections share an agent, a maximum of 200 SQL, Shell, and Python scripts submitted through the connections can run concurrently. Excess tasks will be queued. You are advised to plan multiple agents based on the workload.

    • When scheduling shell or Python scripts, the agent accesses the ECS. If shell and Python scripts are scheduled frequently, the ECS adds the private IP address of the agent to the blocklist. To ensure normal job scheduling, you are advised to use the root user of the ECS to add the private IP address bound to the agent (CDM cluster) to the /etc/hosts.allow file.

      For details about how to obtain the private IP address of the CDM cluster, see Viewing and Modifying CDM Cluster Configurations.

    Port

    Yes

    SSH port number of the host.

    By default, port 22 is used to log in to a Linux host. If the port number has been changed, you can obtain the new port number from the port field in the /etc/ssh/sshd_config file.

    KMS Key

    Yes

    KMS key used to encrypt and decrypt data source authentication information. Select a default or custom key.
    NOTE:

    When you use KMS for encryption through DataArts Studio or KPS for the first time, the default key dlf/default or kps/default is automatically generated. For more information about default keys, see What Is a Default Master Key?.

    Data Source Authentication and Other Function Configuration

    Username

    Yes

    Username for logging in to the host

    Login Mode

    Yes

    Mode for logging in to the host

    • Key Pair
    • Password

    Key Pair

    Yes

    This parameter is available only when Login Mode is set to Key Pair.

    If Key Pair is the login mode of the host, you need to obtain the private key file, upload it to OBS, and select an OBS path.

    NOTE:

    The uploaded private key must match the public key configured on the host. For details, see Application Scenarios for Using Key Pairs.

    Key Pair Password

    Yes

    If no password is set for the key pair, you do not need to set this parameter.

    Password

    Yes

    This parameter is available only when Login Mode is set to Password.

    If the login mode of the host is to use a password, enter a login password.

    Host Connection Description

    No

    Descriptive information about the host connection

    Figure 1 Creating a host connection

    NOTE:

    The key parameters are as follows:

  5. Click Test to test connectivity of the data connection. If the test fails, the data connection cannot be created.
  6. After the test is successful, click OK to create the data connection.

Developing a Python Script

  1. Choose DataArts Factory > Develop Script and create a Python script named python_test.

    Figure 2 Creating a Python script

  2. Select a Python version (for example, Python 3) and host connection, and set input parameters as needed.

    NOTE:

    The parameters will be transferred to the Python script when the script is executed. The parameters are separated by spaces, for example, Microsoft Oracle. The parameters must be referenced by the Python script. Otherwise, the parameters are invalid.

  3. Edit Python statements in the editor.

    This example defines a string template for saving company information and uses the template to output information about different companies.
    import sys
    Company_Name1=sys.argv[1]
    Company_Name2=sys.argv[2]
    template='No.:{:0>9s} \t CompanyName: {:s} \t Website: https://www.{:s}.com'
    context1=template.format('1',Company_Name1,Company_Name1.lower())
    context2=template.format('2',Company_Name2,Company_Name2.lower())
    print(context1)
    print(context2)
    NOTE:
    • The script development area in Figure 3 is a temporary debugging area. After you close the script tab, the development area will be cleared.
    • Connection: Select the data connection created in Creating an ECS Data Connection.
    Figure 3 Editing the Python statements

  4. Click Save and then Submit.
  5. Click Execute to execute the Python statements.
  6. View the script execution result.

    Figure 4 Viewing the script execution result

Referencing the Python Script in a Job

  1. Create a job.
  2. Select a Python node and configure the node properties.

    Select the created Python script and set the node parameters. Set Script Parameters.
    NOTE:

    The parameters will be transferred to the Python statement when the statement is executed. The parameters are separated by spaces, for example, Microsoft Oracle. The parameters must be referenced by the Python statement. Otherwise, the parameters are invalid.

    Figure 5 Configuring properties of the Python node

  3. Click Test and view the job running result.

    Figure 6 Checking the job execution result

  4. Click Save. The job configuration is complete.
  5. Click Submit. After a version is submitted, the job can be scheduled.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback