更新函数#
功能介绍#
该 API 用于在 openYuanrong 集群,调用 meta_service 接口更新函数。
接口约束#
无
URI#
PUT /serverless/v1/functions/{name}
名称 |
类型 |
是否必填 |
描述 |
|---|---|---|---|
name |
String |
是 |
请求参数#
请求 Header 参数#
参数 |
类型 |
是否必填 |
描述 |
|---|---|---|---|
Content-Type |
string |
是 |
消息体类型,建议填写 |
x-storage-type |
string |
是 |
代码包上传方式,取值: |
请求 Body 参数#
名称 |
类型 |
是否必填 |
描述 |
|---|---|---|---|
revisionId |
String |
是 |
函数 revisionId,需与更新前一致,可通过查询接口获取,如:查询函数列表、查询函数的所有版本、查询函数的指定版本。 |
description |
String |
否 |
函数描述。 |
handler |
String |
否 |
调用处理器。 |
kind |
String |
是 |
函数类型,取值 |
cpu |
int |
是 |
函数 CPU 大小,单位: |
memory |
int |
是 |
函数 MEM 大小,单位: |
timeout |
int |
是 |
函数调用超时时间。 |
customResources |
map |
否 |
函数自定义资源。 |
environment |
map |
否 |
函数环境变量。 |
extendedHandler |
ExtendedHandler |
否 |
配置 init handler 信息。 |
extendedTimeout |
ExtendedTimeout |
否 |
配置 init 超时信息。 |
minInstance |
String |
否 |
最小实例数(函数服务使用)。 |
maxInstance |
String |
否 |
最大实例数(函数服务使用)。 |
concurrentNum |
String |
否 |
实例并发度(函数服务使用)。 |
storageType |
String |
否 |
代码包存储类型。 |
codePath |
String |
否 |
代码包本地路径。 |
s3CodePath |
S3Object |
否 |
代码包 S3 路径, |
poolId |
String |
否 |
自定义亲和 pool 池 ID。函数实例创建资源不足(或者亲和条件不满足),内核创建指定 poolID 的 POD,用于实例调度。 |
resourceAffinitySelectors |
ResourceAffinitySelector |
否 |
函数调度亲和、优先级配置。 |
Note
当 storageType 配置为 copy 时,openYuanrong会将 codePath 里的代码包拷贝到容器其他目录缓存,相比 local 方式,可以降低加载代码时磁盘 IO 带来的性能下降,建议设置目录权限为 755,确保有权限被容器内 sn 用户拷贝。
S3Object 介绍#
名称 |
类型 |
是否必填 |
描述 |
|---|---|---|---|
bucketId |
String |
否 |
存储桶名。 |
objectId |
String |
否 |
存储对象 ID。 |
bucketUrl |
String |
否 |
存储 URL。 |
sha512 |
String |
否 |
代码包 sha512 值,可通过执行 sha512sum 命令获取。 |
ExtendedHandler 介绍#
名称 |
类型 |
是否必填 |
描述 |
|---|---|---|---|
initializer |
String |
否 |
初始化接口,函数服务按需配置。 |
pre_stop |
String |
否 |
停止接口,函数停止之前执行的退出逻辑,函数服务按需配置。 |
ExtendedTimeout 介绍#
名称 |
类型 |
是否必填 |
描述 |
|---|---|---|---|
initializer |
int |
否 |
初始化超时时间,函数服务按需配置。 |
pre_stop |
int |
否 |
函数停止超时时间,最大值 |
Note
当 storageType 配置为 copy 或 s3 时,init 超时时间需包含 init handler 的执行时间,以及代码包的拷贝或者下载时间,对于超大代码包,建议设置一个较大的超时时间。
ResourceAffinitySelector 介绍#
名称 |
类型 |
是否必填 |
描述 |
|---|---|---|---|
group |
String |
否 |
资源组名称。 |
priority |
int |
否 |
优先级(字段预留)。 |
响应参数#
名称 |
类型 |
是否必填 |
描述 |
|---|---|---|---|
code |
int |
是 |
返回码。 |
message |
String |
是 |
返回错误信息。 |
function |
UpdateFunctionResult |
是 |
创建结果。 |
UpdateFunctionResult 介绍#
名称 |
类型 |
是否必填 |
描述 |
|---|---|---|---|
id |
int |
是 |
函数 ID。 |
functionVersionUrn |
String |
是 |
函数版本 URN,用于调用函数。 |
revisionId |
String |
是 |
函数 revisionId,用于发布函数。 |
状态码#
状态码 |
描述 |
|---|---|
200 |
请求成功(ok)。 |
500 |
内部服务器错误(Internal Server Error)。 |
请求示例#
POST {meta service endpoint}/serverless/v1/functions/{name}
{
"revisionId": "20250318064354416",
"description": "this is a function",
"handler": "handler.my_handler",
"kind": "faas",
"cpu": 600,
"memory": 512,
"timeout": 600,
"customResources": {},
"environment": {},
"extendedHandler": {
"initializer": "handler.init",
"pre_stop": "test.prestop"
},
"extendedTimeout": {
"initializer": 600,
"pre_stop": 10
},
"minInstance": "0",
"maxInstance": "10",
"concurrentNum": "2",
"storageType": "local",
"codePath": "/home/sn/function-packages",
"s3CodePath": {
},
"resourceAffinitySelectors": [
{
"group": "rg1",
"priority": 1
},
{
"group": "rg2",
"priority": 2
}
]
}
响应示例#
正常响应#
{
"code": 0,
"message": "SUCCESS",
"function": {
"id": "sn:cn:yrk:12345678901234561234567890123456:function:0@faaspy@hello2:latest",
"createTime": "",
"updateTime": "",
"functionUrn": "",
"name": "",
"tenantId": "",
"businessId": "",
"productId": "",
"reversedConcurrency": 0,
"description": "",
"tag": null,
"functionVersionUrn": "sn:cn:yrk:12345678901234561234567890123456:function:0@faaspy@hello2:latest",
"revisionId": "20240302084750473",
"codeSize": 0,
"codeSha256": "",
"bucketId": "",
"objectId": "",
"handler": "",
"layers": null,
"cpu": 0,
"memory": 0,
"runtime": "",
"timeout": 0,
"versionNumber": "",
"versionDesc": "",
"environment": null,
"customResources": null,
"statefulFlag": 0,
"lastModified": "",
"Published": "",
"minInstance": 0,
"maxInstance": 0,
"concurrentNum": 0,
"funcLayer": null,
"status": "",
"instanceNum": 0,
"device": {},
"created": ""
}
}
错误响应#
{
"code": 4134,
"message": "revisionID is not the same"
}