Skip to content

Commit

Permalink
Merge pull request #2674 from jsonwan/github_perf/step_api
Browse files Browse the repository at this point in the history
perf: 提供步骤详情与步骤执行结果查询的APIGW接口 #2596
  • Loading branch information
jsonwan authored Dec 18, 2023
2 parents ad2653b + fdd3ea4 commit d1e5e5d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 53 deletions.
106 changes: 65 additions & 41 deletions docs/apidoc/bk-api-gateway/v3/zh/get_step_instance_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
}
Expand All @@ -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_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_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 |


##### host_result

| 字段 | 类型 | 是否一定存在 | 描述 |
|--------------------|-----------|------------|-----------|
Expand All @@ -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时间戳,单位毫秒 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HostResult> stepHostResultList;
private List<StepResultGroup> 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<HostResult> hostResultList;
}

@Setter
@Getter
Expand Down Expand Up @@ -113,9 +131,6 @@ public static class HostResult {

private String tag;

@JsonProperty("group_key")
private String groupKey;

@JsonProperty("exit_code")
private Integer exitCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,13 +83,23 @@ private EsbStepInstanceStatusV3DTO buildEsbStepInstanceStatusV3DTO(StepExecution
stepInst.setEndTime(stepInstance.getEndTime());
stepInst.setTotalTime(stepInstance.getTotalTime());

List<EsbStepInstanceStatusV3DTO.HostResult> stepHostResults = new ArrayList<>();
List<EsbStepInstanceStatusV3DTO.StepResultGroup> stepResultGroupList = new ArrayList<>();
List<AgentTaskResultGroupDTO> resultGroups = executionResult.getResultGroups();
for (AgentTaskResultGroupDTO resultGroup : resultGroups) {
List<AgentTaskDetailDTO> 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<EsbStepInstanceStatusV3DTO.HostResult> hostResults = new ArrayList<>();
for (AgentTaskDetailDTO agentTask : agentTaskList) {
EsbStepInstanceStatusV3DTO.HostResult stepHostResult = new EsbStepInstanceStatusV3DTO.HostResult();
stepHostResult.setHostId(agentTask.getHostId());
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void tearDown() {
}

@Nested
class GetStepInstanceDetailTest {
class GetStepInstanceStatusTest {
@Test
@DisplayName("测试正常获取脚本步骤状态")
void testGetScriptStepInstanceStatus() {
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d1e5e5d

Please sign in to comment.