From 4e68a4ea1af982f00bbf20233ccb1c54fc26a43e Mon Sep 17 00:00:00 2001 From: jsonwan Date: Mon, 18 Dec 2023 12:20:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?perf:=20=E6=8F=90=E4=BE=9B=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E8=AF=A6=E6=83=85=E4=B8=8E=E6=AD=A5=E9=AA=A4=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E7=BB=93=E6=9E=9C=E6=9F=A5=E8=AF=A2=E7=9A=84APIGW?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20#2596?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整接口返回数据结构,补充分组内主机总量字段 --- .../v3/zh/get_step_instance_status.md | 106 +++++++++++------- 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/docs/apidoc/bk-api-gateway/v3/zh/get_step_instance_status.md b/docs/apidoc/bk-api-gateway/v3/zh/get_step_instance_status.md index 11d632fd02..04542c04a0 100644 --- a/docs/apidoc/bk-api-gateway/v3/zh/get_step_instance_status.md +++ b/docs/apidoc/bk-api-gateway/v3/zh/get_step_instance_status.md @@ -54,38 +54,52 @@ "start_time": 1605064271000, "end_time": 1605064272000, "total_time": 1000, - "step_host_result_list": [ + "step_result_group_list": [ { - "bk_host_id": 101, - "ip": "127.0.0.1", - "ipv6": null, - "bk_agent_id": null, - "bk_cloud_id": 0, - "bk_cloud_name": "Default Area", - "status": 9, - "status_desc": "执行成功", + "result_type": 9, + "result_type_desc": "执行成功", "tag": "tag1", - "group_key": "9_tag1", - "exit_code": 0, - "start_time": 1605064271000, - "end_time": 1605064272000, - "total_time": 1000 + "host_size": 2, + "host_result_list": [ + { + "bk_host_id": 101, + "ip": "127.0.0.1", + "ipv6": null, + "bk_agent_id": null, + "bk_cloud_id": 0, + "bk_cloud_name": "Default Area", + "status": 9, + "status_desc": "执行成功", + "tag": "tag1", + "exit_code": 0, + "start_time": 1605064271000, + "end_time": 1605064272000, + "total_time": 1000 + } + ] }, { - "bk_host_id": 102, - "ip": "127.0.0.2", - "ipv6": null, - "bk_agent_id": null, - "bk_cloud_id": 0, - "bk_cloud_name": "Default Area", - "status": 9, - "status_desc": "执行成功", + "result_type": 9, + "result_type_desc": "执行成功", "tag": "tag2", - "group_key": "9_tag2", - "exit_code": 0, - "start_time": 1605064271000, - "end_time": 1605064272000, - "total_time": 1000 + "host_size": 2, + "host_result_list": [ + { + "bk_host_id": 102, + "ip": "127.0.0.2", + "ipv6": null, + "bk_agent_id": null, + "bk_cloud_id": 0, + "bk_cloud_name": "Default Area", + "status": 9, + "status_desc": "执行成功", + "tag": "tag2", + "exit_code": 0, + "start_time": 1605064271000, + "end_time": 1605064272000, + "total_time": 1000 + } + ] } ] } @@ -103,21 +117,32 @@ ##### data -| 字段 | 类型 | 是否一定存在 | 描述 | -|-----------------------|--------------------------|------------|-----------| -| step_instance_id | long | 是 | 作业步骤实例ID | -| execute_count | int | 是 | 步骤重试次数 | -| name | string | 是 | 步骤名称 | -| type | int | 是 | 步骤类型:1-脚本步骤;2-文件步骤;4-SQL步骤 | -| status | int | 是 | 作业步骤状态码: 1-未执行,2-正在执行,3-执行成功,4-执行失败,5-跳过,6-忽略错误,7-等待用户,8-手动结束,9-状态异常,10-步骤强制终止中,11-步骤强制终止成功,12-步骤强制终止失败 | -| create_time | long | 是 | 作业步骤实例创建时间,Unix时间戳,单位毫秒 | -| start_time | long | 是 | 开始执行时间,Unix时间戳,单位毫秒 | -| end_time | long | 是 | 执行结束时间,Unix时间戳,单位毫秒 | -| total_time | int | 是 | 总耗时,单位毫秒 | -| step_host_result_list | list | 是 | 每个主机的任务执行结果,定义见step_host_result | +| 字段 | 类型 | 是否一定存在 | 描述 | +|------------------------|--------------------------|------------|-----------| +| step_instance_id | long | 是 | 作业步骤实例ID | +| execute_count | int | 是 | 步骤重试次数 | +| name | string | 是 | 步骤名称 | +| type | int | 是 | 步骤类型:1-脚本步骤;2-文件步骤;4-SQL步骤 | +| status | int | 是 | 作业步骤状态码: 1-未执行,2-正在执行,3-执行成功,4-执行失败,5-跳过,6-忽略错误,7-等待用户,8-手动结束,9-状态异常,10-步骤强制终止中,11-步骤强制终止成功,12-步骤强制终止失败 | +| create_time | long | 是 | 作业步骤实例创建时间,Unix时间戳,单位毫秒 | +| start_time | long | 是 | 开始执行时间,Unix时间戳,单位毫秒 | +| end_time | long | 是 | 执行结束时间,Unix时间戳,单位毫秒 | +| total_time | int | 是 | 总耗时,单位毫秒 | +| step_result_group_list | list | 是 | 任务执行结果分组列表,元素定义见step_result_group | -##### step_host_result +##### step_result_group + +| 字段 | 类型 | 是否一定存在 | 描述 | +|--------------------|--------------------|------------|-------------| +| result_type | int | 是 | 分组类型 | +| result_type_desc | string | 是 | 分组类型描述 | +| tag | string | 是 | 分组标签 | +| host_size | int | 是 | 分组内主机总量 | +| host_result_list | list | 是 | 每个分组内的主机任务执行结果列表,元素定义见host_result | + + +##### host_result | 字段 | 类型 | 是否一定存在 | 描述 | |--------------------|-----------|------------|-----------| @@ -130,7 +155,6 @@ | status | int | 是 | 任务状态:0-未知错误,1-Agent异常,2-无效主机,3-上次已成功,5-等待执行,7-正在执行,9-执行成功,11-执行失败,12-任务下发失败,13-任务超时,15-任务日志错误,16-GSE脚本日志超时,17-GSE文件日志超时,101-脚本执行失败,102-脚本执行超时,103-脚本执行被终止,104-脚本返回码非零,202-文件传输失败,203-源文件不存在,301-文件任务系统错误-未分类的,303-文件任务超时,310-Agent异常,311-用户名不存在,312-用户密码错误,320-文件获取失败,321-文件超出限制,329-文件传输错误,399-任务执行出错,403-任务强制终止成功,404-任务强制终止失败,500-未知状态 | | status_desc | string | 是 | 任务状态描述 | | tag | string | 否 | 用户通过job_success/job_fail函数模板自定义输出的结果。仅脚本任务存在该参数 | -| group_key | string | 否 | 基于status与tag字段的分组键,仅用于调用方验证分组内数据数量是否正确,请勿强依赖该字段 | | exit_code | int | 否 | 脚本任务exit code | | start_time | long | 是 | 开始执行时间,Unix时间戳,单位毫秒 | | end_time | long | 是 | 执行结束时间,Unix时间戳,单位毫秒 | From d3212a4bbed8c08a319f87751753f6160a00a0d8 Mon Sep 17 00:00:00 2001 From: jsonwan Date: Mon, 18 Dec 2023 20:14:25 +0800 Subject: [PATCH 2/3] =?UTF-8?q?perf:=20=E6=8F=90=E4=BE=9B=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E8=AF=A6=E6=83=85=E4=B8=8E=E6=AD=A5=E9=AA=A4=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E7=BB=93=E6=9E=9C=E6=9F=A5=E8=AF=A2=E7=9A=84APIGW?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20#2596?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 代码实现:调整接口返回数据结构 --- .../esb/v3/EsbStepInstanceStatusV3DTO.java | 25 +++++++++++++++---- ...sbGetStepInstanceStatusV3ResourceImpl.java | 20 ++++++++++++--- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbStepInstanceStatusV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbStepInstanceStatusV3DTO.java index d093409c8c..e31346e5c3 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbStepInstanceStatusV3DTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbStepInstanceStatusV3DTO.java @@ -83,9 +83,27 @@ public class EsbStepInstanceStatusV3DTO { @JsonProperty("total_time") private Long totalTime; - @JsonProperty("step_host_result_list") + @JsonProperty("step_result_group_list") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private List stepHostResultList; + private List stepResultGroupList; + + @Setter + @Getter + public static class StepResultGroup { + @JsonProperty("result_type") + private Integer resultType; + + @JsonProperty("result_type_desc") + private String resultTypeDesc; + + private String tag; + + @JsonProperty("host_size") + private Integer hostSize; + + @JsonProperty("host_result_list") + private List hostResultList; + } @Setter @Getter @@ -113,9 +131,6 @@ public static class HostResult { private String tag; - @JsonProperty("group_key") - private String groupKey; - @JsonProperty("exit_code") private Integer exitCode; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetStepInstanceStatusV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetStepInstanceStatusV3ResourceImpl.java index a183983da2..5742fdfefd 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetStepInstanceStatusV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetStepInstanceStatusV3ResourceImpl.java @@ -35,6 +35,7 @@ import com.tencent.bk.job.common.metrics.CommonMetricNames; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.service.AppScopeMappingService; +import com.tencent.bk.job.execute.engine.consts.AgentTaskStatusEnum; import com.tencent.bk.job.execute.model.AgentTaskDetailDTO; import com.tencent.bk.job.execute.model.AgentTaskResultGroupDTO; import com.tencent.bk.job.execute.model.StepExecutionDetailDTO; @@ -82,13 +83,23 @@ private EsbStepInstanceStatusV3DTO buildEsbStepInstanceStatusV3DTO(StepExecution stepInst.setEndTime(stepInstance.getEndTime()); stepInst.setTotalTime(stepInstance.getTotalTime()); - List stepHostResults = new ArrayList<>(); + List stepResultGroupList = new ArrayList<>(); List resultGroups = executionResult.getResultGroups(); for (AgentTaskResultGroupDTO resultGroup : resultGroups) { List agentTaskList = resultGroup.getAgentTasks(); if (CollectionUtils.isEmpty(agentTaskList)) { continue; } + EsbStepInstanceStatusV3DTO.StepResultGroup stepResultGroup = + new EsbStepInstanceStatusV3DTO.StepResultGroup(); + stepResultGroup.setResultType(resultGroup.getStatus()); + AgentTaskStatusEnum taskStatusEnum = AgentTaskStatusEnum.valueOf(resultGroup.getStatus()); + if (taskStatusEnum != null) { + stepResultGroup.setResultTypeDesc(messageI18nService.getI18n(taskStatusEnum.getI18nKey())); + } + stepResultGroup.setTag(resultGroup.getTag()); + stepResultGroup.setHostSize(resultGroup.getTotalAgentTasks()); + List hostResults = new ArrayList<>(); for (AgentTaskDetailDTO agentTask : agentTaskList) { EsbStepInstanceStatusV3DTO.HostResult stepHostResult = new EsbStepInstanceStatusV3DTO.HostResult(); stepHostResult.setHostId(agentTask.getHostId()); @@ -100,15 +111,16 @@ private EsbStepInstanceStatusV3DTO buildEsbStepInstanceStatusV3DTO(StepExecution stepHostResult.setStatus(agentTask.getStatus().getValue()); stepHostResult.setStatusDesc(messageI18nService.getI18n(agentTask.getStatus().getI18nKey())); stepHostResult.setTag(agentTask.getTag()); - stepHostResult.setGroupKey(resultGroup.getGroupKey()); stepHostResult.setExitCode(agentTask.getExitCode()); stepHostResult.setStartTime(agentTask.getStartTime()); stepHostResult.setEndTime(agentTask.getEndTime()); stepHostResult.setTotalTime(agentTask.getTotalTime()); - stepHostResults.add(stepHostResult); + hostResults.add(stepHostResult); } + stepResultGroup.setHostResultList(hostResults); + stepResultGroupList.add(stepResultGroup); } - stepInst.setStepHostResultList(stepHostResults); + stepInst.setStepResultGroupList(stepResultGroupList); return stepInst; } From fdd3ea479a604cf8315a1ae5503bcf75dfb64175 Mon Sep 17 00:00:00 2001 From: jsonwan Date: Mon, 18 Dec 2023 20:47:49 +0800 Subject: [PATCH 3/3] =?UTF-8?q?perf:=20=E6=8F=90=E4=BE=9B=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E8=AF=A6=E6=83=85=E4=B8=8E=E6=AD=A5=E9=AA=A4=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E7=BB=93=E6=9E=9C=E6=9F=A5=E8=AF=A2=E7=9A=84APIGW?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20#2596?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复测试用例 --- .../testcase/EsbGetStepInstanceStatusV3ResourceAPITest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/EsbGetStepInstanceStatusV3ResourceAPITest.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/EsbGetStepInstanceStatusV3ResourceAPITest.java index 54a741b147..c27f779ef1 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/EsbGetStepInstanceStatusV3ResourceAPITest.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/EsbGetStepInstanceStatusV3ResourceAPITest.java @@ -28,7 +28,7 @@ static void tearDown() { } @Nested - class GetStepInstanceDetailTest { + class GetStepInstanceStatusTest { @Test @DisplayName("测试正常获取脚本步骤状态") void testGetScriptStepInstanceStatus() { @@ -50,7 +50,7 @@ void testGetScriptStepInstanceStatus() { .body("data.execute_count", equalTo(0)) .body("data.type", equalTo(1)) .body("data.status", notNullValue()) - .body("data.step_host_result_list", hasSize(1)); + .body("data.step_result_group_list", hasSize(1)); } @Test @@ -73,7 +73,7 @@ void testGetFileStepInstanceStatus() { .body("data.execute_count", equalTo(0)) .body("data.type", equalTo(2)) .body("data.status", notNullValue()) - .body("data.step_host_result_list", hasSize(1)); + .body("data.step_result_group_list", hasSize(1)); } @Test