Skip to content

Commit

Permalink
Merge pull request #5952 from royalhuang/issue_5951
Browse files Browse the repository at this point in the history
bug: Container事件处理缺少状态校验 #5951
  • Loading branch information
irwinsun authored Jan 5, 2022
2 parents 6c7073c + 0d66cf5 commit 9cbd9f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,25 @@ class PipelineContextService @Autowired constructor(
val contextMap = mutableMapOf<String, String>()
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
)
}
}
Expand Down Expand Up @@ -127,7 +129,8 @@ class PipelineContextService @Autowired constructor(
containerId: String?,
contextMap: MutableMap<String, String>,
variables: Map<String, String>,
inMatrix: Boolean
inMatrix: Boolean,
groupIndex: Int
) {
// current job
if (c.id?.let { it == containerId } == true) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class MatrixExecuteContainerCmd(
var finishContainerNum = 0
val containersToRun = mutableListOf<PipelineBuildContainer>()

// 完全复用stage的执行状态判断逻辑
groupContainers.forEach { container ->
if (container.status.isFinish()) finishContainerNum++
if (container.status.isCancel()) {
Expand All @@ -158,6 +159,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
Expand Down

0 comments on commit 9cbd9f9

Please sign in to comment.