From df8c95c25f2d43a945cea0dcfbca0dd4be0d8e22 Mon Sep 17 00:00:00 2001 From: wangyu096 Date: Mon, 1 Jan 2024 18:22:14 +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 --- .../bk/job/common/context/JobContext.java | 4 +- .../RollingConfigDAOImplIntegrationTest.java | 42 +- .../EsbGetStepInstanceStatusResourceImpl.java | 9 +- .../impl/EsbPushConfigFileResourceImpl.java | 2 +- .../v3/EsbPushConfigFileResourceV3Impl.java | 2 +- .../web/impl/WebTaskInstanceResourceImpl.java | 2 +- .../executor/FileGseTaskStartCommand.java | 4 +- .../executor/ScriptGseTaskStartCommand.java | 5 +- .../engine/listener/GseStepEventHandler.java | 6 +- .../execute/engine/model/ExecuteObject.java | 35 +- .../local/LocalFilePrepareService.java | 2 +- .../third/ThirdFilePrepareService.java | 14 +- .../prepare/third/ThirdFilePrepareTask.java | 19 +- .../execute/engine/util/JobSrcFileUtils.java | 10 +- .../JobLastHostsVariableResolver.java | 19 +- .../job/execute/model/ExecuteObjectsDTO.java | 112 ++++- .../execute/model/StepInstanceBaseDTO.java | 22 +- .../bk/job/execute/model/StepInstanceDTO.java | 38 +- .../model/db/RollingConfigDetailDO.java | 4 +- .../db/RollingExecuteObjectsBatchDO.java | 6 +- .../bk/job/execute/service/AgentService.java | 2 +- .../AbstractExecuteObjectTaskServiceImpl.java | 25 +- .../service/impl/AgentServiceImpl.java | 10 +- .../FileExecuteObjectTaskServiceImpl.java | 14 +- .../service/impl/LogExportServiceImpl.java | 2 +- .../execute/service/impl/LogServiceImpl.java | 22 +- .../service/impl/NotifyServiceImpl.java | 2 +- .../impl/RollingConfigServiceImpl.java | 12 +- .../ScriptExecuteObjectTaskServiceImpl.java | 14 +- .../service/impl/StepInstanceServiceImpl.java | 6 +- .../service/impl/TaskExecuteServiceImpl.java | 54 ++- .../service/impl/TaskResultServiceImpl.java | 48 +-- .../ExponentIncrementRollingExprPartTest.java | 26 +- .../rolling/PercentRollingExprPartTest.java | 30 +- .../PlusIncrementRollingExprPartTest.java | 28 +- .../rolling/QuantityRollingExprPartTest.java | 24 +- ...RollingExecuteObjectBatchResolverTest.java | 390 +++++++++--------- 37 files changed, 606 insertions(+), 460 deletions(-) diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/context/JobContext.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/context/JobContext.java index 0050cc9cfb..400740b5b7 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/context/JobContext.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/context/JobContext.java @@ -36,9 +36,7 @@ import java.util.List; import java.util.Map; -/** - * @since 6/11/2019 10:26 - */ + @Data public class JobContext { 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 affa8c0471..1b88814c59 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 @@ -81,21 +81,21 @@ void queryRollingConfig() { assertThat(stepRollingConfigs.get(101L).isBatch()).isEqualTo(false); assertThat(stepRollingConfigs.get(102L).isBatch()).isEqualTo(true); assertThat(stepRollingConfigs.get(103L).isBatch()).isEqualTo(true); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList()).hasSize(3); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(0).getBatch()).isEqualTo(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(0).getMergedExecuteObjects()).hasSize(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(0).getMergedExecuteObjects().get(0).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(0).getMergedExecuteObjects().get(0).getHost().getIp()).isEqualTo("127.0.0.1"); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(1).getBatch()).isEqualTo(2); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(1).getMergedExecuteObjects()).hasSize(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(1).getMergedExecuteObjects().get(0).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(1).getMergedExecuteObjects().get(0).getHost().getIp()).isEqualTo("127.0.0.2"); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(2).getBatch()).isEqualTo(3); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(2).getMergedExecuteObjects()).hasSize(2); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(2).getMergedExecuteObjects().get(0).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(2).getMergedExecuteObjects().get(0).getHost().getIp()).isEqualTo("127.0.0.3"); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(2).getMergedExecuteObjects().get(1).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(2).getMergedExecuteObjects().get(1).getHost().getIp()).isEqualTo("127.0.0.4"); + 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"); } @Test @@ -122,7 +122,7 @@ void saveRollingConfig() { rollingConfig.setStepRollingConfigs(stepRollingConfigs); List executeObjectsBatchList = new ArrayList<>(); List executeObjects = new ArrayList<>(); - executeObjects.add(new ExecuteObject(new HostDTO(1L, 0L, "127.0.0.1"))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject((new HostDTO(1L, 0L, "127.0.0.1")))); RollingExecuteObjectsBatchDO hostBatch1 = new RollingExecuteObjectsBatchDO(1, executeObjects); executeObjectsBatchList.add(hostBatch1); rollingConfig.setExecuteObjectsBatchList(executeObjectsBatchList); @@ -148,11 +148,11 @@ void saveRollingConfig() { assertThat(savedStepRollingConfigs.get(1001L).isBatch()).isEqualTo(false); assertThat(savedStepRollingConfigs.get(1002L).isBatch()).isEqualTo(true); assertThat(savedStepRollingConfigs.get(1003L).isBatch()).isEqualTo(true); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList()).hasSize(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(0).getBatch()).isEqualTo(1); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(0).getMergedExecuteObjects().get(0).getHost().getHostId()).isEqualTo(1L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(0).getMergedExecuteObjects().get(0).getHost().getBkCloudId()).isEqualTo(0L); - assertThat(savedTaskInstanceRollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList().get(0).getMergedExecuteObjects().get(0).getHost().getIp()).isEqualTo("127.0.0.1"); + 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"); } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetStepInstanceStatusResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetStepInstanceStatusResourceImpl.java index 052d66818e..a0fd5a8a83 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetStepInstanceStatusResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetStepInstanceStatusResourceImpl.java @@ -40,6 +40,7 @@ import com.tencent.bk.job.common.model.dto.HostDTO; import com.tencent.bk.job.execute.api.esb.v2.EsbGetStepInstanceStatusResource; import com.tencent.bk.job.execute.engine.consts.ExecuteObjectTaskStatusEnum; +import com.tencent.bk.job.execute.engine.model.ExecuteObject; import com.tencent.bk.job.execute.model.ExecuteObjectTask; import com.tencent.bk.job.execute.model.ResultGroupDTO; import com.tencent.bk.job.execute.model.StepExecutionDetailDTO; @@ -116,7 +117,13 @@ private EsbStepInstanceStatusDTO.StepInstance convertStepInstance(StepInstanceBa stepInst.setId(stepInstance.getId()); stepInst.setEndTime(stepInstance.getEndTime()); stepInst.setStartTime(stepInstance.getStartTime()); - stepInst.setIpList(convertToIpListStr(stepInstance.getTargetExecuteObjects().getIpList())); + stepInst.setIpList( + convertToIpListStr( + stepInstance.getTargetExecuteObjects() + .getExecuteObjectsCompatibly() + .stream() + .map(ExecuteObject::getHost) + .collect(Collectors.toList()))); stepInst.setName(stepInstance.getName()); stepInst.setOperator(stepInstance.getOperator()); stepInst.setExecuteCount(stepInstance.getExecuteCount()); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbPushConfigFileResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbPushConfigFileResourceImpl.java index 21faf30744..42ddfee270 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbPushConfigFileResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbPushConfigFileResourceImpl.java @@ -204,7 +204,7 @@ private List convertConfigFileSource(String userName, files.add(new FileDetailDTO(configFileLocalPath)); fileSourceDTO.setFiles(files); // 设置配置文件所在机器IP信息 - fileSourceDTO.setServers(agentService.getLocalServersDTO()); + fileSourceDTO.setServers(agentService.getLocalHostExecuteObjectDTO()); fileSourceDTOS.add(fileSourceDTO); }); return fileSourceDTOS; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileResourceV3Impl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileResourceV3Impl.java index ac5cc0a381..9d62f34b7c 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileResourceV3Impl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileResourceV3Impl.java @@ -185,7 +185,7 @@ private List convertConfigFileSource( files.add(new FileDetailDTO(configFileLocalPath)); fileSourceDTO.setFiles(files); // 设置配置文件所在机器IP信息 - fileSourceDTO.setServers(agentService.getLocalServersDTO()); + fileSourceDTO.setServers(agentService.getLocalHostExecuteObjectDTO()); fileSourceDTOS.add(fileSourceDTO); }); return fileSourceDTOS; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskInstanceResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskInstanceResourceImpl.java index 62feb9ded7..91e6684672 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskInstanceResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskInstanceResourceImpl.java @@ -297,7 +297,7 @@ private ExecuteVariableVO convertToVariableVO(TaskVariableDTO variable) { vo.setRequired(variable.isRequired() ? 1 : 0); if (variable.getType() == TaskVariableTypeEnum.HOST_LIST.getType()) { ExecuteObjectsDTO servers = variable.getTargetServers(); - if (servers != null && servers.getIpList() != null) { + if (servers != null && servers.getExecuteObjectsCompatibly() != null) { TaskTargetVO taskTargetVO = servers.convertToTaskTargetVO(); vo.setTargetValue(taskTargetVO); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/FileGseTaskStartCommand.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/FileGseTaskStartCommand.java index 51bbab5d6b..fcb4537c55 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/FileGseTaskStartCommand.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/FileGseTaskStartCommand.java @@ -281,7 +281,7 @@ private void initFileSourceExecuteObjectTasks() { } } List executeObjectTasks = new ArrayList<>(); - boolean isSupportExecuteObject = stepInstance.isSupportExecuteObject(); + boolean isSupportExecuteObject = stepInstance.isSupportExecuteObjectFeature(); for (ExecuteObject sourceExecuteObject : sourceExecuteObjects) { ExecuteObjectTask executeObjectTask = new ExecuteObjectTask(); executeObjectTask.setStepInstanceId(stepInstanceId); @@ -448,7 +448,7 @@ private ServiceExecuteObjectLogDTO initExecuteObjectLogIfAbsent( executeObjectLogDTO.setStepInstanceId(stepInstanceId); executeObjectLogDTO.setExecuteCount(executeCount); } - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { executeObjectLogDTO.setExecuteObjectId(executeObject.getId()); } else { executeObjectLogDTO.setHostId(executeObject.getHost().getHostId()); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/ScriptGseTaskStartCommand.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/ScriptGseTaskStartCommand.java index 1004faadfd..31700065cf 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/ScriptGseTaskStartCommand.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/ScriptGseTaskStartCommand.java @@ -373,8 +373,9 @@ private void appendImportVariablesDeclareScript(StringBuffer sb, List executeObjectTasks = new ArrayList<>( buildInitialExecuteObjectTasks(stepInstanceId, executeCount, executeCount, batch, - gseTaskId, stepInstance.getTargetExecuteObjects().getMergedExecuteObjects())); + gseTaskId, stepInstance.getTargetExecuteObjects().getExecuteObjectsCompatibly())); saveExecuteObjectTasks(stepInstance, executeObjectTasks); } } @@ -289,7 +289,7 @@ private void saveGseExecuteObjectTasksForStartRollingStep(Long gseTaskId, List executeObjectTasks = new ArrayList<>(); if (rollingConfig.isBatchRollingStep(stepInstanceId)) { List executeObjectsBatchList = - rollingConfig.getConfigDetail().getMergedExecuteObjectsBatchList(); + rollingConfig.getConfigDetail().getExecuteObjectsBatchListCompatibly(); executeObjectsBatchList.forEach(executeObjectsBatch -> { executeObjectTasks.addAll( buildInitialExecuteObjectTasks( @@ -298,7 +298,7 @@ private void saveGseExecuteObjectTasksForStartRollingStep(Long gseTaskId, executeObjectsBatch.getBatch() == 1 ? executeCount : null, executeObjectsBatch.getBatch(), executeObjectsBatch.getBatch() == 1 ? gseTaskId : 0, - executeObjectsBatch.getMergedExecuteObjects() + executeObjectsBatch.getExecuteObjectsCompatibly() ) ); }); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/model/ExecuteObject.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/model/ExecuteObject.java index 8aaac28c06..8ff4fd9afa 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/model/ExecuteObject.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/model/ExecuteObject.java @@ -27,7 +27,9 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; +import com.tencent.bk.job.common.annotation.CompatibleImplementation; import com.tencent.bk.job.common.annotation.PersistenceObject; +import com.tencent.bk.job.common.constant.CompatibleType; import com.tencent.bk.job.common.constant.ExecuteObjectTypeEnum; import com.tencent.bk.job.common.gse.v2.model.Agent; import com.tencent.bk.job.common.gse.v2.model.ExecuteObjectGseKey; @@ -88,16 +90,26 @@ public class ExecuteObject implements Cloneable { @JsonIgnore private ExecuteObjectGseKey executeObjectGseKey; - public ExecuteObject(Container container) { - this.type = ExecuteObjectTypeEnum.CONTAINER; - this.container = container; - this.resourceId = container.getId(); - } - - public ExecuteObject(HostDTO host) { - this.type = ExecuteObjectTypeEnum.HOST; - this.host = host; - this.resourceId = host.getHostId(); +// public ExecuteObject(Container container) { +// this.type = ExecuteObjectTypeEnum.CONTAINER; +// this.container = container; +// this.resourceId = container.getId(); +// } +// +// public ExecuteObject(HostDTO host) { +// this.type = ExecuteObjectTypeEnum.HOST; +// this.host = host; +// this.resourceId = host.getHostId(); +// } + + @CompatibleImplementation(name = "execute_object", deprecatedVersion = "3.9.x", type = CompatibleType.HISTORY_DATA, + explain = "数据失效后该构造方法可以删除") + public static ExecuteObject buildCompatibleExecuteObject(HostDTO host) { + ExecuteObject executeObject = new ExecuteObject(); + executeObject.setType(ExecuteObjectTypeEnum.HOST); + executeObject.setResourceId(host.getHostId()); + executeObject.setHost(host); + return executeObject; } @JsonCreator(mode = JsonCreator.Mode.DELEGATING) @@ -137,7 +149,8 @@ public ExecuteObjectGseKey toExecuteObjectGseKey() { if (isHostExecuteObject()) { executeObjectGseKey = ExecuteObjectGseKey.ofHost(host.getAgentId()); } else { - executeObjectGseKey = ExecuteObjectGseKey.ofContainer(container.getNodeAgentId(), container.getContainerId()); + executeObjectGseKey = ExecuteObjectGseKey.ofContainer(container.getNodeAgentId(), + container.getContainerId()); } return executeObjectGseKey; } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/local/LocalFilePrepareService.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/local/LocalFilePrepareService.java index 38778d1e74..9fbc365a34 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/local/LocalFilePrepareService.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/local/LocalFilePrepareService.java @@ -123,7 +123,7 @@ private void fillLocalFileSourceHost(List fileSourceList, StepIns boolean isGseV2Task = stepInstance.isTargetGseV2Agent(); fileSourceList.forEach(fileSourceDTO -> { if (fileSourceDTO.getFileType() == TaskFileTypeEnum.LOCAL.getType() || fileSourceDTO.isLocalUpload()) { - ExecuteObjectsDTO localHost = agentService.getLocalServersDTO(); + ExecuteObjectsDTO localHost = agentService.getLocalHostExecuteObjectDTO(); if (!isGseV2Task) { // 如果目标Agent是GSE V1, 那么源Agent也必须要GSE1.0 Agent,设置agentId={云区域:ip} localHost.getIpList().forEach(host -> host.setAgentId(host.toCloudIp())); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/third/ThirdFilePrepareService.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/third/ThirdFilePrepareService.java index 0687a958ba..99394f0220 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/third/ThirdFilePrepareService.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/third/ThirdFilePrepareService.java @@ -37,6 +37,7 @@ import com.tencent.bk.job.execute.model.FileDetailDTO; import com.tencent.bk.job.execute.model.FileSourceDTO; import com.tencent.bk.job.execute.model.FileSourceTaskLogDTO; +import com.tencent.bk.job.execute.model.StepInstanceBaseDTO; import com.tencent.bk.job.execute.model.StepInstanceDTO; import com.tencent.bk.job.execute.service.AccountService; import com.tencent.bk.job.execute.service.HostService; @@ -106,7 +107,9 @@ public ThirdFilePrepareService(ResultHandleManager resultHandleManager, * @param taskInfoDTO 文件源文件下载任务信息 * @param fileSourceDTO 分发源文件数据 */ - private void setTaskInfoIntoThirdFileSource(TaskInfoDTO taskInfoDTO, FileSourceDTO fileSourceDTO) { + private void setTaskInfoIntoThirdFileSource(StepInstanceBaseDTO stepInstance, + TaskInfoDTO taskInfoDTO, + FileSourceDTO fileSourceDTO) { String fileSourceTaskId = taskInfoDTO.getTaskId(); if (fileSourceDTO.getServers() == null) { fileSourceDTO.setServers(new ExecuteObjectsDTO()); @@ -114,7 +117,7 @@ private void setTaskInfoIntoThirdFileSource(TaskInfoDTO taskInfoDTO, FileSourceD List hostDTOList = new ArrayList<>(); hostDTOList.add(new HostDTO(taskInfoDTO.getCloudId(), taskInfoDTO.getIp())); fileSourceDTO.getServers().setStaticIpList(hostDTOList); - fileSourceDTO.getServers().setIpList(hostDTOList); + fileSourceDTO.getServers().buildMergedExecuteObjects(stepInstance.isSupportExecuteObjectFeature()); fileSourceDTO.setFileSourceTaskId(fileSourceTaskId); fileSourceDTO.getFiles().forEach(fileDetailDTO -> { // 含文件源名称的文件路径 @@ -130,7 +133,8 @@ private void setTaskInfoIntoThirdFileSource(TaskInfoDTO taskInfoDTO, FileSourceD * @param batchTaskInfoDTO 文件源批量任务信息 * @param thirdFileSourceList 第三方文件源列表 */ - private void setBatchTaskInfoIntoThirdFileSource(BatchTaskInfoDTO batchTaskInfoDTO, + private void setBatchTaskInfoIntoThirdFileSource(StepInstanceDTO stepInstance, + BatchTaskInfoDTO batchTaskInfoDTO, List thirdFileSourceList) { List taskInfoList = batchTaskInfoDTO.getTaskInfoList(); for (int i = 0; i < taskInfoList.size(); i++) { @@ -138,7 +142,7 @@ private void setBatchTaskInfoIntoThirdFileSource(BatchTaskInfoDTO batchTaskInfoD FileSourceDTO fileSourceDTO = thirdFileSourceList.get(i); Integer fileSourceId = fileSourceDTO.getFileSourceId(); if (fileSourceId != null && fileSourceId > 0) { - setTaskInfoIntoThirdFileSource(taskInfoDTO, fileSourceDTO); + setTaskInfoIntoThirdFileSource(stepInstance, taskInfoDTO, fileSourceDTO); } } } @@ -216,7 +220,7 @@ public void prepareThirdFileAsync( batchTaskInfoDTO.getTaskInfoList() ); // 填充任务信息到分发源文件数据 - setBatchTaskInfoIntoThirdFileSource(batchTaskInfoDTO, thirdFileSourceList); + setBatchTaskInfoIntoThirdFileSource(stepInstance, batchTaskInfoDTO, thirdFileSourceList); log.debug("[{}]: fileSourceList={}", stepInstance.getUniqueKey(), fileSourceList); // 放进文件源下载任务进度表中 FileSourceTaskLogDTO fileSourceTaskLogDTO = buildInitFileSourceTaskLog(stepInstance, batchTaskInfoDTO); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/third/ThirdFilePrepareTask.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/third/ThirdFilePrepareTask.java index 26dbda660d..317b4cc486 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/third/ThirdFilePrepareTask.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/prepare/third/ThirdFilePrepareTask.java @@ -74,7 +74,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -285,7 +284,7 @@ private void handleFileSourceTaskResult( boolean allSuccess = statePair.getLeft(); boolean stopped = statePair.getRight(); if (allSuccess) { - onSuccess(taskStatusList); + onSuccess(stepInstance, taskStatusList); } else if (stopped) { resultHandler.onStopped(this); } else { @@ -321,7 +320,7 @@ private Pair checkSuccessAndStopState(List fileSourceTaskStatusList) { + private void onSuccess(StepInstanceDTO stepInstance, List fileSourceTaskStatusList) { Map map = new HashMap<>(); fileSourceTaskStatusList.forEach(taskStatus -> map.put(taskStatus.getTaskId(), taskStatus)); //添加服务器文件信息 @@ -348,7 +347,7 @@ private void onSuccess(List fileSourceTaskStatusList) { fileSourceDTO.setAccountId(accountDTO.getId()); fileSourceDTO.setLocalUpload(false); - ExecuteObjectsDTO servers = new ExecuteObjectsDTO(); + ExecuteObjectsDTO executeObjectsDTO = new ExecuteObjectsDTO(); HostDTO hostDTO = parseFileWorkerHostWithCache( fileSourceTaskStatusDTO.getCloudId(), fileSourceTaskStatusDTO.getIpProtocol(), @@ -376,15 +375,9 @@ private void onSuccess(List fileSourceTaskStatusList) { sourceHost.setAgentId(sourceHost.toCloudIp()); } List hostDTOList = Collections.singletonList(sourceHost); - servers.addStaticHosts(hostDTOList); - if (servers.getIpList() == null) { - servers.setIpList(hostDTOList); - } else { - servers.getIpList().addAll(hostDTOList); - // 去重 - servers.setIpList(new ArrayList<>(new HashSet<>(servers.getIpList()))); - } - fileSourceDTO.setServers(servers); + executeObjectsDTO.addStaticHosts(hostDTOList); + executeObjectsDTO.buildMergedExecuteObjects(stepInstance.isSupportExecuteObjectFeature()); + fileSourceDTO.setServers(executeObjectsDTO); Map filePathMap = fileSourceTaskStatusDTO.getFilePathMap(); log.debug( "[{}]: filePathMap={}", diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/util/JobSrcFileUtils.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/util/JobSrcFileUtils.java index a72d84eb05..c9933d3eca 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/util/JobSrcFileUtils.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/util/JobSrcFileUtils.java @@ -123,7 +123,7 @@ public static Set parseSrcFiles(StepInstanceDTO stepInstance, // 远程服务器文件分发 Long accountId = fileSource.getAccountId(); String accountAlias = fileSource.getAccountAlias(); - boolean isSupportExecuteObject = stepInstance.isSupportExecuteObject(); + boolean isSupportExecuteObject = stepInstance.isSupportExecuteObjectFeature(); // 远程文件 for (FileDetailDTO file : files) { String filePath = StringUtils.isNotEmpty(file.getResolvedFilePath()) ? file.getResolvedFilePath() @@ -131,7 +131,7 @@ public static Set parseSrcFiles(StepInstanceDTO stepInstance, Pair fileNameAndPath = FilePathUtils.parseDirAndFileName(filePath); String dir = fileNameAndPath.getLeft(); String fileName = fileNameAndPath.getRight(); - List sourceExecuteObjects = fileSource.getServers().getMergedExecuteObjects(); + List sourceExecuteObjects = fileSource.getServers().getExecuteObjectsCompatibly(); for (ExecuteObject sourceExecuteObject : sourceExecuteObjects) { // 第三方源文件的displayName不同 if (isThirdFile) { @@ -154,8 +154,8 @@ public static Set parseSrcFiles(StepInstanceDTO stepInstance, + fileNameAndPath.getLeft(); String fileName = fileNameAndPath.getRight(); ExecuteObjectsDTO servers = fileSource.getServers(); - if (servers != null && CollectionUtils.isNotEmpty(servers.getMergedExecuteObjects())) { - List executeObjects = servers.getMergedExecuteObjects(); + if (servers != null && CollectionUtils.isNotEmpty(servers.getExecuteObjectsCompatibly())) { + List executeObjects = servers.getExecuteObjectsCompatibly(); for (ExecuteObject executeObject : executeObjects) { sendFiles.add(new JobFile(TaskFileTypeEnum.LOCAL, executeObject, file.getFilePath(), dir, fileName, "root", null, @@ -170,7 +170,7 @@ public static Set parseSrcFiles(StepInstanceDTO stepInstance, String dir = NFSUtils.getFileDir(jobStorageRootDir, FileDirTypeConf.UPLOAD_FILE_DIR) + fileNameAndPath.getLeft(); String fileName = fileNameAndPath.getRight(); - List executeObjects = fileSource.getServers().getMergedExecuteObjects(); + List executeObjects = fileSource.getServers().getExecuteObjectsCompatibly(); for (ExecuteObject executeObject : executeObjects) { sendFiles.add(new JobFile(TaskFileTypeEnum.BASE64_FILE, executeObject, file.getFilePath(), dir, fileName, "root", null, diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/variable/JobLastHostsVariableResolver.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/variable/JobLastHostsVariableResolver.java index 41be57f2de..67bc3586b3 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/variable/JobLastHostsVariableResolver.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/variable/JobLastHostsVariableResolver.java @@ -91,7 +91,7 @@ public String resolve(VariableResolveContext context, String variableName) { Set hosts = null; switch (variableName) { case JobBuildInVariables.JOB_LAST_ALL: - hosts = extractAllHosts(preStepInstance); + hosts = preStepInstance.extractAllHosts(); break; case JobBuildInVariables.JOB_LAST_SUCCESS: { List executeObjectTasks = listAgentTasks(preStepInstance); @@ -136,21 +136,4 @@ private List listAgentTasks(StepInstanceDTO stepInstance) { } return agentTasks; } - - - private Set extractAllHosts(StepInstanceDTO stepInstance) { - Set hosts = new HashSet<>(); - if (CollectionUtils.isNotEmpty(stepInstance.getTargetExecuteObjects().getIpList())) { - hosts.addAll(stepInstance.getTargetExecuteObjects().getIpList()); - } - if (CollectionUtils.isNotEmpty(stepInstance.getFileSourceList())) { - stepInstance.getFileSourceList().forEach(fileSource -> { - if (fileSource.getServers() != null - && CollectionUtils.isNotEmpty(fileSource.getServers().getIpList())) { - hosts.addAll(fileSource.getServers().getIpList()); - } - }); - } - return hosts; - } } 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 d32bbf6bd5..29339d67ac 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 @@ -34,6 +34,7 @@ import com.tencent.bk.job.common.gse.util.AgentUtils; import com.tencent.bk.job.common.model.dto.Container; import com.tencent.bk.job.common.model.dto.HostDTO; +import com.tencent.bk.job.common.model.vo.ContainerVO; import com.tencent.bk.job.common.model.vo.HostInfoVO; import com.tencent.bk.job.common.model.vo.TaskContainerNodeVO; import com.tencent.bk.job.common.model.vo.TaskHostNodeVO; @@ -99,6 +100,7 @@ public static ExecuteObjectsDTO emptyInstance() { executeObjectsDTO.setDynamicServerGroups(Collections.emptyList()); executeObjectsDTO.setStaticIpList(Collections.emptyList()); executeObjectsDTO.setTopoNodes(Collections.emptyList()); + executeObjectsDTO.setStaticContainerList(Collections.emptyList()); return executeObjectsDTO; } @@ -228,22 +230,46 @@ public List extractHosts() { } public TaskTargetVO convertToTaskTargetVO() { - TaskTargetVO targetServer = new TaskTargetVO(); - targetServer.setVariable(variable); - TaskHostNodeVO taskHostNodeVO = new TaskHostNodeVO(); - if (CollectionUtils.isNotEmpty(ipList)) { - List hostVOs = new ArrayList<>(); - ipList.forEach(host -> { - HostInfoVO hostInfoVO = host.toHostInfoVO(); - hostInfoVO.setAgentId(AgentUtils.displayAsRealAgentId(host.getAgentId())); - hostVOs.add(hostInfoVO); - }); - taskHostNodeVO.setHostList(hostVOs); - targetServer.setHostNodeInfo(taskHostNodeVO); + TaskTargetVO target = new TaskTargetVO(); + target.setVariable(variable); + + List executeObjects = getExecuteObjectsCompatibly(); + if (CollectionUtils.isNotEmpty(executeObjects)) { + // 主机 + List hostInfoVOS = executeObjects.stream() + .filter(ExecuteObject::isHostExecuteObject) + .map(ExecuteObject::getHost) + .map(host -> { + HostInfoVO hostInfoVO = host.toHostInfoVO(); + hostInfoVO.setAgentId(AgentUtils.displayAsRealAgentId(host.getAgentId())); + return hostInfoVO; + }) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(hostInfoVOS)) { + TaskHostNodeVO taskHostNodeVO = new TaskHostNodeVO(); + taskHostNodeVO.setHostList(hostInfoVOS); + target.setHostNodeInfo(taskHostNodeVO); + } + + // 容器 + List containerVOs = executeObjects.stream() + .filter(ExecuteObject::isContainerExecuteObject) + .map(ExecuteObject::getContainer) + .map(Container::toContainerVO) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(containerVOs)) { + TaskContainerNodeVO taskContainerNodeVO = new TaskContainerNodeVO(); + taskContainerNodeVO.setContainerList(containerVOs); + target.setContainerNodeInfo(taskContainerNodeVO); + } } - return targetServer; + + return target; } + /** + * 转换为 EsbServerV3DTO + */ public EsbServerV3DTO toEsbServerV3DTO() { EsbServerV3DTO esbServerV3DTO = new EsbServerV3DTO(); esbServerV3DTO.setVariable(variable); @@ -290,7 +316,7 @@ public ExecuteObject findExecuteObjectByCompositeKey(ExecuteObjectCompositeKey e .filter(host -> executeObjectCompositeKey.getHostId().equals(host.getHostId())) .findFirst() .orElse(null); - return matchHost == null ? null : new ExecuteObject(matchHost); + return matchHost == null ? null : ExecuteObject.buildCompatibleExecuteObject(matchHost); } } else if (executeObjectCompositeKey.getCloudIp() != null) { // 兼容使用 云区域+ip 的方式 @@ -305,7 +331,7 @@ public ExecuteObject findExecuteObjectByCompositeKey(ExecuteObjectCompositeKey e .filter(host -> executeObjectCompositeKey.getCloudIp().equals(host.toCloudIp())) .findFirst() .orElse(null); - return matchHost == null ? null : new ExecuteObject(matchHost); + return matchHost == null ? null : ExecuteObject.buildCompatibleExecuteObject(matchHost); } } else { throw new IllegalArgumentException("InvalidExecuteObjectCompositeKey"); @@ -346,7 +372,8 @@ public List findExecuteObjectByCompositeKeys( if (CollectionUtils.isEmpty(matchHosts)) { return Collections.emptyList(); } - return matchHosts.stream().map(ExecuteObject::new).collect(Collectors.toList()); + return matchHosts.stream().map(ExecuteObject::buildCompatibleExecuteObject) + .collect(Collectors.toList()); } } else if (anyKey.getCloudIp() != null) { // 兼容使用 云区域+ip 的方式 @@ -366,13 +393,17 @@ public List findExecuteObjectByCompositeKeys( if (CollectionUtils.isEmpty(matchHosts)) { return Collections.emptyList(); } - return matchHosts.stream().map(ExecuteObject::new).collect(Collectors.toList()); + return matchHosts.stream().map(ExecuteObject::buildCompatibleExecuteObject) + .collect(Collectors.toList()); } } else { throw new IllegalArgumentException("InvalidExecuteObjectCompositeKey"); } } + /** + * 转换TaskTargetVO 为 ExecuteObjectsDTO + */ public static ExecuteObjectsDTO fromTaskTargetVO(TaskTargetVO target) { ExecuteObjectsDTO executeObjectsDTO = new ExecuteObjectsDTO(); @@ -426,16 +457,57 @@ public static ExecuteObjectsDTO fromTaskTargetVO(TaskTargetVO target) { } /** - * 获取合并之后的所有执行对象列表 + * 获取所有执行对象列表(兼容当前版本+历史版本数据) */ @JsonIgnore - public List getMergedExecuteObjects() { + public List getExecuteObjectsCompatibly() { if (executeObjects != null) { return executeObjects; } else if (ipList != null) { - return ipList.stream().map(ExecuteObject::new).collect(Collectors.toList()); + return ipList.stream().map(ExecuteObject::buildCompatibleExecuteObject).collect(Collectors.toList()); } else { return Collections.emptyList(); } } + + /** + * 获取所有主机执行对象列表(兼容当前版本+历史版本数据) + */ + @JsonIgnore + public List getHostsCompatibly() { + if (executeObjects != null) { + return executeObjects.stream().filter(ExecuteObject::isHostExecuteObject) + .map(ExecuteObject::getHost).collect(Collectors.toList()); + } else if (ipList != null) { + return ipList; + } else { + return Collections.emptyList(); + } + } + + + /** + * 合并所有的执行对象 + * + * @param isSupportExecuteObjectFeature 是否支持执行对象特性 + */ + public void buildMergedExecuteObjects(boolean isSupportExecuteObjectFeature) { + if (isSupportExecuteObjectFeature) { + // 支持执行对象,写入 executeObjects 字段 + List executeObjects = new ArrayList<>(); + List hosts = extractHosts(); + if (CollectionUtils.isNotEmpty(hosts)) { + executeObjects.addAll(hosts.stream().map(ExecuteObject::buildCompatibleExecuteObject) + .collect(Collectors.toList())); + } + if (CollectionUtils.isNotEmpty(staticContainerList)) { + executeObjects.addAll(hosts.stream().map(ExecuteObject::buildCompatibleExecuteObject) + .collect(Collectors.toList())); + } + this.executeObjects = executeObjects; + } else { + // 兼容方式,写入 ipList 字段 + this.ipList = extractHosts(); + } + } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/StepInstanceBaseDTO.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/StepInstanceBaseDTO.java index 75f8607d04..c467d464cc 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/StepInstanceBaseDTO.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/StepInstanceBaseDTO.java @@ -181,9 +181,9 @@ public boolean isScriptStep() { return getStepType() == TaskStepTypeEnum.SCRIPT; } - public int getTargetServerTotalCount() { - if (this.targetExecuteObjects != null && this.targetExecuteObjects.getIpList() != null) { - return this.targetExecuteObjects.getIpList().size(); + public int getTargetExecuteObjectCount() { + if (this.targetExecuteObjects != null && this.targetExecuteObjects.getExecuteObjectsCompatibly() != null) { + return this.targetExecuteObjects.getExecuteObjectsCompatibly().size(); } else { return 0; } @@ -215,15 +215,23 @@ public String getUniqueKey() { */ public boolean isTargetGseV2Agent() { // 只需要判断任意一个即可,因为前置校验已经保证所有的主机的agentId全部都是V1或者V2 - boolean isTargetGseV1Agent = this.targetExecuteObjects.getIpList().stream() - .anyMatch(host -> AgentUtils.isGseV1AgentId(host.getAgentId())); + boolean isTargetGseV1Agent = this.targetExecuteObjects.getExecuteObjectsCompatibly().stream() + .anyMatch(executeObject -> { + if (executeObject.isHostExecuteObject()) { + return AgentUtils.isGseV1AgentId(executeObject.getHost().getAgentId()); + } else if (executeObject.isContainerExecuteObject()) { + // 只有 GSE V2 agent 才支持容器执行特性,这里这里必然是 true + return true; + } + return false; + }); return !isTargetGseV1Agent; } /** - * 通过执行目标判断是否支持"执行对象" + * 通过执行目标判断是否支持"执行对象特性" */ - public boolean isSupportExecuteObject() { + public boolean isSupportExecuteObjectFeature() { if (supportExecuteObject == null) { supportExecuteObject = CollectionUtils.isNotEmpty(targetExecuteObjects.getExecuteObjects()); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/StepInstanceDTO.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/StepInstanceDTO.java index 4e61b3a127..c162e46cb0 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/StepInstanceDTO.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/StepInstanceDTO.java @@ -28,6 +28,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.model.dto.Container; +import com.tencent.bk.job.common.model.dto.HostDTO; import com.tencent.bk.job.execute.engine.model.ExecuteObject; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import com.tencent.bk.job.manage.common.consts.task.TaskStepTypeEnum; @@ -37,7 +38,9 @@ import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * 步骤实例 @@ -90,7 +93,6 @@ public class StepInstanceDTO extends StepInstanceBaseDTO { /** * 执行脚本的类型:1(shell脚本)、2(bat脚本)、3(perl脚本)、4(python脚本)、5(powershell脚本) - * */ private ScriptTypeEnum scriptType; /** @@ -273,4 +275,38 @@ public List extractStaticContainerList() { } return containers; } + + public Set extractAllHosts() { + Set hosts = new HashSet<>(targetExecuteObjects.getHostsCompatibly()); + + if (CollectionUtils.isNotEmpty(fileSourceList)) { + fileSourceList.forEach(fileSource -> { + if (fileSource.getServers() != null) { + List fileSourceHosts = fileSource.getServers().getHostsCompatibly(); + if (CollectionUtils.isNotEmpty(fileSourceHosts)) { + hosts.addAll(fileSourceHosts); + } + } + }); + } + return hosts; + } + + /** + * 步骤包含的执行对象 ExecuteObjectsDTO 的最终处理 + * + * @param isSupportExecuteObjectFeature 是否执行执行对象特性 + */ + public void buildStepFinalExecuteObjects(boolean isSupportExecuteObjectFeature) { + if (targetExecuteObjects != null) { + targetExecuteObjects.buildMergedExecuteObjects(isSupportExecuteObjectFeature); + } + if (CollectionUtils.isNotEmpty(fileSourceList)) { + fileSourceList.forEach(fileSource -> { + if (fileSource.getServers() != null) { + fileSource.getServers().buildMergedExecuteObjects(isSupportExecuteObjectFeature); + } + }); + } + } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/db/RollingConfigDetailDO.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/db/RollingConfigDetailDO.java index 1821078289..d0a0f44d17 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/db/RollingConfigDetailDO.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/db/RollingConfigDetailDO.java @@ -113,10 +113,10 @@ public boolean isLastRollingStep(long stepInstanceId) { } /** - * 获取合并后的执行对象滚动批次 + * 获取执行对象滚动批次(兼容当前版本+历史版本) */ @JsonIgnore - public List getMergedExecuteObjectsBatchList() { + public List getExecuteObjectsBatchListCompatibly() { if (executeObjectsBatchList != null) { return executeObjectsBatchList; } else if (hostsBatchList != null) { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/db/RollingExecuteObjectsBatchDO.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/db/RollingExecuteObjectsBatchDO.java index 581850f1e8..af4fea8134 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/db/RollingExecuteObjectsBatchDO.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/db/RollingExecuteObjectsBatchDO.java @@ -72,14 +72,14 @@ public RollingExecuteObjectsBatchDO(Integer batch, List executeOb } /** - * 获取合并之后的执行对象列表 + * 获取所有执行对象列表(兼容当前版本+历史版本数据) */ @JsonIgnore - public List getMergedExecuteObjects() { + public List getExecuteObjectsCompatibly() { if (executeObjects != null) { return executeObjects; } else if (hosts != null) { - return hosts.stream().map(ExecuteObject::new).collect(Collectors.toList()); + return hosts.stream().map(ExecuteObject::buildCompatibleExecuteObject).collect(Collectors.toList()); } else { return Collections.emptyList(); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/AgentService.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/AgentService.java index a25d33f484..7cea98d059 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/AgentService.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/AgentService.java @@ -39,5 +39,5 @@ public interface AgentService { /** * 获取本地主机的Agent */ - ExecuteObjectsDTO getLocalServersDTO(); + ExecuteObjectsDTO getLocalHostExecuteObjectDTO(); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AbstractExecuteObjectTaskServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AbstractExecuteObjectTaskServiceImpl.java index ad8a815b61..59854b9aad 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AbstractExecuteObjectTaskServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AbstractExecuteObjectTaskServiceImpl.java @@ -7,6 +7,7 @@ import com.tencent.bk.job.execute.model.StepInstanceBaseDTO; import com.tencent.bk.job.execute.service.ExecuteObjectTaskService; import com.tencent.bk.job.execute.service.StepInstanceService; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; @@ -19,6 +20,7 @@ /** * 执行对象任务公共实现 Service */ +@Slf4j public abstract class AbstractExecuteObjectTaskServiceImpl implements ExecuteObjectTaskService { protected final StepInstanceService stepInstanceService; @@ -35,16 +37,29 @@ protected final void fillExecuteObjectForExecuteObjectTasks( return; } - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { Map executeObjectMap = stepInstanceService.computeStepExecuteObjects(stepInstance, ExecuteObject::getId); - tasks.forEach( - task -> task.setExecuteObject(executeObjectMap.get(task.getExecuteObjectId()))); + tasks.forEach(task -> { + ExecuteObject executeObject = executeObjectMap.get(task.getExecuteObjectId()); + if (executeObject == null) { + log.error("Can not find execute object for execute object task! stepInstanceId: {}, " + + "executeObjectId: {}", stepInstance.getId(), task.getExecuteObjectId()); + } + task.setExecuteObject(executeObject); + }); } else { // 兼容老版本不支持执行对象的数据 Map hostExecuteObjects = stepInstanceService.computeStepExecuteObjects( stepInstance, executeObject -> executeObject.getHost().getHostId()); - tasks.forEach(task -> task.setExecuteObject(hostExecuteObjects.get(task.getHostId()))); + tasks.forEach(task -> { + ExecuteObject hostExecuteObject = hostExecuteObjects.get(task.getHostId()); + if (hostExecuteObject == null) { + log.error("Can not find host for execute object task! stepInstanceId: {}, " + + "hostId: {}", stepInstance.getId(), task.getHostId()); + } + task.setExecuteObject(hostExecuteObject); + }); } } @@ -53,7 +68,7 @@ protected final void fillExecuteObjectForExecuteObjectTask( ExecuteObjectTask task ) { ExecuteObject executeObject; - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { executeObject = stepInstance.findExecuteObjectByCompositeKey( ExecuteObjectCompositeKey.ofExecuteObjectId(task.getExecuteObjectId())); } else { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AgentServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AgentServiceImpl.java index da4d566919..3580e771d0 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AgentServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AgentServiceImpl.java @@ -97,13 +97,13 @@ public HostDTO getLocalAgentHost() { } @Override - public ExecuteObjectsDTO getLocalServersDTO() { + public ExecuteObjectsDTO getLocalHostExecuteObjectDTO() { List hostDTOList = new ArrayList<>(); hostDTOList.add(getLocalAgentHost()); - ExecuteObjectsDTO servers = new ExecuteObjectsDTO(); - servers.setStaticIpList(hostDTOList); - servers.setIpList(hostDTOList); - return servers; + ExecuteObjectsDTO executeObjects = new ExecuteObjectsDTO(); + executeObjects.setStaticIpList(hostDTOList); + executeObjects.buildMergedExecuteObjects(true); + return executeObjects; } private HostDTO getAgentBindHost() { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/FileExecuteObjectTaskServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/FileExecuteObjectTaskServiceImpl.java index 57992951ac..f2df204eaf 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/FileExecuteObjectTaskServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/FileExecuteObjectTaskServiceImpl.java @@ -89,7 +89,7 @@ public List listTasks(StepInstanceBaseDTO stepInstance, Integ public List listTasksByGseTaskId(StepInstanceBaseDTO stepInstance, Long gseTaskId) { StepInstanceDTO fileStepInstance = castToStepInstanceDTO(stepInstance); List executeObjectTasks; - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { executeObjectTasks = fileExecuteObjectTaskDAO.listTasksByGseTaskId(gseTaskId); } else { // 兼容老版本数据 @@ -116,7 +116,7 @@ public ExecuteObjectTask getTaskByExecuteObjectCompositeKey(StepInstanceBaseDTO long stepInstanceId = fileStepInstance.getId(); ExecuteObjectTask executeObjectTask; - if (fileStepInstance.isSupportExecuteObject()) { + if (fileStepInstance.isSupportExecuteObjectFeature()) { executeObjectTask = fileExecuteObjectTaskDAO.getTaskByExecuteObjectId(stepInstanceId, executeCount, batch, fileTaskMode, executeObject.getId()); } else { @@ -164,7 +164,7 @@ public List listResultGroups(StepInstanceBaseDTO stepInstanc List resultGroups; long stepInstanceId = fileStepInstance.getId(); - if (fileStepInstance.isSupportExecuteObject()) { + if (fileStepInstance.isSupportExecuteObjectFeature()) { resultGroups = fileExecuteObjectTaskDAO.listResultGroups(stepInstanceId, executeCount, batch); } else { // 兼容历史数据 @@ -182,7 +182,7 @@ public List listTaskByResultGroup(StepInstanceBaseDTO stepIns StepInstanceDTO fileStepInstance = castToStepInstanceDTO(stepInstance); List executeObjectTasks; - if (fileStepInstance.isSupportExecuteObject()) { + if (fileStepInstance.isSupportExecuteObjectFeature()) { executeObjectTasks = fileExecuteObjectTaskDAO.listTaskByResultGroup(fileStepInstance.getId(), executeCount, batch, status); } else { @@ -208,7 +208,7 @@ public List listTaskByResultGroup(StepInstanceBaseDTO stepIns StepInstanceDTO fileStepInstance = castToStepInstanceDTO(stepInstance); List executeObjectTasks; - if (fileStepInstance.isSupportExecuteObject()) { + if (fileStepInstance.isSupportExecuteObjectFeature()) { executeObjectTasks = fileExecuteObjectTaskDAO.listTaskByResultGroup(fileStepInstance.getId(), executeCount, batch, status, limit, orderField, order); } else { @@ -232,7 +232,7 @@ public void updateTaskFields(StepInstanceBaseDTO stepInstance, Integer actualExecuteCount, Long gseTaskId) { StepInstanceDTO fileStepInstance = castToStepInstanceDTO(stepInstance); - if (fileStepInstance.isSupportExecuteObject()) { + if (fileStepInstance.isSupportExecuteObjectFeature()) { fileExecuteObjectTaskDAO.updateTaskFields(fileStepInstance.getId(), executeCount, batch, actualExecuteCount, gseTaskId); } else { @@ -250,7 +250,7 @@ public List listTasks(StepInstanceBaseDTO stepInstance, StepInstanceDTO fileStepInstance = castToStepInstanceDTO(stepInstance); List executeObjectTasks; long stepInstanceId = fileStepInstance.getId(); - if (fileStepInstance.isSupportExecuteObject()) { + if (fileStepInstance.isSupportExecuteObjectFeature()) { executeObjectTasks = fileExecuteObjectTaskDAO.listTasks(stepInstanceId, executeCount, batch, fileTaskMode); } else { // 兼容老版本数据 diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogExportServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogExportServiceImpl.java index 4c1c0e76a3..ea3e142b2e 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogExportServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogExportServiceImpl.java @@ -295,7 +295,7 @@ private void writeOneBatchExecuteObjectLogs(PrintWriter out, LogBatchQuery query, List executeObjects) { List keys; - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { keys = executeObjects.stream() .map(executeObject -> ExecuteObjectCompositeKey.ofExecuteObjectId(executeObject.getId())) .collect(Collectors.toList()); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java index c85ede4473..024fa6b3b5 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java @@ -117,7 +117,7 @@ public ServiceExecuteObjectScriptLogDTO buildScriptLog(StepInstanceBaseDTO stepI int offset) { int length = content.getBytes(StandardCharsets.UTF_8).length; - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { return new ServiceExecuteObjectScriptLogDTO( executeObject.getId(), content, offset + length); } else { @@ -221,7 +221,7 @@ public ScriptExecuteObjectLogContent getScriptExecuteObjectLogContent(StepInstan } ExecuteObject executeObject = executeObjectTask.getExecuteObject(); - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { resp = logResource.getScriptLogByExecuteObjectId(taskCreateDateStr, stepInstanceId, actualExecuteCount, executeObject.getId(), batch); } else { @@ -249,7 +249,7 @@ public List batchGetScriptExecuteObjectLogContent List queryExecuteObjects = stepInstance.findExecuteObjectByCompositeKeys(executeObjectCompositeKeys); - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { List executeObjectId = queryExecuteObjects.stream() .map(ExecuteObject::getId).collect(Collectors.toList()); query.setExecuteObjectIds(executeObjectId); @@ -272,7 +272,7 @@ public List batchGetScriptExecuteObjectLogContent return Collections.emptyList(); } - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { Map executeObjectMap = queryExecuteObjects.stream() .collect(Collectors.toMap(ExecuteObject::getId, executeObject -> executeObject)); return resp.getData().stream().map(logDTO -> { @@ -338,7 +338,7 @@ public FileExecuteObjectLogContent getFileExecuteObjectLogContent(StepInstanceBa long stepInstanceId = stepInstance.getId(); InternalResponse resp; ExecuteObject executeObject = executeObjectTask.getExecuteObject(); - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { resp = logResource.getFileLogByExecuteObjectId(taskCreateDateStr, stepInstanceId, actualExecuteCount, executeObject.getId(), executeObjectTask.getFileTaskMode().getValue(), batch); } else { @@ -380,7 +380,7 @@ private List batchConvertToAtomicFileTaskLog( return Collections.emptyList(); } - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { Map executeObjectMap = stepInstanceService.computeStepExecuteObjects(stepInstance, ExecuteObject::getId); return batchConvertToAtomicFileTaskLog( @@ -452,7 +452,7 @@ private List batchConvertToFileExecuteObjectLogCont if (CollectionUtils.isEmpty(executeObjectLogs)) { return Collections.emptyList(); } - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { Map executeObjectMap = stepInstanceService.computeStepExecuteObjects(stepInstance, ExecuteObject::getId); @@ -515,7 +515,7 @@ public List batchGetFileExecuteObjectLogContent( List queryExecuteObjects = stepInstance.findExecuteObjectByCompositeKeys(executeObjectCompositeKeys); - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { List executeObjectId = queryExecuteObjects.stream() .map(ExecuteObject::getId).collect(Collectors.toList()); request.setExecuteObjectIds(executeObjectId); @@ -544,7 +544,7 @@ public List getExecuteObjectsCompositeKeysByContentKe ) { String taskCreateDateStr = buildTaskCreateDateStr(stepInstance); long stepInstanceId = stepInstance.getId(); - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { InternalResponse> resp = logResource.queryExecuteObjectsByLogKeyword(taskCreateDateStr, stepInstanceId, executeCount, batch, keyword); if (!resp.isSuccess()) { @@ -624,7 +624,7 @@ public ServiceFileTaskLogDTO buildUploadServiceFileTaskLogDTO(StepInstanceDTO st String speed, String process, String content) { - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { return new ServiceFileTaskLogDTO( FileDistModeEnum.UPLOAD.getValue(), null, @@ -674,7 +674,7 @@ public ServiceFileTaskLogDTO buildDownloadServiceFileTaskLogDTO(StepInstanceDTO String speed, String process, String content) { - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { return new ServiceFileTaskLogDTO( FileDistModeEnum.DOWNLOAD.getValue(), targetExecuteObject.getId(), diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/NotifyServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/NotifyServiceImpl.java index d57bf0759f..d535bc2152 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/NotifyServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/NotifyServiceImpl.java @@ -260,7 +260,7 @@ private Map getTemplateVariablesMap(TaskNotifyDTO taskNotifyDTO, if (taskInstanceDTO.getTotalTime() != null) { variablesMap.put("task.total_duration", "" + taskInstanceDTO.getTotalTime() / 1000.0); } - int totalTargetIpCount = stepInstanceDTO.getTargetExecuteObjects().getIpList().size(); + int totalTargetIpCount = stepInstanceDTO.getTargetExecuteObjectCount(); if (executeStatus == ExecuteStatusEnum.SUCCESS) { variablesMap.put("task.step.success_cnt", "" + totalTargetIpCount); variablesMap.put("task.step.failed_cnt", "" + 0); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/RollingConfigServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/RollingConfigServiceImpl.java index b992ceec72..8fabee9e7c 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/RollingConfigServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/RollingConfigServiceImpl.java @@ -71,19 +71,19 @@ public List getRollingServers(StepInstanceBaseDTO stepInstance, I if (rollingConfig.isBatchRollingStep(stepInstanceId)) { if (batch == null || batch == 0) { // 忽略滚动批次,返回当前步骤的所有目标服务器 - return stepInstance.getTargetExecuteObjects().getMergedExecuteObjects(); + return stepInstance.getTargetExecuteObjects().getExecuteObjectsCompatibly(); } else { return rollingConfig .getConfigDetail() - .getMergedExecuteObjectsBatchList() + .getExecuteObjectsBatchListCompatibly() .stream() .filter(serverBatch -> serverBatch.getBatch().equals(batch)) .findFirst() .orElseThrow(() -> new InternalException(ErrorCode.INTERNAL_ERROR)) - .getMergedExecuteObjects(); + .getExecuteObjectsCompatibly(); } } else { - return stepInstance.getTargetExecuteObjects().getMergedExecuteObjects(); + return stepInstance.getTargetExecuteObjects().getExecuteObjectsCompatibly(); } } @@ -106,7 +106,7 @@ public RollingConfigDTO saveRollingConfigForFastJob(FastTaskDTO fastTask) { RollingBatchExecuteObjectsResolver resolver = new RollingBatchExecuteObjectsResolver( - fastTask.getStepInstance().getTargetExecuteObjects().getMergedExecuteObjects(), + fastTask.getStepInstance().getTargetExecuteObjects().getExecuteObjectsCompatibly(), rollingConfig.getExpr()); List executeObjectsBatchList = resolver.resolve(); rollingConfigDetailDO.setExecuteObjectsBatchList( @@ -116,7 +116,7 @@ public RollingConfigDTO saveRollingConfigForFastJob(FastTaskDTO fastTask) { rollingExecuteObjectBatch.getExecuteObjects())) .collect(Collectors.toList())); - rollingConfigDetailDO.setTotalBatch(rollingConfigDetailDO.getMergedExecuteObjectsBatchList().size()); + rollingConfigDetailDO.setTotalBatch(rollingConfigDetailDO.getExecuteObjectsBatchListCompatibly().size()); taskInstanceRollingConfig.setConfigDetail(rollingConfigDetailDO); rollingConfigDetailDO.setIncludeStepInstanceIdList(Lists.newArrayList(stepInstance.getId())); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/ScriptExecuteObjectTaskServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/ScriptExecuteObjectTaskServiceImpl.java index fb248a1cf2..c1ef4576aa 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/ScriptExecuteObjectTaskServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/ScriptExecuteObjectTaskServiceImpl.java @@ -77,7 +77,7 @@ public int getSuccessTaskCount(long stepInstanceId, int executeCount) { public List listTasks(StepInstanceBaseDTO stepInstance, Integer executeCount, Integer batch) { List executeObjectTasks; long stepInstanceId = stepInstance.getId(); - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { executeObjectTasks = scriptExecuteObjectTaskDAO.listTasks(stepInstanceId, executeCount, batch); } else { // 兼容老版本数据 @@ -91,7 +91,7 @@ public List listTasks(StepInstanceBaseDTO stepInstance, Integ public List listTasksByGseTaskId(StepInstanceBaseDTO stepInstance, Long gseTaskId) { List executeObjectTasks; - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { executeObjectTasks = scriptExecuteObjectTaskDAO.listTasksByGseTaskId(gseTaskId); } else { // 兼容老版本数据 @@ -114,7 +114,7 @@ public ExecuteObjectTask getTaskByExecuteObjectCompositeKey(StepInstanceBaseDTO long stepInstanceId = stepInstance.getId(); ExecuteObjectTask executeObjectTask; - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { executeObjectTask = scriptExecuteObjectTaskDAO.getTaskByExecuteObjectId(stepInstanceId, executeCount, batch, executeObject.getId()); } else { @@ -150,7 +150,7 @@ public List listResultGroups(StepInstanceBaseDTO stepInstanc List resultGroups; long stepInstanceId = stepInstance.getId(); - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { resultGroups = scriptExecuteObjectTaskDAO.listResultGroups(stepInstanceId, executeCount, batch); } else { // 兼容历史数据 @@ -167,7 +167,7 @@ public List listTaskByResultGroup(StepInstanceBaseDTO stepIns String tag) { List executeObjectTasks; - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { executeObjectTasks = scriptExecuteObjectTaskDAO.listTasksByResultGroup(stepInstance.getId(), executeCount, batch, status, tag); } else { @@ -191,7 +191,7 @@ public List listTaskByResultGroup(StepInstanceBaseDTO stepIns Order order) { List executeObjectTasks; - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { executeObjectTasks = scriptExecuteObjectTaskDAO.listTasksByResultGroup(stepInstance.getId(), executeCount, batch, status, tag, limit, orderField, order); } else { @@ -214,7 +214,7 @@ public void updateTaskFields(StepInstanceBaseDTO stepInstance, Integer batch, Integer actualExecuteCount, Long gseTaskId) { - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { scriptExecuteObjectTaskDAO.updateTaskFields(stepInstance.getId(), executeCount, batch, actualExecuteCount, gseTaskId); } else { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/StepInstanceServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/StepInstanceServiceImpl.java index 69138a63ea..ee99e36d49 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/StepInstanceServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/StepInstanceServiceImpl.java @@ -78,7 +78,7 @@ public Map computeStepExecuteObjects(StepInstanceBaseDTO s Function keyMapper) { Map executeObjects = new HashMap<>(); - stepInstance.getTargetExecuteObjects().getMergedExecuteObjects() + stepInstance.getTargetExecuteObjects().getExecuteObjectsCompatibly() .forEach(executeObject -> { K key = keyMapper.apply(executeObject); if (key != null) { @@ -99,8 +99,8 @@ public Map computeStepExecuteObjects(StepInstanceBaseDTO s fileSourceList.forEach( fileSource -> { if (fileSource.getServers() != null - && CollectionUtils.isNotEmpty(fileSource.getServers().getExecuteObjects())) { - fileSource.getServers().getMergedExecuteObjects() + && CollectionUtils.isNotEmpty(fileSource.getServers().getExecuteObjectsCompatibly())) { + fileSource.getServers().getExecuteObjectsCompatibly() .forEach(executeObject -> { K key = keyMapper.apply(executeObject); if (key != null) { 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 d14ea00bcc..097875dff0 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 @@ -342,6 +342,9 @@ private TaskInstanceExecuteObjects processExecuteObjects(TaskInstanceDTO taskIns TaskInstanceExecuteObjects taskInstanceExecuteObjects = new TaskInstanceExecuteObjects(); acquireAndSetHosts(taskInstanceExecuteObjects, taskInstance, stepInstanceList, variables); acquireAndSetContainers(taskInstanceExecuteObjects, taskInstance, stepInstanceList); + boolean isSupportExecuteObjectFeature = isSupportExecuteObjectFeature(taskInstance); + stepInstanceList.forEach(stepInstance -> + stepInstance.buildStepFinalExecuteObjects(isSupportExecuteObjectFeature)); checkExecuteObjectExist(taskInstanceExecuteObjects); watch.stop(); @@ -372,6 +375,18 @@ private TaskInstanceExecuteObjects processExecuteObjects(TaskInstanceDTO taskIns } } + private boolean isSupportExecuteObjectFeature(TaskInstanceDTO taskInstance) { + FeatureExecutionContext featureExecutionContext = + FeatureExecutionContext.builder() + .addContextParam(ToggleStrategyContextParams.CTX_PARAM_RESOURCE_SCOPE, + appScopeMappingService.getScopeByAppId(taskInstance.getAppId())); + + return FeatureToggle.checkFeature( + FeatureIdConstants.FEATURE_EXECUTE_OBJECT, + featureExecutionContext + ); + } + private void saveTaskInstance(StopWatch watch, FastTaskDTO fastTask, TaskInstanceDTO taskInstance, @@ -1032,7 +1047,7 @@ private void checkExecuteObjectAccessible(List stepInstanceList } TaskStepTypeEnum stepType = stepInstance.getStepType(); // 检查目标主机 - stepInstance.getTargetExecuteObjects().getMergedExecuteObjects().stream() + stepInstance.getTargetExecuteObjects().getExecuteObjectsCompatibly().stream() .filter(ExecuteObject::isHostExecuteObject) .forEach(executeObject -> { if (isHostUnAccessible(stepType, executeObject.getHost(), notInAppHostMap, whileHostAllowActions)) { @@ -1066,10 +1081,10 @@ private void checkFileSourceHostAccessible(Set invalidHosts, // 远程文件分发需要校验文件源主机;其他类型不需要 if (fileSource.getFileType().equals(TaskFileTypeEnum.SERVER.getType())) { ExecuteObjectsDTO servers = fileSource.getServers(); - if (servers == null || CollectionUtils.isEmpty(servers.getMergedExecuteObjects())) { + if (servers == null || CollectionUtils.isEmpty(servers.getExecuteObjectsCompatibly())) { continue; } - servers.getMergedExecuteObjects().stream() + servers.getExecuteObjectsCompatibly().stream() .filter(ExecuteObject::isHostExecuteObject) .forEach(executeObject -> { if (isHostUnAccessible(stepType, executeObject.getHost(), @@ -1173,8 +1188,9 @@ private void checkStepInstanceHostNonEmpty(StepInstanceDTO stepInstance) { if (!isStepContainsExecuteObject(stepInstance)) { return; } - ExecuteObjectsDTO targetServers = stepInstance.getTargetExecuteObjects(); - if (targetServers == null || CollectionUtils.isEmpty(targetServers.getIpList())) { + ExecuteObjectsDTO targetExecuteObjects = stepInstance.getTargetExecuteObjects(); + if (targetExecuteObjects == null + || CollectionUtils.isEmpty(targetExecuteObjects.getExecuteObjectsCompatibly())) { log.warn("Empty target server! stepInstanceName: {}", stepInstance.getName()); throw new FailedPreconditionException(ErrorCode.STEP_TARGET_HOST_EMPTY, new String[]{stepInstance.getName()}); @@ -1185,7 +1201,7 @@ private void checkStepInstanceHostNonEmpty(StepInstanceDTO stepInstance) { // 远程文件分发需要判断文件源主机是否为空 if (TaskFileTypeEnum.SERVER.getType() == fileSource.getFileType()) { ExecuteObjectsDTO servers = fileSource.getServers(); - if (servers != null && CollectionUtils.isEmpty(servers.getIpList())) { + if (servers != null && CollectionUtils.isEmpty(servers.getExecuteObjectsCompatibly())) { log.warn("Empty file source server, stepInstanceName: {}", stepInstance.getName()); throw new FailedPreconditionException(ErrorCode.STEP_SOURCE_HOST_EMPTY, new String[]{stepInstance.getName()}); @@ -1234,7 +1250,7 @@ private void fillTaskInstanceHostDetail(TaskInstanceDTO taskInstance, if (CollectionUtils.isNotEmpty(variables)) { variables.forEach(variable -> { if (variable.getType() == TaskVariableTypeEnum.HOST_LIST.getType()) { - fillServersDetail(variable.getTargetServers(), hostMap); + fillHostsDetail(variable.getTargetServers(), hostMap); } }); } @@ -1280,7 +1296,7 @@ private void setHostAgentId(boolean isUsingGseV2, HostDTO host, Set inv } private void fillTargetHostDetail(StepInstanceDTO stepInstance, Map hostMap) { - fillServersDetail(stepInstance.getTargetExecuteObjects(), hostMap); + fillHostsDetail(stepInstance.getTargetExecuteObjects(), hostMap); } private void fillFileSourceHostDetail(StepInstanceDTO stepInstance, Map hostMap) { @@ -1288,22 +1304,22 @@ private void fillFileSourceHostDetail(StepInstanceDTO stepInstance, Map fileSourceList = stepInstance.getFileSourceList(); if (fileSourceList != null) { for (FileSourceDTO fileSource : fileSourceList) { - fillServersDetail(fileSource.getServers(), hostMap); + fillHostsDetail(fileSource.getServers(), hostMap); } } } } - private void fillServersDetail(ExecuteObjectsDTO servers, Map hostMap) { - if (servers != null) { - fillHostsDetail(servers.getStaticIpList(), hostMap); - if (CollectionUtils.isNotEmpty(servers.getDynamicServerGroups())) { - servers.getDynamicServerGroups().forEach(group -> fillHostsDetail(group.getIpList(), hostMap)); + private void fillHostsDetail(ExecuteObjectsDTO executeObjectsDTO, Map hostMap) { + if (executeObjectsDTO != null) { + fillHostsDetail(executeObjectsDTO.getStaticIpList(), hostMap); + if (CollectionUtils.isNotEmpty(executeObjectsDTO.getDynamicServerGroups())) { + executeObjectsDTO.getDynamicServerGroups() + .forEach(group -> fillHostsDetail(group.getIpList(), hostMap)); } - if (CollectionUtils.isNotEmpty(servers.getTopoNodes())) { - servers.getTopoNodes().forEach(topoNode -> fillHostsDetail(topoNode.getIpList(), hostMap)); + if (CollectionUtils.isNotEmpty(executeObjectsDTO.getTopoNodes())) { + executeObjectsDTO.getTopoNodes().forEach(topoNode -> fillHostsDetail(topoNode.getIpList(), hostMap)); } - servers.setIpList(servers.extractHosts()); } } @@ -1404,7 +1420,7 @@ private void checkStepInstanceAtomicTasksLimit(TaskInstanceDTO taskInstance, for (StepInstanceDTO stepInstance : stepInstanceList) { String operator = stepInstance.getOperator(); if (stepInstance.isFileStep()) { - int targetServerSize = stepInstance.getTargetServerTotalCount(); + int targetServerSize = stepInstance.getTargetExecuteObjectCount(); int totalSourceFileSize = 0; for (FileSourceDTO fileSource : stepInstance.getFileSourceList()) { int sourceServerSize = 1; @@ -1429,7 +1445,7 @@ private void checkStepInstanceAtomicTasksLimit(TaskInstanceDTO taskInstance, new Integer[]{jobExecuteConfig.getFileTasksMax()}); } } else if (stepInstance.isScriptStep()) { - int targetServerSize = stepInstance.getTargetServerTotalCount(); + int targetServerSize = stepInstance.getTargetExecuteObjectCount(); if (targetServerSize > 10000) { TASK_MONITOR_LOGGER.info("LargeTask|type:script|taskName:{}|appCode:{}|appId:{}|operator:{}" + "|targetServerSize:{}", diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskResultServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskResultServiceImpl.java index cc09bc50a7..a533d96419 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskResultServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskResultServiceImpl.java @@ -237,19 +237,19 @@ private void involveFileSourceTaskLog(StepExecutionDetailDTO stepExecutionDetail if (resultGroup == null) { continue; } - List agentTaskExecutionDetailList = resultGroup.getExecuteObjectTasks(); - if (agentTaskExecutionDetailList == null) { + List executeObjectTasks = resultGroup.getExecuteObjectTasks(); + if (executeObjectTasks == null) { continue; } - for (ExecuteObjectTask agentTaskDetail : agentTaskExecutionDetailList) { - if (agentTaskDetail == null) { + for (ExecuteObjectTask executeObjectTask : executeObjectTasks) { + if (executeObjectTask == null) { continue; } - agentTaskDetail.setStartTime(fileSourceTaskLog.getStartTime()); - if (agentTaskDetail.getEndTime() == null || agentTaskDetail.getEndTime() == 0) { - agentTaskDetail.setEndTime(stepExecutionDetail.getEndTime()); + executeObjectTask.setStartTime(fileSourceTaskLog.getStartTime()); + if (executeObjectTask.getEndTime() == null || executeObjectTask.getEndTime() == 0) { + executeObjectTask.setEndTime(stepExecutionDetail.getEndTime()); } - agentTaskDetail.calculateTotalTime(); + executeObjectTask.calculateTotalTime(); } } } @@ -423,7 +423,7 @@ private List filterTargetExecuteObjectsByBatch(StepInstanceBaseDT if (stepInstance.isRollingStep()) { executeObjects = rollingConfigService.getRollingServers(stepInstance, batch); } else { - executeObjects = stepInstance.getTargetExecuteObjects().getMergedExecuteObjects(); + executeObjects = stepInstance.getTargetExecuteObjects().getExecuteObjectsCompatibly(); } return executeObjects; @@ -456,7 +456,7 @@ public StepExecutionDetailDTO getStepExecutionResult(String username, Long appId StepExecutionDetailDTO stepExecutionDetail; // 如果步骤的目标服务器数量<100,或者通过IP匹配的方式过滤执行对象任务,为了提升性能,直接全量从DB查询数据,在内存进行处理 - if ((stepInstance.getTargetServerTotalCount() <= 100) || query.hasIpCondition()) { + if ((stepInstance.getTargetExecuteObjectCount() <= 100) || query.hasIpCondition()) { stepExecutionDetail = loadAllTasksFromDBAndBuildExecutionResultInMemory(watch, stepInstance, query); } else { stepExecutionDetail = filterAndSortExecutionResultInDB(watch, stepInstance, query); @@ -516,7 +516,7 @@ private StepExecutionDetailDTO loadAllTasksFromDBAndBuildExecutionResultInMemory } watch.start("loadAllTasksFromDbAndGroup"); - List resultGroups = listAndGroupAgentTasks(stepInstance, + List resultGroups = listAndGroupExecuteObjectTasks(stepInstance, query.getExecuteCount(), query.getBatch()); if (CollectionUtils.isNotEmpty(query.getMatchExecuteObjectCompositeKeys())) { @@ -530,7 +530,7 @@ private StepExecutionDetailDTO loadAllTasksFromDBAndBuildExecutionResultInMemory watch.start("sortAndLimitTasks"); - sortAgentTasksAndLimitSize(resultGroups, query); + sortExecuteObjectTasksAndLimitSize(resultGroups, query); watch.stop(); executeDetail.setResultGroups(resultGroups); @@ -544,9 +544,9 @@ private StepExecutionDetailDTO loadAllTasksFromDBAndBuildExecutionResultInMemory } - private List listAndGroupAgentTasks(StepInstanceBaseDTO stepInstance, - int executeCount, - Integer batch) { + private List listAndGroupExecuteObjectTasks(StepInstanceBaseDTO stepInstance, + int executeCount, + Integer batch) { List resultGroups = null; if (stepInstance.isScriptStep()) { resultGroups = scriptExecuteObjectTaskService.listAndGroupTasks(stepInstance, executeCount, batch); @@ -569,22 +569,22 @@ private List listResultGroups(StepInstanceBaseDTO stepInstan } - private void sortAgentTasksAndLimitSize(List resultGroups, - StepExecutionResultQuery query) { + private void sortExecuteObjectTasksAndLimitSize(List resultGroups, + StepExecutionResultQuery query) { resultGroups.stream() .filter(resultGroup -> CollectionUtils.isNotEmpty(resultGroup.getExecuteObjectTasks())) .forEach(resultGroup -> { // 排序 if (StringUtils.isNotEmpty(query.getOrderField())) { - List agentTasks = resultGroup.getExecuteObjectTasks(); + List executeObjectTasks = resultGroup.getExecuteObjectTasks(); if (StepExecutionResultQuery.ORDER_FIELD_TOTAL_TIME.equals(query.getOrderField())) { - agentTasks.sort(Comparator.comparingLong(task -> task.getTotalTime() == null ? 0L : + executeObjectTasks.sort(Comparator.comparingLong(task -> task.getTotalTime() == null ? 0L : task.getTotalTime())); if (query.getOrder() == DESCENDING) { - Collections.reverse(agentTasks); + Collections.reverse(executeObjectTasks); } } else if (StepExecutionResultQuery.ORDER_FIELD_EXIT_CODE.equals(query.getOrderField())) { - agentTasks.sort((o1, o2) -> { + executeObjectTasks.sort((o1, o2) -> { if (o1.getExitCode() != null && o2.getExitCode() != null) { if (o1.getExitCode().equals(o2.getExitCode())) { return 0; @@ -600,7 +600,7 @@ private void sortAgentTasksAndLimitSize(List resultGroups, } }); if (query.getOrder() == DESCENDING) { - Collections.reverse(agentTasks); + Collections.reverse(executeObjectTasks); } } } @@ -837,13 +837,13 @@ private List getExecuteObjectCompositeKeysByLogConten private List fuzzySearchHostsByIp(StepInstanceBaseDTO stepInstance, String searchIp) { List matchExecuteObjects = - stepInstance.getTargetExecuteObjects().getMergedExecuteObjects().stream() + stepInstance.getTargetExecuteObjects().getExecuteObjectsCompatibly().stream() .filter(executeObject -> isMatchByIp(executeObject, searchIp)) .collect(Collectors.toList()); if (CollectionUtils.isEmpty(matchExecuteObjects)) { return null; } - if (stepInstance.isSupportExecuteObject()) { + if (stepInstance.isSupportExecuteObjectFeature()) { return matchExecuteObjects.stream() .map(executeObject -> ExecuteObjectCompositeKey.ofExecuteObjectId(executeObject.getId())) .collect(Collectors.toList()); diff --git a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/ExponentIncrementRollingExprPartTest.java b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/ExponentIncrementRollingExprPartTest.java index 50c68c1aae..d60351eeb1 100644 --- a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/ExponentIncrementRollingExprPartTest.java +++ b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/ExponentIncrementRollingExprPartTest.java @@ -74,24 +74,24 @@ void parseValidExpr() { @Test void compute() { List rollingExecuteObjects = new ArrayList<>(); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); RollingExecuteObjectBatchContext context = new RollingExecuteObjectBatchContext(rollingExecuteObjects); List remainingExecuteObjects = new ArrayList<>(); - remainingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - remainingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - remainingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - remainingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); + remainingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + remainingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + remainingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + remainingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); context.setRemainedExecuteObjects(remainingExecuteObjects); RollingExecuteObjectBatch preRollingExecuteObjectBatch = new RollingExecuteObjectBatch(); preRollingExecuteObjectBatch.setBatch(1); preRollingExecuteObjectBatch.setExecuteObjects( - Collections.singletonList(new ExecuteObject(HostDTO.fromHostId(1L)))); + Collections.singletonList(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)))); context.addExecuteObjectBatch(preRollingExecuteObjectBatch); context.setBatchCount(1); @@ -99,9 +99,9 @@ void compute() { (ExponentIncrementRollingExprPart) ROLLING_EXPR_PART.parseExpr("*3"); List executeObjectsOnBatch = exponentIncrementRollingExprPart.compute(context); assertThat(executeObjectsOnBatch).containsSequence( - new ExecuteObject(HostDTO.fromHostId(2L)), - new ExecuteObject(HostDTO.fromHostId(3L)), - new ExecuteObject(HostDTO.fromHostId(4L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L)) ); } } diff --git a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/PercentRollingExprPartTest.java b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/PercentRollingExprPartTest.java index e3dd6434b8..bb12795c67 100644 --- a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/PercentRollingExprPartTest.java +++ b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/PercentRollingExprPartTest.java @@ -80,9 +80,9 @@ class ComputeTest { @DisplayName("验证100%表达式") void compute() { List rollingExecuteObjects = new ArrayList<>(); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); PercentRollingExprPart percentRollingExprPart = (PercentRollingExprPart) PERCENT_ROLLING_EXPR_PART.parseExpr("100%"); @@ -90,9 +90,9 @@ void compute() { List executeObjectsOnBatch = percentRollingExprPart.compute(context); assertThat(executeObjectsOnBatch).hasSize(3); assertThat(executeObjectsOnBatch).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)), - new ExecuteObject(HostDTO.fromHostId(2L)), - new ExecuteObject(HostDTO.fromHostId(3L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)) ); } @@ -100,11 +100,11 @@ void compute() { @DisplayName("验证批次计算向上取整") void testCeil() { List rollingExecuteObjects = new ArrayList<>(); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); RollingExecuteObjectBatchContext context = new RollingExecuteObjectBatchContext(rollingExecuteObjects); PercentRollingExprPart percentRollingExprPart = @@ -112,7 +112,7 @@ void testCeil() { List executeObjectsOnBatch = percentRollingExprPart.compute(context); assertThat(executeObjectsOnBatch).hasSize(1); assertThat(executeObjectsOnBatch).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)) ); percentRollingExprPart = @@ -120,7 +120,7 @@ void testCeil() { executeObjectsOnBatch = percentRollingExprPart.compute(context); assertThat(executeObjectsOnBatch).hasSize(1); assertThat(executeObjectsOnBatch).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)) ); percentRollingExprPart = @@ -128,8 +128,8 @@ void testCeil() { executeObjectsOnBatch = percentRollingExprPart.compute(context); assertThat(executeObjectsOnBatch).hasSize(2); assertThat(executeObjectsOnBatch).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)), - new ExecuteObject(HostDTO.fromHostId(2L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)) ); } } diff --git a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/PlusIncrementRollingExprPartTest.java b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/PlusIncrementRollingExprPartTest.java index 6328395b0c..f22704fcb7 100644 --- a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/PlusIncrementRollingExprPartTest.java +++ b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/PlusIncrementRollingExprPartTest.java @@ -80,24 +80,24 @@ void parseValidExpr() { @Test void compute() { List rollingExecuteObjects = new ArrayList<>(); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); RollingExecuteObjectBatchContext context = new RollingExecuteObjectBatchContext(rollingExecuteObjects); List remainingExecuteObjects = new ArrayList<>(); - remainingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - remainingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - remainingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - remainingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); + remainingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + remainingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + remainingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + remainingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); context.setRemainedExecuteObjects(remainingExecuteObjects); RollingExecuteObjectBatch preRollingExecuteObjectBatch = new RollingExecuteObjectBatch(); preRollingExecuteObjectBatch.setBatch(1); preRollingExecuteObjectBatch.setExecuteObjects( - Collections.singletonList(new ExecuteObject(HostDTO.fromHostId(1L)))); + Collections.singletonList(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)))); context.addExecuteObjectBatch(preRollingExecuteObjectBatch); context.setBatchCount(1); @@ -105,10 +105,10 @@ void compute() { (PlusIncrementRollingExprPart) ROLLING_EXPR_PART.parseExpr("+3"); List executeObjectsOnBatch = plusIncrementRollingExprPart.compute(context); assertThat(executeObjectsOnBatch).containsSequence( - new ExecuteObject(HostDTO.fromHostId(2L)), - new ExecuteObject(HostDTO.fromHostId(3L)), - new ExecuteObject(HostDTO.fromHostId(4L)), - new ExecuteObject(HostDTO.fromHostId(5L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L)) ); } } diff --git a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/QuantityRollingExprPartTest.java b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/QuantityRollingExprPartTest.java index 2d823e96fd..8c57ca90a6 100644 --- a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/QuantityRollingExprPartTest.java +++ b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/QuantityRollingExprPartTest.java @@ -72,11 +72,11 @@ void parseValidExpr() { @Test void compute() { List rollingExecuteObjects = new ArrayList<>(); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - rollingExecuteObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + rollingExecuteObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); RollingExecuteObjectBatchContext context = new RollingExecuteObjectBatchContext(rollingExecuteObjects); QuantityRollingExprPart quantityRollingExprPart = @@ -84,8 +84,8 @@ void compute() { List executeObjectsOnBatch = quantityRollingExprPart.compute(context); assertThat(executeObjectsOnBatch).hasSize(2); assertThat(executeObjectsOnBatch).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)), - new ExecuteObject(HostDTO.fromHostId(2L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)) ); quantityRollingExprPart = @@ -93,11 +93,11 @@ void compute() { executeObjectsOnBatch = quantityRollingExprPart.compute(context); assertThat(executeObjectsOnBatch).hasSize(5); assertThat(executeObjectsOnBatch).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)), - new ExecuteObject(HostDTO.fromHostId(2L)), - new ExecuteObject(HostDTO.fromHostId(3L)), - new ExecuteObject(HostDTO.fromHostId(4L)), - new ExecuteObject(HostDTO.fromHostId(5L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L)) ); } } diff --git a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/RollingExecuteObjectBatchResolverTest.java b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/RollingExecuteObjectBatchResolverTest.java index 4bea8b2436..a016d5b138 100644 --- a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/RollingExecuteObjectBatchResolverTest.java +++ b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/rolling/RollingExecuteObjectBatchResolverTest.java @@ -44,22 +44,22 @@ class RollingExecuteObjectBatchResolverTest { @DisplayName("计算滚动批次 - 一个子表达式,按百分比分批") void resolveForSinglePercentExpr() { List executeObjects = new ArrayList<>(); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(6L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(7L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(8L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(9L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(10L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(11L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(12L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(13L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(14L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(15L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(16L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L))); RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "25%"); List executeObjectBatchList = context.resolve(); @@ -67,37 +67,37 @@ void resolveForSinglePercentExpr() { assertThat(executeObjectBatchList.get(0).getBatch()).isEqualTo(1); assertThat(executeObjectBatchList.get(0).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)), - new ExecuteObject(HostDTO.fromHostId(2L)), - new ExecuteObject(HostDTO.fromHostId(3L)), - new ExecuteObject(HostDTO.fromHostId(4L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L)) ); assertThat(executeObjectBatchList.get(0).getRollingExprPart().getExpr()).isEqualTo("25%"); assertThat(executeObjectBatchList.get(1).getBatch()).isEqualTo(2); assertThat(executeObjectBatchList.get(1).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(5L)), - new ExecuteObject(HostDTO.fromHostId(6L)), - new ExecuteObject(HostDTO.fromHostId(7L)), - new ExecuteObject(HostDTO.fromHostId(8L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L)) ); assertThat(executeObjectBatchList.get(1).getRollingExprPart().getExpr()).isEqualTo("25%"); assertThat(executeObjectBatchList.get(2).getBatch()).isEqualTo(3); assertThat(executeObjectBatchList.get(2).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(9L)), - new ExecuteObject(HostDTO.fromHostId(10L)), - new ExecuteObject(HostDTO.fromHostId(11L)), - new ExecuteObject(HostDTO.fromHostId(12L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L)) ); assertThat(executeObjectBatchList.get(2).getRollingExprPart().getExpr()).isEqualTo("25%"); assertThat(executeObjectBatchList.get(3).getBatch()).isEqualTo(4); assertThat(executeObjectBatchList.get(3).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(13L)), - new ExecuteObject(HostDTO.fromHostId(14L)), - new ExecuteObject(HostDTO.fromHostId(15L)), - new ExecuteObject(HostDTO.fromHostId(16L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L)) ); assertThat(executeObjectBatchList.get(3).getRollingExprPart().getExpr()).isEqualTo("25%"); } @@ -106,59 +106,59 @@ void resolveForSinglePercentExpr() { @DisplayName("计算滚动批次 - 多个子表达式,按百分比分批") void resolveForMultiPercentExpr() { List executeObjects = new ArrayList<>(); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(6L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(7L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(8L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(9L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(10L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(11L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(12L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(13L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(14L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(15L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(16L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L))); RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "10% 30%"); List executeObjectBatchList = context.resolve(); assertThat(executeObjectBatchList).hasSize(4); assertThat(executeObjectBatchList.get(0).getBatch()).isEqualTo(1); assertThat(executeObjectBatchList.get(0).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)), - new ExecuteObject(HostDTO.fromHostId(2L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)) ); assertThat(executeObjectBatchList.get(0).getRollingExprPart().getExpr()).isEqualTo("10%"); assertThat(executeObjectBatchList.get(1).getBatch()).isEqualTo(2); assertThat(executeObjectBatchList.get(1).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(3L)), - new ExecuteObject(HostDTO.fromHostId(4L)), - new ExecuteObject(HostDTO.fromHostId(5L)), - new ExecuteObject(HostDTO.fromHostId(6L)), - new ExecuteObject(HostDTO.fromHostId(7L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L)) ); assertThat(executeObjectBatchList.get(1).getRollingExprPart().getExpr()).isEqualTo("30%"); assertThat(executeObjectBatchList.get(2).getBatch()).isEqualTo(3); assertThat(executeObjectBatchList.get(2).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(8L)), - new ExecuteObject(HostDTO.fromHostId(9L)), - new ExecuteObject(HostDTO.fromHostId(10L)), - new ExecuteObject(HostDTO.fromHostId(11L)), - new ExecuteObject(HostDTO.fromHostId(12L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L)) ); assertThat(executeObjectBatchList.get(2).getRollingExprPart().getExpr()).isEqualTo("30%"); assertThat(executeObjectBatchList.get(3).getBatch()).isEqualTo(4); assertThat(executeObjectBatchList.get(3).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(13L)), - new ExecuteObject(HostDTO.fromHostId(14L)), - new ExecuteObject(HostDTO.fromHostId(15L)), - new ExecuteObject(HostDTO.fromHostId(16L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L)) ); assertThat(executeObjectBatchList.get(3).getRollingExprPart().getExpr()).isEqualTo("30%"); } @@ -167,49 +167,49 @@ void resolveForMultiPercentExpr() { @DisplayName("计算滚动批次 - 一个子表达式,按数量分批") void resolveForSingleQuantityExpr() { List executeObjects = new ArrayList<>(); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(6L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(7L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(8L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(9L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(10L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(11L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(12L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(13L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(14L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(15L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(16L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L))); RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "10"); List executeObjectBatchList = context.resolve(); assertThat(executeObjectBatchList).hasSize(2); assertThat(executeObjectBatchList.get(0).getBatch()).isEqualTo(1); assertThat(executeObjectBatchList.get(0).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)), - new ExecuteObject(HostDTO.fromHostId(2L)), - new ExecuteObject(HostDTO.fromHostId(3L)), - new ExecuteObject(HostDTO.fromHostId(4L)), - new ExecuteObject(HostDTO.fromHostId(5L)), - new ExecuteObject(HostDTO.fromHostId(6L)), - new ExecuteObject(HostDTO.fromHostId(7L)), - new ExecuteObject(HostDTO.fromHostId(8L)), - new ExecuteObject(HostDTO.fromHostId(9L)), - new ExecuteObject(HostDTO.fromHostId(10L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L)) ); assertThat(executeObjectBatchList.get(0).getRollingExprPart().getExpr()).isEqualTo("10"); assertThat(executeObjectBatchList.get(1).getBatch()).isEqualTo(2); assertThat(executeObjectBatchList.get(1).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(11L)), - new ExecuteObject(HostDTO.fromHostId(12L)), - new ExecuteObject(HostDTO.fromHostId(13L)), - new ExecuteObject(HostDTO.fromHostId(14L)), - new ExecuteObject(HostDTO.fromHostId(15L)), - new ExecuteObject(HostDTO.fromHostId(16L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L)) ); assertThat(executeObjectBatchList.get(1).getRollingExprPart().getExpr()).isEqualTo("10"); } @@ -218,59 +218,59 @@ void resolveForSingleQuantityExpr() { @DisplayName("计算滚动批次 - 多个子表达式,按数量分批") void resolveForMultiQuantityExpr() { List executeObjects = new ArrayList<>(); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(6L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(7L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(8L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(9L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(10L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(11L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(12L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(13L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(14L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(15L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(16L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L))); RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "1 5"); List executeObjectBatchList = context.resolve(); assertThat(executeObjectBatchList).hasSize(4); assertThat(executeObjectBatchList.get(0).getBatch()).isEqualTo(1); assertThat(executeObjectBatchList.get(0).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)) ); assertThat(executeObjectBatchList.get(0).getRollingExprPart().getExpr()).isEqualTo("1"); assertThat(executeObjectBatchList.get(1).getBatch()).isEqualTo(2); assertThat(executeObjectBatchList.get(1).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(2L)), - new ExecuteObject(HostDTO.fromHostId(3L)), - new ExecuteObject(HostDTO.fromHostId(4L)), - new ExecuteObject(HostDTO.fromHostId(5L)), - new ExecuteObject(HostDTO.fromHostId(6L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L)) ); assertThat(executeObjectBatchList.get(1).getRollingExprPart().getExpr()).isEqualTo("5"); assertThat(executeObjectBatchList.get(2).getBatch()).isEqualTo(3); assertThat(executeObjectBatchList.get(2).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(7L)), - new ExecuteObject(HostDTO.fromHostId(8L)), - new ExecuteObject(HostDTO.fromHostId(9L)), - new ExecuteObject(HostDTO.fromHostId(10L)), - new ExecuteObject(HostDTO.fromHostId(11L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L)) ); assertThat(executeObjectBatchList.get(2).getRollingExprPart().getExpr()).isEqualTo("5"); assertThat(executeObjectBatchList.get(3).getBatch()).isEqualTo(4); assertThat(executeObjectBatchList.get(3).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(12L)), - new ExecuteObject(HostDTO.fromHostId(13L)), - new ExecuteObject(HostDTO.fromHostId(14L)), - new ExecuteObject(HostDTO.fromHostId(15L)), - new ExecuteObject(HostDTO.fromHostId(16L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L)) ); assertThat(executeObjectBatchList.get(3).getRollingExprPart().getExpr()).isEqualTo("5"); } @@ -279,57 +279,57 @@ void resolveForMultiQuantityExpr() { @DisplayName("计算滚动批次 - 混合表达式,按数量和百分比分批") void resolveForMixedExpr() { List executeObjects = new ArrayList<>(); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(6L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(7L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(8L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(9L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(10L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(11L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(12L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(13L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(14L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(15L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L))); RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "1 30%"); List executeObjectBatchList = context.resolve(); assertThat(executeObjectBatchList).hasSize(4); assertThat(executeObjectBatchList.get(0).getBatch()).isEqualTo(1); assertThat(executeObjectBatchList.get(0).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)) ); assertThat(executeObjectBatchList.get(0).getRollingExprPart().getExpr()).isEqualTo("1"); assertThat(executeObjectBatchList.get(1).getBatch()).isEqualTo(2); assertThat(executeObjectBatchList.get(1).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(2L)), - new ExecuteObject(HostDTO.fromHostId(3L)), - new ExecuteObject(HostDTO.fromHostId(4L)), - new ExecuteObject(HostDTO.fromHostId(5L)), - new ExecuteObject(HostDTO.fromHostId(6L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L)) ); assertThat(executeObjectBatchList.get(1).getRollingExprPart().getExpr()).isEqualTo("30%"); assertThat(executeObjectBatchList.get(2).getBatch()).isEqualTo(3); assertThat(executeObjectBatchList.get(2).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(7L)), - new ExecuteObject(HostDTO.fromHostId(8L)), - new ExecuteObject(HostDTO.fromHostId(9L)), - new ExecuteObject(HostDTO.fromHostId(10L)), - new ExecuteObject(HostDTO.fromHostId(11L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L)) ); assertThat(executeObjectBatchList.get(2).getRollingExprPart().getExpr()).isEqualTo("30%"); assertThat(executeObjectBatchList.get(3).getBatch()).isEqualTo(4); assertThat(executeObjectBatchList.get(3).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(12L)), - new ExecuteObject(HostDTO.fromHostId(13L)), - new ExecuteObject(HostDTO.fromHostId(14L)), - new ExecuteObject(HostDTO.fromHostId(15L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L)) ); assertThat(executeObjectBatchList.get(3).getRollingExprPart().getExpr()).isEqualTo("30%"); @@ -340,22 +340,22 @@ void resolveForMixedExpr() { @DisplayName("计算滚动批次 - 最后一批包含所有") void resolveForAllRemainedExpr() { List executeObjects = new ArrayList<>(); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(1L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(2L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(3L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(4L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(5L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(6L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(7L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(8L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(9L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(10L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(11L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(12L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(13L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(14L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(15L))); - executeObjects.add(new ExecuteObject(HostDTO.fromHostId(16L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L))); RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "1 30% " + "100%"); List executeObjectBatchList = context.resolve(); @@ -363,32 +363,32 @@ void resolveForAllRemainedExpr() { assertThat(executeObjectBatchList.get(0).getBatch()).isEqualTo(1); assertThat(executeObjectBatchList.get(0).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(1L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(1L)) ); assertThat(executeObjectBatchList.get(0).getRollingExprPart().getExpr()).isEqualTo("1"); assertThat(executeObjectBatchList.get(1).getBatch()).isEqualTo(2); assertThat(executeObjectBatchList.get(1).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(2L)), - new ExecuteObject(HostDTO.fromHostId(3L)), - new ExecuteObject(HostDTO.fromHostId(4L)), - new ExecuteObject(HostDTO.fromHostId(5L)), - new ExecuteObject(HostDTO.fromHostId(6L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(2L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(3L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(4L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(5L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(6L)) ); assertThat(executeObjectBatchList.get(1).getRollingExprPart().getExpr()).isEqualTo("30%"); assertThat(executeObjectBatchList.get(2).getBatch()).isEqualTo(3); assertThat(executeObjectBatchList.get(2).getExecuteObjects()).containsSequence( - new ExecuteObject(HostDTO.fromHostId(7L)), - new ExecuteObject(HostDTO.fromHostId(8L)), - new ExecuteObject(HostDTO.fromHostId(9L)), - new ExecuteObject(HostDTO.fromHostId(10L)), - new ExecuteObject(HostDTO.fromHostId(11L)), - new ExecuteObject(HostDTO.fromHostId(12L)), - new ExecuteObject(HostDTO.fromHostId(13L)), - new ExecuteObject(HostDTO.fromHostId(14L)), - new ExecuteObject(HostDTO.fromHostId(15L)), - new ExecuteObject(HostDTO.fromHostId(16L)) + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(7L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(8L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(9L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(10L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(11L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(12L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(13L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(14L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(15L)), + ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId(16L)) ); assertThat(executeObjectBatchList.get(2).getRollingExprPart().getExpr()).isEqualTo("100%"); } @@ -398,7 +398,7 @@ void resolveForAllRemainedExpr() { void resolveExceedMaxBatchSize() { List executeObjects = new ArrayList<>(); for (int i = 1; i <= 1000; i++) { - executeObjects.add(new ExecuteObject(HostDTO.fromHostId((long) i))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId((long) i))); } RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "1"); assertThatExceptionOfType(FailedPreconditionException.class).isThrownBy( @@ -416,7 +416,7 @@ class RollingResolvePerformanceTest { void resolveQuantityExpr() { List executeObjects = new ArrayList<>(); for (int i = 1; i <= 50000; i++) { - executeObjects.add(new ExecuteObject(HostDTO.fromHostId((long) i))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId((long) i))); } RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "500"); List executeObjectBatchList = context.resolve(); @@ -429,7 +429,7 @@ void resolveQuantityExpr() { void resolvePercentExpr() { List executeObjects = new ArrayList<>(); for (int i = 1; i <= 50000; i++) { - executeObjects.add(new ExecuteObject(HostDTO.fromHostId((long) i))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId((long) i))); } RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "1%"); List executeObjectBatchList = context.resolve(); @@ -442,7 +442,7 @@ void resolvePercentExpr() { void resolvePlusIncrementRollingExpr() { List executeObjects = new ArrayList<>(); for (int i = 1; i <= 50000; i++) { - executeObjects.add(new ExecuteObject(HostDTO.fromHostId((long) i))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId((long) i))); } RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "+10"); List executeObjectBatchList = context.resolve(); @@ -455,7 +455,7 @@ void resolvePlusIncrementRollingExpr() { void resolveExponentIncrRollingExpr() { List executeObjects = new ArrayList<>(); for (int i = 1; i <= 50000; i++) { - executeObjects.add(new ExecuteObject(HostDTO.fromHostId((long) i))); + executeObjects.add(ExecuteObject.buildCompatibleExecuteObject(HostDTO.fromHostId((long) i))); } RollingBatchExecuteObjectsResolver context = new RollingBatchExecuteObjectsResolver(executeObjects, "*2"); context.resolve();