恢复历史版本¶
POST /api/v1/pipeline_history/{pipeline_history_uuid}/restore
概述¶
恢复历史配置;configVersion为当前配置版本号,过期返回409。无需先测试,名称和source冲突仍报错;isForce仅确认默认替换。
路由参数¶
| 参数名 | 类型 | 必选 | 说明 |
|---|---|---|---|
| pipeline_history_uuid | string | Y | 历史列表 historyRecord[].uuid 返回的历史 UUID,不是 Pipeline UUID 或数字 id。 |
Body 请求参数¶
| 参数名 | 类型 | 必选 | 说明 |
|---|---|---|---|
| configVersion | integer | Y | 调用前从当前 Pipeline 详情或历史列表首屏读取的 configVersion,整数且大于等于1;不是目标历史版本号。用于检测并发修改,过期返回409。 允许为空: False $minValue: 1 |
| isForce | boolean | 恢复为默认 Pipeline 时,是否确认替换现有默认 Pipeline 允许为空: False |
参数补充说明¶
将指定历史配置覆盖到原 Pipeline。本操作会改变客户资源配置,请先读取并确认目标历史详情。
推荐调用流程¶
- 查询当前 Pipeline 详情或历史首屏,取得当前 configVersion。
- 从历史列表选择目标 uuid,读取历史详情并确认配置。
- 将当前 configVersion 放入请求体,调用目标历史 uuid 的 restore。
- 成功后以响应中的 configVersion 和配置为准,刷新本地缓存。
例如当前版本为 3、目标历史为 1,请求体应传 {"configVersion":3},而不是 1。成功且配置实际变化时归档原当前配置,产生新的当前版本(如 4);不会把当前版本号改回 1,也不会修改目标历史快照。恢复内容不包含启停状态,无需先运行测试;若目标配置与当前配置相同,则不生成新版本。
冲突与确认¶
- HTTP 409 / ft.PipelineConfigVersionConflict:当前配置已被其他调用修改。停止覆盖,重新读取并比较最新配置,经调用方确认后再提交;不要自动用新版本号盲目重试。
- ft.PipelineSourceExists:历史 source 已被其他 Pipeline 占用。解决冲突后再恢复;isForce=true 不能绕过 source 或版本冲突。
- 若恢复为默认 Pipeline 与现有默认项冲突且未确认,可能返回成功响应中的 content.confirm(如 {"confirm":["logging"]})。这只是确认提示,不代表恢复完成;由调用方确认后携带 isForce=true 和仍有效的 configVersion 再调用。
- 超时或连接中断时,写入结果可能未知,应先查询当前配置和版本,不要无条件重复写入。
使用前提¶
使用所属工作空间的 DF-API-KEY 调用 OpenAPI 服务。查询需要读取权限;恢复和克隆需要 Pipeline 管理及写入权限。接口不支持通过请求体指定其他工作空间或操作人。示例中的 Endpoint、资源 UUID 和 API-Key 均为占位符,请替换后调用,不要在日志中输出 API Key。
响应示例使用虚构资源,展示典型业务字段;实际响应可能包含普通 Pipeline 接口的其他字段。调用方应兼容新增字段。
版本字段¶
| 字段 | 含义 |
|---|---|
| configVersion | 配置版本号,新建资源从 1 开始;启用、禁用不推进此版本 |
| configVersionAt | 此配置版本生成时间,Unix 秒级时间戳,不是毫秒 |
| configVersionOperator / configVersionOperatorInfo | 操作人标识及展示信息;无法解析展示信息时可能为空对象 |
| configVersionSource / configVersionAction | 版本来源及动作,例如 openapi/modify、history/history_restore |
| configVersionSourceInfo | 来源补充信息;历史操作含 pipelineHistoryUUID、pipelineUUID、configVersion |
| createAt | 历史快照归档时间,可能晚于 configVersionAt;历史列表保留窗口按此字段计算 |
历史 config.content 和 config.testData 为 Base64 编码字符串。调用方先 Base64 解码,再按 UTF-8 读取;testData 是测试样例,不会因读取或恢复接口自动执行。不要把 configVersionSourceInfo 中的来源版本号当成当前版本号。
返回说明¶
成功写入的 content 沿用普通修改接口的 Pipeline 对象,含 uuid、配置字段及版本元数据;确认分支的 content 仅包含 confirm。资源被删除、历史被清理或无权限时不执行恢复。
请求例子¶
curl -X POST 'https://openapi.guance.com/api/v1/pipeline_history/<pipeline_history_uuid>/restore' -H 'DF-API-KEY: <API-Key>' -H 'Content-Type: application/json' -d '{"configVersion":3,"isForce":false}'
响应¶
{
"code": 200,
"content": {
"name": "demo",
"type": "local",
"category": "logging",
"source": [
"nginx"
],
"content": "YWRkX2tleShjaXR5LCAic2hhbmdoYWkiKQ==",
"testData": "W10=",
"dataType": "line_protocol",
"asDefault": 0,
"enableByLogBackup": 0,
"extend": {},
"id": 10,
"uuid": "pl_example",
"workspaceUUID": "wksp_example",
"status": 0,
"creator": "acnt_example",
"updator": "acnt_example",
"createAt": 1788799900,
"updateAt": 1788800200,
"deleteAt": -1,
"configVersion": 4,
"configVersionAt": 1788800200,
"configVersionOperator": "acnt_example",
"configVersionSource": "history",
"configVersionAction": "history_restore",
"configVersionSourceInfo": {
"pipelineHistoryUUID": "plh_example",
"pipelineUUID": "pl_example",
"configVersion": 2
}
},
"errorCode": "",
"message": "",
"success": true,
"traceId": "TRACE_EXAMPLE"
}