diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/PipelineBuildContainer.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/PipelineBuildContainer.kt index d5c1436ff12c..f7d1d464f56f 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/PipelineBuildContainer.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/PipelineBuildContainer.kt @@ -37,6 +37,7 @@ data class PipelineBuildContainer( val stageId: String, val containerId: String, // 与seq id同值 val containerHashId: String?, // 与model中的container.containerHashId同值 + val containPostTaskFlag: Boolean?, val jobId: String?, val matrixGroupFlag: Boolean?, val matrixGroupId: String?, diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/pipeline/record/BuildRecordContainer.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/pipeline/record/BuildRecordContainer.kt index e1b857904796..855b27414d58 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/pipeline/record/BuildRecordContainer.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/pipeline/record/BuildRecordContainer.kt @@ -117,6 +117,7 @@ data class BuildRecordContainer( containerId = container.id!!, containerType = container.getClassType(), executeCount = context.executeCount, + containPostTaskFlag = container.containPostTaskFlag, matrixGroupFlag = container.matrixGroupFlag, status = buildStatus?.name, containerVar = containerVar, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/dao/record/BuildRecordContainerDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/dao/record/BuildRecordContainerDao.kt index 11dcfa47c545..9a815acd71b8 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/dao/record/BuildRecordContainerDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/dao/record/BuildRecordContainerDao.kt @@ -39,7 +39,7 @@ import com.tencent.devops.process.pojo.KEY_EXECUTE_COUNT import com.tencent.devops.process.pojo.pipeline.record.BuildRecordContainer import org.jooq.Condition import org.jooq.DSLContext -import org.jooq.Record15 +import org.jooq.Record16 import org.jooq.RecordMapper import org.jooq.impl.DSL import org.jooq.util.mysql.MySQLDSL @@ -63,6 +63,7 @@ class BuildRecordContainerDao { EXECUTE_COUNT, CONTAINER_VAR, CONTAINER_TYPE, + CONTAIN_POST_TASK, MATRIX_GROUP_FLAG, MATRIX_GROUP_ID, STATUS, @@ -81,6 +82,7 @@ class BuildRecordContainerDao { record.executeCount, JsonUtil.toJson(record.containerVar, false), record.containerType, + record.containPostTaskFlag, record.matrixGroupFlag, record.matrixGroupId, record.status, @@ -240,7 +242,7 @@ class BuildRecordContainerDao { ).from(this).where(conditions).groupBy(CONTAINER_ID) val result = dslContext.select( BUILD_ID, PROJECT_ID, PIPELINE_ID, RESOURCE_VERSION, STAGE_ID, CONTAINER_ID, - CONTAINER_VAR, EXECUTE_COUNT, CONTAINER_TYPE, STATUS, MATRIX_GROUP_FLAG, + CONTAINER_VAR, EXECUTE_COUNT, CONTAINER_TYPE, STATUS, CONTAIN_POST_TASK, MATRIX_GROUP_FLAG, MATRIX_GROUP_ID, START_TIME, END_TIME, TIMESTAMPS ).from(this).join(max).on( CONTAINER_ID.eq(max.field(KEY_CONTAINER_ID, String::class.java)) @@ -273,7 +275,7 @@ class BuildRecordContainerDao { ).from(this).where(conditions).groupBy(CONTAINER_ID) val result = dslContext.select( BUILD_ID, PROJECT_ID, PIPELINE_ID, RESOURCE_VERSION, STAGE_ID, CONTAINER_ID, - CONTAINER_VAR, EXECUTE_COUNT, CONTAINER_TYPE, STATUS, MATRIX_GROUP_FLAG, + CONTAINER_VAR, EXECUTE_COUNT, CONTAINER_TYPE, STATUS, CONTAIN_POST_TASK, MATRIX_GROUP_FLAG, MATRIX_GROUP_ID, START_TIME, END_TIME, TIMESTAMPS ).from(this).join(max).on( CONTAINER_ID.eq(max.field(KEY_CONTAINER_ID, String::class.java)) @@ -287,8 +289,8 @@ class BuildRecordContainerDao { } private fun TPipelineBuildRecordContainer.generateBuildRecordContainer( - record: Record15 + record: Record16 ) = BuildRecordContainer( buildId = record[BUILD_ID], @@ -303,6 +305,7 @@ class BuildRecordContainerDao { record[CONTAINER_VAR], object : TypeReference>() {} ), containerType = record[CONTAINER_TYPE], + containPostTaskFlag = record[CONTAIN_POST_TASK], matrixGroupFlag = record[MATRIX_GROUP_FLAG], matrixGroupId = record[MATRIX_GROUP_ID], startTime = record[START_TIME], diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/dao/record/BuildRecordTaskDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/dao/record/BuildRecordTaskDao.kt index 571937565769..9a751bf89a5d 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/dao/record/BuildRecordTaskDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/dao/record/BuildRecordTaskDao.kt @@ -145,7 +145,8 @@ class BuildRecordTaskDao { executeCount: Int, buildStatus: BuildStatus, stageId: String? = null, - containerId: String? = null + containerId: String? = null, + taskIds: Set? = null ) { with(TPipelineBuildRecordTask.T_PIPELINE_BUILD_RECORD_TASK) { val update = dslContext.update(this) @@ -158,6 +159,7 @@ class BuildRecordTaskDao { ) stageId?.let { update.and(STAGE_ID.eq(stageId)) } containerId?.let { update.and(CONTAINER_ID.eq(containerId)) } + taskIds?.let { update.and(TASK_ID.`in`(taskIds)) } update.execute() } } @@ -169,7 +171,8 @@ class BuildRecordTaskDao { buildId: String, executeCount: Int, containerId: String? = null, - buildStatusSet: Set? = null + buildStatusSet: Set? = null, + queryPostTaskFlag: Boolean? = null ): List { with(TPipelineBuildRecordTask.T_PIPELINE_BUILD_RECORD_TASK) { val conditions = mutableListOf() @@ -179,8 +182,12 @@ class BuildRecordTaskDao { conditions.add(EXECUTE_COUNT.eq(executeCount)) containerId?.let { conditions.add(CONTAINER_ID.eq(containerId)) } buildStatusSet?.let { conditions.add(STATUS.`in`(it.map { status -> status.name })) } - return dslContext.selectFrom(this) - .where(conditions).orderBy(TASK_SEQ.asc()).fetch(mapper) + if (queryPostTaskFlag == true) { + conditions.add(POST_INFO.isNotNull) + } else if (queryPostTaskFlag == false) { + conditions.add(POST_INFO.isNull) + } + return dslContext.selectFrom(this).where(conditions).orderBy(TASK_SEQ.asc()).fetch(mapper) } } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildContainerDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildContainerDao.kt index 1b8ad9fe54d8..ca65b922e776 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildContainerDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildContainerDao.kt @@ -351,6 +351,7 @@ class PipelineBuildContainerDao { containerType = containerType, containerId = containerId, containerHashId = containerHashId, + containPostTaskFlag = controlOption.containPostTaskFlag, jobId = jobId, matrixGroupFlag = matrixGroupFlag, matrixGroupId = matrixGroupId, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildTaskDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildTaskDao.kt index 853556d02f27..44c25c7ece57 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildTaskDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildTaskDao.kt @@ -283,7 +283,9 @@ class PipelineBuildTaskDao { projectId: String, buildId: String, containerId: String?, - statusSet: Collection? + statusSet: Collection?, + startTaskSeq: Int? = null, + endTaskSeq: Int? = null ): List { return with(T_PIPELINE_BUILD_TASK) { val where = dslContext.selectFrom(this) @@ -292,6 +294,8 @@ class PipelineBuildTaskDao { if (!statusSet.isNullOrEmpty()) { where.and(STATUS.`in`(statusSet.map { it.ordinal })) } + startTaskSeq?.let { where.and(TASK_SEQ.ge(startTaskSeq)) } + endTaskSeq?.let { where.and(TASK_SEQ.le(endTaskSeq)) } where.orderBy(TASK_SEQ.asc()).fetch(mapper) } } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineBuildQualityService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineBuildQualityService.kt index f64589e49c23..eb64a297f094 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineBuildQualityService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineBuildQualityService.kt @@ -27,6 +27,7 @@ package com.tencent.devops.process.engine.service +import com.tencent.devops.common.api.constant.CommonMessageCode import com.tencent.devops.common.api.enums.BuildReviewType import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.exception.TaskExecuteException @@ -76,10 +77,10 @@ import com.tencent.devops.process.utils.PIPELINE_BUILD_NUM import com.tencent.devops.quality.api.v2.ServiceQualityRuleResource import com.tencent.devops.quality.api.v2.pojo.ControlPointPosition import com.tencent.devops.quality.api.v2.pojo.request.BuildCheckParams -import java.time.LocalDateTime -import javax.ws.rs.core.Response import org.slf4j.LoggerFactory import org.springframework.stereotype.Service +import java.time.LocalDateTime +import javax.ws.rs.core.Response @Suppress( "LongParameterList", @@ -95,7 +96,6 @@ class PipelineBuildQualityService( private val client: Client, private val pipelineEventDispatcher: PipelineEventDispatcher, private val pipelineRepositoryService: PipelineRepositoryService, - private val buildDetailService: PipelineBuildDetailService, private val taskBuildRecordService: TaskBuildRecordService, private val pipelineRuntimeService: PipelineRuntimeService, private val buildVariableService: BuildVariableService @@ -135,61 +135,39 @@ class PipelineBuildQualityService( ) } - val model = buildDetailService.getBuildModel(projectId, buildId) + val buildInfo = pipelineRuntimeService.getBuildInfo(projectId, pipelineId, buildId) ?: throw ErrorCodeException( statusCode = Response.Status.NOT_FOUND.statusCode, errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, params = arrayOf(buildId) ) - - var find = false - var taskType = "" - model.stages.forEachIndexed nextStage@{ index, s -> - if (index == 0) { - return@nextStage - } - s.containers.forEach nextContainer@{ c -> - c.elements.forEach nextElement@{ element -> - if (element.id != elementId) return@nextElement - logger.info("${element.id}, ${element.name}") - when (element) { - is QualityGateInElement -> { - find = true - taskType = element.interceptTask!! - } - is QualityGateOutElement -> { - find = true - taskType = element.interceptTask!! - } - } - return@nextStage - } - c.fetchGroupContainers()?.forEach { - it.elements.forEach nextElement@{ element -> - if (element.id != elementId || element !is MatrixStatusElement) return@nextElement - logger.info("${element.id}, ${element.name}") - if (element.originClassType == QualityGateInElement.classType || - element.originClassType == QualityGateOutElement.classType - ) { - find = true - taskType = element.interceptTask!! - } - return@nextStage - } - } - } - } - - if (!find) { + val buildRecordTask = taskBuildRecordService.getTaskBuildRecord( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + taskId = elementId, + executeCount = buildInfo.executeCount ?: 1 + ) + val atomCode = buildRecordTask?.atomCode + if (atomCode.isNullOrBlank() || atomCode !in listOf( + QualityGateInElement.classType, + QualityGateOutElement.classType + ) + ) { throw ErrorCodeException( statusCode = Response.Status.FORBIDDEN.statusCode, errorCode = ProcessMessageCode.ERROR_QUALITY_TASK_NOT_FOUND, params = arrayOf(elementId) ) } + val interceptTaskKey = QualityGateInElement::interceptTask.name + val interceptTask = buildRecordTask.taskVar[interceptTaskKey]?.toString() ?: throw ErrorCodeException( + errorCode = CommonMessageCode.PARAMETER_IS_NULL, + params = arrayOf(interceptTaskKey) + ) // 校验审核权限 - val auditUserSet = getAuditUserList(projectId, pipelineId, buildId, taskType) + val auditUserSet = getAuditUserList(projectId, pipelineId, buildId, interceptTask) if (!auditUserSet.contains(userId)) { throw ErrorCodeException( statusCode = Response.Status.NOT_FOUND.statusCode, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineContainerService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineContainerService.kt index b9243b239aa6..b3c142fb28da 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineContainerService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineContainerService.kt @@ -404,6 +404,7 @@ class PipelineContainerService @Autowired constructor( containPostTaskFlag = container.containPostTaskFlag, agentReuseMutex = agentReuseMutex ), + containPostTaskFlag = container.containPostTaskFlag, matrixGroupFlag = false, matrixGroupId = matrixGroupId ) @@ -680,6 +681,7 @@ class PipelineContainerService @Autowired constructor( seq = context.containerSeq, status = BuildStatus.QUEUE, controlOption = controlOption, + containPostTaskFlag = container.containPostTaskFlag, matrixGroupFlag = container.matrixGroupFlag, matrixGroupId = null ), @@ -695,9 +697,9 @@ class PipelineContainerService @Autowired constructor( projectId = context.projectId, pipelineId = context.pipelineId, buildId = context.buildId, resourceVersion = context.resourceVersion, stageId = stage.id!!, containerId = container.id!!, containerType = container.getClassType(), - executeCount = context.executeCount, matrixGroupFlag = container.matrixGroupFlag, - matrixGroupId = null, status = BuildStatus.SKIP.name, containerVar = mutableMapOf(), - startTime = null, endTime = null, timestamps = mapOf() + executeCount = context.executeCount, containPostTaskFlag = container.containPostTaskFlag, + matrixGroupFlag = container.matrixGroupFlag, matrixGroupId = null, status = BuildStatus.SKIP.name, + containerVar = mutableMapOf(), startTime = null, endTime = null, timestamps = mapOf() ) ) } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineProgressRateService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineProgressRateService.kt index b09cc842efa2..60d64052031b 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineProgressRateService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineProgressRateService.kt @@ -5,6 +5,7 @@ import com.tencent.devops.common.pipeline.enums.BuildStatus import com.tencent.devops.common.pipeline.pojo.JobHeartbeatRequest import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.dao.record.BuildRecordTaskDao +import com.tencent.devops.process.engine.dao.PipelineBuildDao import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService import com.tencent.devops.process.engine.service.record.TaskBuildRecordService import com.tencent.devops.process.pojo.BuildStageProgressInfo @@ -22,6 +23,7 @@ class PipelineProgressRateService constructor( private val pipelineRuntimeService: PipelineRuntimeService, private val buildRecordService: ContainerBuildRecordService, private val buildRecordTaskDao: BuildRecordTaskDao, + private val pipelineBuildDao: PipelineBuildDao, private val dslContext: DSLContext ) { fun reportProgressRate( @@ -33,7 +35,9 @@ class PipelineProgressRateService constructor( logger.info("report progress rate:$projectId|$buildId|$executeCount|$jobHeartbeatRequest") val task2ProgressRate = jobHeartbeatRequest?.task2ProgressRate ?: return if (task2ProgressRate.isEmpty()) return - val pipelineId = pipelineRuntimeService.getBuildInfo(projectId, buildId)?.pipelineId ?: return + val pipelineId = pipelineBuildDao.getBuildInfo( + dslContext = dslContext, projectId = projectId, buildId = buildId + )?.pipelineId ?: return task2ProgressRate.forEach { (taskId, progressRate) -> taskBuildRecordService.updateTaskRecord( projectId = projectId, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt index 9d9c88ca1dc8..b36d3823a4a0 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt @@ -68,7 +68,6 @@ import com.tencent.devops.common.websocket.enum.RefreshType import com.tencent.devops.model.process.tables.records.TPipelineBuildSummaryRecord import com.tencent.devops.model.process.tables.records.TPipelineInfoRecord import com.tencent.devops.process.constant.ProcessMessageCode -import com.tencent.devops.process.dao.BuildDetailDao import com.tencent.devops.process.dao.record.BuildRecordModelDao import com.tencent.devops.process.engine.common.BS_CANCEL_BUILD_SOURCE import com.tencent.devops.process.engine.common.BS_MANUAL_ACTION @@ -173,7 +172,6 @@ class PipelineRuntimeService @Autowired constructor( private val pipelineStageService: PipelineStageService, private val pipelineContainerService: PipelineContainerService, private val pipelineTaskService: PipelineTaskService, - private val buildDetailDao: BuildDetailDao, private val recordModelDao: BuildRecordModelDao, private val buildVariableService: BuildVariableService, private val pipelineSettingService: PipelineSettingService, @@ -988,8 +986,6 @@ class PipelineRuntimeService @Autowired constructor( context.pipelineParamMap[PIPELINE_START_TASK_ID] = BuildParameters(PIPELINE_START_TASK_ID, context.firstTaskId, readOnly = true) - val modelJson = JsonUtil.toJson(fullModel, formatted = false) - val retryInfo = if (buildInfo != null) { context.buildNum = buildInfo.buildNum BuildRetryInfo( @@ -1025,15 +1021,6 @@ class PipelineRuntimeService @Autowired constructor( buildId = context.buildId, retryInfo = retryInfo!! ) - // 重置状态和人 - buildDetailDao.update( - dslContext = transactionContext, - projectId = context.projectId, - buildId = context.buildId, - model = modelJson, - buildStatus = context.startBuildStatus, - cancelUser = "" - ) } else { context.watcher.start("updateBuildNum") // 构建号递增 @@ -1048,18 +1035,6 @@ class PipelineRuntimeService @Autowired constructor( context.watcher.stop() // 创建构建记录 pipelineBuildDao.create(dslContext = transactionContext, startBuildContext = context) - - // detail记录,未正式启动,先排队状态 - buildDetailDao.create( - dslContext = transactionContext, - projectId = context.projectId, - buildId = context.buildId, - startUser = context.userId, - startType = context.startType, - buildNum = context.buildNum, - model = modelJson, - buildStatus = context.startBuildStatus - ) } context.pipelineParamMap[PIPELINE_BUILD_NUM] = BuildParameters( @@ -1270,8 +1245,8 @@ class PipelineRuntimeService @Autowired constructor( resourceVersion = resourceVersion, buildId = build.buildId, stageId = build.stageId, containerId = build.containerId, containerType = build.containerType, executeCount = build.executeCount, - matrixGroupFlag = build.matrixGroupFlag, matrixGroupId = build.matrixGroupId, - status = null, startTime = build.startTime, + containPostTaskFlag = build.containPostTaskFlag, matrixGroupFlag = build.matrixGroupFlag, + matrixGroupId = build.matrixGroupId, status = null, startTime = build.startTime, endTime = build.endTime, timestamps = mapOf(), containerVar = containerVar ) ) @@ -1319,13 +1294,6 @@ class PipelineRuntimeService @Autowired constructor( buildStatus = newBuildStatus, executeCount = executeCount ) - buildDetailDao.updateStatus( - dslContext = transactionContext, - projectId = buildInfo.projectId, - buildId = buildInfo.buildId, - buildStatus = newBuildStatus, - startTime = now - ) buildLogPrinter.addYellowLine( buildId = buildInfo.buildId, message = "Approved by user($userId)", tag = TAG, containerHashId = JOB_ID, executeCount = 1, @@ -1666,13 +1634,6 @@ class PipelineRuntimeService @Autowired constructor( dslContext.transaction { configuration -> val transactionContext = DSL.using(configuration) val startTime = LocalDateTime.now() - buildDetailDao.updateStatus( - dslContext = transactionContext, - projectId = latestRunningBuild.projectId, - buildId = latestRunningBuild.buildId, - buildStatus = BuildStatus.RUNNING, - startTime = startTime - ) recordModelDao.updateStatus( dslContext = transactionContext, projectId = latestRunningBuild.projectId, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineTaskService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineTaskService.kt index 3a781897d5c1..964217601345 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineTaskService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineTaskService.kt @@ -30,6 +30,7 @@ package com.tencent.devops.process.engine.service import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import com.tencent.devops.common.api.constant.KEY_VERSION +import com.tencent.devops.common.api.constant.NAME import com.tencent.devops.common.api.pojo.ErrorType import com.tencent.devops.common.api.pojo.Page import com.tencent.devops.common.api.util.JsonUtil @@ -37,7 +38,6 @@ import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.db.utils.JooqUtils import com.tencent.devops.common.log.utils.BuildLogPrinter -import com.tencent.devops.common.pipeline.Model import com.tencent.devops.common.pipeline.enums.BuildStatus import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.pipeline.pojo.element.ElementAdditionalOptions @@ -52,7 +52,6 @@ import com.tencent.devops.process.engine.dao.PipelineModelTaskDao import com.tencent.devops.process.engine.pojo.PipelineBuildTask import com.tencent.devops.process.engine.pojo.PipelineModelTask import com.tencent.devops.process.engine.pojo.UpdateTaskInfo -import com.tencent.devops.process.engine.service.detail.TaskBuildDetailService import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService import com.tencent.devops.process.engine.service.record.PipelineBuildRecordService import com.tencent.devops.process.engine.service.record.TaskBuildRecordService @@ -90,7 +89,6 @@ class PipelineTaskService @Autowired constructor( private val redisOperation: RedisOperation, private val objectMapper: ObjectMapper, private val pipelineInfoDao: PipelineInfoDao, - private val taskBuildDetailService: TaskBuildDetailService, private val taskBuildRecordService: TaskBuildRecordService, private val pipelineModelTaskDao: PipelineModelTaskDao, private val pipelineBuildTaskDao: PipelineBuildTaskDao, @@ -526,7 +524,14 @@ class PipelineTaskService @Autowired constructor( fun createFailTaskVar(buildId: String, projectId: String, pipelineId: String, taskId: String) { val taskRecord = getBuildTask(projectId, buildId, taskId) ?: return - val model = taskBuildDetailService.getBuildModel(projectId, buildId) + val buildRecordContainer = containerBuildRecordService.getRecord( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + containerId = taskRecord.containerId, + executeCount = taskRecord.executeCount + ) ?: return + val containerName = buildRecordContainer.containerVar[NAME]?.toString() ?: taskRecord.containerId val failTask = pipelineVariableService.getVariable( projectId, pipelineId, buildId, BK_CI_BUILD_FAIL_TASKS ) @@ -534,7 +539,7 @@ class PipelineTaskService @Autowired constructor( projectId, pipelineId, buildId, BK_CI_BUILD_FAIL_TASKNAMES ) try { - val errorElement = findElementMsg(model, taskRecord) + val errorElement = findElementMsg(containerName, taskRecord) // 存在的不重复添加 fix:流水线设置的变量重试一次就会叠加一次变量值 #6058 if (inFailTasks(failTasks = failTask, failTask = errorElement.first)) { @@ -619,10 +624,9 @@ class PipelineTaskService @Autowired constructor( } private fun findElementMsg( - model: Model?, + containerName: String, taskRecord: PipelineBuildTask ): Pair { - val containerName = model?.getContainer(taskRecord.containerId)?.name ?: "" val failTask = "[${taskRecord.stageId}][$containerName]${taskRecord.taskName} \n" val failTaskName = taskRecord.taskName @@ -650,8 +654,6 @@ class PipelineTaskService @Autowired constructor( projectId = task.projectId, pipelineId = task.pipelineId, buildId = task.buildId, - stageId = task.stageId, - containerId = task.containerId, taskId = task.taskId, executeCount = task.executeCount ?: 1 ) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/BaseBuildRecordService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/BaseBuildRecordService.kt index 9b80b14bfd6c..7d0154759a76 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/BaseBuildRecordService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/BaseBuildRecordService.kt @@ -50,13 +50,13 @@ import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.utils.LogUtils import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.websocket.enum.RefreshType +import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.dao.record.BuildRecordModelDao import com.tencent.devops.process.engine.control.lock.PipelineBuildRecordLock import com.tencent.devops.process.engine.dao.PipelineBuildDao import com.tencent.devops.process.engine.dao.PipelineResourceDao import com.tencent.devops.process.engine.dao.PipelineResourceVersionDao import com.tencent.devops.process.engine.pojo.event.PipelineBuildWebSocketPushEvent -import com.tencent.devops.process.engine.service.PipelineElementService import com.tencent.devops.process.engine.utils.PipelineUtils import com.tencent.devops.process.pojo.BuildStageStatus import com.tencent.devops.process.pojo.pipeline.record.BuildRecordModel @@ -68,19 +68,19 @@ import com.tencent.devops.process.utils.KEY_PIPELINE_ID import com.tencent.devops.process.utils.KEY_PROJECT_ID import org.jooq.DSLContext import org.slf4j.LoggerFactory +import javax.ws.rs.core.Response @Suppress("LongParameterList", "MagicNumber", "ReturnCount", "ComplexMethod") open class BaseBuildRecordService( private val dslContext: DSLContext, private val buildRecordModelDao: BuildRecordModelDao, - private val pipelineBuildDao: PipelineBuildDao, + val pipelineBuildDao: PipelineBuildDao, private val pipelineEventDispatcher: PipelineEventDispatcher, private val redisOperation: RedisOperation, private val stageTagService: StageTagService, private val recordModelService: PipelineRecordModelService, private val pipelineResourceDao: PipelineResourceDao, - private val pipelineResourceVersionDao: PipelineResourceVersionDao, - private val pipelineElementService: PipelineElementService + private val pipelineResourceVersionDao: PipelineResourceVersionDao ) { protected fun update( @@ -151,6 +151,51 @@ open class BaseBuildRecordService( return } + fun getRecordModel( + projectId: String, + pipelineId: String, + version: Int, + buildId: String, + executeCount: Int? = null, + queryDslContext: DSLContext? = null, + debug: Boolean? = false + ): Model? { + val fixedExecuteCount = if (executeCount == null) { + val buildInfo = pipelineBuildDao.getBuildInfo( + dslContext = queryDslContext ?: dslContext, projectId = projectId, buildId = buildId + ) ?: throw ErrorCodeException( + statusCode = Response.Status.NOT_FOUND.statusCode, + errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, + params = arrayOf(buildId) + ) + buildInfo.executeCount + } else { + executeCount + } + val buildRecordModel = buildRecordModelDao.getRecord( + dslContext = queryDslContext ?: dslContext, + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + executeCount = fixedExecuteCount + ) + return if (buildRecordModel != null) { + getRecordModel( + projectId = projectId, + pipelineId = pipelineId, + version = version, + buildId = buildId, + fixedExecuteCount = fixedExecuteCount, + buildRecordModel = buildRecordModel, + executeCount = executeCount, + queryDslContext = queryDslContext, + debug = debug + ) + } else { + null + } + } + fun getRecordModel( projectId: String, pipelineId: String, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/ContainerBuildRecordService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/ContainerBuildRecordService.kt index d5593c6c9216..c1002c976bd5 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/ContainerBuildRecordService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/ContainerBuildRecordService.kt @@ -47,8 +47,6 @@ import com.tencent.devops.process.engine.common.BuildTimeCostUtils.generateMatri import com.tencent.devops.process.engine.dao.PipelineBuildDao import com.tencent.devops.process.engine.dao.PipelineResourceDao import com.tencent.devops.process.engine.dao.PipelineResourceVersionDao -import com.tencent.devops.process.engine.service.PipelineElementService -import com.tencent.devops.process.engine.service.detail.ContainerBuildDetailService import com.tencent.devops.process.engine.utils.ContainerUtils import com.tencent.devops.process.pojo.VmInfo import com.tencent.devops.process.pojo.pipeline.record.BuildRecordContainer @@ -67,12 +65,10 @@ class ContainerBuildRecordService( private val dslContext: DSLContext, private val recordContainerDao: BuildRecordContainerDao, private val recordTaskDao: BuildRecordTaskDao, - private val containerBuildDetailService: ContainerBuildDetailService, recordModelService: PipelineRecordModelService, pipelineResourceDao: PipelineResourceDao, pipelineBuildDao: PipelineBuildDao, pipelineResourceVersionDao: PipelineResourceVersionDao, - pipelineElementService: PipelineElementService, stageTagService: StageTagService, buildRecordModelDao: BuildRecordModelDao, pipelineEventDispatcher: PipelineEventDispatcher, @@ -86,25 +82,30 @@ class ContainerBuildRecordService( recordModelService = recordModelService, pipelineResourceDao = pipelineResourceDao, pipelineBuildDao = pipelineBuildDao, - pipelineResourceVersionDao = pipelineResourceVersionDao, - pipelineElementService = pipelineElementService + pipelineResourceVersionDao = pipelineResourceVersionDao ) { fun getRecord( - transactionContext: DSLContext?, + transactionContext: DSLContext? = null, projectId: String, pipelineId: String, buildId: String, containerId: String, - executeCount: Int + executeCount: Int? = null ): BuildRecordContainer? { + val finalExecuteCount = if (executeCount == null) { + val buildInfo = pipelineBuildDao.getBuildInfo(dslContext, projectId, buildId) + buildInfo?.executeCount ?: 1 + } else { + executeCount + } return recordContainerDao.getRecord( transactionContext ?: dslContext, projectId = projectId, pipelineId = pipelineId, buildId = buildId, containerId = containerId, - executeCount = executeCount + executeCount = finalExecuteCount ) } @@ -128,7 +129,6 @@ class ContainerBuildRecordService( containerId: String, executeCount: Int ) { - containerBuildDetailService.containerPreparing(projectId, buildId, containerId) update( projectId, pipelineId, buildId, executeCount, BuildStatus.RUNNING, cancelUser = null, operation = "containerPreparing#$containerId" @@ -156,12 +156,6 @@ class ContainerBuildRecordService( executeCount: Int, containerBuildStatus: BuildStatus ) { - containerBuildDetailService.containerStarted( - projectId = projectId, - buildId = buildId, - containerId = containerId, - containerBuildStatus = containerBuildStatus - ) update( projectId, pipelineId, buildId, executeCount, BuildStatus.RUNNING, cancelUser = null, operation = "containerStarted#$containerId" @@ -195,13 +189,6 @@ class ContainerBuildRecordService( buildStatus: BuildStatus, operation: String ) { - containerBuildDetailService.updateContainerStatus( - projectId = projectId, - buildId = buildId, - containerId = containerId, - buildStatus = buildStatus, - executeCount = executeCount - ) update( projectId, pipelineId, buildId, executeCount, BuildStatus.RUNNING, cancelUser = null, operation = "$operation#$containerId" @@ -300,15 +287,6 @@ class ContainerBuildRecordService( matrixOption: MatrixControlOption, modelContainer: Container? ) { - containerBuildDetailService.updateMatrixGroupContainer( - projectId = projectId, - buildId = buildId, - stageId = stageId, - matrixGroupId = matrixGroupId, - buildStatus = buildStatus, - matrixOption = matrixOption, - modelContainer = modelContainer - ) update( projectId, pipelineId, buildId, executeCount, BuildStatus.RUNNING, cancelUser = null, operation = "updateMatrixGroupContainer#$matrixGroupId" @@ -335,7 +313,6 @@ class ContainerBuildRecordService( executeCount: Int, containerId: String ) { - containerBuildDetailService.containerSkip(projectId, buildId, containerId) update( projectId, pipelineId, buildId, executeCount, BuildStatus.RUNNING, cancelUser = null, operation = "containerSkip#$containerId" @@ -363,13 +340,6 @@ class ContainerBuildRecordService( vmInfo: VmInfo, executeCount: Int? ) { - containerBuildDetailService.saveBuildVmInfo( - projectId = projectId, - pipelineId = pipelineId, - buildId = buildId, - containerId = containerId, - vmInfo = vmInfo - ) logger.info("ENGINE|$buildId|saveBuildVmInfo|containerId=$containerId|$vmInfo") if (executeCount == null) return update( diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/PipelineBuildRecordService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/PipelineBuildRecordService.kt index ca7f2401572a..2fab838f73e8 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/PipelineBuildRecordService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/PipelineBuildRecordService.kt @@ -27,7 +27,9 @@ package com.tencent.devops.process.engine.service.record +import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.pojo.ErrorInfo +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.Watcher import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher @@ -51,8 +53,10 @@ import com.tencent.devops.common.pipeline.utils.ModelUtils import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.utils.LogUtils import com.tencent.devops.common.web.utils.I18nUtil +import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.BK_EVENT import com.tencent.devops.process.constant.ProcessMessageCode.BK_WAREHOUSE_EVENTS +import com.tencent.devops.process.dao.BuildDetailDao import com.tencent.devops.process.dao.record.BuildRecordContainerDao import com.tencent.devops.process.dao.record.BuildRecordModelDao import com.tencent.devops.process.dao.record.BuildRecordStageDao @@ -64,8 +68,6 @@ import com.tencent.devops.process.engine.dao.PipelineResourceDao import com.tencent.devops.process.engine.dao.PipelineResourceVersionDao import com.tencent.devops.process.engine.dao.PipelineTriggerReviewDao import com.tencent.devops.process.engine.pojo.BuildInfo -import com.tencent.devops.process.engine.service.PipelineBuildDetailService -import com.tencent.devops.process.engine.service.PipelineElementService import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.utils.ContainerUtils import com.tencent.devops.process.pojo.BuildStageStatus @@ -86,6 +88,7 @@ import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service +import javax.ws.rs.core.Response @Suppress( "LongParameterList", @@ -96,7 +99,6 @@ import org.springframework.stereotype.Service ) @Service class PipelineBuildRecordService @Autowired constructor( - private val pipelineBuildDetailService: PipelineBuildDetailService, private val pipelineRepositoryService: PipelineRepositoryService, private val pipelineBuildSummaryDao: PipelineBuildSummaryDao, private val pipelineTriggerReviewDao: PipelineTriggerReviewDao, @@ -105,11 +107,11 @@ class PipelineBuildRecordService @Autowired constructor( private val recordStageDao: BuildRecordStageDao, private val recordContainerDao: BuildRecordContainerDao, private val recordTaskDao: BuildRecordTaskDao, + private val buildDetailDao: BuildDetailDao, recordModelService: PipelineRecordModelService, pipelineResourceDao: PipelineResourceDao, pipelineBuildDao: PipelineBuildDao, pipelineResourceVersionDao: PipelineResourceVersionDao, - pipelineElementService: PipelineElementService, redisOperation: RedisOperation, stageTagService: StageTagService, pipelineEventDispatcher: PipelineEventDispatcher @@ -122,8 +124,7 @@ class PipelineBuildRecordService @Autowired constructor( recordModelService = recordModelService, pipelineResourceDao = pipelineResourceDao, pipelineBuildDao = pipelineBuildDao, - pipelineResourceVersionDao = pipelineResourceVersionDao, - pipelineElementService = pipelineElementService + pipelineResourceVersionDao = pipelineResourceVersionDao ) { @Value("\${pipeline.build.retry.limit_days:21}") @@ -154,6 +155,47 @@ class PipelineBuildRecordService @Autowired constructor( return (System.currentTimeMillis() - startTime) < TimeUnit.DAYS.toMillis(retryLimitDays.toLong()) } + /** + * 查询ModelRecord + * @param projectId: 项目Id + * @param pipelineId: 流水线Id + * @param buildId: 构建Id + * @param refreshStatus: 是否刷新状态 + * @param executeCount: 执行次数 + * @param queryDslContext: 查询jooq上下文 + */ + fun getBuildRecord( + projectId: String, + pipelineId: String, + buildId: String, + refreshStatus: Boolean = true, + executeCount: Int? = null, + queryDslContext: DSLContext? = null + ): ModelRecord? { + val buildInfo = pipelineBuildDao.getBuildInfo( + dslContext = queryDslContext ?: dslContext, + projectId = projectId, + buildId = buildId + ) ?: throw ErrorCodeException( + statusCode = Response.Status.NOT_FOUND.statusCode, + errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, + params = arrayOf(buildId) + ) + if (projectId != buildInfo.projectId || pipelineId != buildInfo.pipelineId) { + throw ErrorCodeException( + statusCode = Response.Status.NOT_FOUND.statusCode, + errorCode = ProcessMessageCode.ERROR_NO_PIPELINE_EXISTS_BY_ID, + params = arrayOf(buildId) + ) + } + return getBuildRecord( + buildInfo = buildInfo, + executeCount = executeCount, + refreshStatus = refreshStatus, + queryDslContext = queryDslContext + ) + } + /** * 查询ModelRecord * @param buildInfo: 构建信息 @@ -205,7 +247,8 @@ class PipelineBuildRecordService @Autowired constructor( "fixedExecuteCount=$fixedExecuteCount" ) watcher.start("getDetailModel") - val detail = pipelineBuildDetailService.getBuildModel(projectId, buildId, queryDslContext) ?: return null + val record = buildDetailDao.get(queryDslContext ?: dslContext, projectId, buildId) ?: return null + val detail = JsonUtil.to(record.model, Model::class.java) fixDetailTimeCost(buildInfo, detail) detail } @@ -462,12 +505,6 @@ class PipelineBuildRecordService @Autowired constructor( cancelUser: String, executeCount: Int ) { - pipelineBuildDetailService.buildCancel( - projectId = projectId, - buildId = buildId, - buildStatus = buildStatus, - cancelUser = cancelUser - ) logger.info("[$buildId]|BUILD_CANCEL|cancelUser=$cancelUser|buildStatus=$buildStatus") dslContext.transaction { configuration -> val context = DSL.using(configuration) @@ -551,18 +588,26 @@ class PipelineBuildRecordService @Autowired constructor( errorMsg: String? ): Triple, BuildRecordTimeCost?> { logger.info("[$buildId]|BUILD_END|buildStatus=$buildStatus") -// var allStageStatus: List = emptyList() var timeCost: BuildRecordTimeCost? = null + val recordModel = recordModelDao.getRecord( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + executeCount = executeCount + ) ?: run { + logger.warn( + "ENGINE|$buildId|buildEnd| get model($buildId) record failed." + ) + throw ErrorCodeException( + statusCode = Response.Status.NOT_FOUND.statusCode, + errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, + params = arrayOf(buildId) + ) + } + var allStageStatus: List = emptyList() dslContext.transaction { configuration -> val context = DSL.using(configuration) - val recordModel = recordModelDao.getRecord( - context, projectId, pipelineId, buildId, executeCount - ) ?: run { - logger.warn( - "ENGINE|$buildId|buildEnd| get model($buildId) record failed." - ) - return@transaction - } val now = LocalDateTime.now() val runningStatusSet = enumValues().filter { it.isRunning() }.toSet() // 刷新运行中stage状态,取出所有stage记录还需用于耗时计算 @@ -601,12 +646,9 @@ class PipelineBuildRecordService @Autowired constructor( recordTaskDao.batchSave(context, recordTasks) recordContainerDao.batchSave(context, recordContainers) recordStageDao.batchSave(context, recordStages) - -// allStageStatus = fetchHistoryStageStatus( -// recordStages = recordStages, -// buildStatus = buildStatus, -// errorMsg = errorMsg -// ) + allStageStatus = fetchHistoryStageStatus( + recordStages = recordStages, buildStatus = buildStatus, errorMsg = errorMsg + ) val modelVar = mutableMapOf() timeCost = recordModel.generateBuildTimeCost(recordStages) @@ -624,13 +666,18 @@ class PipelineBuildRecordService @Autowired constructor( executeCount = executeCount ) } - val detail = pipelineBuildDetailService.buildEnd( + val model = getRecordModel( projectId = projectId, + pipelineId = pipelineId, + version = recordModel.resourceVersion, buildId = buildId, - buildStatus = buildStatus, - errorMsg = errorMsg + executeCount = executeCount + ) ?: throw ErrorCodeException( + statusCode = Response.Status.NOT_FOUND.statusCode, + errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, + params = arrayOf(buildId) ) - return Triple(detail.first, detail.second, timeCost) + return Triple(model, allStageStatus, timeCost) } fun updateBuildCancelUser( @@ -639,11 +686,6 @@ class PipelineBuildRecordService @Autowired constructor( executeCount: Int, cancelUserId: String ) { - pipelineBuildDetailService.updateBuildCancelUser( - projectId = projectId, - buildId = buildId, - cancelUserId = cancelUserId - ) recordModelDao.updateBuildCancelUser( dslContext = dslContext, projectId = projectId, @@ -698,4 +740,12 @@ class PipelineBuildRecordService @Autowired constructor( ) } } + + fun getPipelineIdByBuildId(projectId: String, buildId: String): String? { + return pipelineBuildDao.getBuildInfo( + dslContext = dslContext, + projectId = projectId, + buildId = buildId + )?.pipelineId + } } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/StageBuildRecordService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/StageBuildRecordService.kt index a2debf3c657e..505f22749242 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/StageBuildRecordService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/StageBuildRecordService.kt @@ -44,8 +44,6 @@ import com.tencent.devops.process.engine.dao.PipelineBuildDao import com.tencent.devops.process.engine.dao.PipelineResourceDao import com.tencent.devops.process.engine.dao.PipelineResourceVersionDao import com.tencent.devops.process.engine.pojo.PipelineBuildStageControlOption -import com.tencent.devops.process.engine.service.PipelineElementService -import com.tencent.devops.process.engine.service.detail.StageBuildDetailService import com.tencent.devops.process.pojo.BuildStageStatus import com.tencent.devops.process.service.StageTagService import com.tencent.devops.process.service.record.PipelineRecordModelService @@ -62,12 +60,10 @@ class StageBuildRecordService( private val recordStageDao: BuildRecordStageDao, private val recordContainerDao: BuildRecordContainerDao, private val recordTaskDao: BuildRecordTaskDao, - private val stageBuildDetailService: StageBuildDetailService, - private val pipelineBuildDao: PipelineBuildDao, + pipelineBuildDao: PipelineBuildDao, recordModelService: PipelineRecordModelService, pipelineResourceDao: PipelineResourceDao, pipelineResourceVersionDao: PipelineResourceVersionDao, - pipelineElementService: PipelineElementService, stageTagService: StageTagService, buildRecordModelDao: BuildRecordModelDao, pipelineEventDispatcher: PipelineEventDispatcher, @@ -81,8 +77,7 @@ class StageBuildRecordService( recordModelService = recordModelService, pipelineResourceDao = pipelineResourceDao, pipelineBuildDao = pipelineBuildDao, - pipelineResourceVersionDao = pipelineResourceVersionDao, - pipelineElementService = pipelineElementService + pipelineResourceVersionDao = pipelineResourceVersionDao ) { fun updateStageStatus( @@ -117,10 +112,36 @@ class StageBuildRecordService( buildStatus = buildStatus ) } - return stageBuildDetailService.updateStageStatus( - projectId = projectId, buildId = buildId, stageId = stageId, - buildStatus = buildStatus, executeCount = executeCount + return getHistoryStageStatusList( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + executeCount = executeCount, + buildStatus = buildStatus + ) + } + + private fun getHistoryStageStatusList( + projectId: String, + pipelineId: String, + buildId: String, + executeCount: Int, + buildStatus: BuildStatus, + reviewers: List? = null + ): List { + val recordStages = recordStageDao.getRecords( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + executeCount = executeCount + ) + val historyStageStatusList = fetchHistoryStageStatus( + recordStages = recordStages, + buildStatus = buildStatus, + reviewers = reviewers ) + return historyStageStatusList } fun stageSkip( @@ -149,10 +170,12 @@ class StageBuildRecordService( stageVar = mutableMapOf() ) } - return stageBuildDetailService.stageSkip( + return getHistoryStageStatusList( projectId = projectId, + pipelineId = pipelineId, buildId = buildId, - stageId = stageId + executeCount = executeCount, + buildStatus = BuildStatus.RUNNING ) } @@ -175,7 +198,6 @@ class StageBuildRecordService( val stageVar = mutableMapOf() stageVar[Stage::startEpoch.name] = System.currentTimeMillis() stageVar[Stage::stageControlOption.name] = controlOption.stageControlOption - stageVar[Stage::startEpoch.name] = System.currentTimeMillis() checkIn?.let { stageVar[Stage::checkIn.name] = checkIn } checkOut?.let { stageVar[Stage::checkOut.name] = checkOut } updateStageRecord( @@ -188,13 +210,13 @@ class StageBuildRecordService( ) ) } - return stageBuildDetailService.stagePause( + return getHistoryStageStatusList( projectId = projectId, + pipelineId = pipelineId, buildId = buildId, - stageId = stageId, - controlOption = controlOption, - checkIn = checkIn, - checkOut = checkOut + executeCount = executeCount, + buildStatus = BuildStatus.REVIEWING, + reviewers = checkIn?.groupToReview()?.reviewers ) } @@ -233,10 +255,6 @@ class StageBuildRecordService( ) ) } - stageBuildDetailService.stageCancel( - projectId = projectId, buildId = buildId, stageId = stageId, controlOption = controlOption, - checkIn = checkIn, checkOut = checkOut - ) } fun stageCheckQuality( @@ -290,10 +308,12 @@ class StageBuildRecordService( ) pipelineBuildDao.updateStatus(dslContext, projectId, buildId, oldBuildStatus, newBuildStatus) } - return stageBuildDetailService.stageCheckQuality( - projectId = projectId, buildId = buildId, stageId = stageId, - controlOption = controlOption, - checkIn = checkIn, checkOut = checkOut + return getHistoryStageStatusList( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + executeCount = executeCount, + buildStatus = newBuildStatus ) } @@ -308,11 +328,6 @@ class StageBuildRecordService( checkOut: StagePauseCheck? ) { logger.info("[$buildId]|stage_review|stageId=$stageId") - stageBuildDetailService.stageReview( - projectId = projectId, buildId = buildId, stageId = stageId, - controlOption = controlOption, - checkIn = checkIn, checkOut = checkOut - ) update( projectId, pipelineId, buildId, executeCount, BuildStatus.STAGE_SUCCESS, cancelUser = null, operation = "stageReview#$stageId" @@ -368,9 +383,12 @@ class StageBuildRecordService( ) ) } - return stageBuildDetailService.stageStart( - projectId = projectId, buildId = buildId, stageId = stageId, - controlOption = controlOption, checkIn = checkIn, checkOut = checkOut + return getHistoryStageStatusList( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + executeCount = executeCount, + buildStatus = BuildStatus.RUNNING ) } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/TaskBuildRecordService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/TaskBuildRecordService.kt index 69ed46746158..2e8a3b5a485a 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/TaskBuildRecordService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/TaskBuildRecordService.kt @@ -33,6 +33,7 @@ import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatch import com.tencent.devops.common.pipeline.enums.BuildRecordTimeStamp import com.tencent.devops.common.pipeline.enums.BuildStatus import com.tencent.devops.common.pipeline.pojo.element.Element +import com.tencent.devops.common.pipeline.pojo.element.RunCondition import com.tencent.devops.common.pipeline.pojo.element.agent.ManualReviewUserTaskElement import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement @@ -44,12 +45,12 @@ import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.process.dao.record.BuildRecordModelDao import com.tencent.devops.process.dao.record.BuildRecordTaskDao import com.tencent.devops.process.engine.common.BuildTimeCostUtils.generateTaskTimeCost +import com.tencent.devops.process.engine.common.VMUtils import com.tencent.devops.process.engine.dao.PipelineBuildDao +import com.tencent.devops.process.engine.dao.PipelineBuildTaskDao import com.tencent.devops.process.engine.dao.PipelineResourceDao import com.tencent.devops.process.engine.dao.PipelineResourceVersionDao import com.tencent.devops.process.engine.pojo.PipelineTaskStatusInfo -import com.tencent.devops.process.engine.service.PipelineElementService -import com.tencent.devops.process.engine.service.detail.TaskBuildDetailService import com.tencent.devops.process.pojo.pipeline.record.BuildRecordTask import com.tencent.devops.process.pojo.task.TaskBuildEndParam import com.tencent.devops.process.service.BuildVariableService @@ -76,13 +77,12 @@ class TaskBuildRecordService( private val buildVariableService: BuildVariableService, private val dslContext: DSLContext, private val recordTaskDao: BuildRecordTaskDao, + private val pipelineBuildTaskDao: PipelineBuildTaskDao, private val containerBuildRecordService: ContainerBuildRecordService, - private val taskBuildDetailService: TaskBuildDetailService, recordModelService: PipelineRecordModelService, pipelineResourceDao: PipelineResourceDao, pipelineBuildDao: PipelineBuildDao, pipelineResourceVersionDao: PipelineResourceVersionDao, - pipelineElementService: PipelineElementService, stageTagService: StageTagService, buildRecordModelDao: BuildRecordModelDao, pipelineEventDispatcher: PipelineEventDispatcher, @@ -96,30 +96,19 @@ class TaskBuildRecordService( recordModelService = recordModelService, pipelineResourceDao = pipelineResourceDao, pipelineBuildDao = pipelineBuildDao, - pipelineResourceVersionDao = pipelineResourceVersionDao, - pipelineElementService = pipelineElementService + pipelineResourceVersionDao = pipelineResourceVersionDao ) { fun updateTaskStatus( projectId: String, pipelineId: String, buildId: String, - stageId: String, - containerId: String, taskId: String, executeCount: Int, buildStatus: BuildStatus, operation: String, timestamps: Map? = null ) { - taskBuildDetailService.updateTaskStatus( - projectId = projectId, - buildId = buildId, - taskId = taskId, - taskStatus = buildStatus, - buildStatus = BuildStatus.RUNNING, - operation = operation - ) updateTaskRecord( projectId = projectId, pipelineId = pipelineId, @@ -140,7 +129,6 @@ class TaskBuildRecordService( taskId: String, executeCount: Int ) { - taskBuildDetailService.taskStart(projectId, buildId, taskId) update( projectId = projectId, pipelineId = pipelineId, buildId = buildId, executeCount = executeCount, buildStatus = BuildStatus.RUNNING, @@ -229,19 +217,9 @@ class TaskBuildRecordService( projectId: String, pipelineId: String, buildId: String, - stageId: String, - containerId: String, taskId: String, executeCount: Int ) { - taskBuildDetailService.taskPause( - projectId = projectId, - buildId = buildId, - stageId = stageId, - containerId = containerId, - taskId = taskId, - buildStatus = BuildStatus.PAUSE - ) updateTaskRecord( projectId = projectId, pipelineId = pipelineId, @@ -282,19 +260,9 @@ class TaskBuildRecordService( projectId: String, pipelineId: String, buildId: String, - stageId: String, - containerId: String, taskId: String, - executeCount: Int, - cancelUser: String + executeCount: Int ) { - taskBuildDetailService.taskCancel( - projectId = projectId, - buildId = buildId, - containerId = containerId, - taskId = taskId, - cancelUser = cancelUser // fix me: 是否要直接更新取消人,暂时维护原有逻辑 - ) updateTaskRecord( projectId = projectId, pipelineId = pipelineId, @@ -315,20 +283,10 @@ class TaskBuildRecordService( projectId: String, pipelineId: String, buildId: String, - stageId: String, containerId: String, taskId: String, - executeCount: Int, - element: Element? + executeCount: Int ) { - taskBuildDetailService.taskContinue( - projectId = projectId, - buildId = buildId, - stageId = stageId, - containerId = containerId, - taskId = taskId, - element = element - ) // #7983 此处需要保持Container状态独立刷新,不能放进更新task的并发锁 containerBuildRecordService.updateContainerStatus( projectId = projectId, @@ -344,8 +302,6 @@ class TaskBuildRecordService( projectId = projectId, pipelineId = pipelineId, buildId = buildId, - stageId = stageId, - containerId = containerId, taskId = taskId, executeCount = executeCount, buildStatus = BuildStatus.QUEUE, @@ -363,14 +319,26 @@ class TaskBuildRecordService( val pipelineId = taskBuildEndParam.pipelineId val buildId = taskBuildEndParam.buildId val taskId = taskBuildEndParam.taskId + val executeCount = taskBuildEndParam.executeCount + val recordTask = recordTaskDao.getRecord( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + taskId = taskId, + executeCount = executeCount + ) ?: run { + logger.warn( + "ENGINE|$buildId|taskEnd| get task($taskId) record failed." + ) + return emptyList() + } // #7983 将RETRY中间态过滤,不体现在详情页面 val buildStatus = taskBuildEndParam.buildStatus.let { if (it == BuildStatus.RETRY) null else it } val atomVersion = taskBuildEndParam.atomVersion val errorType = taskBuildEndParam.errorType - val executeCount = taskBuildEndParam.executeCount - update( projectId = projectId, pipelineId = pipelineId, buildId = buildId, executeCount = executeCount, buildStatus = BuildStatus.RUNNING, @@ -379,19 +347,6 @@ class TaskBuildRecordService( dslContext.transaction { configuration -> val context = DSL.using(configuration) val now = LocalDateTime.now() - val recordTask = recordTaskDao.getRecord( - dslContext = context, - projectId = projectId, - pipelineId = pipelineId, - buildId = buildId, - taskId = taskId, - executeCount = executeCount - ) ?: run { - logger.warn( - "ENGINE|$buildId|taskEnd| get task($taskId) record failed." - ) - return@transaction - } // 插件存在自动重试,永远更新一次当前时间为结束时间 recordTask.endTime = now val taskVar = mutableMapOf() @@ -443,8 +398,156 @@ class TaskBuildRecordService( ) } } + if (buildStatus?.isCancel() != true && buildStatus?.isSkip() != true) { + // 如果状态不是取消状态或者跳过状态,无需处理后续更新task状态的逻辑 + return emptyList() + } + val pipelineTaskStatusInfos = mutableListOf() + val buildRecordContainer = containerBuildRecordService.getRecord( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + containerId = taskBuildEndParam.containerId, + executeCount = executeCount + ) + buildRecordContainer?.let { + val buildTask = pipelineBuildTaskDao.get( + dslContext = dslContext, + projectId = projectId, + buildId = buildId, + taskId = taskId, + stepId = null, + executeCount = executeCount + ) ?: return@let + val runCondition = buildTask.additionalOptions?.runCondition + val containPostTaskFlag = buildRecordContainer.containPostTaskFlag + val containerId = buildRecordContainer.containerId + // 判断取消的task任务对应的container是否包含post任务 + val cancelTaskPostFlag = buildStatus == BuildStatus.CANCELED && containPostTaskFlag == true + val currentTaskSeq = recordTask.taskSeq + if (cancelTaskPostFlag) { + val postTaskFlag = recordTask.elementPostInfo != null + // 判断当前取消的任务是否是post任务 + if (!postTaskFlag && runCondition != RunCondition.PRE_TASK_FAILED_EVEN_CANCEL) { + // 查询post任务列表 + val recordPostTasks = recordTaskDao.getRecords( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + executeCount = executeCount, + containerId = containerId, + queryPostTaskFlag = true + ) + val startTaskSeq = currentTaskSeq + 1 + var endTaskSeq = startTaskSeq + recordPostTasks.forEach { recordPostTask -> + // 计算post父任务序号 + val parentElementJobIndex = + recordPostTask.elementPostInfo?.parentElementJobIndex ?: return@forEach + val parentTaskSeq = parentElementJobIndex + 2 + // 判断父任务的序号是否在取消任务之后 + if (parentTaskSeq <= currentTaskSeq) { + endTaskSeq = recordPostTask.taskSeq - 1 + } + } + addCancelTaskStatusInfo( + taskBuildEndParam = taskBuildEndParam, + startTaskSeq = startTaskSeq, + endTaskSeq = endTaskSeq, + pipelineTaskStatusInfos = pipelineTaskStatusInfos + ) + } + } else if (buildStatus.isCancel() && runCondition != RunCondition.PRE_TASK_FAILED_EVEN_CANCEL) { + val startTaskSeq = currentTaskSeq + 1 + val endTaskSeq = VMUtils.genVMTaskSeq(containerId.toInt(), 0) - 1 + addCancelTaskStatusInfo( + taskBuildEndParam = taskBuildEndParam, + startTaskSeq = startTaskSeq, + endTaskSeq = endTaskSeq, + pipelineTaskStatusInfos = pipelineTaskStatusInfos + ) + } else if (buildStatus.isSkip()) { + pipelineTaskStatusInfos.add( + PipelineTaskStatusInfo( + taskId = taskId, + containerHashId = containerId, + buildStatus = buildStatus, + executeCount = executeCount, + message = taskBuildEndParam.errorMsg, + stepId = buildTask.stepId + ) + ) + updateTaskStatus( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + taskId = taskId, + executeCount = executeCount, + buildStatus = buildStatus, + operation = "taskSkip#$taskId" + ) + } + } + return pipelineTaskStatusInfos + } - return taskBuildDetailService.taskEnd(taskBuildEndParam) + private fun addCancelTaskStatusInfo( + taskBuildEndParam: TaskBuildEndParam, + startTaskSeq: Int, + endTaskSeq: Int, + pipelineTaskStatusInfos: MutableList + ) { + if (endTaskSeq < startTaskSeq) { + return + } + val projectId = taskBuildEndParam.projectId + val containerId = taskBuildEndParam.containerId + val buildId = taskBuildEndParam.buildId + val executeCount = taskBuildEndParam.executeCount + // 把post任务和取消任务之间的任务置为UNEXEC状态 + val buildTasks = pipelineBuildTaskDao.getTasksInCondition( + dslContext = dslContext, + projectId = projectId, + buildId = buildId, + containerId = containerId, + statusSet = null, + startTaskSeq = startTaskSeq, + endTaskSeq = endTaskSeq + ) + var unExecTaskIds: MutableSet? = null + buildTasks.forEach { pipelineBuildTask -> + val additionalOptions = pipelineBuildTask.additionalOptions + if (!pipelineBuildTask.status.isFinish() && additionalOptions?.elementPostInfo == null) { + if (unExecTaskIds == null) { + unExecTaskIds = mutableSetOf() + } + val unExecBuildStatus = BuildStatus.UNEXEC + val taskId = pipelineBuildTask.taskId + unExecTaskIds?.add(taskId) + pipelineTaskStatusInfos.add( + PipelineTaskStatusInfo( + taskId = taskId, + containerHashId = containerId, + buildStatus = unExecBuildStatus, + executeCount = executeCount, + message = "Do not meet the run conditions, ignored.", + stepId = pipelineBuildTask.stepId + ) + ) + } + } + if (!unExecTaskIds.isNullOrEmpty()) { + recordTaskDao.updateRecordStatus( + dslContext = dslContext, + projectId = projectId, + pipelineId = taskBuildEndParam.pipelineId, + buildId = buildId, + executeCount = executeCount, + buildStatus = BuildStatus.UNEXEC, + taskIds = unExecTaskIds + ) + } } fun updateTaskRecord( diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/vmbuild/EngineVMBuildService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/vmbuild/EngineVMBuildService.kt index f154334063b6..a5f764301433 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/vmbuild/EngineVMBuildService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/vmbuild/EngineVMBuildService.kt @@ -88,7 +88,6 @@ import com.tencent.devops.process.engine.service.PipelineContainerService import com.tencent.devops.process.engine.service.PipelineProgressRateService import com.tencent.devops.process.engine.service.PipelineRuntimeService import com.tencent.devops.process.engine.service.PipelineTaskService -import com.tencent.devops.process.engine.service.detail.ContainerBuildDetailService import com.tencent.devops.process.engine.service.measure.MeasureService import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService import com.tencent.devops.process.engine.service.record.TaskBuildRecordService @@ -129,7 +128,6 @@ import javax.ws.rs.NotFoundException @Service class EngineVMBuildService @Autowired(required = false) constructor( private val pipelineRuntimeService: PipelineRuntimeService, - private val containerBuildDetailService: ContainerBuildDetailService, private val containerBuildRecordService: ContainerBuildRecordService, private val taskBuildRecordService: TaskBuildRecordService, private val buildVariableService: BuildVariableService, @@ -199,7 +197,13 @@ class EngineVMBuildService @Autowired(required = false) constructor( val pipelineId = buildInfo.pipelineId val variables = buildVariableService.getAllVariable(projectId, buildInfo.pipelineId, buildId) val variablesWithType = buildVariableService.getAllVariableWithType(projectId, buildId).toMutableList() - val model = containerBuildDetailService.getBuildModel(projectId, buildId) + val model = containerBuildRecordService.getRecordModel( + projectId = projectId, + pipelineId = pipelineId, + version = buildInfo.version, + buildId = buildId, + executeCount = buildInfo.executeCount + ) // TODO 没有升级的worker还需要用到这个变量,下一版删除 val asCodeSettings = pipelineAsCodeService.getPipelineAsCodeSettings( projectId = projectId, pipelineId = buildInfo.pipelineId @@ -851,7 +855,7 @@ class EngineVMBuildService @Autowired(required = false) constructor( buildId = buildId, containerId = vmSeqId, taskId = result.elementId, - executeCount = result.executeCount ?: buildInfo.executeCount ?: 1, + executeCount = result.executeCount ?: buildInfo.executeCount, buildStatus = buildStatus, errorType = errorType, errorCode = result.errorCode, @@ -1003,7 +1007,7 @@ class EngineVMBuildService @Autowired(required = false) constructor( buildId = buildId, pipelineId = buildInfo.pipelineId, containerId = vmSeqId, - executeCount = result.executeCount ?: buildInfo.executeCount ?: 1 + executeCount = result.executeCount ?: buildInfo.executeCount ) BuildStatus.RETRY } 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 92292987bc3b..13db955f9d8c 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 @@ -41,8 +41,8 @@ import com.tencent.devops.common.pipeline.type.BuildType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_TIME_TRIGGER_KIND import com.tencent.devops.process.engine.control.ControlUtils -import com.tencent.devops.process.engine.service.PipelineBuildDetailService import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService +import com.tencent.devops.process.engine.service.record.PipelineBuildRecordService import com.tencent.devops.process.engine.service.record.TaskBuildRecordService import com.tencent.devops.process.utils.JOB_RETRY_TASK_ID import com.tencent.devops.process.utils.PIPELINE_RETRY_START_TASK_ID @@ -62,7 +62,7 @@ import org.springframework.stereotype.Service ) @Service class PipelineContextService @Autowired constructor( - private val pipelineBuildDetailService: PipelineBuildDetailService, + private val pipelineBuildRecordService: PipelineBuildRecordService, private val taskBuildRecordService: TaskBuildRecordService, private val containerBuildRecordService: ContainerBuildRecordService ) { @@ -79,7 +79,9 @@ class PipelineContextService @Autowired constructor( model: Model? = null, executeCount: Int? = 1 ): MutableMap { - val modelDetail = model ?: pipelineBuildDetailService.get(projectId, buildId)?.model ?: return mutableMapOf() + val modelDetail = model ?: pipelineBuildRecordService.getBuildRecord( + projectId = projectId, pipelineId = pipelineId, buildId = buildId + )?.model ?: return mutableMapOf() val contextMap = mutableMapOf() var previousStageStatus = BuildStatus.RUNNING val failTaskNameList = mutableListOf() @@ -156,7 +158,9 @@ class PipelineContextService @Autowired constructor( buildId: String, variables: Map ): Map { - val modelDetail = pipelineBuildDetailService.get(projectId, buildId) ?: return emptyMap() + val modelDetail = pipelineBuildRecordService.getBuildRecord( + projectId = projectId, pipelineId = pipelineId, buildId = buildId + ) ?: return emptyMap() val contextMap = mutableMapOf() var previousStageStatus = BuildStatus.RUNNING val failTaskNameList = mutableListOf() diff --git a/src/backend/ci/core/process/biz-base/src/test/kotlin/com/tencent/devops/process/TestBase.kt b/src/backend/ci/core/process/biz-base/src/test/kotlin/com/tencent/devops/process/TestBase.kt index 4fff14dca970..74160590eda8 100644 --- a/src/backend/ci/core/process/biz-base/src/test/kotlin/com/tencent/devops/process/TestBase.kt +++ b/src/backend/ci/core/process/biz-base/src/test/kotlin/com/tencent/devops/process/TestBase.kt @@ -334,6 +334,7 @@ open class TestBase : BkCiAbstractTest() { mutexGroup = null ), cost = containerCost, + containPostTaskFlag = null, matrixGroupId = null, matrixGroupFlag = null ) diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/vm/DispatchBuildLessDockerStartupTaskAtom.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/vm/DispatchBuildLessDockerStartupTaskAtom.kt index 6af7c45c5e1f..9992b8e0bc66 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/vm/DispatchBuildLessDockerStartupTaskAtom.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/vm/DispatchBuildLessDockerStartupTaskAtom.kt @@ -51,7 +51,6 @@ import com.tencent.devops.process.engine.exception.BuildTaskException import com.tencent.devops.process.engine.pojo.PipelineBuildTask import com.tencent.devops.process.engine.pojo.PipelineInfo import com.tencent.devops.process.engine.service.PipelineRepositoryService -import com.tencent.devops.process.engine.service.detail.ContainerBuildDetailService import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService import com.tencent.devops.process.pojo.mq.PipelineBuildLessShutdownEvent import com.tencent.devops.process.pojo.mq.PipelineBuildLessStartupEvent @@ -71,7 +70,6 @@ import org.springframework.stereotype.Component class DispatchBuildLessDockerStartupTaskAtom @Autowired constructor( private val pipelineRepositoryService: PipelineRepositoryService, private val client: Client, - private val containerBuildDetailService: ContainerBuildDetailService, private val containerBuildRecordService: ContainerBuildRecordService, private val pipelineEventDispatcher: SampleEventDispatcher, private val buildLogPrinter: BuildLogPrinter @@ -155,8 +153,20 @@ class DispatchBuildLessDockerStartupTaskAtom @Autowired constructor( buildId = buildId, taskId = taskId )) - - val container = containerBuildDetailService.getBuildModel(projectId, buildId)?.getContainer(vmSeqId) + val buildRecordContainer = containerBuildRecordService.getRecord( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + containerId = vmSeqId, + executeCount = task.executeCount ?: 1 + ) + val container = containerBuildRecordService.getRecordModel( + projectId = projectId, + pipelineId = pipelineId, + version = buildRecordContainer?.resourceVersion ?: 1, + buildId = buildId, + executeCount = task.executeCount ?: 1 + )?.getContainer(vmSeqId) Preconditions.checkNotNull(container, BuildTaskException( errorType = ErrorType.SYSTEM, errorCode = ERROR_PIPELINE_NODEL_CONTAINER_NOT_EXISTS.toInt(), diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/vm/DispatchVMStartupTaskAtom.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/vm/DispatchVMStartupTaskAtom.kt index 3aedb903f5f3..4422ce43650c 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/vm/DispatchVMStartupTaskAtom.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/vm/DispatchVMStartupTaskAtom.kt @@ -62,7 +62,6 @@ import com.tencent.devops.process.engine.pojo.PipelineInfo import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.PipelineRuntimeService import com.tencent.devops.process.engine.service.PipelineTaskService -import com.tencent.devops.process.engine.service.detail.ContainerBuildDetailService import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService import com.tencent.devops.process.pojo.mq.PipelineAgentShutdownEvent import com.tencent.devops.process.pojo.mq.PipelineAgentStartupEvent @@ -87,7 +86,6 @@ import java.util.concurrent.TimeUnit class DispatchVMStartupTaskAtom @Autowired constructor( private val pipelineRepositoryService: PipelineRepositoryService, private val client: Client, - private val containerBuildDetailService: ContainerBuildDetailService, private val containerBuildRecordService: ContainerBuildRecordService, private val pipelineRuntimeService: PipelineRuntimeService, private val pipelineEventDispatcher: SampleEventDispatcher, @@ -205,7 +203,20 @@ class DispatchVMStartupTaskAtom @Autowired constructor( ) ) - val container = containerBuildDetailService.getBuildModel(projectId, buildId)?.getContainer(vmSeqId) + val buildRecordContainer = containerBuildRecordService.getRecord( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + containerId = vmSeqId, + executeCount = task.executeCount ?: 1 + ) + val container = containerBuildRecordService.getRecordModel( + projectId = projectId, + pipelineId = pipelineId, + version = buildRecordContainer?.resourceVersion ?: 1, + buildId = buildId, + executeCount = task.executeCount ?: 1 + )?.getContainer(vmSeqId) Preconditions.checkNotNull( obj = container, exception = BuildTaskException( diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildCancelControl.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildCancelControl.kt index f3eda3eb0789..a95f8fdbd256 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildCancelControl.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildCancelControl.kt @@ -51,13 +51,12 @@ import com.tencent.devops.process.engine.pojo.PipelineBuildStage import com.tencent.devops.process.engine.pojo.event.PipelineBuildCancelEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildFinishEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildStageEvent -import com.tencent.devops.process.engine.service.PipelineBuildDetailService -import com.tencent.devops.process.engine.service.record.PipelineBuildRecordService import com.tencent.devops.process.engine.service.PipelineContainerService import com.tencent.devops.process.engine.service.PipelineRuntimeService import com.tencent.devops.process.engine.service.PipelineStageService import com.tencent.devops.process.engine.service.measure.MeasureService import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService +import com.tencent.devops.process.engine.service.record.PipelineBuildRecordService import com.tencent.devops.process.engine.utils.BuildUtils import com.tencent.devops.process.pojo.mq.PipelineAgentShutdownEvent import com.tencent.devops.process.pojo.mq.PipelineBuildLessShutdownEvent @@ -78,7 +77,6 @@ class BuildCancelControl @Autowired constructor( private val pipelineRuntimeService: PipelineRuntimeService, private val pipelineContainerService: PipelineContainerService, private val pipelineStageService: PipelineStageService, - private val pipelineBuildDetailService: PipelineBuildDetailService, private val pipelineBuildRecordService: PipelineBuildRecordService, private val containerBuildRecordService: ContainerBuildRecordService, private val buildVariableService: BuildVariableService, @@ -119,7 +117,13 @@ class BuildCancelControl @Autowired constructor( return false } - val model = pipelineBuildDetailService.getBuildModel(projectId = event.projectId, buildId = buildId) + val model = pipelineBuildRecordService.getRecordModel( + projectId = event.projectId, + pipelineId = event.pipelineId, + version = buildInfo.version, + buildId = buildId, + executeCount = buildInfo.executeCount + ) return if (model != null) { LOG.info("ENGINE|${event.buildId}|${event.source}|CANCEL|status=${event.status}") if (event.actionType != ActionType.TERMINATE) { @@ -224,7 +228,7 @@ class BuildCancelControl @Autowired constructor( val executeCount: Int by lazy { buildVariableService.getBuildExecuteCount(projectId, pipelineId, buildId) } val stages = model.stages stages.forEachIndexed nextStage@{ index, stage -> - if (stage.status == null || index == 0) { // Trigger 和 未启动的忽略 + if (stage.status.isNullOrBlank() || index == 0) { // Trigger 和 未启动的忽略 return@nextStage } @@ -241,7 +245,7 @@ class BuildCancelControl @Autowired constructor( } stage.containers.forEach nextC@{ container -> - if (container.status == null || BuildStatus.parse(container.status).isFinish()) { // 未启动的和已完成的忽略 + if (container.status.isNullOrBlank() || BuildStatus.parse(container.status).isFinish()) { // 未启动的和已完成的忽略 return@nextC } val stageId = stage.id ?: "" @@ -253,7 +257,7 @@ class BuildCancelControl @Autowired constructor( executeCount = executeCount ) container.fetchGroupContainers()?.forEach matrix@{ c -> - if (c.status == null || BuildStatus.parse(c.status).isFinish()) { // 未启动的和已完成的忽略 + if (c.status.isNullOrBlank() || BuildStatus.parse(c.status).isFinish()) { // 未启动的和已完成的忽略 return@matrix } cancelContainerPendingTask( diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildEndControl.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildEndControl.kt index 0606c9ff87a5..8d58d8d6f653 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildEndControl.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildEndControl.kt @@ -44,6 +44,7 @@ import com.tencent.devops.common.pipeline.container.AgentReuseMutex import com.tencent.devops.common.pipeline.container.Container import com.tencent.devops.common.pipeline.container.VMBuildContainer import com.tencent.devops.common.pipeline.enums.BuildStatus +import com.tencent.devops.common.pipeline.pojo.BuildNo import com.tencent.devops.common.pipeline.pojo.BuildNoType import com.tencent.devops.common.pipeline.type.agent.ThirdPartyAgentDispatch import com.tencent.devops.common.pipeline.utils.BuildStatusSwitcher @@ -54,6 +55,7 @@ import com.tencent.devops.common.service.prometheus.BkTimed import com.tencent.devops.common.service.utils.LogUtils import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher import com.tencent.devops.common.event.enums.PipelineBuildStatusBroadCastEventType +import com.tencent.devops.common.pipeline.container.TriggerContainer import com.tencent.devops.common.websocket.enum.RefreshType import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.common.VMUtils @@ -67,7 +69,6 @@ import com.tencent.devops.process.engine.pojo.event.PipelineBuildAtomTaskEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildFinishEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildStartEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildWebSocketPushEvent -import com.tencent.devops.process.engine.service.PipelineBuildDetailService import com.tencent.devops.process.engine.service.PipelineRedisService import com.tencent.devops.process.engine.service.PipelineRuntimeExtService import com.tencent.devops.process.engine.service.PipelineRuntimeService @@ -101,7 +102,6 @@ class BuildEndControl @Autowired constructor( private val pipelineRuntimeService: PipelineRuntimeService, private val pipelineTaskService: PipelineTaskService, private val pipelineStageService: PipelineStageService, - private val pipelineBuildDetailService: PipelineBuildDetailService, private val containerBuildRecordService: ContainerBuildRecordService, private val pipelineBuildRecordService: PipelineBuildRecordService, private val pipelineRuntimeExtService: PipelineRuntimeExtService, @@ -172,7 +172,7 @@ class BuildEndControl @Autowired constructor( buildStatus = buildStatus, errorInfoList = buildInfo.errorInfoList, errorMsg = errorMsg, - executeCount = buildInfo.executeCount ?: 1 + executeCount = buildInfo.executeCount ) // 记录本流水线最后一次构建的状态 @@ -181,7 +181,7 @@ class BuildEndControl @Autowired constructor( latestRunningBuild = LatestRunningBuild( projectId = projectId, pipelineId = pipelineId, buildId = buildId, userId = buildInfo.startUser, status = buildStatus, taskCount = buildInfo.taskCount, - endTime = endTime, buildNum = buildInfo.buildNum, executeCount = buildInfo.executeCount ?: 1, + endTime = endTime, buildNum = buildInfo.buildNum, executeCount = buildInfo.executeCount, debug = buildInfo.debug ), currentBuildStatus = buildInfo.status, @@ -280,10 +280,14 @@ class BuildEndControl @Autowired constructor( } private fun setBuildNoWhenBuildSuccess(projectId: String, pipelineId: String, buildId: String, debug: Boolean) { - val model = pipelineBuildDetailService.getBuildModel(projectId, buildId) ?: return - val triggerContainer = model.getTriggerContainer() - val buildNoObj = triggerContainer.buildNo ?: return - + val triggerRecordContainer = containerBuildRecordService.getRecord( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + containerId = "0" + ) ?: return + val buildNoStr = triggerRecordContainer.containerVar[TriggerContainer::buildNo.name]?.toString() ?: return + val buildNoObj = JsonUtil.to(buildNoStr, BuildNo::class.java) if (buildNoObj.buildNoType == BuildNoType.SUCCESS_BUILD_INCREMENT) { // 使用分布式锁防止并发更新 PipelineBuildNoLock(redisOperation = redisOperation, pipelineId = pipelineId).use { buildNoLock -> @@ -421,12 +425,17 @@ class BuildEndControl @Autowired constructor( } LOG.info("ENGINE|$buildId|$source|FETCH_QUEUE|next build: ${nextBuild.buildId} ${nextBuild.status}") - val model = pipelineBuildDetailService.getBuildModel(nextBuild.projectId, nextBuild.buildId) - ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, - params = arrayOf(nextBuild.buildId) - ) - val triggerContainer = model.getTriggerContainer() + val triggerRecordContainer = containerBuildRecordService.getRecord( + projectId = projectId, pipelineId = pipelineId, buildId = buildId, containerId = "0" + ) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, params = arrayOf(nextBuild.buildId) + ) + val buildNoStr = triggerRecordContainer.containerVar[TriggerContainer::buildNo.name]?.toString() + val buildNoObj = if (!buildNoStr.isNullOrBlank()) { + JsonUtil.to(buildNoStr, BuildNo::class.java) + } else { + null + } pipelineEventDispatcher.dispatch( PipelineBuildStartEvent( source = "build_finish_$buildId", @@ -438,7 +447,7 @@ class BuildEndControl @Autowired constructor( status = nextBuild.status, actionType = ActionType.START, executeCount = nextBuild.executeCount, - buildNoType = triggerContainer.buildNo?.buildNoType + buildNoType = buildNoObj?.buildNoType ) ) } diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildMonitorControl.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildMonitorControl.kt index 7a5846319594..9d79e67e20f0 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildMonitorControl.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildMonitorControl.kt @@ -30,14 +30,17 @@ package com.tencent.devops.process.engine.control import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.pojo.ErrorCode import com.tencent.devops.common.api.pojo.ErrorType +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.event.enums.ActionType import com.tencent.devops.common.log.utils.BuildLogPrinter import com.tencent.devops.common.pipeline.enums.BuildStatus +import com.tencent.devops.common.pipeline.pojo.BuildNo import com.tencent.devops.common.pipeline.pojo.StageReviewRequest import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher +import com.tencent.devops.common.pipeline.container.TriggerContainer import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.BK_JOB_QUEUE_TIMEOUT import com.tencent.devops.process.constant.ProcessMessageCode.BK_QUEUE_TIMEOUT @@ -53,13 +56,13 @@ import com.tencent.devops.process.engine.pojo.event.PipelineBuildContainerEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildFinishEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildMonitorEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildStartEvent -import com.tencent.devops.process.engine.service.PipelineBuildDetailService import com.tencent.devops.process.engine.service.PipelineContainerService import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.PipelineRuntimeExtService import com.tencent.devops.process.engine.service.PipelineRuntimeService import com.tencent.devops.process.engine.service.PipelineSettingService import com.tencent.devops.process.engine.service.PipelineStageService +import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService import com.tencent.devops.process.pojo.StageQualityRequest import com.tencent.devops.quality.api.v2.pojo.ControlPointPosition import org.slf4j.LoggerFactory @@ -83,7 +86,7 @@ class BuildMonitorControl @Autowired constructor( private val pipelineContainerService: PipelineContainerService, private val pipelineRuntimeExtService: PipelineRuntimeExtService, private val pipelineStageService: PipelineStageService, - private val pipelineBuildDetailService: PipelineBuildDetailService, + private val containerBuildRecordService: ContainerBuildRecordService, private val pipelineRepositoryService: PipelineRepositoryService, private val redisOperation: RedisOperation ) { @@ -486,12 +489,17 @@ class BuildMonitorControl @Autowired constructor( if (canStart) { val buildId = event.buildId LOG.info("ENGINE|$buildId|BUILD_QUEUE_TRY_START") - val model = pipelineBuildDetailService.getBuildModel(event.projectId, buildInfo.buildId) - ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, - params = arrayOf(buildInfo.buildId) - ) - val triggerContainer = model.getTriggerContainer() + val triggerRecordContainer = containerBuildRecordService.getRecord( + projectId = event.projectId, pipelineId = event.pipelineId, buildId = buildId, containerId = "0" + ) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, params = arrayOf(buildId) + ) + val buildNoStr = triggerRecordContainer.containerVar[TriggerContainer::buildNo.name]?.toString() + val buildNoObj = if (!buildNoStr.isNullOrBlank()) { + JsonUtil.to(buildNoStr, BuildNo::class.java) + } else { + null + } pipelineEventDispatcher.dispatch( PipelineBuildStartEvent( source = START_EVENT_SOURCE, @@ -503,7 +511,7 @@ class BuildMonitorControl @Autowired constructor( status = BuildStatus.RUNNING, actionType = ActionType.START, executeCount = buildInfo.executeCount, - buildNoType = triggerContainer.buildNo?.buildNoType + buildNoType = buildNoObj?.buildNoType ) ) } diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildStartControl.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildStartControl.kt index fe5ce51f6940..96ce07cb79a8 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildStartControl.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/BuildStartControl.kt @@ -76,7 +76,6 @@ import com.tencent.devops.process.engine.pojo.event.PipelineBuildCancelEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildFinishEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildStageEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildStartEvent -import com.tencent.devops.process.engine.service.PipelineBuildDetailService import com.tencent.devops.process.engine.service.PipelineContainerService import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.PipelineRepositoryVersionService @@ -116,7 +115,6 @@ class BuildStartControl @Autowired constructor( private val pipelineStageService: PipelineStageService, private val pipelineRepositoryVersionService: PipelineRepositoryVersionService, private val pipelineRepositoryService: PipelineRepositoryService, - private val buildDetailService: PipelineBuildDetailService, private val pipelineRecordService: PipelineBuildRecordService, private val stageRecordService: StageBuildRecordService, private val containerRecordService: ContainerBuildRecordService, @@ -171,7 +169,7 @@ class BuildStartControl @Autowired constructor( watcher.stop() watcher.start("buildModel") - buildModel(buildInfo = buildInfo) + buildModel(buildInfo = buildInfo, executeCount = executeCount) watcher.stop() buildLogPrinter.addDebugLine( @@ -566,8 +564,6 @@ class BuildStartControl @Autowired constructor( projectId = buildInfo.projectId, pipelineId = buildInfo.pipelineId, buildId = buildInfo.buildId, - stageId = stage.id!!, - containerId = container.id!!, taskId = taskId, buildStatus = BuildStatus.SUCCEED, executeCount = executeCount, @@ -626,8 +622,6 @@ class BuildStartControl @Autowired constructor( Container::timeCost.name to BuildRecordTimeCost() ) ) - - buildDetailService.updateModel(projectId = buildInfo.projectId, buildId = buildInfo.buildId, model = model) buildLogPrinter.addLine( message = I18nUtil.getCodeLanMessage( messageCode = BK_TRIGGER_USER, @@ -768,8 +762,14 @@ class BuildStartControl @Autowired constructor( } } - private fun PipelineBuildStartEvent.buildModel(buildInfo: BuildInfo) { - val model = buildDetailService.getBuildModel(projectId, buildId) ?: run { + private fun PipelineBuildStartEvent.buildModel(buildInfo: BuildInfo, executeCount: Int) { + val model = pipelineRecordService.getRecordModel( + projectId = projectId, + pipelineId = pipelineId, + version = buildInfo.version, + buildId = buildId, + executeCount = executeCount + ) ?: run { pipelineEventDispatcher.dispatch( PipelineBuildCancelEvent( source = TAG, projectId = projectId, pipelineId = pipelineId, diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/StageControl.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/StageControl.kt index ee96cfd40705..091957b9633b 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/StageControl.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/StageControl.kt @@ -130,6 +130,10 @@ class StageControl @Autowired constructor( return // 不再往下运行 } } + if (actionType.isEnd()) { + LOG.warn("ENGINE|$buildId|$source|END_STAGE|$stageId|${buildInfo.status}") + return + } } val variables = buildVariableService.getAllVariable(projectId, pipelineId, buildId) diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/InitializeMatrixGroupStageCmd.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/InitializeMatrixGroupStageCmd.kt index 4ca56c8c6325..019aef47d34b 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/InitializeMatrixGroupStageCmd.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/InitializeMatrixGroupStageCmd.kt @@ -64,7 +64,6 @@ import com.tencent.devops.process.engine.pojo.PipelineBuildContainer import com.tencent.devops.process.engine.pojo.PipelineBuildTask import com.tencent.devops.process.engine.service.PipelineContainerService import com.tencent.devops.process.engine.service.PipelineTaskService -import com.tencent.devops.process.engine.service.detail.ContainerBuildDetailService import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService import com.tencent.devops.process.pojo.TemplateAcrossInfoType import com.tencent.devops.process.pojo.pipeline.record.BuildRecordContainer @@ -95,7 +94,6 @@ import kotlin.math.min @Service class InitializeMatrixGroupStageCmd( private val dslContext: DSLContext, - private val containerBuildDetailService: ContainerBuildDetailService, private val containerBuildRecordService: ContainerBuildRecordService, private val templateAcrossInfoService: PipelineBuildTemplateAcrossInfoService, private val pipelineContainerService: PipelineContainerService, @@ -179,9 +177,20 @@ class InitializeMatrixGroupStageCmd( val event = commandContext.event val variables = commandContext.variables - val modelStage = containerBuildDetailService.getBuildModel( + val recordContainer = containerBuildRecordService.getRecord( + transactionContext = null, + projectId = parentContainer.projectId, + pipelineId = parentContainer.pipelineId, + buildId = parentContainer.buildId, + containerId = parentContainer.containerId, + executeCount = parentContainer.executeCount + ) + val modelStage = containerBuildRecordService.getRecordModel( projectId = parentContainer.projectId, - buildId = parentContainer.buildId + pipelineId = parentContainer.pipelineId, + version = recordContainer?.resourceVersion ?: 1, + buildId = parentContainer.buildId, + executeCount = parentContainer.executeCount )?.getStage(parentContainer.stageId) ?: throw DependNotFoundException( "stage(${parentContainer.stageId}) cannot be found in model" ) @@ -190,14 +199,6 @@ class InitializeMatrixGroupStageCmd( ) ?: throw DependNotFoundException( "container(${parentContainer.containerId}) cannot be found in model" ) - val recordContainer = containerBuildRecordService.getRecord( - transactionContext = null, - projectId = parentContainer.projectId, - pipelineId = parentContainer.pipelineId, - buildId = parentContainer.buildId, - containerId = parentContainer.containerId, - executeCount = parentContainer.executeCount - ) val dialect = PipelineDialectUtil.getPipelineDialect(variables[PIPELINE_DIALECT]) // #4518 待生成的分裂后container表和task表记录 val buildContainerList = mutableListOf() @@ -394,6 +395,7 @@ class InitializeMatrixGroupStageCmd( containerId = newContainer.containerId!!, containerType = recordContainer.containerType, executeCount = context.executeCount, + containPostTaskFlag = newContainer.containPostTaskFlag, matrixGroupFlag = false, matrixGroupId = matrixGroupId, containerVar = containerVar, @@ -518,6 +520,7 @@ class InitializeMatrixGroupStageCmd( containerId = newContainer.containerId!!, containerType = recordContainer.containerType, executeCount = context.executeCount, + containPostTaskFlag = newContainer.containPostTaskFlag, matrixGroupFlag = false, matrixGroupId = matrixGroupId, containerVar = containerVar, diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/StartActionTaskContainerCmd.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/StartActionTaskContainerCmd.kt index 177f45ca6fe3..12fa5c1ab5cf 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/StartActionTaskContainerCmd.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/StartActionTaskContainerCmd.kt @@ -427,8 +427,6 @@ class StartActionTaskContainerCmd( projectId = projectId, pipelineId = pipelineId, buildId = buildId, - stageId = stageId, - containerId = containerId, taskId = taskId, executeCount = executeCount ?: 1, buildStatus = BuildStatus.FAILED, @@ -658,8 +656,6 @@ class StartActionTaskContainerCmd( projectId = currentTask.projectId, pipelineId = currentTask.pipelineId, buildId = currentTask.buildId, - stageId = currentTask.stageId, - containerId = currentTask.containerId, taskId = currentTask.taskId, executeCount = currentTask.executeCount ?: 1, buildStatus = taskStatus, diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/listener/run/PipelineTaskPauseListener.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/listener/run/PipelineTaskPauseListener.kt index 49d35a713cf1..e2b75c2b11f7 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/listener/run/PipelineTaskPauseListener.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/listener/run/PipelineTaskPauseListener.kt @@ -127,11 +127,9 @@ class PipelineTaskPauseListener @Autowired constructor( projectId = task.projectId, pipelineId = task.pipelineId, buildId = task.buildId, - stageId = task.stageId, containerId = task.containerId, executeCount = task.executeCount ?: 1, - taskId = task.taskId, - element = newElement + taskId = task.taskId ) // issues_6210 添加继续操作操作人变量 buildVariableService.saveVariable( @@ -180,11 +178,8 @@ class PipelineTaskPauseListener @Autowired constructor( projectId = task.projectId, pipelineId = task.pipelineId, buildId = task.buildId, - stageId = task.stageId, - containerId = task.containerId, taskId = task.taskId, - executeCount = task.executeCount ?: 1, - cancelUser = userId // fix me: 是否要直接更新取消人,暂时维护原有逻辑 + executeCount = task.executeCount ?: 1 ) buildLogPrinter.addYellowLine( diff --git a/src/backend/ci/core/process/biz-engine/src/test/kotlin/com/tencent/devops/process/engine/control/MutexControlTest.kt b/src/backend/ci/core/process/biz-engine/src/test/kotlin/com/tencent/devops/process/engine/control/MutexControlTest.kt index 0c9997e5670a..7354602c9410 100644 --- a/src/backend/ci/core/process/biz-engine/src/test/kotlin/com/tencent/devops/process/engine/control/MutexControlTest.kt +++ b/src/backend/ci/core/process/biz-engine/src/test/kotlin/com/tencent/devops/process/engine/control/MutexControlTest.kt @@ -73,6 +73,7 @@ class MutexControlTest { seq = containerId.toInt(), status = BuildStatus.RUNNING, controlOption = PipelineBuildContainerControlOption(jobControlOption = JobControlOption()), + containPostTaskFlag = null, matrixGroupId = null, matrixGroupFlag = false ) diff --git a/src/backend/ci/core/process/biz-engine/src/test/kotlin/com/tencent/devops/process/engine/utils/TestTool.kt b/src/backend/ci/core/process/biz-engine/src/test/kotlin/com/tencent/devops/process/engine/utils/TestTool.kt index ad8391be2bbd..2e910dfd472e 100644 --- a/src/backend/ci/core/process/biz-engine/src/test/kotlin/com/tencent/devops/process/engine/utils/TestTool.kt +++ b/src/backend/ci/core/process/biz-engine/src/test/kotlin/com/tencent/devops/process/engine/utils/TestTool.kt @@ -76,6 +76,7 @@ object TestTool { mutexGroup = null ), cost = containerCost, + containPostTaskFlag = null, matrixGroupId = null, matrixGroupFlag = null ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/control/CallBackControl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/control/CallBackControl.kt index adee440ae74d..9f7a00a1cb77 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/control/CallBackControl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/control/CallBackControl.kt @@ -55,10 +55,10 @@ import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.service.utils.LogUtils import com.tencent.devops.common.util.HttpRetryUtils import com.tencent.devops.process.engine.pojo.event.PipelineStreamEnabledEvent -import com.tencent.devops.process.engine.service.PipelineBuildDetailService import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.ProjectPipelineCallBackService import com.tencent.devops.process.engine.service.ProjectPipelineCallBackUrlGenerator +import com.tencent.devops.process.engine.service.record.PipelineBuildRecordService import com.tencent.devops.process.pojo.CallBackHeader import com.tencent.devops.process.pojo.ProjectPipelineCallBackHistory import com.tencent.devops.project.api.service.ServiceAllocIdResource @@ -93,7 +93,7 @@ import javax.net.ssl.X509TrustManager @Suppress("ALL") @Service class CallBackControl @Autowired constructor( - private val pipelineBuildDetailService: PipelineBuildDetailService, + private val pipelineBuildRecordService: PipelineBuildRecordService, private val pipelineRepositoryService: PipelineRepositoryService, private val projectPipelineCallBackService: ProjectPipelineCallBackService, private val client: Client, @@ -236,9 +236,10 @@ class CallBackControl @Autowired constructor( return } - val modelDetail = pipelineBuildDetailService.get( + val modelDetail = pipelineBuildRecordService.getBuildRecord( projectId = projectId, - buildId = event.buildId, + pipelineId = pipelineId, + buildId = buildId, refreshStatus = false ) ?: return @@ -250,7 +251,7 @@ class CallBackControl @Autowired constructor( triggerUser = modelDetail.triggerUser, cancelUserId = modelDetail.cancelUserId, status = modelDetail.status, - startTime = modelDetail.startTime, + startTime = modelDetail.startTime ?: 0, endTime = modelDetail.endTime ?: 0, model = SimpleModel(parseModel(modelDetail.model)), projectId = event.projectId, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt index d0d7172c1245..160fa65347be 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt @@ -89,7 +89,6 @@ import com.tencent.devops.process.engine.interceptor.InterceptData import com.tencent.devops.process.engine.interceptor.PipelineInterceptorChain import com.tencent.devops.process.engine.pojo.BuildInfo import com.tencent.devops.process.engine.pojo.event.PipelineBuildContainerEvent -import com.tencent.devops.process.engine.service.PipelineBuildDetailService import com.tencent.devops.process.engine.service.PipelineBuildQualityService import com.tencent.devops.process.engine.service.PipelineContainerService import com.tencent.devops.process.engine.service.PipelineRedisService @@ -163,7 +162,6 @@ class PipelineBuildFacadeService( private val pipelineContainerService: PipelineContainerService, private val pipelineStageService: PipelineStageService, private val redisOperation: RedisOperation, - private val buildDetailService: PipelineBuildDetailService, private val buildRecordService: PipelineBuildRecordService, private val pipelineTaskPauseService: PipelineTaskPauseService, private val containerBuildRecordService: ContainerBuildRecordService, @@ -434,7 +432,13 @@ class PipelineBuildFacadeService( throw ErrorCodeException(errorCode = ProcessMessageCode.ERROR_PIPELINE_LOCK) } - val model = buildDetailService.getBuildModel(projectId, buildId) ?: throw ErrorCodeException( + val model = buildRecordService.getRecordModel( + projectId = projectId, + pipelineId = pipelineId, + version = buildInfo.version, + buildId = buildId, + executeCount = buildInfo.executeCount + ) ?: throw ErrorCodeException( errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS ) @@ -985,7 +989,13 @@ class PipelineBuildFacadeService( ) } - val model = buildDetailService.get(projectId, buildId)?.model ?: throw ErrorCodeException( + val model = buildRecordService.getRecordModel( + projectId = projectId, + pipelineId = pipelineId, + version = buildInfo.version, + buildId = buildId, + executeCount = buildInfo.executeCount + ) ?: throw ErrorCodeException( statusCode = Response.Status.NOT_FOUND.statusCode, errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS ) @@ -1294,14 +1304,19 @@ class PipelineBuildFacadeService( elementId: String ): ReviewParam { - pipelineRuntimeService.getBuildInfo(projectId, buildId) - ?: throw ErrorCodeException( - statusCode = Response.Status.NOT_FOUND.statusCode, - errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, - params = arrayOf(buildId) - ) + val buildInfo = pipelineRuntimeService.getBuildInfo(projectId, buildId) ?: throw ErrorCodeException( + statusCode = Response.Status.NOT_FOUND.statusCode, + errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, + params = arrayOf(buildId) + ) - val model = buildDetailService.get(projectId, buildId)?.model ?: throw ErrorCodeException( + val model = buildRecordService.getRecordModel( + projectId = projectId, + pipelineId = pipelineId, + version = buildInfo.version, + buildId = buildId, + executeCount = buildInfo.executeCount + ) ?: throw ErrorCodeException( statusCode = Response.Status.NOT_FOUND.statusCode, errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS ) @@ -1444,21 +1459,35 @@ class PipelineBuildFacadeService( buildId: String, channelCode: ChannelCode ): ModelDetail { - val newModel = buildDetailService.get(projectId, buildId) ?: throw ErrorCodeException( + val newModel = buildRecordService.getBuildRecord(projectId, pipelineId, buildId) ?: throw ErrorCodeException( statusCode = Response.Status.NOT_FOUND.statusCode, errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS ) - if (newModel.pipelineId != pipelineId) { - throw ErrorCodeException( - statusCode = Response.Status.NOT_FOUND.statusCode, - errorCode = ProcessMessageCode.ERROR_PIPELINE_NOT_EXISTS - ) - } - pipelineBuildQualityService.addQualityGateReviewUsers(projectId, pipelineId, buildId, newModel.model) - return newModel + return ModelDetail( + id = newModel.id, + pipelineId = newModel.pipelineId, + pipelineName = newModel.pipelineName, + userId = newModel.userId, + triggerUser = newModel.triggerUser, + trigger = newModel.trigger, + startTime = newModel.startTime ?: 0, + endTime = newModel.endTime ?: 0, + status = newModel.status, + model = newModel.model, + currentTimestamp = newModel.currentTimestamp, + buildNum = newModel.buildNum, + cancelUserId = newModel.cancelUserId ?: "", + curVersion = newModel.curVersion, + latestVersion = newModel.latestVersion, + latestBuildNum = newModel.latestBuildNum, + lastModifyUser = newModel.lastModifyUser, + executeTime = newModel.executeTime, + triggerReviewers = newModel.triggerReviewers, + debug = newModel.debug + ) } fun getBuildDetailByBuildNo( @@ -1565,7 +1594,9 @@ class PipelineBuildFacadeService( ) } return buildRecordService.getBuildRecord( - buildInfo = buildInfo, + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, executeCount = executeCount, queryDslContext = queryDslContext ) ?: throw ErrorCodeException( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineRetryFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineRetryFacadeService.kt index 2d9142367a0f..63ae68fd5a27 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineRetryFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineRetryFacadeService.kt @@ -264,12 +264,19 @@ class PipelineRetryFacadeService @Autowired constructor( ) } else { BuildRecordContainer( - projectId = containerInfo.projectId, pipelineId = containerInfo.pipelineId, - resourceVersion = resourceVersion, buildId = containerInfo.buildId, - stageId = containerInfo.stageId, containerId = containerInfo.containerId, - containerType = containerInfo.containerType, executeCount = executeCount, - matrixGroupFlag = containerInfo.matrixGroupFlag, status = BuildStatus.QUEUE.name, - containerVar = mutableMapOf(), timestamps = mapOf() + projectId = containerInfo.projectId, + pipelineId = containerInfo.pipelineId, + resourceVersion = resourceVersion, + buildId = containerInfo.buildId, + stageId = containerInfo.stageId, + containerId = containerInfo.containerId, + containerType = containerInfo.containerType, + executeCount = executeCount, + containPostTaskFlag = containerInfo.containPostTaskFlag, + matrixGroupFlag = containerInfo.matrixGroupFlag, + status = BuildStatus.QUEUE.name, + containerVar = mutableMapOf(), + timestamps = mapOf() ) } pipelineBuildRecordService.batchSave( diff --git a/src/backend/ci/core/process/biz-process/src/test/kotlin/com/tencent/devops/process/TestBase.kt b/src/backend/ci/core/process/biz-process/src/test/kotlin/com/tencent/devops/process/TestBase.kt index 330268e0678c..0c3d7064e0cc 100644 --- a/src/backend/ci/core/process/biz-process/src/test/kotlin/com/tencent/devops/process/TestBase.kt +++ b/src/backend/ci/core/process/biz-process/src/test/kotlin/com/tencent/devops/process/TestBase.kt @@ -232,6 +232,7 @@ open class TestBase { mutexGroup = null ), cost = containerCost, + containPostTaskFlag = null, matrixGroupId = null, matrixGroupFlag = false, containerHashId = containerHashId diff --git a/src/backend/ci/core/process/biz-process/src/test/kotlin/com/tencent/devops/process/engine/control/CallBackControlTest.kt b/src/backend/ci/core/process/biz-process/src/test/kotlin/com/tencent/devops/process/engine/control/CallBackControlTest.kt index b64f6c1c90ba..bfb455e95833 100644 --- a/src/backend/ci/core/process/biz-process/src/test/kotlin/com/tencent/devops/process/engine/control/CallBackControlTest.kt +++ b/src/backend/ci/core/process/biz-process/src/test/kotlin/com/tencent/devops/process/engine/control/CallBackControlTest.kt @@ -27,6 +27,7 @@ package com.tencent.devops.process.engine.control +import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.client.Client import com.tencent.devops.common.event.enums.ActionType import com.tencent.devops.common.event.pojo.pipeline.PipelineBuildStatusBroadCastEvent @@ -34,11 +35,11 @@ import com.tencent.devops.common.pipeline.enums.BuildStatus import com.tencent.devops.common.pipeline.event.CallBackEvent import com.tencent.devops.common.pipeline.event.ProjectPipelineCallBack import com.tencent.devops.process.TestBase -import com.tencent.devops.process.engine.service.PipelineBuildDetailService import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.ProjectPipelineCallBackService import com.tencent.devops.process.engine.service.ProjectPipelineCallBackUrlGenerator -import com.tencent.devops.process.pojo.pipeline.ModelDetail +import com.tencent.devops.process.engine.service.record.PipelineBuildRecordService +import com.tencent.devops.process.pojo.pipeline.ModelRecord import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry import io.micrometer.core.instrument.MeterRegistry import io.mockk.every @@ -46,10 +47,11 @@ import io.mockk.mockk import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import java.time.LocalDateTime class CallBackControlTest : TestBase() { - private val pipelineBuildDetailService: PipelineBuildDetailService = mockk() + private val pipelineBuildRecordService: PipelineBuildRecordService = mockk() private val pipelineRepositoryService: PipelineRepositoryService = mockk(relaxed = true) private val projectPipelineCallBackService: ProjectPipelineCallBackService = mockk() private val client: Client = mockk() @@ -58,7 +60,7 @@ class CallBackControlTest : TestBase() { private val projectPipelineCallBackUrlGenerator: ProjectPipelineCallBackUrlGenerator = mockk() private val callBackControl = CallBackControl( - pipelineBuildDetailService = pipelineBuildDetailService, + pipelineBuildRecordService = pipelineBuildRecordService, pipelineRepositoryService = pipelineRepositoryService, projectPipelineCallBackService = projectPipelineCallBackService, client = client, @@ -68,7 +70,7 @@ class CallBackControlTest : TestBase() { ) private val testUrl = "https://mock/callback" - private var modelDetail: ModelDetail? = null + private var modelRecord: ModelRecord? = null private var callbacks: MutableList? = null @@ -77,7 +79,7 @@ class CallBackControlTest : TestBase() { val existsModel = genModel(stageSize = 4, jobSize = 3, elementSize = 2) - modelDetail = ModelDetail( + modelRecord = ModelRecord( id = buildId, pipelineId = pipelineId, pipelineName = "testCase", @@ -94,16 +96,29 @@ class CallBackControlTest : TestBase() { latestBuildNum = 1, latestVersion = 1, lastModifyUser = "yongyiduan", - executeTime = 100 + executeTime = 100, + buildMsg = null, + curVersionName = null, + errorInfoList = null, + executeCount = 1, + material = null, + queueTime = LocalDateTime.now().timestampmilli(), + recordList = emptyList(), + queueTimeCost = 0L, + remark = null, + stageStatus = null, + startUserList = listOf("admin"), + webhookInfo = null ) every { - pipelineBuildDetailService.get( + pipelineBuildRecordService.getBuildRecord( projectId = projectId, + pipelineId = pipelineId, buildId = buildId, refreshStatus = false ) - } returns (modelDetail) + } returns (modelRecord) } @Test @@ -169,7 +184,7 @@ class CallBackControlTest : TestBase() { @Test fun `stage running cover finish`() { val expectStatus = BuildStatus.RUNNING.name - val existsModel = modelDetail!!.model + val existsModel = modelRecord!!.model val currentTimeMillis = System.currentTimeMillis() existsModel.stages.forEachIndexed { si, s -> if (si == 0) { @@ -221,7 +236,7 @@ class CallBackControlTest : TestBase() { @Test fun `stage failure cover other`() { val expectStatus = BuildStatus.FAILED.name - val existsModel = modelDetail!!.model + val existsModel = modelRecord!!.model val currentTimeMillis = System.currentTimeMillis() existsModel.stages.forEachIndexed { si, s -> if (si == 0) {