華為云計算 云知識 創(chuàng)建函數(shù)流CreateWorkflow
創(chuàng)建函數(shù)流CreateWorkflow

 

功能介紹

創(chuàng)建函數(shù)流

調試

您可以在API Explorer中調試該接口,支持自動認證鑒權。API Explorer可以自動生成SDK代碼示例,并提供SDK代碼示例調試功能。

URI

POST /v2/{project_id}/fgs/workflows

表1 路徑參數(shù)

參數(shù)

是否必選

參數(shù)類型

描述

project_id

String

項目ID,獲取方式請參見獲取項目ID。

最小長度:1

最大長度:64

請求參數(shù)

表2 請求Body參數(shù)

參數(shù)

是否必選

參數(shù)類型

描述

name

String

函數(shù)流名稱

最小長度:1

最大長度:64

description

String

函數(shù)流描述

最小長度:1

最大長度:512

start

String

流程開始節(jié)點ID

最小長度:1

最大長度:256

triggers

Array of Trigger objects

觸發(fā)器列表

functions

Array of Function objects

函數(shù)列表

states

Array of OperationState objects

函數(shù)流節(jié)點清單,定義參考SleepState和OperationState

constants

Object

函數(shù)流中的常量

retries

Array of Retry objects

重試策略清單

mode

String

函數(shù)流模式,當前支持兩種模式NORMAL: 標準模式,普通模式面向普通的業(yè)務場景,支持長時間任務,支持執(zhí)行歷史持久化和查詢,只支持異步調用EXPRESS: 快速模式,快速模式面向業(yè)務執(zhí)行時長較短,需要極致性能的場景,只支持流程執(zhí)行時長低于5分鐘的場景,不支持執(zhí)行歷史持久化,支持同步和異步調用默認為標準模式

缺省值:NORMAL

枚舉值:

  • NORMAL

  • EXPRESS

express_config

ExpressConfig object

快速函數(shù)流模式配置,當mode為EXPRESS時需要設置

enterprise_project_id

String

企業(yè)項目ID

最小長度:0

最大長度:64

enable_stream_response

Boolean

是否返回流數(shù)據(jù)

缺省值:false

表3 Trigger

參數(shù)

是否必選

參數(shù)類型

描述

trigger_name

String

觸發(fā)器名稱

最小長度:1

最大長度:256

trigger_type

String

觸發(fā)器類型 FLOWTIMER:定時觸發(fā)器 SMN :SMN觸發(fā)器 APIG:APIG觸發(fā)器(共享版) APIG_DE:APIG觸發(fā)器(專享版) OBS:OBS觸發(fā)器

最小長度:1

最大長度:32

枚舉值:

  • FLOWTIMER

  • SMN

  • APIG

  • APIG_DE

  • OBS

enabled

Boolean

是否啟用觸發(fā)器

缺省值:true

枚舉值:

  • true

  • false

trigger_config

OBSTriggerConfig object

OBS觸發(fā)器配置,當trigger_type為OBS時需要設置

表4 OBSTriggerConfig

參數(shù)

是否必選

參數(shù)類型

描述

bucket

String

OBS桶名(trigger_type為OBS時配置)

最小長度:1

最大長度:64

events

Array of strings

OBS事件列表(trigger_type為OBS時配置)

prefix

String

對象名前綴(trigger_type為OBS時配置)

最小長度:1

最大長度:1024

suffix

String

對象名后綴(trigger_type為OBS時配置)

最小長度:1

最大長度:1024

表5 Function

參數(shù)

是否必選

參數(shù)類型

描述

name

String

函數(shù)名稱,在單個流程中,名稱需要唯一

最小長度:0

最大長度:256

operation

String

函數(shù)調用URN

最小長度:0

最大長度:256

metadata

Object

函數(shù)擴展屬性,由用戶自己定制

表6 OperationState

參數(shù)

是否必選

參數(shù)類型

描述

action_mode

String

Action執(zhí)行模式,支持串行,并行兩種模式,默認串行

最小長度:1

最大長度:32

枚舉值:

  • sequential

  • parallel

actions

Array of Action objects

節(jié)點中要執(zhí)行的操作列表

on_errors

Array of OnError objects

錯誤處理策略

id

String

節(jié)點ID,需要在當前函數(shù)流中唯一

最小長度:0

最大長度:64

name

String

節(jié)點名稱

最小長度:1

最大長度:256

type

String

節(jié)點類型

最小長度:1

最大長度:32

枚舉值:

  • Operation

  • Sleep

  • End

end

Boolean

是否是結束節(jié)點

transition

String

下一步驟節(jié)點ID

最小長度:0

最大長度:256

state_data_filter

StateDataFilter object

過濾表達式

duration

Long

時間等待節(jié)點等待時間(秒),節(jié)點類型為Sleep時為必填,節(jié)點類型不為Sleep時無效

最小值:0.001

最大值:86400

表7 Action

參數(shù)

是否必選

參數(shù)類型

描述

function_ref

FunctionRef object

函數(shù)調用信息

表8 FunctionRef

參數(shù)

是否必選

參數(shù)類型

描述

ref_name

String

函數(shù)引用名稱,需要和外層functions中的name對應

最小長度:0

最大長度:256

invoke_mode

String

函數(shù)調用模式,目前只支持同步調用

最小長度:1

最大長度:32

枚舉值:

  • synchronize

  • asynchronous

arguments

Object

函數(shù)執(zhí)行時的入?yún)ⅲС忠胏onstants中的常量 定義方式:參數(shù)路徑 | 常量值/常量路徑 參數(shù)路徑指輸入?yún)?shù)的JsonPath路徑,如$.a.b[0].c 常量值可以為數(shù)字類型,字符串類型(需要用單引號括起來),布爾類型 常量路徑為常量的JsonPath路徑,但是根節(jié)點需要用$CONST表示,示例:$CONST.a.b

表9 OnError

參數(shù)

是否必選

參數(shù)類型

描述

error

String

錯誤匹配表達式,用來過濾需要處理的異常

最小長度:0

最大長度:256

transition

String

下一步驟節(jié)點ID

最小長度:0

最大長度:256

retry_ref

String

重試策略名稱

最小長度:0

最大長度:256

表10 StateDataFilter

參數(shù)

是否必選

參數(shù)類型

描述

input

String

輸入過濾表達式(JsonPath)

最小長度:0

最大長度:256

output

String

輸出過濾表達式(JsonPath)

最小長度:0

最大長度:256

表11 Retry

參數(shù)

是否必選

參數(shù)類型

描述

name

String

重試策略名稱,在單個流程中,名稱需要唯一

最小長度:1

最大長度:256

delay

Long

重試間隔,單位:秒。若不傳,默認為1

最小值:1

最大值:30

max_attempts

Long

最大重試次數(shù),。若不傳,默認為3

最小值:1

最大值:8

表12 ExpressConfig

參數(shù)

是否必選

參數(shù)類型

描述

log_level

String

快速模式相關配置,僅在mode配置為EXPRESS時生效 快速模式下流程的執(zhí)行日志級別,當前支持: ALL: 記錄所有節(jié)點的執(zhí)行日志 ERROR:僅記錄異常節(jié)點執(zhí)行日志 NONE:不記錄日志 注意:當配置為ALL和ERROR級別時租戶需要開啟 LTS 相關權限

最小長度:1

最大長度:5

枚舉值:

  • ALL

  • ERROR

  • NONE

響應參數(shù)

狀態(tài)碼: 201

表13 響應Body參數(shù)

參數(shù)

參數(shù)類型

描述

id

String

唯一標識ID,流程定義ID

最小長度:1

最大長度:64

workflow_urn

String

函數(shù)工作流 URN, 格式為:urn:fss:<region_id>:<project_id>:workflow:<package>:<workflow_name>:<version>注意:package當前只支持defaultversion當前只支持latest

name

String

流程定義名稱

最小長度:1

最大長度:64

description

String

流程定義描述

最小長度:0

最大長度:512

created_time

String

流程創(chuàng)建時間,格式:yyyy-MM-ddTHH:mm:ssZ,UTC時間

最小長度:0

最大長度:64

updated_time

String

流程修改時間,格式:yyyy-MM-ddTHH:mm:ssZ,UTC時間

最小長度:0

最大長度:64

created_by

String

流程創(chuàng)建者

最小長度:0

最大長度:64

enable_stream_response

Boolean

是否返回流數(shù)據(jù)

缺省值:false

狀態(tài)碼: 400

表14 響應Body參數(shù)

參數(shù)

參數(shù)類型

描述

error_code

String

錯誤碼

最小長度:1

最大長度:36

error_msg

String

錯誤描述

最小長度:2

最大長度:512

request_id

String

請求ID

最小長度:2

最大長度:512

狀態(tài)碼: 500

表15 響應Body參數(shù)

參數(shù)

參數(shù)類型

描述

error_code

String

錯誤碼

最小長度:1

最大長度:36

error_msg

String

錯誤描述

最小長度:2

最大長度:512

request_id

String

請求ID

最小長度:2

最大長度:512

請求示例

創(chuàng)建名為workflow_test,開始節(jié)點的名稱為test的函數(shù)流。

POST /v2/{project_id}/fgs/workflows

{
  "name" : "workflow_test",
  "start" : "test",
  "functions" : [ {
    "name" : "test",
    "operation" : "urn:fss:{regin}:c53626012ba84727b938ca8bf03108ef:test:latest"
  } ],
  "constants" : { },
  "states" : [ {
    "id" : "test",
    "name" : "test",
    "type" : "Operation",
    "end" : false,
    "transition" : "end",
    "actions" : [ {
      "function_ref" : {
        "ref_name" : "test",
        "arguments" : {
          "execution_name" : "$.test"
        }
      }
    } ]
  }, {
    "id" : "end",
    "name" : "end",
    "type" : "End",
    "end" : true,
    "transition" : "",
    "state_data_filter" : {
      "input" : "",
      "output" : ""
    },
    "actions" : [ ],
    "action_mode" : ""
  } ],
  "retries" : [ {
    "name" : "test"
  } ]
}

響應示例

狀態(tài)碼: 201

Created

{
  "id" : "48aff955-ea10-4ffd-b426-190bc192dc14",
  "workflow_urn" : "urn:fss:cn-north-7:73d69ae0cfcf460190522d060f05ad:workflow:default:testflow:latest",
  "name" : "test-flow",
  "description" : "desc",
  "created_time" : "2021-01-01T00:00:00Z",
  "updated_time" : "2021-01-01T00:00:00Z",
  "created_by" : "admin"
}

狀態(tài)碼

狀態(tài)碼

描述

201

Created

400

Bad Request

500

Internal Server Error

錯誤碼

請參見錯誤碼。