调用ListJobs获取任务列表。

说明 在调用该接口前,需要在POM文件添加以下依赖:
<dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>aliyun-java-sdk-schedulerx2</artifactId>
      <version>1.0.5</version>
</dependency>

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

名称 类型 是否必选 示例值 描述
Action String ListJobs

系统规定参数。取值:ListJobs。

GroupId String DocTest.Group

应用ID,在控制台的应用管理页面中获取。

Namespace String 1a72ecb1-b4cc-400a-a71b-20cdec9b****

命名空间,在控制台的命名空间页面中获取。

RegionId String cn-hangzhou

地域ID。

NamespaceSource String schedulerx

特殊第三方才需要填写。

JobName String helloword

任务名称。

Status String 1

任务状态。

  • 0:表示禁用
  • 1:表示启用

返回数据

名称 类型 示例值 描述
Code Integer 200

请求状态码。

Data Struct

任务列表信息。

Jobs Array of Job

任务列表及任务详情。

AttemptInterval Integer 30

错误重试间隔,单位s,默认值为30。

ClassName String com.alibaba.schedulerx.test.helloworld

任务接口类完整路径。

当您的任务是Java任务类型时,才有该字段信息。

Content String echo 'hello'

python、shell、go任务类型的脚本代码内容。

Description String Test

任务描述。

ExecuteMode String standalone

任务执行模式,可能出现的结果如下:

  • standalone:单机运行
  • broadcast:广播运行
  • parallel:并行计算
  • grid:内存网格
  • batch:网格计算
  • shard:分片运行
JarUrl String https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.2-SNAPSHOT.jar

JAR包的OSS完整路径。

JobId Long 99341

任务ID。

JobMonitorInfo Struct

任务监控信息。

ContactInfo Array of ContactInfo

联系人信息。

UserName String userA

用户名称。

UserPhone String 1381111****

用户手机号。

MonitorConfig Struct

报警开关以及阈值配置。

FailEnable Boolean true

失败报警开关。取值如下:

  • true:开启
  • false:关闭
SendChannel String sms

报警发送形式,目前只支持sms。

Timeout Long 12300

超时阈值,单位s,默认7200。

TimeoutEnable Boolean true

超时报警开关。取值如下:

  • true:开启
  • false:关闭
TimeoutKillEnable Boolean false

超时终止本次触发开关,默认关闭。

  • true:开启
  • false:关闭
MapTaskXAttrs Struct

高级配置,仅限于并行计算、内存网格和网格计算使用。

ConsumerSize Integer 5

单机单次触发执行线程数,默认值为5。

DispatcherSize Integer 5

子任务分发线程数,默认值为5。

PageSize Integer 100

并行任务单次拉取子任务数,默认值为100。

QueueSize Integer 10000

子任务队列缓存上限,默认值为10000。

TaskAttemptInterval Integer 0

子任务失败重试间隔。

TaskMaxAttempt Integer 0

子任务失败重试次数。

MaxAttempt Integer 0

错误最大重试次数,根据业务需求填写,默认值为0。

MaxConcurrency String 1

最大同时运行实例数量,默认值为1, 即上次触发没有运行结束,即使到了运行时刻也不会进行下次触发。

Name String helloworld

任务名。

Parameters String test

用户自定义参数,运行时可以获取。

Status Integer 1

任务状态。取值如下:

  • 1:启用,可以被正常触发。
  • 0:禁用,不会被触发。
TimeConfig Struct

时间配置信息

Calendar String 工作日

cron类型可以选择填写自定义日历。

DataOffset Integer 0

cron类型可以选择时间偏移,单位s。

TimeExpression String 0 0/10 * * * ?

时间表达式,目前支持以下几种时间表达类型:

  • api:无时间表达式。
  • fix_rate:具体固定频率值,如30表示每隔30s触发一次。
  • cron:标准的cron表达式。
  • second_delay:固定延迟多少秒执行一次(1s~60s可选)。
TimeType Integer 1

时间配置类型,目前支持以下几种时间类型:

  • 1:cron
  • 3:fix_rate
  • 4:second_delay
  • 100:api
Message String namespace can not find namespace: 1a72ecb1-b4cc-400a-a71b-20cdec9b****, namespaceSource:null

错误信息,仅出错时返回错误信息。

RequestId String 71BCC0E3-64B2-4B63-A870-AFB64EBCB58B

请求唯一ID。

Success Boolean true

调用接口是否成功。取值如下:

  • true:成功
  • false:失败

示例

请求示例

http(s)://[Endpoint]/?Action=ListJobs
&GroupId=DocTest.Group
&Namespace=1a72ecb1-b4cc-400a-a71b-20cdec9b****
&RegionId=cn-hangzhou
&<公共请求参数>

正常返回示例

XML格式

<ListJobsResponse>
  <Message>namespace can not find namespace: 1a72ecb1-b4cc-400a-a71b-20cdec9b****, namespaceSource:null</Message>
  <RequestId>71BCC0E3-64B2-4B63-A870-AFB64EBCB58B</RequestId>
  <Data>
        <Jobs>
              <Status>1</Status>
              <MaxAttempt>0</MaxAttempt>
              <Parameters>test</Parameters>
              <Description>Test</Description>
              <Content>echo 'hello'</Content>
              <JarUrl>https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.2-SNAPSHOT.jar</JarUrl>
              <MaxConcurrency>1</MaxConcurrency>
              <ClassName>com.alibaba.schedulerx.test.helloworld</ClassName>
              <AttemptInterval>30</AttemptInterval>
              <ExecuteMode>standalone</ExecuteMode>
              <JobId>99341</JobId>
              <Name>helloworld</Name>
              <MapTaskXAttrs>
                    <TaskAttemptInterval>0</TaskAttemptInterval>
                    <QueueSize>10000</QueueSize>
                    <DispatcherSize>5</DispatcherSize>
                    <PageSize>100</PageSize>
                    <TaskMaxAttempt>0</TaskMaxAttempt>
                    <ConsumerSize>5</ConsumerSize>
              </MapTaskXAttrs>
              <TimeConfig>
                    <Calendar>工作日</Calendar>
                    <TimeExpression>0 0/10 * * * ?</TimeExpression>
                    <DataOffset>0</DataOffset>
                    <TimeType>1</TimeType>
              </TimeConfig>
              <JobMonitorInfo>
                    <ContactInfo>
                          <UserName>userA</UserName>
                          <UserPhone>1381111****</UserPhone>
                    </ContactInfo>
                    <MonitorConfig>
                          <TimeoutEnable>true</TimeoutEnable>
                          <Timeout>12300</Timeout>
                          <FailEnable>true</FailEnable>
                          <SendChannel>sms</SendChannel>
                          <TimeoutKillEnable>false</TimeoutKillEnable>
                    </MonitorConfig>
              </JobMonitorInfo>
        </Jobs>
  </Data>
  <Code>200</Code>
  <Success>true</Success>
</ListJobsResponse>

JSON格式

{
    "Message": "namespace can not find namespace: 1a72ecb1-b4cc-400a-a71b-20cdec9b****, namespaceSource:null",
    "RequestId": "71BCC0E3-64B2-4B63-A870-AFB64EBCB58B",
    "Data": {
        "Jobs": {
            "Status": 1,
            "MaxAttempt": 0,
            "Parameters": "test",
            "Description": "Test",
            "Content": "echo 'hello'",
            "JarUrl": "https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.2-SNAPSHOT.jar",
            "MaxConcurrency": 1,
            "ClassName": "com.alibaba.schedulerx.test.helloworld",
            "AttemptInterval": 30,
            "ExecuteMode": "standalone",
            "JobId": 99341,
            "Name": "helloworld",
            "MapTaskXAttrs": {
                "TaskAttemptInterval": 0,
                "QueueSize": 10000,
                "DispatcherSize": 5,
                "PageSize": 100,
                "TaskMaxAttempt": 0,
                "ConsumerSize": 5
            },
            "TimeConfig": {
                "Calendar": "工作日",
                "TimeExpression": "0 0/10 * * * ?",
                "DataOffset": 0,
                "TimeType": 1
            },
            "JobMonitorInfo": {
                "ContactInfo": {
                    "UserName": "userA",
                    "UserPhone": "1381111****"
                },
                "MonitorConfig": {
                    "TimeoutEnable": true,
                    "Timeout": 12300,
                    "FailEnable": true,
                    "SendChannel": "sms",
                    "TimeoutKillEnable": false
                }
            }
        }
    },
    "Code": 200,
    "Success": true
}

Demo


package com.alibaba.schedulerx.pop;

import java.util.List;

import com.alibaba.schedulerx.common.util.JsonUtil;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.schedulerx2.model.v20190430.ListJobsRequest;
import com.aliyuncs.schedulerx2.model.v20190430.ListJobsResponse;
import com.aliyuncs.schedulerx2.model.v20190430.ListJobsResponse.Data.Job;

public class TestListJobs {

    public static void main(String[] args) {
        //OpenAPI的接入点,具体查看支持地域列表以及购买机器地域填写。
        String regionId = "cn-hangzhou";
        //鉴权使用的AccessKey ID,由阿里云官网控制台获取。
        String accessKeyId = "XXXXXXXX";
        //鉴权使用的AccessKey Secret,由阿里云官网控制台获取。
        String accessKeySecret = "XXXXXXXX";
        //产品名称
        String productName ="schedulerx2";
        //对照支持地域列表选择Domain填写
        String domain ="schedulerx.cn.hangzhou.aliyuncs.com";
        //构建OpenAPI客户端。
        DefaultProfile.addEndpoint(regionId, productName, domain);
        DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
        
        ListJobsRequest request = new ListJobsRequest();
        //命名空间。
        request.setNamespace("433d8b23-06e9-408c-aaaa-90d4d1b****");
        //应用ID。
        request.setGroupId("DocTest.Group");
        ListJobsResponse response;
        try {
            response = client.getAcsResponse(request);
            if (!response.getSuccess()) {
                System.out.println(JsonUtil.toJson(response));
                System.out.println(response.getCode());
            } else {
                System.out.println(JsonUtil.toJson(response));
                List<Job> jobs = response.getData().getJobs();
                for (Job job : jobs) {
                    System.out.println("jobId:" + job.getJobId() + ", name:" + job.getName() + ", status=" + job.getStatus());
                }
            }
        } catch (ServerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
}