Skip to content

Commit

Permalink
perf: 提供步骤详情与步骤执行结果查询的APIGW接口 TencentBlueKing#2596
Browse files Browse the repository at this point in the history
处理review意见
  • Loading branch information
jsonwan committed Nov 27, 2023
1 parent c4b8673 commit e57a418
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
| bk_scope_id | string || 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID |
| job_instance_id | long || 作业实例ID |
| step_instance_id | long || 步骤实例ID |
| execute_count | int || 步骤重试次数,从0开始计数,默认值为0|
| execute_count | int || 步骤重试次数,从0开始计数,不传表示获取最近一次重试的数据|
| batch | int || 滚动批次,从0开始计数,默认值为null表示获取所有批次的数据。 |
| max_host_num_per_group | int || 每个分组(按照status与tag进行分组,分组键可参考返回值字段中的group_key字段)里的最大主机数量,不传则返回全量数据。 |
| keyword | string || 日志搜索关键字,只返回日志中包含该关键字的主机执行状态数据(注意:仅脚本步骤支持) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ validation.constraints.AccountCategory_illegal.message=账号用途取值非法
validation.constraints.AccountPassword_tooLong.message=账号密码不能超过255字符
validation.constraints.AccountAlias_tooLong.message=账号别名不能超过255字符
validation.constraints.AccountDescription_tooLong.message=账号描述不能超过1024字符
validation.constraints.InvalidJobInstanceId.message=任务实例ID必须为正整数
validation.constraints.InvalidStepInstanceId.message=步骤实例ID必须为正整数
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ validation.constraints.AccountCategory_illegal.message=Account category value is
validation.constraints.AccountPassword_tooLong.message=Account password length cannot be larger than 255
validation.constraints.AccountAlias_tooLong.message=Account alias length cannot be larger than 255
validation.constraints.AccountDescription_tooLong.message=Account description length cannot be larger than 1024
validation.constraints.InvalidJobInstanceId.message=Job instance id must be a positive number
validation.constraints.InvalidStepInstanceId.message=Step instance id must be a positive number
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ validation.constraints.AccountCategory_illegal.message=Account category value is
validation.constraints.AccountPassword_tooLong.message=Account password length cannot be larger than 255
validation.constraints.AccountAlias_tooLong.message=Account alias length cannot be larger than 255
validation.constraints.AccountDescription_tooLong.message=Account description length cannot be larger than 1024
validation.constraints.InvalidJobInstanceId.message=Job instance id must be a positive number
validation.constraints.InvalidStepInstanceId.message=Step instance id must be a positive number
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ validation.constraints.AccountCategory_illegal.message=账号用途取值非法
validation.constraints.AccountPassword_tooLong.message=账号密码不能超过255字符
validation.constraints.AccountAlias_tooLong.message=账号别名不能超过255字符
validation.constraints.AccountDescription_tooLong.message=账号描述不能超过1024字符
validation.constraints.InvalidJobInstanceId.message=任务实例ID必须为正整数
validation.constraints.InvalidStepInstanceId.message=步骤实例ID必须为正整数
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ validation.constraints.AccountCategory_illegal.message=账号用途取值非法
validation.constraints.AccountPassword_tooLong.message=账号密码不能超过255字符
validation.constraints.AccountAlias_tooLong.message=账号别名不能超过255字符
validation.constraints.AccountDescription_tooLong.message=账号描述不能超过1024字符
validation.constraints.InvalidJobInstanceId.message=任务实例ID必须为正整数
validation.constraints.InvalidStepInstanceId.message=步骤实例ID必须为正整数
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,38 @@
import com.tencent.bk.job.common.constant.JobCommonHeaders;
import com.tencent.bk.job.common.esb.model.EsbResp;
import com.tencent.bk.job.common.esb.model.job.v3.resp.EsbStepV3DTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;

/**
* 根据步骤实例 ID 查询步骤执行详情API-V3
*/
@Validated
@RequestMapping("/esb/api/v3")
@RestController
@EsbAPI
public interface EsbGetStepInstanceDetailV3Resource {

@GetMapping("/get_step_instance_detail")
EsbResp<EsbStepV3DTO> getStepInstanceStatus(
EsbResp<EsbStepV3DTO> getStepInstanceDetail(
@RequestHeader(value = JobCommonHeaders.USERNAME) String username,
@RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode,
@RequestParam(value = "bk_scope_type") String scopeType,
@RequestParam(value = "bk_scope_id") String scopeId,
@RequestParam(value = "job_instance_id") Long taskInstanceId,
@RequestParam(value = "step_instance_id") Long stepInstanceId);
@RequestParam(value = "job_instance_id")
@NotNull(message = "{validation.constraints.InvalidJobInstanceId.message}")
@Positive(message = "{validation.constraints.InvalidJobInstanceId.message}")
Long taskInstanceId,
@RequestParam(value = "step_instance_id")
@NotNull(message = "{validation.constraints.InvalidStepInstanceId.message}")
@Positive(message = "{validation.constraints.InvalidStepInstanceId.message}")
Long stepInstanceId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@
import com.tencent.bk.job.common.constant.JobCommonHeaders;
import com.tencent.bk.job.common.esb.model.EsbResp;
import com.tencent.bk.job.execute.model.esb.v3.EsbStepInstanceStatusV3DTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;

/**
* 根据步骤实例 ID 查询步骤执行状态API-V3
*/
@Validated
@RequestMapping("/esb/api/v3")
@RestController
@EsbAPI
Expand All @@ -48,9 +53,13 @@ EsbResp<EsbStepInstanceStatusV3DTO> getStepInstanceStatus(
@RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode,
@RequestParam(value = "bk_scope_type") String scopeType,
@RequestParam(value = "bk_scope_id") String scopeId,
@NotNull(message = "{validation.constraints.InvalidJobInstanceId.message}")
@Positive(message = "{validation.constraints.InvalidJobInstanceId.message}")
@RequestParam(value = "job_instance_id") Long taskInstanceId,
@NotNull(message = "{validation.constraints.InvalidStepInstanceId.message}")
@Positive(message = "{validation.constraints.InvalidStepInstanceId.message}")
@RequestParam(value = "step_instance_id") Long stepInstanceId,
@RequestParam(value = "execute_count", required = false, defaultValue = "0") Integer executeCount,
@RequestParam(value = "execute_count", required = false) Integer executeCount,
@RequestParam(value = "batch", required = false) Integer batch,
@RequestParam(value = "max_host_num_per_group", required = false) Integer maxHostNumPerGroup,
@RequestParam(value = "keyword", required = false) String keyword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class EsbStepInstanceDetailV3DTO {

/**
* 作业步骤ID
* 步骤实例ID
*/
private Long id;

Expand All @@ -56,21 +56,21 @@ public class EsbStepInstanceDetailV3DTO {
* 脚本步骤信息
*/
@JsonProperty("script_step_info")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonInclude(JsonInclude.Include.NON_NULL)
private ScriptStepInfo scriptStepInfo;

/**
* 文件步骤信息
*/
@JsonProperty("file_step_info")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonInclude(JsonInclude.Include.NON_NULL)
private FileStepInfo fileStepInfo;

/**
* 审批步骤信息
*/
@JsonProperty("approval_step_info")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonInclude(JsonInclude.Include.NON_NULL)
private ApprovalStepInfo approvalStepInfo;

@Setter
Expand All @@ -96,7 +96,7 @@ public static class ScriptStepInfo {
private Long scriptVersionId;

/**
* BASE64编码的脚本内容
* 脚本内容
*/
private String content;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class EsbStepInstanceStatusV3DTO {

/**
* id
* 步骤实例id
*/
@JsonProperty("step_instance_id")
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
import com.tencent.bk.job.execute.model.FileDetailDTO;
import com.tencent.bk.job.execute.model.FileSourceDTO;
import com.tencent.bk.job.execute.model.StepInstanceDTO;
import com.tencent.bk.job.execute.service.FileTransferModeService;
import com.tencent.bk.job.execute.service.StepInstanceValidateService;
import com.tencent.bk.job.execute.service.TaskInstanceAccessProcessor;
import com.tencent.bk.job.execute.service.TaskInstanceService;
import com.tencent.bk.job.execute.util.FileTransferModeUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
Expand All @@ -61,23 +61,20 @@ public class EsbGetStepInstanceDetailV3ResourceImpl implements EsbGetStepInstanc
private final AppScopeMappingService appScopeMappingService;
private final TaskInstanceAccessProcessor taskInstanceAccessProcessor;
private final StepInstanceValidateService stepInstanceValidateService;
private final FileTransferModeService fileTransferModeService;

public EsbGetStepInstanceDetailV3ResourceImpl(TaskInstanceService taskInstanceService,
AppScopeMappingService appScopeMappingService,
TaskInstanceAccessProcessor taskInstanceAccessProcessor,
StepInstanceValidateService stepInstanceValidateService,
FileTransferModeService fileTransferModeService) {
StepInstanceValidateService stepInstanceValidateService) {
this.taskInstanceService = taskInstanceService;
this.appScopeMappingService = appScopeMappingService;
this.taskInstanceAccessProcessor = taskInstanceAccessProcessor;
this.stepInstanceValidateService = stepInstanceValidateService;
this.fileTransferModeService = fileTransferModeService;
}

@Override
@AuditEntry(actionId = ActionId.VIEW_HISTORY)
public EsbResp<EsbStepV3DTO> getStepInstanceStatus(String username,
public EsbResp<EsbStepV3DTO> getStepInstanceDetail(String username,
String appCode,
String scopeType,
String scopeId,
Expand Down Expand Up @@ -149,7 +146,7 @@ private EsbStepV3DTO convertToEsbStepV3DTO(StepInstanceDTO stepInstance) {
if (downloadSpeedLimit != null) {
fileStepInfo.setDestinationSpeedLimit(downloadSpeedLimit >> 10);
}
Integer transferMode = fileTransferModeService.getTransferMode(
Integer transferMode = FileTransferModeUtil.getTransferMode(
stepInstance.getFileDuplicateHandle(),
stepInstance.getNotExistPathHandler()
).getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
import com.tencent.bk.job.execute.model.web.vo.TaskInstanceDetailVO;
import com.tencent.bk.job.execute.model.web.vo.TaskInstanceVO;
import com.tencent.bk.job.execute.model.web.vo.TaskOperationLogVO;
import com.tencent.bk.job.execute.service.FileTransferModeService;
import com.tencent.bk.job.execute.service.RollingConfigService;
import com.tencent.bk.job.execute.service.TaskInstanceAccessProcessor;
import com.tencent.bk.job.execute.service.TaskInstanceService;
import com.tencent.bk.job.execute.service.TaskInstanceVariableService;
import com.tencent.bk.job.execute.service.TaskOperationLogService;
import com.tencent.bk.job.execute.util.FileTransferModeUtil;
import com.tencent.bk.job.manage.common.consts.task.TaskFileTypeEnum;
import com.tencent.bk.job.manage.common.consts.task.TaskStepTypeEnum;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -91,7 +91,6 @@ public class WebTaskInstanceResourceImpl implements WebTaskInstanceResource {
private final BusinessAuthService businessAuthService;
private final RollingConfigService rollingConfigService;
private final TaskInstanceAccessProcessor taskInstanceAccessProcessor;
private final FileTransferModeService fileTransferModeService;

@Autowired
public WebTaskInstanceResourceImpl(TaskInstanceService taskInstanceService,
Expand All @@ -100,16 +99,14 @@ public WebTaskInstanceResourceImpl(TaskInstanceService taskInstanceService,
MessageI18nService i18nService,
BusinessAuthService businessAuthService,
RollingConfigService rollingConfigService,
TaskInstanceAccessProcessor taskInstanceAccessProcessor,
FileTransferModeService fileTransferModeService) {
TaskInstanceAccessProcessor taskInstanceAccessProcessor) {
this.taskInstanceService = taskInstanceService;
this.taskInstanceVariableService = taskInstanceVariableService;
this.taskOperationLogService = taskOperationLogService;
this.i18nService = i18nService;
this.businessAuthService = businessAuthService;
this.rollingConfigService = rollingConfigService;
this.taskInstanceAccessProcessor = taskInstanceAccessProcessor;
this.fileTransferModeService = fileTransferModeService;
}

@Override
Expand Down Expand Up @@ -245,7 +242,7 @@ private ExecuteStepVO convertToStepVO(StepInstanceDTO stepInstance) {
fileStepVO.setFileDestination(fileDestinationInfoVO);

fileStepVO.setIgnoreError(stepInstance.isIgnoreError() ? 1 : 0);
Integer transferMode = fileTransferModeService.getTransferMode(
Integer transferMode = FileTransferModeUtil.getTransferMode(
stepInstance.getFileDuplicateHandle(),
stepInstance.getNotExistPathHandler()
).getValue();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ public StepInstanceValidateServiceImpl(TaskInstanceService taskInstanceService)

@Override
public ValidateResult checkStepInstance(long appId, Long taskInstanceId, Long stepInstanceId) {
if (taskInstanceId == null || taskInstanceId < 1) {
log.warn("TaskInstanceId is empty or illegal, taskInstanceId={}", taskInstanceId);
return ValidateResult.fail(ErrorCode.MISSING_OR_ILLEGAL_PARAM_WITH_PARAM_NAME, "job_instance_id");
}
if (stepInstanceId == null || stepInstanceId < 1) {
log.warn("StepInstanceId is empty or illegal, stepInstanceId={}", stepInstanceId);
return ValidateResult.fail(ErrorCode.MISSING_OR_ILLEGAL_PARAM_WITH_PARAM_NAME, "step_instance_id");
}
// 检查taskInstanceId与stepInstanceId关联关系的正确性
Long realTaskInstanceId = taskInstanceService.getTaskInstanceId(appId, stepInstanceId);
if (realTaskInstanceId == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.tencent.bk.job.execute.service.impl;
package com.tencent.bk.job.execute.util;

import com.tencent.bk.job.common.constant.DuplicateHandlerEnum;
import com.tencent.bk.job.common.constant.NotExistPathHandlerEnum;
import com.tencent.bk.job.execute.common.constants.FileTransferModeEnum;
import com.tencent.bk.job.execute.service.FileTransferModeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

Expand All @@ -15,18 +14,17 @@

@Slf4j
@Service
public class FileTransferModeServiceImpl implements FileTransferModeService {
public class FileTransferModeUtil {

@Override
public FileTransferModeEnum getTransferMode(Integer duplicateHandler, Integer notExistPathHandler) {
public static FileTransferModeEnum getTransferMode(Integer duplicateHandler, Integer notExistPathHandler) {
return getTransferMode(
DuplicateHandlerEnum.valueOf(duplicateHandler),
NotExistPathHandlerEnum.valueOf(notExistPathHandler)
);
}

private FileTransferModeEnum getTransferMode(DuplicateHandlerEnum duplicateHandlerEnum,
NotExistPathHandlerEnum notExistPathHandlerEnum) {
private static FileTransferModeEnum getTransferMode(DuplicateHandlerEnum duplicateHandlerEnum,
NotExistPathHandlerEnum notExistPathHandlerEnum) {
if (duplicateHandlerEnum == null) {
// 默认覆盖
duplicateHandlerEnum = OVERWRITE;
Expand Down

0 comments on commit e57a418

Please sign in to comment.