文档首页> 函数工作流 FunctionGraph> API参考> API> 函数流> 修改指定函数流实例的元数据
更新时间:2024-03-21 GMT+08:00
分享

修改指定函数流实例的元数据

功能介绍

修改指定函数流实例的元数据

调用方法

请参见如何调用API

URI

PUT /v2/{project_id}/fgs/workflows/{workflow_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方式请参见获取项目ID

最小长度:1

最大长度:64

workflow_id

String

函数工作流ID

最小长度:1

最大长度:512

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

name

String

函数流名称

最小长度:1

最大长度:64

description

String

函数流描述

最小长度:1

最大长度:512

start

String

流程开始节点ID

最小长度:1

最大长度:256

triggers

Array of Trigger objects

触发器列表

数组长度:0 - 200

functions

Array of Function objects

函数列表

数组长度:0 - 100

states

Array of OperationState objects

函数流节点清单,定义参考SleepState和OperationState

数组长度:1 - 100

constants

Object

函数流中的常量

retries

Array of Retry objects

重试策略清单

数组长度:0 - 200

mode

String

函数流模式,当前支持两种模式NORMAL: 标准模式,普通模式面向普通的业务场景,支持长时间任务,支持执行历史持久化和查询,只支持异步调用EXPRESS: 快速模式,快速模式面向业务执行时长较短,需要极致性能的场景,只支持流程执行时长低于5分钟的场景,不支持执行历史持久化,支持同步和异步调用默认为标准模式

缺省值:NORMAL

枚举值:

  • NORMAL

  • EXPRESS

express_config

ExpressConfig object

快速函数流模式配置,当mode为EXPRESS时需要设置

enterprise_project_id

String

企业项目ID

最小长度:0

最大长度:64

enable_stream_response

Boolean

是否返回流数据

缺省值:false

表3 Trigger

参数

是否必选

参数类型

描述

trigger_name

String

触发器名称

最小长度:1

最大长度:256

trigger_type

String

触发器类型 FLOWTIMER:定时触发器 SMN:SMN触发器 APIG:APIG触发器(共享版) APIG_DE:APIG触发器(专享版) OBS:OBS触发器

最小长度:1

最大长度:32

枚举值:

  • FLOWTIMER

  • SMN

  • APIG

  • APIG_DE

  • OBS

enabled

Boolean

是否启用触发器

缺省值:true

枚举值:

  • true

  • false

trigger_config

OBSTriggerConfig object

OBS触发器配置,当trigger_type为OBS时需要设置

表4 OBSTriggerConfig

参数

是否必选

参数类型

描述

bucket

String

OBS桶名(trigger_type为OBS时配置)

最小长度:1

最大长度:64

events

Array of strings

OBS事件列表(trigger_type为OBS时配置)

数组长度:1 - 64

prefix

String

对象名前缀(trigger_type为OBS时配置)

最小长度:1

最大长度:1024

suffix

String

对象名后缀(trigger_type为OBS时配置)

最小长度:1

最大长度:1024

表5 Function

参数

是否必选

参数类型

描述

name

String

函数名称,在单个流程中,名称需要唯一

最小长度:0

最大长度:256

operation

String

函数调用URN

最小长度:0

最大长度:256

metadata

Object

函数扩展属性,由用户自己定制

表6 OperationState

参数

是否必选

参数类型

描述

action_mode

String

Action执行模式,支持串行,并行两种模式,默认串行

最小长度:1

最大长度:32

枚举值:

  • sequential

  • parallel

actions

Array of Action objects

节点中要执行的操作列表

数组长度:1 - 10

on_errors

Array of OnError objects

错误处理策略

数组长度:0 - 200

id

String

节点ID,需要在当前函数流中唯一

最小长度:0

最大长度:64

name

String

节点名称

最小长度:1

最大长度:256

type

String

节点类型

最小长度:1

最大长度:32

枚举值:

  • Operation

  • Sleep

  • End

end

Boolean

是否是结束节点

transition

String

下一步骤节点ID

最小长度:0

最大长度:256

state_data_filter

StateDataFilter object

过滤表达式

duration

Long

时间等待节点等待时间(秒),节点类型为Sleep时为必填,节点类型不为Sleep时无效

最小值:0.001

最大值:86400

表7 Action

参数

是否必选

参数类型

描述

function_ref

FunctionRef object

函数调用信息

表8 FunctionRef

参数

是否必选

参数类型

描述

ref_name

String

函数引用名称,需要和外层functions中的name对应

最小长度:0

最大长度:256

invoke_mode

String

函数调用模式,目前只支持同步调用

最小长度:1

最大长度:32

枚举值:

  • synchronize

  • asynchronous

arguments

Object

函数执行时的入参,支持引用constants中的常量 定义方式:参数路径 | 常量值/常量路径 参数路径指输入参数的JsonPath路径,如$.a.b[0].c 常量值可以为数字类型,字符串类型(需要用单引号括起来),布尔类型 常量路径为常量的JsonPath路径,但是根节点需要用$CONST表示,示例:$CONST.a.b

表9 OnError

参数

是否必选

参数类型

描述

error

String

错误匹配表达式,用来过滤需要处理的异常

最小长度:0

最大长度:256

transition

String

下一步骤节点ID

最小长度:0

最大长度:256

retry_ref

String

重试策略名称

最小长度:0

最大长度:256

表10 StateDataFilter

参数

是否必选

参数类型

描述

input

String

输入过滤表达式(JsonPath)

最小长度:0

最大长度:256

output

String

输出过滤表达式(JsonPath)

最小长度:0

最大长度:256

表11 Retry

参数

是否必选

参数类型

描述

name

String

重试策略名称,在单个流程中,名称需要唯一

最小长度:1

最大长度:256

delay

Long

重试间隔,单位:秒。若不传,默认为1

最小值:1

最大值:30

max_attempts

Long

最大重试次数,。若不传,默认为3

最小值:1

最大值:8

表12 ExpressConfig

参数

是否必选

参数类型

描述

log_level

String

快速模式相关配置,仅在mode配置为EXPRESS时生效 快速模式下流程的执行日志级别,当前支持: ALL: 记录所有节点的执行日志 ERROR:仅记录异常节点执行日志 NONE:不记录日志 注意:当配置为ALL和ERROR级别时租户需要开启LTS相关权限

最小长度:1

最大长度:5

枚举值:

  • ALL

  • ERROR

  • NONE

响应参数

状态码: 200

表13 响应Body参数

参数

参数类型

描述

id

String

唯一标识ID,流程定义ID

最小长度:1

最大长度:64

workflow_urn

String

函数工作流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

流程创建时间,格式:yyyy-MM-ddTHH:mm:ssZ,UTC时间

最小长度:0

最大长度:64

updated_time

String

流程修改时间,格式:yyyy-MM-ddTHH:mm:ssZ,UTC时间

最小长度:0

最大长度:64

created_by

String

流程创建者

最小长度:0

最大长度:64

enable_stream_response

Boolean

是否返回流数据

缺省值:false

状态码: 400

表14 响应Body参数

参数

参数类型

描述

error_code

String

错误码

最小长度:1

最大长度:36

error_msg

String

错误描述

最小长度:2

最大长度:512

request_id

String

请求ID

最小长度:2

最大长度:512

状态码: 500

表15 响应Body参数

参数

参数类型

描述

error_code

String

错误码

最小长度:1

最大长度:36

error_msg

String

错误描述

最小长度:2

最大长度:512

request_id

String

请求ID

最小长度:2

最大长度:512

请求示例

修改函数流id为{workflow_id}的函数流元数据。

PUT /v2/{project_id}/fgs/workflows/{workflow_id}

{
  "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"
  } ]
}

响应示例

状态码: 200

Success

{
  "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"
}

SDK代码示例

SDK代码示例如下。

修改函数流id为{workflow_id}的函数流元数据。

 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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.functiongraph.v2.region.FunctionGraphRegion;
import com.huaweicloud.sdk.functiongraph.v2.*;
import com.huaweicloud.sdk.functiongraph.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class UpdateWorkFlowSolution {

    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);

        FunctionGraphClient client = FunctionGraphClient.newBuilder()
                .withCredential(auth)
                .withRegion(FunctionGraphRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateWorkFlowRequest request = new UpdateWorkFlowRequest();
        WorkflowCreateBody body = new WorkflowCreateBody();
        List<Retry> listbodyRetries = new ArrayList<>();
        listbodyRetries.add(
            new Retry()
                .withName("test")
        );
        StateDataFilter stateDataFilterStates = new StateDataFilter();
        stateDataFilterStates.withInput("")
            .withOutput("");
        FunctionRef functionRefActions = new FunctionRef();
        functionRefActions.withRefName("test")
            .withArguments("{\"execution_name\":\"$.test\"}");
        List<Action> listStatesActions = new ArrayList<>();
        listStatesActions.add(
            new Action()
                .withFunctionRef(functionRefActions)
        );
        List<OperationState> listbodyStates = new ArrayList<>();
        listbodyStates.add(
            new OperationState()
                .withActions(listStatesActions)
                .withId("test")
                .withName("test")
                .withType(OperationState.TypeEnum.fromValue("Operation"))
                .withEnd(false)
                .withTransition("end")
        );
        listbodyStates.add(
            new OperationState()
                .withActionMode(OperationState.ActionModeEnum.fromValue(""))
                .withActions()
                .withId("end")
                .withName("end")
                .withType(OperationState.TypeEnum.fromValue("End"))
                .withEnd(true)
                .withTransition("")
                .withStateDataFilter(stateDataFilterStates)
        );
        List<Function> listbodyFunctions = new ArrayList<>();
        listbodyFunctions.add(
            new Function()
                .withName("test")
                .withOperation("urn:fss:{regin}:c53626012ba84727b938ca8bf03108ef:test:latest")
        );
        body.withRetries(listbodyRetries);
        body.withConstants(new Object());
        body.withStates(listbodyStates);
        body.withFunctions(listbodyFunctions);
        body.withStart("test");
        body.withName("workflow_test");
        request.withBody(body);
        try {
            UpdateWorkFlowResponse response = client.updateWorkFlow(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());
        }
    }
}

修改函数流id为{workflow_id}的函数流元数据。

 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkfunctiongraph.v2.region.functiongraph_region import FunctionGraphRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkfunctiongraph.v2 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 = FunctionGraphClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(FunctionGraphRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateWorkFlowRequest()
        listRetriesbody = [
            Retry(
                name="test"
            )
        ]
        stateDataFilterStates = StateDataFilter(
            input="",
            output=""
        )
        functionRefActions = FunctionRef(
            ref_name="test",
            arguments="{\"execution_name\":\"$.test\"}"
        )
        listActionsStates = [
            Action(
                function_ref=functionRefActions
            )
        ]
        listStatesbody = [
            OperationState(
                actions=listActionsStates,
                id="test",
                name="test",
                type="Operation",
                end=False,
                transition="end"
            ),
            OperationState(
                action_mode="",
                id="end",
                name="end",
                type="End",
                end=True,
                transition="",
                state_data_filter=stateDataFilterStates
            )
        ]
        listFunctionsbody = [
            Function(
                name="test",
                operation="urn:fss:{regin}:c53626012ba84727b938ca8bf03108ef:test:latest"
            )
        ]
        request.body = WorkflowCreateBody(
            retries=listRetriesbody,
            constants={},
            states=listStatesbody,
            functions=listFunctionsbody,
            start="test",
            name="workflow_test"
        )
        response = client.update_work_flow(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

修改函数流id为{workflow_id}的函数流元数据。

 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    functiongraph "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/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 := functiongraph.NewFunctionGraphClient(
        functiongraph.FunctionGraphClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateWorkFlowRequest{}
	var listRetriesbody = []model.Retry{
        {
            Name: "test",
        },
    }
	inputStateDataFilter:= ""
	outputStateDataFilter:= ""
	stateDataFilterStates := &model.StateDataFilter{
		Input: &inputStateDataFilter,
		Output: &outputStateDataFilter,
	}
	var argumentsFunctionRef interface{} = "{\"execution_name\":\"$.test\"}"
	functionRefActions := &model.FunctionRef{
		RefName: "test",
		Arguments: &argumentsFunctionRef,
	}
	var listActionsStates = []model.Action{
        {
            FunctionRef: functionRefActions,
        },
    }
	actionModeStates:= model.GetOperationStateActionModeEnum().EMPTY
	var listStatesbody = []model.OperationState{
        {
            Actions: listActionsStates,
            Id: "test",
            Name: "test",
            Type: model.GetOperationStateTypeEnum().OPERATION,
            End: false,
            Transition: "end",
        },
        {
            ActionMode: &actionModeStates,
            Id: "end",
            Name: "end",
            Type: model.GetOperationStateTypeEnum().END,
            End: true,
            Transition: "",
            StateDataFilter: stateDataFilterStates,
        },
    }
	var listFunctionsbody = []model.Function{
        {
            Name: "test",
            Operation: "urn:fss:{regin}:c53626012ba84727b938ca8bf03108ef:test:latest",
        },
    }
	var constantsWorkflowCreateBody interface{} = make(map[string]string)
	request.Body = &model.WorkflowCreateBody{
		Retries: listRetriesbody,
		Constants: &constantsWorkflowCreateBody,
		States: listStatesbody,
		Functions: listFunctionsbody,
		Start: "test",
		Name: "workflow_test",
	}
	response, err := client.UpdateWorkFlow(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

Success

400

Bad Request

500

Internal Server Error

错误码

请参见错误码

分享:

    相关文档

    相关产品