List Flow Instances

查询满足条件的所有任务流实例。

前提条件

用户必须为EnOS用户。

请求格式

POST https://{apigw-address}/dataflow-batch-service/v2.0/flowInstances

请求参数(URI)

名称

位置(Path/Query)

必需/可选

数据类型

描述

userId

Query

必需

String

用户ID。如何获取userId信息>>

orgId

Query

必需

String

用户所属的组织ID。如何获取orgId信息>>

action

Query

必需

String

固定值:search

请求参数(Body)

名称

必需/可选

数据类型

描述

type

必需

Integer

任务流实例调度类型(0:手动调度任务;1:周期调度任务;2:临时任务)。

expression

可选

String

指定在 flowInstanceId 和 flowName 字段中模糊匹配查询条件(若不指定,则返回当前用户相关的所有任务流实例)。

owner

必需

String

任务所有者的用户名(若该字段为空字符串,则不对 owner 字段进行过滤)。

fromTriggerTime

必需

Long

toTriggerTime`参数配合使用,查询调度时间( `triggerTime )在 [fromTriggerTime,toTriggerTime) 范围内的任务流实例(单位为毫秒)。

toTriggerTime

必需

Long

fromTriggerTime`参数配合使用,查询调度时间( `triggerTime )在 [fromTriggerTime,toTriggerTime) 范围内的任务流实例(单位为毫秒)。

status

必需

String

任务流实例的状态,状态描述参见 FlowInstanceStatus (同时搜索多种状态,用英文逗号隔开,如status=”1,2,3”;若该字段为空字符串,则不对 status 字段进行过滤)。

pagination

必需

Pagination请求结构体

分页信息结构体。详见 Pagination请求结构体

FlowInstanceStatus

Status

描述

-1

FAIL

0

INIT

1

SUCCESS

2

RUNNING

3

SUSPEND

4

INTERNAL_ERROR

5

WAIT

6

READY

7

TIMEOUT

8

CANCEL

9

RERUN

10

SKIP

Pagination请求结构体

示例

{
    "pagination": {
        "pageNo": 0,
        "pageSize": 10,
        "sorters": [{
            "field": "start_time",
            "order": "ASC"
        }]
    }
}

参数

名称

必需/可选

数据类型

描述

pageNo

必需

Integer

请求页数,从 0 开始。

pageSize

必需

Integer

每页记录数,必须大于 0 。

sorters

可选

jsonArray

分页排序方式(sorters结构体包含两个字段:sorter.field 和 sorter.order,具体见下方 sorters 参数展开)

sorters

名称

必需/可选

数据类型

描述

field

必需

String

分页字段名称。支持字段:create_timeupdate_timestart_timetrigger_time, end_time

order

可选

String

ASC 表示正序排序,DESC 表示倒序排序,默认为正序排序。

响应参数

名称

数据类型

描述

data

List<JSONObject>

包含获取到的所有任务流实例信息和数量。详见 FlowInstances结构体

FlowInstances结构体

示例

{
    "flowInsts":[],
    "count":0
}

参数

名称

数据类型

描述

flowInsts

JSONObject

任务流实例集合。详见 FlowInstance结构体

count

Integer

获取的任务流实例数量,即flowInsts中元素个数。

错误码

代码

错误信息

描述

62102

illegal sorted by field

输入参数 sorters 不正确。参数 field 应为以下字段之一:

  • create_time

  • update_time

  • start_time

  • trigger_time

  • end_time

有关其他错误码的描述,参见 通用错误码

示例

请求示例

url: https://{apigw-address}/dataflow-batch-service/v2.0/flowInstances?action=search&userId={}&orgId={}

method: POST

requestBody:
{
    "type": 1,
    "fromTriggerTime": 1573648355000,
    "toTriggerTime": 1573698120000,
    "status": 1,
    "owner": "",
    "expression": "",
    "pagination":{
        "pageNo": 0,
        "pageSize": 10,
        "sorters": [{
            "field": "update_time",
            "order": "ASC"
        }]
    }
}

返回示例

{
  "status": 0,
  "msg": "SUCCESS",
  "data": {
    "flowInsts": [{
                "instanceId": "2809-20190812080700",
                "flowId": 2809,
                "flowName": "21",
                "freq": "0 0 0 * * ? *",
                "cycle": "D",
                "parameters": "[]",
                "doAs": "your_bd_account",
                "graph": "{\"creator\":\"yourCreator\",\"freq\":\"0 0 0 * * ? *\",\"alertMode\":3,\"owners\":\"yourOwners\",\"cycle\":\"D\",\"doAs\":\"yourDoAs\",\"flows\":[],\"alertTo\":\"\",\"name\":\"21\",\"instId\":\"2809-20190812080700\",\"id\":2809,\"relations\":[],\"parameters\":\"[]\",\"appId\":\"\",\"tasks\":[{\"taskName\":\"tass\",\"taskInstId\":\"104890-20190812080700\",\"x\":0.002,\"y\":0.002,\"taskId\":104890,\"nodeId\":\"t_104890\"}]}",
                "status": 1,
                "statusDesc": "SUCCESS",
                "triggerTime": "2019-08-12 08:07:22",
                "startTime": "2019-08-12 08:07:30",
                "endTime": "2019-08-12 08:07:32",
                "timestamp": "2019-08-12 08:09:48.0",
                "virtual": false,
                "owner": "yourOwners",
                "hasEditPri": true,
                "hasReadPri": true,
                "isCancelled": false
            },
            {
                "instanceId": "2957-20190812075600",
                "flowId": 2957,
                "flowName": "fdd",
                "freq": "0 0 0 * * ? *",
                "cycle": "D",
                "parameters": "[]",
                "doAs": "your_bd_account",
                "graph": "{\"creator\":\"yourCreator\",\"freq\":\"0 0 0 * * ? *\",\"alertMode\":3,\"owners\":\"yourOwners\",\"cycle\":\"D\",\"doAs\":\"yourDoAs\",\"flows\":[],\"alertTo\":\"\",\"name\":\"fdd\",\"instId\":\"2957-20190812075600\",\"id\":2957,\"relations\":[],\"parameters\":\"[]\",\"appId\":\"\",\"tasks\":[{\"taskName\":\"gg\",\"taskInstId\":\"105040-20190812075600\",\"x\":0.0068,\"y\":0.0071,\"taskId\":105040,\"nodeId\":\"t_105040\"}]}",
                "status": 1,
                "statusDesc": "SUCCESS",
                "triggerTime": "2019-08-12 07:56:56",
                "startTime": "2019-08-12 07:57:00",
                "endTime": "2019-08-12 07:57:02",
                "timestamp": "2019-08-12 08:00:09.0",
                "virtual": false,
                "owner": "yourOwners",
                "hasEditPri": true,
                "hasReadPri": true,
                "isCancelled": false
            }],
    "count": 2
  }
}

Java SDK调用示例

import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envision.apim.poseidon.request.PoseidonRequest;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SampleCode{
    public static class Request extends PoseidonRequest {
        public void setQueryParam(String key, Object value){
            queryParams().put(key, value);
        }
        public void setHeaderParam(String key, String value){
            headerParams().put(key, value);
        }
        public void setBodyParam(Map<String, Object> bodyPara){
            bodyParams().putAll(bodyPara);
        }
        public void setMethod(String method) {
            this.method = method;
        }
        private String method;
        public String baseUri() {
            return "";
        }
        public String method() {
            return method;
        }
    }

    @Test
    public void flowInstancesTest(){
        //1.在EnOS Console的左边导航栏中点击应用注册。
        //2.点击需调用API的应用,查看基本信息中的AccessKey即为accessKey、SecretKey即为secretKey
        String accessKey = "AccessKey of your APP";
        String secretKey = "SecretKey of your APP";

        //新建一个request 然后把需要的参数传进去存在Query的map中,key是参数名字,value是参数值
        Request request = new Request();
        HashMap<String,Object> bodyMap = new HashMap<>();
        bodyMap.put("type",0);
        bodyMap.put("owner","");
        bodyMap.put("fromTriggerTime",System.currentTimeMillis()-1000*60*60*24);
        bodyMap.put("toTriggerTime",System.currentTimeMillis());
        bodyMap.put("status","1");
        bodyMap.put("expression","");
        HashMap<String,Object> paginationMap= new HashMap<String, Object>(3);
        paginationMap.put("pageNo",0);
        paginationMap.put("pageSize",10);
        List<HashMap<String,Object>> list = new ArrayList<HashMap<String,Object>>();
        HashMap<String,Object> sorterMap= new HashMap<String, Object>(2);
        sorterMap.put("field","update_time");
        sorterMap.put("order","ASC");
        list.add(sorterMap);
        paginationMap.put("sorters",list );
        bodyMap.put("pagination",paginationMap);
        request.setBodyParam(bodyMap);
        request.setMethod("POST");
        try {
            JSONObject response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
                    .url("https://{apigw-address}/dataflow-batch-service/v2.0/flowInstances")
                    .queryParam("orgId", "yourOrgId")
                    .queryParam("userId", "yourUserId")
                    .queryParam("action", "search")
                    .getResponse(request, JSONObject.class);

            System.out.println(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}