From d99f7ea32c00279f0231499bef93990feaeb2e15 Mon Sep 17 00:00:00 2001 From: wangyu096 Date: Fri, 26 Jan 2024 17:14:05 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20Job=20=E6=94=AF=E6=8C=81=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E6=89=A7=E8=A1=8C=20-=20=E8=84=9A=E6=9C=AC=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=20#2631?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RollingConfigDAOImplIntegrationTest.java | 60 ++++++++++++------- .../v2/impl/EsbExecuteTaskResourceImpl.java | 4 +- .../EsbGetJobInstanceStatusResourceImpl.java | 3 +- ...EsbGetJobInstanceStatusV3ResourceImpl.java | 3 +- .../result/AbstractResultHandleTask.java | 4 +- .../engine/rolling/RollingExprPart.java | 3 +- .../job/execute/model/ExecuteObjectsDTO.java | 3 +- .../service/impl/TaskExecuteServiceImpl.java | 8 ++- .../impl/LogServiceImplIntegrationTest.java | 9 ++- 9 files changed, 66 insertions(+), 31 deletions(-) diff --git a/src/backend/job-execute/boot-job-execute/src/test/java/com/tencent/bk/job/execute/dao/impl/RollingConfigDAOImplIntegrationTest.java b/src/backend/job-execute/boot-job-execute/src/test/java/com/tencent/bk/job/execute/dao/impl/RollingConfigDAOImplIntegrationTest.java index 1b88814c59..c98af72a95 100644 --- a/src/backend/job-execute/boot-job-execute/src/test/java/com/tencent/bk/job/execute/dao/impl/RollingConfigDAOImplIntegrationTest.java +++ b/src/backend/job-execute/boot-job-execute/src/test/java/com/tencent/bk/job/execute/dao/impl/RollingConfigDAOImplIntegrationTest.java @@ -72,7 +72,8 @@ void queryRollingConfig() { assertThat(savedTaskInstanceRollingConfig.getTaskInstanceId()).isEqualTo(1L); assertThat(savedTaskInstanceRollingConfig.getConfigDetail()).isNotNull(); assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExpr()).isEqualTo("1 10% 100%"); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMode()).isEqualTo(RollingModeEnum.PAUSE_IF_FAIL.getValue()); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMode()) + .isEqualTo(RollingModeEnum.PAUSE_IF_FAIL.getValue()); assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getName()).isEqualTo("config1"); assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getStepRollingConfigs()).hasSize(4); Map stepRollingConfigs = @@ -82,20 +83,34 @@ void queryRollingConfig() { assertThat(stepRollingConfigs.get(102L).isBatch()).isEqualTo(true); assertThat(stepRollingConfigs.get(103L).isBatch()).isEqualTo(true); assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly()).hasSize(3); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0).getBatch()).isEqualTo(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0).getExecuteObjectsCompatibly()).hasSize(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0).getExecuteObjectsCompatibly().get(0).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0).getExecuteObjectsCompatibly().get(0).getHost().getIp()).isEqualTo("127.0.0.1"); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(1).getBatch()).isEqualTo(2); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(1).getExecuteObjectsCompatibly()).hasSize(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(1).getExecuteObjectsCompatibly().get(0).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(1).getExecuteObjectsCompatibly().get(0).getHost().getIp()).isEqualTo("127.0.0.2"); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2).getBatch()).isEqualTo(3); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2).getExecuteObjectsCompatibly()).hasSize(2); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2).getExecuteObjectsCompatibly().get(0).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2).getExecuteObjectsCompatibly().get(0).getHost().getIp()).isEqualTo("127.0.0.3"); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2).getExecuteObjectsCompatibly().get(1).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2).getExecuteObjectsCompatibly().get(1).getHost().getIp()).isEqualTo("127.0.0.4"); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0) + .getBatch()).isEqualTo(1); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0) + .getExecuteObjectsCompatibly()).hasSize(1); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0) + .getExecuteObjectsCompatibly().get(0).getHost().getBkCloudId()).isEqualTo(0L); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0) + .getExecuteObjectsCompatibly().get(0).getHost().getIp()).isEqualTo("127.0.0.1"); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(1) + .getBatch()).isEqualTo(2); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(1) + .getExecuteObjectsCompatibly()).hasSize(1); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(1) + .getExecuteObjectsCompatibly().get(0).getHost().getBkCloudId()).isEqualTo(0L); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(1) + .getExecuteObjectsCompatibly().get(0).getHost().getIp()).isEqualTo("127.0.0.2"); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2) + .getBatch()).isEqualTo(3); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2) + .getExecuteObjectsCompatibly()).hasSize(2); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2) + .getExecuteObjectsCompatibly().get(0).getHost().getBkCloudId()).isEqualTo(0L); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2) + .getExecuteObjectsCompatibly().get(0).getHost().getIp()).isEqualTo("127.0.0.3"); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2) + .getExecuteObjectsCompatibly().get(1).getHost().getBkCloudId()).isEqualTo(0L); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(2) + .getExecuteObjectsCompatibly().get(1).getHost().getIp()).isEqualTo("127.0.0.4"); } @Test @@ -139,7 +154,8 @@ void saveRollingConfig() { assertThat(savedTaskInstanceRollingConfig.getTaskInstanceId()).isEqualTo(10L); assertThat(savedTaskInstanceRollingConfig.getConfigDetail()).isNotNull(); assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExpr()).isEqualTo("10%"); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMode()).isEqualTo(RollingModeEnum.PAUSE_IF_FAIL.getValue()); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMode()) + .isEqualTo(RollingModeEnum.PAUSE_IF_FAIL.getValue()); assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getName()).isEqualTo("default"); assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getStepRollingConfigs()).hasSize(4); Map savedStepRollingConfigs = @@ -149,10 +165,14 @@ void saveRollingConfig() { assertThat(savedStepRollingConfigs.get(1002L).isBatch()).isEqualTo(true); assertThat(savedStepRollingConfigs.get(1003L).isBatch()).isEqualTo(true); assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly()).hasSize(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0).getBatch()).isEqualTo(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0).getExecuteObjectsCompatibly().get(0).getHost().getHostId()).isEqualTo(1L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0).getExecuteObjectsCompatibly().get(0).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0).getExecuteObjectsCompatibly().get(0).getHost().getIp()).isEqualTo("127.0.0.1"); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0) + .getBatch()).isEqualTo(1); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0) + .getExecuteObjectsCompatibly().get(0).getHost().getHostId()).isEqualTo(1L); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0) + .getExecuteObjectsCompatibly().get(0).getHost().getBkCloudId()).isEqualTo(0L); + assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly().get(0) + .getExecuteObjectsCompatibly().get(0).getHost().getIp()).isEqualTo("127.0.0.1"); } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java index e5d9e82b52..80ce609c33 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java @@ -100,8 +100,8 @@ public EsbResp executeJob( taskVariableDTO.setName(globalVar.getName()); if ((globalVar.getIpList() != null || globalVar.getDynamicGroupIdList() != null || globalVar.getTargetServer() != null) && StringUtils.isEmpty(globalVar.getValue())) { - ExecuteObjectsDTO executeObjectsDTO = convertToServersDTO(globalVar.getTargetServer(), globalVar.getIpList(), - globalVar.getDynamicGroupIdList()); + ExecuteObjectsDTO executeObjectsDTO = convertToServersDTO( + globalVar.getTargetServer(), globalVar.getIpList(), globalVar.getDynamicGroupIdList()); taskVariableDTO.setTargetServers(executeObjectsDTO); } else { taskVariableDTO.setValue(globalVar.getValue()); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceStatusResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceStatusResourceImpl.java index 9e6b974f9a..2b93865974 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceStatusResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceStatusResourceImpl.java @@ -99,7 +99,8 @@ public EsbResp getJobInstanceStatusUsingPost( TaskInstanceDTO taskInstance = taskInstanceService.getTaskInstance(username, request.getAppResourceScope().getAppId(), request.getTaskInstanceId()); - List stepInstances = stepInstanceService.listBaseStepInstanceByTaskInstanceId(taskInstanceId); + List stepInstances = + stepInstanceService.listBaseStepInstanceByTaskInstanceId(taskInstanceId); if (stepInstances == null || stepInstances.isEmpty()) { log.warn("Get job instance status by taskInstanceId:{}, stepInstanceList is empty!", taskInstanceId); throw new NotFoundException(ErrorCode.STEP_INSTANCE_NOT_EXIST); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3ResourceImpl.java index 05ae120cbc..ef3f507efd 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3ResourceImpl.java @@ -96,7 +96,8 @@ public EsbResp getJobInstanceStatusUsingPost( TaskInstanceDTO taskInstance = taskInstanceService.getTaskInstance( username, request.getAppResourceScope().getAppId(), request.getTaskInstanceId()); - List stepInstances = stepInstanceService.listBaseStepInstanceByTaskInstanceId(taskInstanceId); + List stepInstances = + stepInstanceService.listBaseStepInstanceByTaskInstanceId(taskInstanceId); if (stepInstances == null || stepInstances.isEmpty()) { log.warn("Get job instance status by taskInstanceId:{}, stepInstanceList is empty!", taskInstanceId); throw new NotFoundException(ErrorCode.STEP_INSTANCE_NOT_EXIST); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/AbstractResultHandleTask.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/AbstractResultHandleTask.java index 41fab90ffd..685dad905a 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/AbstractResultHandleTask.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/AbstractResultHandleTask.java @@ -439,7 +439,9 @@ private boolean shouldSkipStep() { private void saveStatusWhenSkip() { List notFinishedExecuteObjectTasks = - targetExecuteObjectTasks.values().stream().filter(not(ExecuteObjectTask::isFinished)).collect(Collectors.toList()); + targetExecuteObjectTasks.values().stream() + .filter(not(ExecuteObjectTask::isFinished)) + .collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(notFinishedExecuteObjectTasks)) { notFinishedExecuteObjectTasks.forEach(executeObjectTask -> { executeObjectTask.setStatus(ExecuteObjectTaskStatusEnum.UNKNOWN); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/rolling/RollingExprPart.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/rolling/RollingExprPart.java index a5266042fb..8e7a0e9c17 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/rolling/RollingExprPart.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/rolling/RollingExprPart.java @@ -58,6 +58,7 @@ public abstract class RollingExprPart { * @param context 解析上下文 * @return 当前批次的执行对象 */ - public abstract List compute(RollingExecuteObjectBatchContext context) throws RollingExprParseException; + public abstract List compute(RollingExecuteObjectBatchContext context) + throws RollingExprParseException; } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/ExecuteObjectsDTO.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/ExecuteObjectsDTO.java index 4c08859ff6..c690f46564 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/ExecuteObjectsDTO.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/ExecuteObjectsDTO.java @@ -303,7 +303,8 @@ public ExecuteObject findExecuteObjectByCompositeKey(ExecuteObjectCompositeKey e switch (compositeKeyType) { case EXECUTE_OBJECT_ID: return getExecuteObjectsCompatibly().stream() - .filter(executeObject -> executeObjectCompositeKey.getExecuteObjectId().equals(executeObject.getId())) + .filter(executeObject -> + executeObjectCompositeKey.getExecuteObjectId().equals(executeObject.getId())) .findFirst() .orElse(null); case RESOURCE_ID: diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java index 53250b8f81..f5d6e64b69 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java @@ -1751,8 +1751,12 @@ username, new AppResourceScope(appId), plan.getTaskTemplateId(), } } - private Pair> extractNeedAuthHostsAndAccounts(StepInstanceDTO stepInstance, - Map> whiteHostAllowActions) { + private Pair> extractNeedAuthHostsAndAccounts + ( + StepInstanceDTO stepInstance, + Map> whiteHostAllowActions + ) { + ExecuteObjectsDTO authServers = new ExecuteObjectsDTO(); Set accountIds = new HashSet<>(); accountIds.add(stepInstance.getAccountId()); diff --git a/src/backend/job-logsvr/boot-job-logsvr/src/test/java/com/tencent/bk/job/logsvr/service/impl/LogServiceImplIntegrationTest.java b/src/backend/job-logsvr/boot-job-logsvr/src/test/java/com/tencent/bk/job/logsvr/service/impl/LogServiceImplIntegrationTest.java index 7a5ac83168..3dd5bc23b6 100644 --- a/src/backend/job-logsvr/boot-job-logsvr/src/test/java/com/tencent/bk/job/logsvr/service/impl/LogServiceImplIntegrationTest.java +++ b/src/backend/job-logsvr/boot-job-logsvr/src/test/java/com/tencent/bk/job/logsvr/service/impl/LogServiceImplIntegrationTest.java @@ -402,8 +402,13 @@ void testSaveFileLog() { } - private TaskExecuteObjectLog buildFileTaskHostLog(long stepInstanceId, int executeCount, String jobCreateDate, Long hostId, - String ip, String ipv6, List fileTaskLogs) { + private TaskExecuteObjectLog buildFileTaskHostLog(long stepInstanceId, + int executeCount, + String jobCreateDate, + Long hostId, + String ip, + String ipv6, + List fileTaskLogs) { TaskExecuteObjectLog taskExecuteObjectLog = new TaskExecuteObjectLog(); taskExecuteObjectLog.setStepInstanceId(stepInstanceId); taskExecuteObjectLog.setExecuteCount(executeCount);