Import Flow

从本地任务流文件导入任务流,任务流以指定的名称保存在指定的目录下。

前提条件

用户必须属于目标任务流所属的OU。

请求格式

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

请求参数(URI)

名称

位置(Path/Query)

必需/可选

数据类型

描述

userId

Query

必需

String

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

orgId

Query

必需

String

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

action

Query

必需

String

固定值:import

请求参数(Body)

名称

必需/可选

数据类型

描述

flowId

可选

Integer

任务流ID(如果指定了flowId且指定的flowId不存在,则以指定的flowId作为导入的任务流ID;如果未指定flowId或指定的flowId已存在,则忽略该参数,生成新的flowId)。

flowName

必需

String

任务流名称。

desc

可选

String

任务流描述信息。

dirId

必需

String

任务流所在目录的目录ID(可通过 List Workflow Directories 接口获取)。

flowJson

必需

List<JSONObject>

包含任务流的详细信息。详见 Flow结构体

响应参数

名称

数据类型

描述

data

JSONObject

包含创建的任务流ID信息。详见 FlowId结构体

FlowId结构体

示例

{
  "flowId":2781
}

参数

名称

数据类型

描述

flowId

Integer

新创建的任务流ID。

错误码

代码

错误信息

描述

62102

可显示为以下错误信息:

  • Incorrect parameter

  • Invalid parameter: flowName

  • Directory does not exist

  • Workflow validation failed: Flow name must be unique

参数不正确

62109

Workflow creating failed

服务器异常,任务流创建失败

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

示例

请求示例

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

method: POST

requestBody:
{
  "flowName": "outuser",
  "desc": "",
  "dirId": "dirId",
  "flowJson": {
        "cycle": "D",
        "cron": "0 0 0 * * ? *",
        "parameters": "[{\"key\":\"REPLACE\",\"value\":\"lili1\"}]",
        "submitter": "yourSubmitter",
        "owners": "yourOwners",
        "visitors": "yourVisitors",
        "type": 1,
        "desc": "",
        "tasks": [
            {
                "name": "tass",
                "resource": "default",
                "type": "DATA_INTEGRATION",
                "cmd": "echo "hello"",
                "submitter": "yourSubmitter",
                "filePackage": "",
                "cron": "",
                "priorityLevel": 0,
                "timeout": 300,
                "retryLimit": 3,
                "retryInterval": 0,
                "successCode": "0",
                "waitCode": "",
                "asLink": true,
                "runMode": "{\"taskMode\":1,\"cpu\":0.5,\"memory\":1,\"maxParallel\":0,\"keyType\":0,\"datasourceId\":0,\"path\":\"\",\"content\":\"\"}",
                "syncType": 1
            }
        ],
        "relations": [],
        "startTime": "2019-11-22",
        "flowLinks": [],
        "syncType": 1,
        "linkRelations": [],
        "alertTo": "",
        "alertMode": 3,
        "taskLinks": [],
        "appId": ""
    }
}

返回示例

{
  "status": 0,
  "msg": "Success",
  "data": {
    "flowId": 2839
  }
}

Java SDK调用示例

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
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.HashMap;
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 importFlowTest(){
        //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> hashMap = new HashMap<String, Object>(20);
        hashMap.put("cycle","D");
        hashMap.put("cron","0 0 0 * * ? *");
        hashMap.put("parameters","[]");
        hashMap.put("alertMode",3);
        hashMap.put("alertTo","");
        hashMap.put("appId","");
        hashMap.put("submitter","yourSubmitter");
        hashMap.put("owners","yourOwners");
        hashMap.put("visitors","yourVisitors");
        hashMap.put("type",1);
        hashMap.put("syncType",1);
        hashMap.put("desc","");
        hashMap.put("startTime","2019-07-25");
        JSONArray jsonArrayTasks = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name","tass");
        jsonObject.put("resource","default");
        jsonObject.put("type","DATA_INTEGRATION");
        jsonObject.put("syncType",1);
        jsonObject.put("cmd","echo hello");
        jsonObject.put("submitter","");
        jsonObject.put("filePackage","");
        jsonObject.put("cron","");
        jsonObject.put("priorityLevel",0);
        jsonObject.put("timeout",300);
        jsonObject.put("retryLimit",3);
        jsonObject.put("retryInterval",0);
        jsonObject.put("successCode","0");
        jsonObject.put("waitCode","");
        jsonObject.put("runMode","{\"taskMode\":1,\"cpu\":0.5,\"memory\":1,\"maxParallel\":0,\"keyType\":0,\"datasourceId\":0,\"path\":\"\",\"content\":\"\"}");
        jsonObject.put("asLink",false);
        jsonArrayTasks.add(jsonObject);
        hashMap.put("tasks",jsonArrayTasks);
        JSONArray jsonArray = new JSONArray();
        hashMap.put("flowLinks",jsonArray);
        hashMap.put("taskLinks",jsonArray);
        hashMap.put("relations",jsonArray);
        hashMap.put("linkRelations",jsonArray);

        HashMap<String,Object> bodyMap = new HashMap<String, Object>(4);
        bodyMap.put("flowName","myFlow1");
        bodyMap.put("desc","this is flow");
        bodyMap.put("dirId","yourDirId");
        bodyMap.put("flowJson",hashMap );
        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/flows")
                    .queryParam("orgId", "yourOrgId")
                    .queryParam("userId", "yourUserId")
                    .queryParam("action", "import")
                    .getResponse(request, JSONObject.class);

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