From ae02b826aaec60f64139e7d8278e6fc6175244de Mon Sep 17 00:00:00 2001 From: royalhuang Date: Tue, 4 Jan 2022 20:47:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?bug:=20Container=E4=BA=8B=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=BC=BA=E5=B0=91=E7=8A=B6=E6=80=81=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20#5951?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/control/ContainerControl.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/ContainerControl.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/ContainerControl.kt index 24058114dfe..718410385f2 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/ContainerControl.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/ContainerControl.kt @@ -51,6 +51,7 @@ import com.tencent.devops.process.engine.control.lock.ContainerIdLock import com.tencent.devops.process.engine.pojo.PipelineBuildContainer import com.tencent.devops.process.engine.pojo.event.PipelineBuildContainerEvent import com.tencent.devops.process.engine.service.PipelineContainerService +import com.tencent.devops.process.engine.service.PipelineStageService import com.tencent.devops.process.engine.service.PipelineTaskService import com.tencent.devops.process.service.BuildVariableService import org.slf4j.LoggerFactory @@ -64,6 +65,7 @@ import org.springframework.stereotype.Service @Service class ContainerControl @Autowired constructor( private val redisOperation: RedisOperation, + private val pipelineStageService: PipelineStageService, private val pipelineContainerService: PipelineContainerService, private val pipelineTaskService: PipelineTaskService, private val buildVariableService: BuildVariableService, @@ -92,6 +94,12 @@ class ContainerControl @Autowired constructor( containerIdLock.lock() watcher.start("execute") watcher.start("getContainer") + // #5951 在已结束或不存在的stage下,不再受理,抛弃消息 + val stage = pipelineStageService.getStage(buildId, stageId) + if (stage == null || stage.status.isFinish()) { + LOG.warn("ENGINE|$buildId|$source|$stageId|j($containerId)|bad stage with status(${stage?.status})") + return + } val container = pipelineContainerService.getContainer( buildId = buildId, stageId = stageId, From bc11e29b6480fb850aa4d41fd08a87debcfb2360 Mon Sep 17 00:00:00 2001 From: royalhuang Date: Tue, 4 Jan 2022 23:14:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?bug:=20Container=E4=BA=8B=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=BC=BA=E5=B0=91=E7=8A=B6=E6=80=81=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20#5951?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../control/command/container/impl/MatrixExecuteContainerCmd.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/MatrixExecuteContainerCmd.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/MatrixExecuteContainerCmd.kt index 3c81dba4f61..7b557fb606e 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/MatrixExecuteContainerCmd.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/MatrixExecuteContainerCmd.kt @@ -158,6 +158,7 @@ class MatrixExecuteContainerCmd( } else if (container.status == BuildStatus.SKIP) { skipContainerNum++ } else if (container.status.isRunning() && !newActionType.isEnd()) { + running = BuildStatus.RUNNING runningContainerNum++ } else if (!container.status.isFinish()) { running = BuildStatus.RUNNING From 0d66cf5ed068bd388b298a83e8179bbe5e057fd9 Mon Sep 17 00:00:00 2001 From: royalhuang Date: Wed, 5 Jan 2022 10:59:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?bug:=20Container=E4=BA=8B=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=BC=BA=E5=B0=91=E7=8A=B6=E6=80=81=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20#5951?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/service/PipelineContextService.kt | 14 +++++++++----- .../container/impl/MatrixExecuteContainerCmd.kt | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineContextService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineContextService.kt index bec04de4b1c..9dd200024f4 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineContextService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineContextService.kt @@ -62,23 +62,25 @@ class PipelineContextService @Autowired constructor( val contextMap = mutableMapOf() try { modelDetail.model.stages.forEach { stage -> - stage.containers.forEach { container -> + stage.containers.forEachIndexed { index, container -> buildJobContext( stage = stage, c = container, containerId = containerId, contextMap = contextMap, variables = variables, - inMatrix = false + inMatrix = false, + groupIndex = 0 ) - container.fetchGroupContainers()?.forEach { c -> + container.fetchGroupContainers()?.forEachIndexed { index, c -> buildJobContext( stage = stage, c = c, containerId = containerId, contextMap = contextMap, variables = variables, - inMatrix = true + inMatrix = true, + groupIndex = index ) } } @@ -127,7 +129,8 @@ class PipelineContextService @Autowired constructor( containerId: String?, contextMap: MutableMap, variables: Map, - inMatrix: Boolean + inMatrix: Boolean, + groupIndex: Int ) { // current job if (c.id?.let { it == containerId } == true) { @@ -138,6 +141,7 @@ class PipelineContextService @Autowired constructor( contextMap["job.container.network"] = getNetWork(c) ?: "" contextMap["job.stage_id"] = stage.id ?: "" contextMap["job.stage_name"] = stage.name ?: "" + contextMap["job.index"] = groupIndex.toString() } // other job diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/MatrixExecuteContainerCmd.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/MatrixExecuteContainerCmd.kt index 7b557fb606e..afb61ddcaf4 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/MatrixExecuteContainerCmd.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/MatrixExecuteContainerCmd.kt @@ -147,6 +147,7 @@ class MatrixExecuteContainerCmd( var finishContainerNum = 0 val containersToRun = mutableListOf() + // 完全复用stage的执行状态判断逻辑 groupContainers.forEach { container -> if (container.status.isFinish()) finishContainerNum++ if (container.status.isCancel()) {