Creating a Job

Function

This API is used to create a job. A job consists of one or more nodes, such as Hive SQL, CS Job, and CDM Job nodes. DLF supports two types of jobs: batch jobs and real-time jobs.

URI

  • URI format

    POST /v1/{project_id}/jobs

  • Parameter description
    Table 1 URI parameter description

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request Message

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

workspace

No

String

Workspace ID.

  • If this parameter is not set, data in the default workspace is queried by default.
  • If you need to query data in other workspaces, this header must be carried.
Table 3 Parameter description

Parameter

Mandatory

Type

Description

name

Yes

String

Name of the job. It contains a maximum of 128 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed. The job name must be unique.

nodes

Yes

List<Node>

Node definition. For details, see Table 4.

schedule

Yes

Schedule data structure

Scheduling configuration. For details, see Table 5.

params

No

List<Param>

Job parameter definition. For details, see Table 6.

directory

No

String

Directory for saving the job. The value must be an existing directory, for example, /dir/a/. The default value is the root directory.

jobType

Yes

String

Job type. The options are as follows:

  • REAL_TIME: real-time processing
  • BATCH: batch processing

basicConfig

No

BasicConfig data structure

Basic job information. For details, see Table 28.

Table 4 Node data structure description

Parameter

Mandatory

Type

Description

name

Yes

String

Name of the node. It contains a maximum of 128 characters. Only letters, digits, hyphens (-), underscores (_), and periods (.) are allowed. Names of the nodes in a job must be unique.

type

Yes

String

Node type. The options are as follows:

  • Hive SQL: Runs Hive SQL scripts.
  • Spark SQL: Runs Spark SQL scripts.
  • DWS SQL: Runs DWS SQL scripts.
  • DLI SQL: Runs DLI SQL scripts.
  • Shell: Runs shell SQL scripts.
  • CDM Job: Runs CDM jobs.
  • DIS Transfer Task: Creates DIS dump tasks.
  • CS Job: Creates and starts CloudStream jobs.
  • CloudTable Manager: Manages CloudTable tables, including creating and deleting tables.
  • OBS Manager: Manages OBS paths, including creating and deleting paths.
  • REST API: Sends REST API requests.
  • SMN: Sends short messages or emails.
  • MRS Spark: Runs Spark jobs of MRS.
  • MapReduce: Runs MapReduce jobs of MRS.
  • DLI Spark: Runs Spark jobs of DLF.
  • RDS SQL: Transfers SQL statements to RDS for execution.

location

Yes

Location data structure

Location of a node on the job canvas. For details, see Table 7.

preNodeName

No

List<String>

Name of the previous node on which the current node depends.

conditions

No

List<Condition>

Node execution condition. Whether the node is executed or not depends on the calculation result of the EL expression saved in the expression field of condition. For details, see Table 8.

properties

Yes

List data structure

Node property. Each type of node has its own property definition, as shown below:

pollingInterval

No

Int

Interval at which node running results are checked.

Unit: second; value range: 1 to 60

Default value: 10

maxExecutionTime

No

Int

Maximum execution time of a node. If a node is not executed within the maximum execution time, the node is set to the failed state.

Unit: minute; value range: 5 to 1,440

Default value: 60

retryTimes

No

Int

Number of the node retries. The value ranges from 0 to 5. 0 indicates no retry.

Default value: 0

retryInterval

No

Int

Interval at which a retry is performed upon a failure. The value ranges from 5 to 120.

Unit: second

Default value: 120

failPolicy

No

String

Job failure policy.

  • FAIL: Stop the job and set the job to the failed state.
  • IGNORE: Go to the next node.
  • SUSPEND: Suspend the job.

    The default value is FAIL.

eventTrigger

No

Event data structure

Node event triggering configuration. For details, see Table 10.

cronTrigger

No

Cron data structure

Node Cron triggering configuration. For details, see Table 9.

Table 5 Schedule data structure description

Parameter

Mandatory

Type

Description

type

Yes

String

Scheduling type.

  • EXECUTE_ONCE: The job runs immediately and runs only once.
  • CRON: The job runs periodically.
  • EVENT: The job runs when specified events occur. Currently, only the DIS data triggering event is supported.

cron

No

Data structure

When type is set to CRON, configure the scheduling frequency and start time. For details, see Table 9.

event

No

Data structure

When type is set to EVENT, configure information such as the event source. For details, see Table 10.

Table 6 Param data structure description

Parameter

Mandatory

Type

Description

name

Yes

String

Parameter name. It contains a maximum of 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

value

Yes

String

The parameter value cannot be greater than 1,024 characters.

type

No

String

Parameter type.

  • variable
  • constants

    Default value: variable

Table 7 Location data structure description

Parameter

Mandatory

Type

Description

x

Yes

Int

Position of the node on the horizontal axis of the job canvas.

y

Yes

Int

Position of the node on the vertical axis of the job canvas.

Table 8 condition data structure description

Parameter

Mandatory

Type

Description

preNodeName

Yes

String

Name of the previous node on which the current node depends.

expression

Yes

String

EL expression. If the calculation result of the EL expression is true, this node is executed.

Table 9 Cron data structure description

Parameter

Mandatory

Type

Description

startTime

Yes

String

Scheduling start time in the format of yyyy-MM-dd'T'HH:mm:ssZ, which is an ISO 8601 time format. For example, 2018-10-22T23:59:59+08, which indicates that a job starts to be scheduled at 23:59:59 on October 22nd, 2018 in the Beijing time zone.

endTime

No

String

Scheduling end time in the format of yyyy-MM-dd'T'HH:mm:ssZ, which is an ISO 8601 time format. For example, 2018-10-22T23:59:59+08, which indicates that a job stops to be scheduled at 23:59:59 on October 22nd, 2018 in the Beijing time zone. If the end time is not set, the job will be executed based on the scheduling period.

expression

Yes

String

Cron expression in the format of <second><minute><hour><day><month><week>. For details about the values input in each field, see Table 7.

expressionTimeZone

No

String

Time zone corresponding to the Cron expression, for example, GMT+8.

Default value: Use the time zone where DGC is located.

dependPrePeriod

No

Boolean

Indicates whether to depend on the execution result of the current job's dependent job in the previous scheduling period.

Default value: false

dependJobs

No

DependJobs data structure

Job dependency configuration. For details, see Table 12.

Table 10 Event data structure description

Parameter

Mandatory

Type

Description

eventType

Yes

String

Event type. Currently, only newly reported data events from the DIS stream can be monitored. Each time a data record is reported, the job runs once.

This parameter is set to DIS.

channel

Yes

String

DIS stream name.

Perform the following operations to obtain the stream name:

  1. Log in to the management console.
  2. Click Data Ingestion Service and choose Ingestion Management > Streams from the list on the left.
  3. The stream management page lists the existing streams.

failPolicy

No

String

Job failure policy.

  • SUSPEND: Suspend the event.
  • IGNORE: Ignore the failure and process with the next event.

Default value: SUSPEND

concurrent

No

int

Number of the concurrently scheduled jobs.

Value range: 1 to 128

Default value: 1

readPolicy

No

String

Access policy.

  • LAST: Access data from the last location.
  • NEW: Access data from a new location.

Default value: LAST

Table 11 Values in the Cron expression fields

Field

Value Range

Allowed Special Character

Description

Second

0-59

, - * /

In the current version, only 0 is allowed.

Minute

0-59

, - * /

-

Hour

0-23

, - * /

-

Day

1-31

, - * ? / L W C

-

Month

1-12

, - * /

In the current version, only * is allowed.

Week

1-7

, - * ? / L C #

Starting from Sunday.

Table 12 DepentJobs data structure description

Parameter

Mandatory

Type

Description

jobs

Yes

List<String>

A list of dependent jobs. Only the existing jobs can be depended on.

dependPeriod

No

String

Dependency period.

  • SAME_PERIOD: To run a job or not depends on the execution result of its depended job in the current scheduling period.
  • PRE_PERIOD: To run a job or not depends on the execution result of its depended job in the previous scheduling period.

Default value: SAME_PERIOD

dependFailPolicy

No

String

Dependency job failure policy.

  • FAIL: Stop the job and set the job to the failed state.
  • IGNORE: Continue to run the job.
  • SUSPEND: Suspend the job.

Default value: FAIL

Table 13 Parameter description of the Hive SQL node

Parameter

Mandatory

Type

Description

scriptName

Yes

String

Script name.

database

No

String

Database name.

Database in the MRS Hive. The default value is default.

connectionName

No

String

Name of the connection.

scriptArgs

No

String

Script parameter in format of key and value. Multiple parameters are separated by slashes (\), for example, key1=value1\nkey2=value2

Table 14 Parameter description of the Spark SQL node

Parameter

Mandatory

Type

Description

scriptName

Yes

String

Script name.

database

No

String

Database name.

Database in the MRS Spark SQL. The default value is default.

connectionName

No

String

Name of the connection.

scriptArgs

No

String

Script parameter in format of key and value. Multiple parameters are separated by slashes (\), for example, key1=value1\nkey2=value2

Table 15 Parameter description of the DWS SQL node

Parameter

Mandatory

Type

Description

scriptName

Yes

String

Script name.

database

No

String

Database name.

Database in DWS. The default value is postgres.

connectionName

No

String

Name of the connection.

scriptArgs

No

String

Script parameter in format of key and value. Multiple parameters are separated by slashes (\), for example, key1=value1\nkey2=value2

Table 16 Parameter description of the DLI SQL node

Parameter

Mandatory

Type

Description

scriptName

Yes

String

Script name.

database

No

String

Database name.

Database in DLI.

connectionName

No

String

Name of the connection.

scriptArgs

No

String

Script parameter in format of key and value. Multiple parameters are separated by slashes (\), for example, key1=value1\nkey2=value2

Table 17 Parameter description of the shell node

Parameter

Mandatory

Type

Description

scriptName

Yes

String

Script name.

connectionName

Yes

String

Name of the connection.

arguments

No

String

Shell script parameter.

Table 18 Parameter description of the CDM Job node

Parameter

Mandatory

Type

Description

clusterName

Yes

String

Name of the cluster.

Perform the following operations to obtain the CDM cluster name:

  1. Log in to the management console.
  2. Click Cloud Data Migration and select Cluster Management from the list on the left.

You can obtain the cluster name from the cluster management list.

jobName

Yes

String

Name of the job.

Perform the following operations to obtain the job name:

  1. Log in to the management console.
  2. Click Cloud Data Migration and select Cluster Management from the list on the left.
  3. Click Job Management of the cluster to obtain the job name.
Table 19 Parameter description of the DISTransferTask node

Parameter

Mandatory

Type

Description

streamName

Yes

String

DIS stream name.

Perform the following operations to obtain the stream name:

  1. Log in to the management console.
  2. Click Data Ingestion Service and choose Ingestion Management > Streams from the list on the left.
  3. The stream management page lists the existing streams.

destinationType

Yes

String

Dump target.

  • CloudTable
  • OBS

duplicatePolicy

Yes

String

Duplicate name policy.

  • OVERWRITE
  • IGNORE

configuration

Yes

Data structure

Dump configuration. For details, see the description of the obs_destination_descriptor and cloudtable_destination_descriptor parameters in Adding a Dump Task.

Table 20 Parameter description of the CS Job node

Parameter

Mandatory

Type

Description

jobName

Yes

String

Name of the CS job.

Perform the following operations to obtain the job name:

  1. Log in to the management console.
  2. Click Cloud Stream Service and select Job Management from the list on the left.

You can obtain the job name from the job management list.

jobType

Yes

String

Job type.

  • exists: existing job
  • flink_sql_job: Flink SQL job
  • flink_jar_job: user-defined Flink job
  • spark_streaming_jar_job: user-defined Spark job

jarPath

No

String

JAR package path.

mainClass

No

String

Main class of the JAR package.

jarArgs

No

String

Parameter of the JAR package.

clusterName

No

String

CS cluster name.

Perform the following operations to obtain the cluster name:

  1. Log in to the management console.
  2. Click Cloud Stream Service and select Cluster Management from the list on the left.

You can obtain the cluster name from the cluster management list.

spuNumber

No

int

Number of SPUs.

Number of SPUs selected by a user for a job. You need to set this parameter when submitting a user-defined Flink job, but not when submitting a user-defined Spark job.

managerSpu

No

int

Number of management units.

Number of management node SPUs selected by a user for a job. For user-defined Flink jobs, the parameter value is the number of Flink job managers. For user-defined Spark jobs, the parameter value is the number of Spark drivers.

parallelNumber

No

int

Number of concurrent running jobs.

Number of parallel tasks selected by a user for a job. You need to set this parameter when submitting a user-defined Flink job, but not when submitting a user-defined Spark job.

executorNumber

No

int

Number of executors.

Number of executors selected by a user for a Spark job. You need to set this parameter when submitting a user-defined Spark job, but not when submitting a user-defined Flink job.

executorSpu

No

int

Executor SPU.

Number of SPUs used by an executor in a job. You need to set this parameter when submitting a user-defined Spark job, but not when submitting a user-defined Flink job.

restartWhenException

No

boolean

Specifies whether the CS job automatically restarts when it is abnormal.

udfJar

No

String

UDF JAR path.

scriptName

No

String

Script name.

scriptArgs

No

String

Script parameter in format of key and value. Multiple parameters are separated by slashes (\), for example, key1=value1\nkey2=value2

Table 21 Parameter description of the CloudTableManager node

Parameter

Mandatory

Type

Description

namespace

No

String

Namespace.

Default value: default

action

Yes

String

Action type.

  • CREATE_TABLE: Create a table.
  • DELETE_TABLE: Delete a table.

table

No

String

Table name.

columnFamily

No

String

Column family.

Table 22 Parameter description of the OBSManager node

Parameter

Mandatory

Type

Description

action

Yes

String

Action type.

  • CREATE_PATH: Create an OBS path.
  • DELETE_PATH: Delete an OBS path.

path

Yes

String

OBS path.

Table 23 Parameter description of the RESTAPI node

Parameter

Mandatory

Type

Description

url

Yes

String

URL address.

URL of the cloud service.

method

Yes

String

HTTP method.

  • GET
  • POST
  • PUT
  • DELETE

headers

No

String

HTTP message header in the format of <message header name>=<value>. Multiple message headers are separated by newlines.

body

No

String

Message body.

Table 24 Parameter description of the SMN node

Parameter

Mandatory

Type

Description

topic

Yes

String

SMN topic.

Perform the following operations to obtain an SMN topic:

  1. Log in to the management console.
  2. Click Simple Message Notification and choose Topic Management > Topics from the list on the left.

You can obtain the SMN topic in the topic list.

subject

Yes

String

Message title, which is used as the subject of an email sent to a subscriber.

messageType

Yes

String

Message type.

  • NORMAL
  • STRUCTURE
  • TEMPLATE

message

Yes

String

Message to be sent.

Table 25 Parameter description of the MRS Spark node

Parameter

Mandatory

Type

Description

clusterName

Yes

String

MRS cluster name.

Perform the following operations to obtain the MRS cluster name:

  1. Log in to the management console.
  2. Click MapReduce Service and choose Clusters > Active Clusters from the list on the left.

You can obtain the cluster name from the active clusters.

jobName

Yes

String

MRS job name.

The job name is user-defined.

resourcePath

Yes

String

Resource path.

parameters

Yes

String

Job parameter.

input

Yes

String

Input path.

Input data path of the MapReduce job. The path can be an HDFS or OBS path.

output

Yes

String

Output path.

Output data path of the MapReduce job. The path can be an HDFS or OBS path.

Table 26 Parameter description of the MapReduce node

Parameter

Mandatory

Type

Description

clusterName

Yes

String

MRS cluster name.

Perform the following operations to obtain the MRS cluster name:

  1. Log in to the management console.
  2. Click MapReduce Service and choose Clusters > Active Clusters from the list on the left.

You can obtain the cluster name from the active clusters.

jobName

Yes

String

MRS job name.

The job name is user-defined.

resourcePath

Yes

String

Resource path.

parameters

Yes

String

Job parameter.

input

Yes

String

Input path.

Input data path of the MapReduce job. The path can be an HDFS or OBS path.

output

Yes

String

Output path.

Output data path of the MapReduce job. The path can be an HDFS or OBS path.

Table 27 Parameter description of the DLI Spark node

Parameter

Mandatory

Type

Description

clusterName

Yes

String

Name of the DLI cluster.

Perform the following operations to obtain the DLI cluster name:

  1. Log in to the management console.
  2. Click Data Lake Insight and then Spark Jobs.
  3. Choose Cluster Management.

You can obtain the cluster name from the cluster management list.

jobName

Yes

String

DLI job name.

Perform the following operations to obtain the DLI cluster name:

  1. Log in to the management console.
  2. Click Data Lake Insight and then Spark Jobs.
  3. Choose Job Management.

You can obtain the job name from the job management list.

resourceType

No

String

Resource type of the DLI job. CUSTOMIZED is returned when the parameter is customized.

jobClass

Yes

String

Main class of the job.

resourcePath

Yes

String

JAR package resource path.

jarArgs

No

String

Main-class entry parameter.

sparkConfig

No

String

Running parameter of the Spark job.

Table 28 BasicConfig job information

Parameter

Mandatory

Type

Description

owner

No

String

Job owner. The length cannot exceed 128 characters.

priority

No

int

Job priority. The value ranges from 0 to 2. The default value is 0. 0 indicates a top priority, 1 indicates a medium priority, and 2 indicates a low priority.

executeUser

No

String

Job execution user. The value must be an existing HUAWEI CLOUD username.

instanceTimeout

No

int

Instance timeout interval. The unit is minute. The value ranges from 5 to 1,440. The default value is 60.

customFields

No

Map<String,String>

User-defined field. The length cannot exceed 2,048 characters.

Response Message

None.

Example

Create a real-time job. The job includes one DLI node (TRIP_RAW_STANDARD), two DIS nodes (DIS_INPUT and DIS_EVENT), and one CS Job (CS_PROCESS). The following figure shows the details:

Figure 1 Real-time job
  • Request
    POST /v1/b384b9e9ab9b4ee8994c8633aabc9505/jobs
    {
    	"logPath":"obs://dlf-log-b384b9e9ab9b4ee8994c8633aabc9505",
    	"name":"myJob",
    	"nodes":[
    		{
    			"failPolicy":"FAIL",
    			"location":{
    				"x":"385.0",
    				"y":"150.0"
    			},
    			"maxExecutionTime":60,
    			"name":"DIS_INPUT",
    			"pollingInterval":1,
    			"preNodeName":[],
    			"properties":[
    				{
    					"name":"streamName",
    					"value":"csinput"
    				}
    			],
    			"resources":[],
    			"retryInterval":120,
    			"retryTimes":0,
    			"type":"DISStream"
    		},
    		{
    			"failPolicy":"FAIL",
    			"location":{
    				"x":"572.0",
    				"y":"151.0"
    			},
    			"maxExecutionTime":60,
    			"name":"CS_PROCESS",
    			"pollingInterval":10,
    			"preNodeName":[
    				"DIS_INPUT"
    			],
    			"properties":[
    				{
    					"name":"scriptName",
    					"value":"CS_PROCESS_TRIP"
    				},
    				{
    					"name":"jobName",
    					"value":"CS_PROCESS"
    				},
    				{
    					"name":"jobType",
    					"value":"flink_sql_job"
    				},
    				{
    					"name":"spuNumber",
    					"value":"2"
    				},
    				{
    					"name":"parallelNumber",
    					"value":"1"
    				}
    			],
    			"resources":[],
    			"retryInterval":120,
    			"retryTimes":0,
    			"type":"CSJob"
    		},
    		{
    			"failPolicy":"FAIL",
    			"location":{
    				"x":"718.0",
    				"y":"121.0"
    			},
    			"maxExecutionTime":60,
    			"name":"DIS_EVENT",
    			"pollingInterval":1,
    			"preNodeName":[
    				"CS_PROCESS"
    			],
    			"properties":[
    				{
    					"name":"streamName",
    					"value":"dis-event"
    				}
    			],
    			"resources":[],
    			"retryInterval":120,
    			"retryTimes":0,
    			"type":"DISStream"
    		},
    		{
    			"eventTrigger":{
    				"channel":"dis-event",
    				"concurrent":1,
    			        "eventType:"DIS",
    				"readPolicy":"LAST"
    			},
    			"failPolicy":"FAIL",
    			"location":{
    				"x":"848.0",
    				"y":"167.0"
    			},
    			"maxExecutionTime":60,
    			"name":"TRIP_RAW_STANDARD",
    			"pollingInterval":10,
    			"preNodeName":[
    				"DIS_EVENT"
    			],
    			"properties":[
    				{
    					"name":"scriptName",
    					"value":"TRIP_RAW_STANDARD"
    				},
    				{
    					"name":"database",
    					"value":"lixinlong"
    				},
    				{
    					"name":"queueName",
    					"value":"default"
    				}
    			],
    			"resources":[],
    			"retryInterval":120,
    			"retryTimes":0,
    			"type":"DLISQL"
    		}
    	],
    	"params":[
    		{
    			"name":"dis_channel",
    			"value":"dis_input"
    		}
    	],
    	"processType":"REAL_TIME",
    	"resources":[],
    	"schedule":{
    		"type":"EXECUTE_ONCE"
    	},
    	"version":"1.0"
    }
  • Success response

    HTTP status code 204

  • Failure response

    HTTP status code 400

    {
        "error_code":"DLF.0102",
        "error_msg":"The job name already exists."
    }