更新时间:2024-03-21 GMT+08:00
分享

更新触发器

功能介绍

更新触发器

调用方法

请参见如何调用API

URI

PUT /v2/{project_id}/fgs/triggers/{function_urn}/{trigger_type_code}/{trigger_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

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

function_urn

String

函数的URN,详细解释见FunctionGraph函数模型的描述。

trigger_type_code

String

触发器类型代码。

枚举值:

  • TIMER

  • APIG

  • CTS

  • DDS

  • DMS

  • DIS

  • LTS

  • OBS

  • SMN

  • KAFKA

  • RABBITMQ

  • DEDICATEDGATEWAY

  • OPENSOURCEKAFKA

  • APIC

  • GAUSSMONGO

  • EVENTGRID

  • IOTDA

trigger_id

String

触发器编码。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

Content-Type

String

消息体的类型(格式)

缺省值:application/json

表3 请求Body参数

参数

是否必选

参数类型

描述

trigger_status

String

触发器状态

枚举值:

  • ACTIVE

  • DISABLED

event_data

Array of UpdateriggerEventData objects

触发器更新事件

表4 UpdateriggerEventData

参数

是否必选

参数类型

描述

is_serial

Boolean

串行处理数据

max_fetch_bytes

Integer

最大字节数

polling_interval

Integer

拉取周期

polling_unit

String

拉取周期单位

枚举值:

  • ms

  • s

响应参数

状态码: 200

表5 响应Body参数

参数

参数类型

描述

trigger_id

String

触发器ID。

trigger_type_code

String

触发器类型。

  • TIMER: "定时触发器。"

  • APIG: "APIG触发器。"

  • CTS: "云审计服务触发器。"

  • DDS: "文档数据库服务触发器。"

  • DMS: "分布式服务触发器。"

  • DIS: "数据接入服务触发器。"

  • LTS: "云日志服务触发器。"

  • OBS: "对象存储触发器。"

  • SMN: "消息通知服务触发器。"

  • KAFKA: "专享版消息通知服务触发器。"

枚举值:

  • TIMER

  • APIG

  • CTS

  • DDS

  • DMS

  • DIS

  • LTS

  • OBS

  • SMN

  • KAFKA

  • RABBITMQ

  • DEDICATEDGATEWAY

  • OPENSOURCEKAFKA

  • APIC

  • GAUSSMONGO

  • EVENTGRID

  • IOTDA

trigger_status

String

"触发器状态"

  • ACTIVE: 启用状态。

  • DISABLED: 禁用状态。

枚举值:

  • ACTIVE

  • DISABLED

event_data

TriggerEventDataResponseBody object

触发器源事件。

last_updated_time

String

最后更新时间。

created_time

String

触发器创建时间。

表6 TriggerEventDataResponseBody

参数

参数类型

描述

name

String

触发器名称

schedule_type

String

定时触发类型(TIMER触发器参数)。

  • Rate:指定固定频率(分钟、小时、天数)定期调用函数,单位为分钟时,输入值不能超过60;单位为小时时,输入值不能超过24;单位为天时,输入值不能超过30。

  • Cron:指定Cron表达式定期调用函数

枚举值:

  • Rate

  • Cron

schedule

String

定时触发规则(TIMER触发器参数)。

  • 触发类型为Rate时对应定时规则

  • 触发类型为Cron时对应Cron表达式

user_event

String

附加信息(TIMER触发器参数)。 当Timer触发器触发函数执行时,执行事件(函数的event参数)为: {"version": "v1.0", "time": "2018-06-01T08:30:00+08:00", "trigger_type": "TIMER", "trigger_name": "Timer_001", "user_event": "您输入的附加信息"}

triggerid

String

APIG触发器id。(APIG触发器参数)

type

Integer

API接口类型(APIG触发器参数)。

  • 1:公有API

  • 2:私有API

path

String

APIG接口PATH路径(APIG触发器参数)。

protocol

String

API的请求协议(APIG触发器参数)。

枚举值:

  • HTTP

  • HTTPS

req_method

String

API的请求方式(APIG触发器参数)。

枚举值:

  • GET

  • POST

  • PUT

  • DELETE

  • HEAD

  • PATCH

  • OPTIONS

  • ANY

group_id

String

API所属的分组编号(APIG触发器参数)。

group_name

String

API所属的分组名称(APIG触发器参数)。

match_mode

String

API的匹配方式(APIG触发器参数)。

  • SWA:前缀匹配

  • NORMAL:正常匹配(绝对匹配)

枚举值:

  • SWA

  • NORMAL

env_name

String

API的发布环境(APIG触发器参数)。

env_id

String

API的发布环境id(APIG触发器参数)。

api_id

String

API编号(APIG触发器参数)。

api_name

String

API名称(APIG触发器参数)。

auth

String

API的认证方式(APIG触发器参数)。

  • IAM:IAM认证,只允许IAM用户能访问,安全级别中等

  • APP:采用Appkey&Appsecret认证,安全级别高,推荐使用

  • NONE:无认证模式,所有用户均可访问,不推荐使用

枚举值:

  • IAM

  • APP

  • NONE

invoke_url

String

API调用地址(APIG触发器参数)。

func_info

ApigTriggerFuncInfo object

APIG触发器函数工作流后端详情(APIG触发器参数)。APIG触发器此参数必填。

sl_domain

String

APIG系统默认分配的子域名(APIG触发器参数)。

最小长度:1

最大长度:255

backend_type

String

API的后端类型(APIG触发器参数)。

枚举值:

  • FUNCTION

instance_id

String

实例id。DDS、KAFKA、RABBITMQ触发器此参数必填。

  • APIG触发器:apig实例id

  • DDS触发器:文档数据库实例id

  • KAFKA触发器:KAFKA实例id

  • RABBITMQ触发器:RABBITMQ实例id

roma_app_id

String

API归属的集成应用编号。(APIG触发器参数)

operations

Array of strings

自定义操作(CTS触发器参数)。 CTS云审计服务类型和操作订阅所需要的事件通知,当CTS云审计服务获取已订阅的操作记录后,通过CTS触发器将采集到的操作记录作为参数传递来调用FunctionGraph函数。

collection_name

String

集合名称(DDS触发器参数)。

db_name

String

文档数据库名称(DDS触发器参数)。

db_password

String

文档数据库密码(DDS触发器参数)。

db_user

String

文档数据库用户名(DDS触发器参数)。

instance_addrs

Array of strings

文档数据库实例地址(DDS触发器参数)。

mode

String

文档数据库实例类型(DDS触发器参数)。

  • Sharding:集群实例

  • ReplicaSet:副本集实例

  • Single:单节点实例

batch_size

Integer

批处理大小,单次函数执行处理的最大数据量。DIS、DDS、KAFKA、RABBITMQ触发器此参数必填。

  • DDS触发器:批处理大小设置1-10,000的范围内

  • DIS触发器:批处理大小设置1-10,000的范围内

  • KAFKA触发器:批处理大小设置1-1,000的范围内

  • RABBITMQ触发器:批处理大小设置1-1,000的范围内

queue_id

String

队列id(DMS触发器参数)。

consumer_group_id

String

消费组id(DMS触发器参数)。

polling_interval

Integer

拉取周期。

stream_name

String

通道名称(DIS触发器参数)。

sharditerator_type

String

起始位置(DIS触发器参数)。

  • TRIM_HORIZON:从最早被存储至分区的有效记录开始读取。

  • LATEST:从分区中的最新记录开始读取,此设置可以保证总是读到分区中最新记录。

枚举值:

  • TRIM_HORIZON

  • LATEST

polling_unit

String

拉取周期单位(DIS触发器参数)。

  • s:秒

  • ms:毫秒

枚举值:

  • s

  • ms

max_fetch_bytes

Integer

最大提取字节数(DIS触发器参数)。

最小值:0

最大值:4194304

is_serial

String

串行处理数据(DIS触发器参数),如果开启该选项,取一次数据处理完之后才会取下一次数据;否则只要拉取周期到了就会取数据进行处理。

枚举值:

  • true

  • false

log_group_id

String

日志组id(LTS触发器参数)。

log_topic_id

String

日志流id(LTS触发器参数)。

bucket

String

桶名称(OBS触发器参数),用作事件源的OBS存储桶,不能和本用户已有桶重名;不能和其他用户已有的桶重名;创建成功后不支持修改。

最小长度:1

最大长度:64

prefix

String

前缀(OBS触发器参数),输入一个可选性前缀来限制对以此关键字开头的对象的通知。

最小长度:0

最大长度:1024

suffix

String

后缀(OBS触发器参数),输入一个可选性后缀来限制对以此关键字结尾的对象的通知

最小长度:0

最大长度:1024

events

Array of strings

触发事件(OBS触发器参数)。

  • ObjectCreated:表示所有创建对象的操作,包含Put、Post、Copy对象以及合并段

  • Put:使用Put方法上传对象

  • Post:使用Post方法上传对象

  • Copy:使用copy方法复制对象

  • CompleteMultipartUpload:表示合并分段任务

  • ObjectRemoved:表示删除对象

  • Delete:指定对象版本号删除对象

  • DeleteMarkerCreated:不指定对象版本号删除对象

topic_urn

String

主题URN(SMN触发器参数)。

最小长度:1

最大长度:255

topic_ids

Array of strings

KAFKA主题id列表(KAFKA触发器参数)。

kafka_user

String

KAFKA账户名(KAFKA触发器参数)。

kafka_password

String

KAFKA账户密码(KAFKA触发器参数)。

kafka_connect_address

String

KAFKA实例连接IP地址(KAFKA触发器参数)。

kafka_ssl_enable

Boolean

KAFKA连接是否开启安全认证(KAFKA触发器参数)。

access_password

String

RABBITMQ账户密码(RABBITMQ触发器参数)。

access_user

String

RABBITMQ账户名(RABBITMQ触发器参数)。

connect_address

String

实例连接IP地址(RABBITMQ触发器参数)。

exchange_name

String

交换机名称(RABBITMQ触发器参数)。

vhost

String

虚拟机名称(RABBITMQ触发器参数)。

ssl_enable

Boolean

RABBITMQ连接是否开启安全认证(RABBITMQ触发器参数)。

表7 ApigTriggerFuncInfo

参数

参数类型

描述

function_urn

String

函数的URN,详细解释见FunctionGraph函数模型的描述。

invocation_type

String

调用函数执行方式。

  • sync:同步执行

  • async:异步执行

枚举值:

  • sync

  • async

timeout

Integer

API网关请求函数服务的超时时间(毫秒)。APIG触发器此参数必填。

最小值:1

最大值:60000

version

String

函数版本信息。

状态码: 404

表8 响应Body参数

参数

参数类型

描述

error_code

String

错误码

error_msg

String

错误信息

请求示例

更新触发器状态为开启。

PUT https://{Endpoint}/v2/{project_id}/fgs/triggers/{function_urn}/{trigger_type_code}/{trigger_id}

{
  "trigger_status" : "ACTIVE"
}

响应示例

状态码: 200

OK

{
  "trigger_id" : "9a14fae1-78cf-4185-ac7a-429eb6dc41fb",
  "trigger_type_code" : "TIMER",
  "trigger_status" : "ACTIVE",
  "event_data" : {
    "name" : "Timer-cpg3",
    "schedule" : "3m",
    "schedule_type" : "Rate"
  },
  "last_updated_time" : "2022-11-09 16:37:24",
  "created_time" : "2019-10-29171553"
}

状态码: 404

Not Found

{
  "error_code" : "FSS.0404",
  "error_msg" : "not found"
}

SDK代码示例

SDK代码示例如下。

更新触发器状态为开启。

 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
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.*;


public class UpdateTriggerSolution {

    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();
        UpdateTriggerRequest request = new UpdateTriggerRequest();
        UpdateTriggerRequestBody body = new UpdateTriggerRequestBody();
        body.withTriggerStatus(UpdateTriggerRequestBody.TriggerStatusEnum.fromValue("ACTIVE"));
        request.withBody(body);
        try {
            UpdateTriggerResponse response = client.updateTrigger(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());
        }
    }
}

更新触发器状态为开启。

 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
# 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 = UpdateTriggerRequest()
        request.body = UpdateTriggerRequestBody(
            trigger_status="ACTIVE"
        )
        response = client.update_trigger(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

更新触发器状态为开启。

 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
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.UpdateTriggerRequest{}
	triggerStatusUpdateTriggerRequestBody:= model.GetUpdateTriggerRequestBodyTriggerStatusEnum().ACTIVE
	request.Body = &model.UpdateTriggerRequestBody{
		TriggerStatus: &triggerStatusUpdateTriggerRequestBody,
	}
	response, err := client.UpdateTrigger(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

OK

404

Not Found

错误码

请参见错误码

分享:

    相关文档

    相关产品