更新时间:2024-03-25 GMT+08:00

查询作业

功能介绍

查询作业接口。

调用方法

请参见如何调用API

URI

GET /v1.1/{project_id}/clusters/{cluster_id}/cdm/job/{job_name}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方法请参见项目ID和账号ID

cluster_id

String

集群ID

job_name

String

查询多个作业用all,查询单个作业输入作业名

表2 Query参数

参数

是否必选

参数类型

描述

filter

String

当“job_name”为“all”时,此参数用于模糊过滤作业。

page_no

Integer

指定作业页号

最小值:1

page_size

Integer

每页作业数,值在10-100之间。

最小值:10

最大值:100

jobType

String

作业类型:

  • jobType=NORMAL_JOB:表示查询表/文件迁移的作业。

  • jobType=BATCH_JOB:表示查询整库迁移的作业。

  • jobType=SCENARIO_JOB:表示查询场景迁移的作业。

  • 不指定该参数时,默认只查询表/文件迁移的作业。

枚举值:

  • NORMAL_JOB

  • BATCH_JOB

  • SCENARIO_JOB

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

total

Integer

作业数,查询单个作业时为0

jobs

Array of Job objects

作业列表,请参见jobs参数说明

page_no

Integer

返回指定页号的作业

page_size

Integer

每页作业数

表5 Job

参数

参数类型

描述

job_type

String

作业类型:

  • NORMAL_JOB:表/文件迁移。

  • BATCH_JOB:整库迁移。

  • SCENARIO_JOB:场景迁移。

枚举值:

  • NORMAL_JOB

  • BATCH_JOB

  • SCENARIO_JOB

from-connector-name

String

源端连接类型,对应的连接参数如下:

  • generic-jdbc-connector:关系数据库连接。

  • obs-connector:OBS连接。

  • hdfs-connector:HDFS连接。

  • hbase-connector:HBase连接、CloudTable连接。

  • hive-connector:Hive连接。

  • ftp-connector/sftp-connector:FTP/SFTP连接。

  • mongodb-connector:MongoDB连接。

  • redis-connector:Redis/DCS连接。

  • kafka-connector:Kafka连接。

  • dis-connector:DIS连接。

  • elasticsearch-connector:Elasticsearch/云搜索服务连接。

  • dli-connector:DLI连接。

  • http-connector:HTTP/HTTPS连接,该连接暂无连接参数。

  • dms-kafka-connector:DMSKafka连接

to-config-values

ConfigValues object

目的连接参数配置。根据不同目的端有不同的参数配置,具体可参考目的端作业参数说明下相应的目的端参数配置。

to-link-name

String

目的端连接名称,即为通过“创建连接”接口创建的连接对应的连接名。

driver-config-values

ConfigValues object

作业任务参数配置。例如配置作业失败重试、抽取并发数,具体可参考作业任务参数说明

from-config-values

ConfigValues object

源连接参数配置。根据不同源端有不同的参数配置,具体可参考源端作业参数说明下相应的源端参数配置。

to-connector-name

String

目的端连接类型,对应的连接参数如下:

  • generic-jdbc-connector:关系数据库连接。

  • obs-connector:OBS连接。

  • hdfs-connector:HDFS连接。

  • hbase-connector:HBase连接、CloudTable连接。

  • hive-connector:Hive连接。

  • ftp-connector/sftp-connector:FTP/SFTP连接。

  • mongodb-connector:MongoDB连接。

  • redis-connector:Redis/DCS连接。

  • kafka-connector:Kafka连接。

  • dis-connector:DIS连接。

  • elasticsearch-connector:Elasticsearch/云搜索服务连接。

  • dli-connector:DLI连接。

  • http-connector:HTTP/HTTPS连接,该连接暂无连接参数。

  • dms-kafka-connector:DMSKafka连接

name

String

作业名称,长度在1到240个字符之间

最小长度:1

最大长度:240

from-link-name

String

源连接名称,即为通过“创建连接”接口创建的连接对应的连接名。

creation-user

String

创建作业的用户。由系统生成,用户无需填写。

creation-date

Long

作业创建的时间,单位:毫秒。由系统生成,用户无需填写。

update-date

Long

作业最后更新的时间,单位:毫秒。由系统生成,用户无需填写。

is_incre_job

Boolean

是否是增量作业。已废弃

flag

Integer

是否是定时作业标记,如果是定时作业则为1,否则为0。由系统根据定时任务配置生成,用户无需填写。

files_read

Integer

已读文件数。由系统生成,用户无需填写。

update-user

String

最后更新作业的用户。由系统生成,用户无需填写。

external_id

String

具体执行的作业id,如果是本地作业,则一般为"job_local1202051771_0002"形式,如果是DLI作业,则为DLI作业ID,比如"12345"。由系统生成,用户无需填写。

type

String

与job_type一致,作业类型:

  • NORMAL_JOB:表/文件迁移。

  • BATCH_JOB:整库迁移。

  • SCENARIO_JOB:场景迁移。

execute_start_date

Long

最近一次执行任务开始时间,单位:毫秒。由系统生成,用户无需填写。

delete_rows

Integer

增量作业删除行数,已废弃。

enabled

Boolean

是否激活连接。由系统生成,用户无需填写。

bytes_written

Long

作业写入的字节。由系统生成,用户无需填写。

id

Integer

作业ID。由系统生成,用户无需填写。

is_use_sql

Boolean

用户是否使用sql。由系统根据源端抽取是否使用sql语句生成,用户无需填写

update_rows

Integer

增量作业更新行数,已废弃。

group_name

String

组名

bytes_read

Long

作业读取的字节。由系统生成,用户无需填写。

execute_update_date

Long

最近一次执行任务更新时间,单位:毫秒。由系统生成,用户无需填写。

write_rows

Integer

增量作业写入行数,已废弃。

rows_written

Integer

作业写入的行数。由系统生成,用户无需填写。

rows_read

Long

作业读取的行数。由系统生成,用户无需填写。

files_written

Integer

写入文件数。由系统生成,用户无需填写。

is_incrementing

Boolean

是否是增量作业,同is_incre_job,已废弃。

execute_create_date

Long

最近一次执行任务创建时间,单位:毫秒。由系统生成,用户无需填写。

status

String

作业最后的执行状态:

  • BOOTING:启动中。

  • RUNNING:运行中。

  • SUCCEEDED:成功。

  • FAILED:失败。

  • NEW:未被执行。

表6 ConfigValues

参数

参数类型

描述

configs

Array of configs objects

源连接参数、目的连接参数和作业任务参数,它们的配置数据结构相同,其中“inputs”里的参数不一样,详细请参见configs数据结构说明。

extended-configs

extended-configs object

扩展配置,请参见extended-configs参数说明。扩展配置暂不对外开放,用户无需填写。

表7 configs

参数

参数类型

描述

inputs

Array of Input objects

输入参数列表,列表中的每个参数为“name,value”结构,请参考inputs数据结构参数说明。在“from-config-values”数据结构中,不同的源连接类型有不同的“inputs”参数列表,请参见源端作业参数说明下的章节。在“to-config-values”数据结构中,不同的目的连接类型有不同的“inputs”参数列表,请参见目的端作业参数说明下面的子章节。在“driver-config-values”数据结构中,“inputs”具体参数请参见作业任务参数说明。

name

String

配置名称:源端作业的配置名称为“fromJobConfig”。目的端作业的配置名称为“toJobConfig”,连接的配置名称固定为“linkConfig”。

id

Integer

配置ID,由系统生成,用户无需填写。

type

String

配置类型,由系统生成,用户无需填写。值为LINK或者JOB,如果是连接管理API,则为LINK;如果是作业管理API,则为JOB。

表8 Input

参数

参数类型

描述

name

String

参数名:

  • 如果是连接管理API,则以“linkConfig.”开头,对于不同连接类型有不同的参数,具体可参见连接参数说明下相应连接的参数说明。

  • 如果是作业管理API,对于源端连接参数,则以“fromJobConfig.”开头,具体可参见源端作业参数说明下相应的源端参数说明;对于目的端连接参数,则以“toJobConfig.”开头,具体可参见目的端作业参数说明下相应的目的端参数说明;对于作业任务参数,请参见作业任务参数说明下相应的任务参数说明。

value

String

参数值,参数名对应的值,必须填写为字符串。

type

String

值类型,如STRING、INTEGER,由系统设定,用户无需填写。

表9 extended-configs

参数

参数类型

描述

name

String

扩展配置名称,暂不对外开放,用户无需填写。

value

String

扩展配置值,暂不对外开放,用户无需填写。

请求示例

GET /v1.1/1551c7f6c808414d8e9f3c514a170f2e/clusters/6ec9a0a4-76be-4262-8697-e7af1fac7920/cdm/job/all?jobType=NORMAL_JOB

响应示例

状态码: 200

ok

{
  "total" : 1,
  "jobs" : [ {
    "job_type" : "NORMAL_JOB",
    "from-connector-name" : "elasticsearch-connector",
    "to-config-values" : {
      "configs" : [ {
        "inputs" : [ {
          "name" : "toJobConfig.streamName",
          "value" : "dis-lkGm"
        }, {
          "name" : "toJobConfig.separator",
          "value" : "|"
        }, {
          "name" : "toJobConfig.columnList",
          "value" : "1&2&3"
        } ],
        "name" : "toJobConfig"
      } ]
    },
    "to-link-name" : "dis",
    "driver-config-values" : {
      "configs" : [ {
        "inputs" : [ {
          "name" : "throttlingConfig.numExtractors",
          "value" : "1"
        }, {
          "name" : "throttlingConfig.submitToCluster",
          "value" : "false"
        }, {
          "name" : "throttlingConfig.numLoaders",
          "value" : "1"
        }, {
          "name" : "throttlingConfig.recordDirtyData",
          "value" : "false"
        } ],
        "name" : "throttlingConfig"
      }, {
        "inputs" : [ ],
        "name" : "jarConfig"
      }, {
        "inputs" : [ {
          "name" : "schedulerConfig.isSchedulerJob",
          "value" : "false"
        }, {
          "name" : "schedulerConfig.disposableType",
          "value" : "NONE"
        } ],
        "name" : "schedulerConfig"
      }, {
        "inputs" : [ ],
        "name" : "transformConfig"
      }, {
        "inputs" : [ {
          "name" : "retryJobConfig.retryJobType",
          "value" : "NONE"
        } ],
        "name" : "retryJobConfig"
      } ]
    },
    "from-config-values" : {
      "configs" : [ {
        "inputs" : [ {
          "name" : "fromJobConfig.index",
          "value" : "52est"
        }, {
          "name" : "fromJobConfig.type",
          "value" : "est_array"
        }, {
          "name" : "fromJobConfig.columnList",
          "value" : "array_f1_int:long&array_f2_text:string&array_f3_object:nested"
        }, {
          "name" : "fromJobConfig.splitNestedField",
          "value" : "false"
        } ],
        "name" : "fromJobConfig"
      } ]
    },
    "to-connector-name" : "dis-connector",
    "name" : "es_css",
    "from-link-name" : "css"
  } ],
  "page_no" : 1,
  "page_size" : 10
}

SDK代码示例

SDK代码示例如下。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.cdm.v1.region.cdmRegion;
import com.huaweicloud.sdk.cdm.v1.*;
import com.huaweicloud.sdk.cdm.v1.model.*;


public class ShowJobsSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        cdmClient client = cdmClient.newBuilder()
                .withCredential(auth)
                .withRegion(cdmRegion.valueOf("<YOUR REGION>"))
                .build();
        ShowJobsRequest request = new ShowJobsRequest();
        request.withFilter("<filter>");
        request.withPageNo(<page_no>);
        request.withPageSize(<page_size>);
        request.withJobType(ShowJobsRequest.JobTypeEnum.fromValue("<jobType>"));
        try {
            ShowJobsResponse response = client.showJobs(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcdm.v1.region.cdm_region import cdmRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcdm.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = cdmClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(cdmRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ShowJobsRequest()
        request.filter = "<filter>"
        request.page_no = <page_no>
        request.page_size = <page_size>
        request.job_type = "<jobType>"
        response = client.show_jobs(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    cdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cdm.NewcdmClient(
        cdm.cdmClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ShowJobsRequest{}
	filterRequest:= "<filter>"
	request.Filter = &filterRequest
	pageNoRequest:= int32(<page_no>)
	request.PageNo = &pageNoRequest
	pageSizeRequest:= int32(<page_size>)
	request.PageSize = &pageSizeRequest
	jobTypeRequest:= model.GetShowJobsRequestJobTypeEnum().<JOB_TYPE>
	request.JobType = &jobTypeRequest
	response, err := client.ShowJobs(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

ok

错误码

请参见错误码