From 1dfcb6de1c2d7ef514cd9ad4f90d4cc24e536d06 Mon Sep 17 00:00:00 2001 From: carlyin <449036249@qq.com> Date: Fri, 21 Jun 2024 11:48:10 +0800 Subject: [PATCH 1/9] =?UTF-8?q?perf:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=97=A7=E6=95=B0=E6=8D=AE=E5=85=BC=E5=AE=B9=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6=20#9522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/record/BaseBuildRecordService.kt | 47 +++++++++++++ .../record/PipelineBuildRecordService.kt | 69 ++++++++++--------- 2 files changed, 84 insertions(+), 32 deletions(-) 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 4ea5f9fd5a5..6069a4291e1 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,6 +50,7 @@ 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 @@ -68,6 +69,7 @@ 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( @@ -151,6 +153,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 ?: 1 + } 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/PipelineBuildRecordService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/record/PipelineBuildRecordService.kt index 747dbc034eb..dabec44ef4c 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 @@ -52,8 +54,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 @@ -87,6 +91,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", @@ -97,7 +102,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, @@ -106,6 +110,7 @@ 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, @@ -206,7 +211,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 } @@ -463,12 +469,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) @@ -552,18 +552,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记录还需用于耗时计算 @@ -602,12 +610,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) @@ -625,13 +630,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( @@ -640,11 +650,6 @@ class PipelineBuildRecordService @Autowired constructor( executeCount: Int, cancelUserId: String ) { - pipelineBuildDetailService.updateBuildCancelUser( - projectId = projectId, - buildId = buildId, - cancelUserId = cancelUserId - ) recordModelDao.updateBuildCancelUser( dslContext = dslContext, projectId = projectId, From df57aca318500546aafdd8b6fd6d5184e9f987f3 Mon Sep 17 00:00:00 2001 From: carlyin <449036249@qq.com> Date: Wed, 10 Jul 2024 16:45:26 +0800 Subject: [PATCH 2/9] =?UTF-8?q?perf:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=97=A7=E6=95=B0=E6=8D=AE=E5=85=BC=E5=AE=B9=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6=20#9522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrate/MigrateV3PolicyServiceTest.kt | Bin 4896 -> 5013 bytes .../service/PipelineBuildQualityService.kt | 68 +++++-------- .../service/PipelineProgressRateService.kt | 7 +- .../engine/service/PipelineRuntimeService.kt | 39 ------- .../engine/service/PipelineStageService.kt | 8 +- .../engine/service/PipelineTaskService.kt | 18 ++-- .../service/record/BaseBuildRecordService.kt | 2 +- .../record/ContainerBuildRecordService.kt | 45 ++------- .../record/PipelineBuildRecordService.kt | 50 ++++++++- .../service/record/StageBuildRecordService.kt | 81 +++++++++------ .../service/record/TaskBuildRecordService.kt | 19 ---- .../service/vmbuild/EngineVMBuildService.kt | 12 ++- .../process/service/PipelineContextService.kt | 12 ++- .../DispatchBuildLessDockerStartupTaskAtom.kt | 18 +++- .../atom/vm/DispatchVMStartupTaskAtom.kt | 28 +++--- .../engine/control/BuildCancelControl.kt | 12 ++- .../process/engine/control/BuildEndControl.kt | 34 ++++--- .../engine/control/BuildMonitorControl.kt | 29 ++++-- .../engine/control/BuildStartControl.kt | 12 ++- .../process/engine/control/StageControl.kt | 4 + .../impl/InitializeMatrixGroupStageCmd.kt | 25 ++--- .../impl/UpdateStateForStageCmdFinally.kt | 2 - .../process/api/ServiceBuildResourceImpl.kt | 6 +- .../process/engine/control/CallBackControl.kt | 11 +- .../builds/PipelineBuildFacadeService.kt | 95 ++++++++++-------- .../engine/control/CallBackControlTest.kt | 37 +++++-- 26 files changed, 356 insertions(+), 318 deletions(-) diff --git a/src/backend/ci/core/auth/biz-auth/src/test/kotlin/com/tencent/devops/auth/rbac/service/migrate/MigrateV3PolicyServiceTest.kt b/src/backend/ci/core/auth/biz-auth/src/test/kotlin/com/tencent/devops/auth/rbac/service/migrate/MigrateV3PolicyServiceTest.kt index 403007b90a81ca1395da4d3318eb19fc316612c6..88f9812050f36da94212b6f59cec870eab982870 100644 GIT binary patch literal 5013 zcmY$9nlmZ4^;~ZLWS>hef9_b%P)$E?U;gUg(e08y#NPePFY_??dNQ%ybnz{%cMEPz zI(#PQ?CjaW3oTkYk^1Mb>pV+(CRX6UEIi8Wtux<7B?{;N|YdxG6uiMCa z|K6>Xm_`lZRPKCv&x%EM##Nd?KB~k!x?|YU-InV_B8cM-)UCvBN=+UDlk7M1l= z7j1u1ZMf61ajM=Y#w72GT|NsM*Z1EQ+O96WzSJVmbb;KYUCgNrID`s7`$4Yo)ZH~nEZI8p<$3OM{~uW|UBFPseJ%B5 z(b-7?ES-0*NYtrw8zzK3TDE$pu2%HPk3LttkEk0t%$H)k^Y6lw-K!RC%A0uhzR?c9 z`wSh&wrzD6;h4JUbEbaiqOIz#?;VyUcs$!#Kf_v*PfXZLY^u-%**$yiaP%GJ*7kat zr@VVllbL`N^Q|q@S&!^=pZaH^U;QQb59-sS6u&)uE4!mJTq3i7x1ZMnhtCgYIsU#A zRkJF3#e0>)+RV9^wr>q&7D*}zadlQ1jsMa3AI<-x`G2(hA1(h!>;KXEf3*EK+Ws4D a|Btr+NBe)H{lC%v|7ibzbo__@<39k;gL`ZM literal 4896 zcmdT{PmkNi6~F6K4ECfAWV*IbS-^m~64%Q{O9>R$u205@9Ia-TR3eK#{sY zfTU;-MS~o2YEhs;(H`2=hklu^*ZCIxy&)-yt6dq+tvpELoA-Y2|9hkRA9dJAED&iZ zQq5$+vRLp!L`*AIlv$>7&GcL_m5G!Us?0;dLX{+CD)o|0mn`8IGCgC5pWN%a?A`Ca z{qgVrdi&+)*Khv%<2PTtef{;-5C6FO>TirMxQzKU78cZz#=gpyxjdU|*6r`Jhd+Dp zF$<1|%zpSW8_Gm#5%m~f*#(UmPnQ;Bb{sP!SFl_ZB43E8fqah%@GX|`lAJ5kNaV(^ z6E|qc4UP>5vn5lr6~nNSqwvTyjLQfRGQ}|nGr4lAie#P?x5ysQ;k^%kNNg7fq zDOoTVxj@{{a-Nzf&2oYC%vd<*`I+cZ;t(p9iM)V-nrbdn$`Idh3owP6=}VpqFh`6R zg$gAH9_fozSSBb3u1O_1Sg{9BvDmA4?=Q1RWUL7_v zqdAT#%asN|liE71u)i$e2PL7$5*5iAeGB7UR!(DC%zG@7ggz}bI13`0%%Wz}=)THX zAy6kkkTAVYWMiP=L6k@(f&?q-SQQky%ehKS-Wzrb`K-)SXsx;;LSrbS^jw5!4rSP9 zDvs49IT)%mlH_$kIVUXvLdU0SL7mf7eX2A}Ho-S#WGtz2Tpty44j-nXRdPgX+=7?o zw9qI6i8N5Bl2W)!Iw@U^3r%4M#}1o}j)Ld5?=W}5#{TG;J8%YU&z|6Yug9Ld!SU!c zVBqj=FL=R5N6hwKuuoiX&|}Uo#=bL|u#wN)lkw1XKy$tR@O0pMPuU^lyiq{Phc4O* zxWNcb?KEhv1JNUP;`sezfZK=e&<$Sn*pVA}1bYNrn~iNhaQml2+h^lbe>|EvuwVdW z&-IRcC~{65FR-APG9K)*Vm~DVeKvy4zG15jBt6fM9Yb|JSi|go;Ep_Ura$rmAFn<5>IW<7 z=kCPmG23@16qzG`1Pv5dNKo)RlJlGjgz7M+ev%#_EBy;Ug7)k0!i zR??X|SBP3=a%ipwQTYrc|zI zYW7tm*kiUgy{O7_Z;KHFe0Fe$Zb(wnx<-gJ+-~CfoOl)wPk4&v$m@~<$W2mj1xNyt zCw-O98_Dc9lLjv^C?%JA+Pb%YyHL!`?tE}4;-aqJYsv!*7-O)|`|?XSRJnP0DJBkS== zI%S%o!mELHSjsr^Q4uzhtaAC8Y3~WHRbq%+<%X?K%y4Zif3h*RyL<2c^ZE6k-eB!q zz5eFv&A;zmfB)U}*I!)y_7B&;|MT0||Ga+ltG%^d6d#SD`0_z3I)qG9(b%;)o8j5k zyzcHT9^E$qdI_yBGqWFG@+gt1b&jRCp{~Kzt;Gz`W;t3~wWlLV5D0j-jIm^zm3pFc z!4nG~(cu!lboT)QB9=|J-Wa%Rm~7Rr-TjTSA_es5Wk!>~Y9!IVIUF1q-4<=6RZ2;y zt~&Zj4~2}{_m2EwJDB>~o#t)-+q-GwZQUG|ep+c}jnM{&Gdo$6YU`K^HkJKg8!k5& zCm^*G){cQSlQ~v>i@3g-SXk8<;{h7Adv|OsSvX0i(OT=;th-M1pI4e+-B&0Y9{W0yE7A1 KZ?8J9I{yRUBQ+iX 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 6812ebe5059..b626d65624c 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/PipelineProgressRateService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineProgressRateService.kt index 5d9c2a33528..60d64052031 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 @@ -18,11 +19,11 @@ import javax.ws.rs.core.Response @Suppress("LongParameterList") class PipelineProgressRateService constructor( private val taskBuildRecordService: TaskBuildRecordService, - private val pipelineBuildDetailService: PipelineBuildDetailService, private val pipelineTaskService: PipelineTaskService, private val pipelineRuntimeService: PipelineRuntimeService, private val buildRecordService: ContainerBuildRecordService, private val buildRecordTaskDao: BuildRecordTaskDao, + private val pipelineBuildDao: PipelineBuildDao, private val dslContext: DSLContext ) { fun reportProgressRate( @@ -34,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 = pipelineBuildDetailService.getBuildDetailPipelineId(projectId, buildId) ?: 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 2c7d028133e..ab101070686 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 @@ -172,7 +171,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, @@ -890,8 +888,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( @@ -926,15 +922,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") // 构建号递增 @@ -949,18 +936,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( @@ -1220,13 +1195,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, @@ -1562,13 +1530,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/PipelineStageService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineStageService.kt index f7bdb074582..ab72974b4d9 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineStageService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineStageService.kt @@ -30,6 +30,7 @@ package com.tencent.devops.process.engine.service import com.tencent.devops.common.api.enums.BuildReviewType import com.tencent.devops.common.api.util.DateTimeUtil import com.tencent.devops.common.client.Client +import com.tencent.devops.common.db.utils.JooqUtils import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher import com.tencent.devops.common.event.enums.ActionType import com.tencent.devops.common.event.pojo.pipeline.PipelineBuildQualityCheckBroadCastEvent @@ -39,7 +40,6 @@ import com.tencent.devops.common.pipeline.enums.BuildStatus import com.tencent.devops.common.pipeline.enums.ManualReviewAction import com.tencent.devops.common.pipeline.pojo.StagePauseCheck import com.tencent.devops.common.pipeline.pojo.StageReviewRequest -import com.tencent.devops.common.db.utils.JooqUtils import com.tencent.devops.common.websocket.enum.RefreshType import com.tencent.devops.process.engine.common.BS_MANUAL_START_STAGE import com.tencent.devops.process.engine.common.BS_QUALITY_ABORT_STAGE @@ -53,7 +53,6 @@ import com.tencent.devops.process.engine.pojo.PipelineBuildStage import com.tencent.devops.process.engine.pojo.event.PipelineBuildNotifyEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildStageEvent import com.tencent.devops.process.engine.pojo.event.PipelineBuildWebSocketPushEvent -import com.tencent.devops.process.engine.service.detail.StageBuildDetailService import com.tencent.devops.process.engine.service.record.StageBuildRecordService import com.tencent.devops.process.pojo.PipelineNotifyTemplateEnum import com.tencent.devops.process.pojo.StageQualityRequest @@ -85,7 +84,6 @@ class PipelineStageService @Autowired constructor( private val pipelineBuildSummaryDao: PipelineBuildSummaryDao, private val pipelineBuildStageDao: PipelineBuildStageDao, private val buildVariableService: BuildVariableService, - private val stageBuildDetailService: StageBuildDetailService, private val stageBuildRecordService: StageBuildRecordService, private val pipelineRepositoryService: PipelineRepositoryService, private val client: Client @@ -472,7 +470,7 @@ class PipelineStageService @Autowired constructor( ), position = ControlPointPosition.BEFORE_POSITION, stageId = stageId, - notifyType = NotifyUtils.checkNotifyType(checkIn?.notifyType) ?: mutableSetOf(), + notifyType = NotifyUtils.checkNotifyType(checkIn?.notifyType), markdownContent = checkIn?.markdownContent ) // #3400 FinishEvent会刷新HISTORY列表的Stage状态 @@ -608,7 +606,7 @@ class PipelineStageService @Autowired constructor( ), position = ControlPointPosition.BEFORE_POSITION, stageId = stage.stageId, - notifyType = NotifyUtils.checkNotifyType(checkIn.notifyType) ?: mutableSetOf(), + notifyType = NotifyUtils.checkNotifyType(checkIn.notifyType), markdownContent = checkIn.markdownContent ) ) 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 b54b8922ba5..6c4993375a3 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, @@ -522,7 +520,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 ) @@ -530,7 +535,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)) { @@ -615,10 +620,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 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 6069a4291e1..c338ab07c39 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 @@ -75,7 +75,7 @@ import javax.ws.rs.core.Response 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, 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 c3cdec48b60..bcf80d77cc2 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 @@ -48,7 +48,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.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,7 +66,6 @@ class ContainerBuildRecordService( private val dslContext: DSLContext, private val recordContainerDao: BuildRecordContainerDao, private val recordTaskDao: BuildRecordTaskDao, - private val containerBuildDetailService: ContainerBuildDetailService, recordModelService: PipelineRecordModelService, pipelineResourceDao: PipelineResourceDao, pipelineBuildDao: PipelineBuildDao, @@ -91,20 +89,26 @@ class ContainerBuildRecordService( ) { 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 +132,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 +159,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 +192,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" @@ -294,15 +284,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" @@ -329,7 +310,6 @@ class ContainerBuildRecordService( executeCount: Int, containerId: String ) { - containerBuildDetailService.containerSkip(projectId, buildId, containerId) update( projectId, pipelineId, buildId, executeCount, BuildStatus.RUNNING, cancelUser = null, operation = "containerSkip#$containerId" @@ -357,13 +337,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 dabec44ef4c..0e7ab4e3895 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 @@ -69,7 +69,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 @@ -160,6 +159,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: 构建信息 @@ -691,4 +731,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 a2debf3c657..7d9c699bff9 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 @@ -45,7 +45,6 @@ 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,8 +61,7 @@ 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, @@ -117,10 +115,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 +173,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 +201,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 +213,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 +258,6 @@ class StageBuildRecordService( ) ) } - stageBuildDetailService.stageCancel( - projectId = projectId, buildId = buildId, stageId = stageId, controlOption = controlOption, - checkIn = checkIn, checkOut = checkOut - ) } fun stageCheckQuality( @@ -290,10 +311,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 +331,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 +386,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 bb8d2513b58..c1a2b3c8ec9 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 @@ -49,7 +49,6 @@ 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 @@ -77,7 +76,6 @@ class TaskBuildRecordService( private val dslContext: DSLContext, private val recordTaskDao: BuildRecordTaskDao, private val containerBuildRecordService: ContainerBuildRecordService, - private val taskBuildDetailService: TaskBuildDetailService, recordModelService: PipelineRecordModelService, pipelineResourceDao: PipelineResourceDao, pipelineBuildDao: PipelineBuildDao, @@ -112,14 +110,6 @@ class TaskBuildRecordService( 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 +130,6 @@ class TaskBuildRecordService( taskId: String, executeCount: Int ) { - taskBuildDetailService.taskStart(projectId, buildId, taskId) update( projectId = projectId, pipelineId = pipelineId, buildId = buildId, executeCount = executeCount, buildStatus = BuildStatus.RUNNING, @@ -230,14 +219,6 @@ class TaskBuildRecordService( taskId: String, executeCount: Int ) { - taskBuildDetailService.taskPause( - projectId = projectId, - buildId = buildId, - stageId = stageId, - containerId = containerId, - taskId = taskId, - buildStatus = BuildStatus.PAUSE - ) updateTaskRecord( projectId = projectId, pipelineId = pipelineId, 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 f755df9ee2a..2dcaad1459d 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 @@ -79,7 +79,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 @@ -92,7 +91,6 @@ import com.tencent.devops.process.pojo.task.TaskBuildEndParam import com.tencent.devops.process.service.BuildVariableService import com.tencent.devops.process.service.PipelineAsCodeService import com.tencent.devops.process.service.PipelineContextService -import com.tencent.devops.process.service.PipelineTaskPauseService import com.tencent.devops.process.util.TaskUtils import com.tencent.devops.process.utils.PIPELINE_BUILD_REMARK import com.tencent.devops.process.utils.PIPELINE_ELEMENT_ID @@ -118,7 +116,6 @@ import org.springframework.stereotype.Service @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, @@ -128,7 +125,6 @@ class EngineVMBuildService @Autowired(required = false) constructor( private val buildLogPrinter: BuildLogPrinter, private val pipelineEventDispatcher: PipelineEventDispatcher, private val pipelineTaskService: PipelineTaskService, - private val pipelineTaskPauseService: PipelineTaskPauseService, private val jmxElements: JmxElements, private val buildExtService: PipelineBuildExtService, private val client: Client, @@ -189,7 +185,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 + ) val asCodeSettings = pipelineAsCodeService.getPipelineAsCodeSettings( projectId, buildInfo.pipelineId, buildId, buildInfo ) 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 92292987bc3..13db955f9d8 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-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 5e8151e18fc..c20f031f77c 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 @@ -53,7 +53,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.PipelineBuildLessShutdownDispatchEvent import com.tencent.devops.process.pojo.mq.PipelineBuildLessStartupDispatchEvent @@ -73,7 +72,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: PipelineEventDispatcher, private val buildLogPrinter: BuildLogPrinter @@ -157,8 +155,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 7b5860440b5..244ac85872f 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 @@ -31,7 +31,6 @@ import com.tencent.devops.common.api.check.Preconditions import com.tencent.devops.common.api.constant.CommonMessageCode.BK_ENV_NOT_YET_SUPPORTED import com.tencent.devops.common.api.pojo.ErrorCode import com.tencent.devops.common.api.pojo.ErrorType -import com.tencent.devops.common.api.pojo.Zone import com.tencent.devops.common.api.util.EnvUtils import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.MessageUtil @@ -62,11 +61,9 @@ 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 -import com.tencent.devops.process.service.BuildVariableService import com.tencent.devops.process.service.PipelineAsCodeService import com.tencent.devops.process.service.PipelineContextService import com.tencent.devops.store.api.container.ServiceContainerAppResource @@ -87,10 +84,8 @@ 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 buildVariableService: BuildVariableService, private val pipelineEventDispatcher: PipelineEventDispatcher, private val buildLogPrinter: BuildLogPrinter, private val dispatchTypeBuilder: DispatchTypeBuilder, @@ -202,7 +197,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( @@ -337,14 +345,6 @@ class DispatchVMStartupTaskAtom @Autowired constructor( return true } - private fun getBuildZone(container: Container): Zone? { - return when { - container !is VMBuildContainer -> null - container.enableExternal == true -> Zone.EXTERNAL - else -> null - } - } - override fun tryFinish( task: PipelineBuildTask, param: VMBuildContainer, 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 f2cc0ee0d37..8e250b83ec6 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 @@ -50,13 +50,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.PipelineBuildLessShutdownDispatchEvent @@ -76,7 +75,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, @@ -117,7 +115,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) { 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 d1c85ece491..72b5ce64fa8 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 @@ -46,6 +46,7 @@ import com.tencent.devops.common.pipeline.container.Container import com.tencent.devops.common.pipeline.container.TriggerContainer 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 @@ -66,7 +67,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 @@ -100,7 +100,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, @@ -279,10 +278,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.stages[0].containers[0] as TriggerContainer - 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 -> @@ -417,12 +420,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.stages[0].containers[0] as TriggerContainer + 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", @@ -433,7 +441,7 @@ class BuildEndControl @Autowired constructor( taskId = nextBuild.firstTaskId, status = nextBuild.status, actionType = ActionType.START, - 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 38c53f48141..1ca89e74e8f 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,12 +30,14 @@ 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.dispatcher.pipeline.PipelineEventDispatcher import com.tencent.devops.common.event.enums.ActionType import com.tencent.devops.common.log.utils.BuildLogPrinter import com.tencent.devops.common.pipeline.container.TriggerContainer 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.web.utils.I18nUtil import com.tencent.devops.process.constant.ProcessMessageCode @@ -52,20 +54,20 @@ 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 java.time.LocalDateTime -import java.util.concurrent.TimeUnit import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service +import java.time.LocalDateTime +import java.util.concurrent.TimeUnit import kotlin.math.min /** @@ -82,7 +84,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 ) { @@ -458,12 +460,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.stages[0].containers[0] as TriggerContainer + 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_monitor", @@ -474,7 +481,7 @@ class BuildMonitorControl @Autowired constructor( taskId = buildInfo.firstTaskId, status = BuildStatus.RUNNING, actionType = ActionType.START, - 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 5d201e724ff..68e90628935 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 @@ -71,7 +71,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 @@ -114,7 +113,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, @@ -577,8 +575,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, @@ -720,7 +716,13 @@ class BuildStartControl @Autowired constructor( } private fun PipelineBuildStartEvent.buildModel(buildInfo: BuildInfo, executeCount: Int) { - val model = buildDetailService.getBuildModel(projectId, buildId) ?: run { + 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 e68e4456530..ab212cfb68f 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 6e0b4dee045..b8cdb21f636 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 @@ -63,7 +63,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 @@ -93,7 +92,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, @@ -178,9 +176,20 @@ class InitializeMatrixGroupStageCmd( val event = commandContext.event val variables = commandContext.variables val asCodeEnabled = commandContext.pipelineAsCodeEnabled ?: false - 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" ) @@ -189,14 +198,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 - ) // #4518 待生成的分裂后container表和task表记录 val buildContainerList = mutableListOf() val buildTaskList = mutableListOf() diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/UpdateStateForStageCmdFinally.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/UpdateStateForStageCmdFinally.kt index a8882d563a7..c8707e61b32 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/UpdateStateForStageCmdFinally.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/UpdateStateForStageCmdFinally.kt @@ -47,7 +47,6 @@ import com.tencent.devops.process.engine.pojo.event.PipelineBuildStageEvent 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.detail.StageBuildDetailService import com.tencent.devops.process.engine.service.record.StageBuildRecordService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -62,7 +61,6 @@ class UpdateStateForStageCmdFinally( private val pipelineStageService: PipelineStageService, private val pipelineRuntimeService: PipelineRuntimeService, private val pipelineContainerService: PipelineContainerService, - private val stageBuildDetailService: StageBuildDetailService, private val stageBuildRecordService: StageBuildRecordService, private val pipelineEventDispatcher: PipelineEventDispatcher, private val buildLogPrinter: BuildLogPrinter, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt index 70f6091c997..32357c09a0e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt @@ -42,8 +42,8 @@ import com.tencent.devops.common.pipeline.pojo.BuildFormValue import com.tencent.devops.common.pipeline.pojo.StageReviewRequest import com.tencent.devops.common.web.RestResource import com.tencent.devops.process.api.service.ServiceBuildResource -import com.tencent.devops.process.engine.service.PipelineBuildDetailService import com.tencent.devops.process.engine.service.PipelineRuntimeService +import com.tencent.devops.process.engine.service.record.PipelineBuildRecordService import com.tencent.devops.process.engine.service.vmbuild.EngineVMBuildService import com.tencent.devops.process.pojo.BuildBasicInfo import com.tencent.devops.process.pojo.BuildHistory @@ -70,7 +70,7 @@ class ServiceBuildResourceImpl @Autowired constructor( private val pipelineBuildMaintainFacadeService: PipelineBuildMaintainFacadeService, private val pipelineBuildFacadeService: PipelineBuildFacadeService, private val engineVMBuildService: EngineVMBuildService, - private val pipelineBuildDetailService: PipelineBuildDetailService, + private val pipelineBuildRecordService: PipelineBuildRecordService, private val pipelinePauseBuildFacadeService: PipelinePauseBuildFacadeService, private val pipelineRuntimeService: PipelineRuntimeService ) : ServiceBuildResource { @@ -79,7 +79,7 @@ class ServiceBuildResourceImpl @Autowired constructor( throw ParamBlankException("Invalid buildId, it must not empty.") } return Result( - pipelineBuildDetailService.getBuildDetailPipelineId(projectId, buildId) + pipelineBuildRecordService.getPipelineIdByBuildId(projectId, buildId) ?: throw ParamBlankException("Invalid buildId, please check if projectId & buildId are related") ) } 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 423f9607272..4dbed4aacf3 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, @@ -257,9 +257,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 @@ -271,7 +272,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 4fc935faffe..45e34e8db5f 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 @@ -136,12 +135,12 @@ import com.tencent.devops.process.utils.PIPELINE_SKIP_FAILED_TASK import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import com.tencent.devops.process.yaml.PipelineYamlFacadeService import com.tencent.devops.quality.api.v2.pojo.ControlPointPosition -import java.util.concurrent.TimeUnit -import javax.ws.rs.core.Response -import javax.ws.rs.core.UriBuilder import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service +import java.util.concurrent.TimeUnit +import javax.ws.rs.core.Response +import javax.ws.rs.core.UriBuilder /** * @@ -160,7 +159,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, @@ -438,7 +436,13 @@ class PipelineBuildFacadeService( ) } - 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 ) @@ -968,7 +972,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 ) @@ -1278,14 +1288,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 ) @@ -1428,21 +1443,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( @@ -1532,24 +1561,10 @@ class PipelineBuildFacadeService( archiveFlag: Boolean? = false ): ModelRecord { val queryDslContext = CommonUtils.getJooqDslContext(archiveFlag, ARCHIVE_SHARDING_DSL_CONTEXT) - val buildInfo = pipelineRuntimeService.getBuildInfo( + return buildRecordService.getBuildRecord( projectId = projectId, + pipelineId = pipelineId, buildId = buildId, - queryDslContext = queryDslContext - ) ?: 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 buildRecordService.getBuildRecord( - buildInfo = buildInfo, executeCount = executeCount, queryDslContext = queryDslContext ) ?: throw ErrorCodeException( @@ -2292,7 +2307,7 @@ class PipelineBuildFacadeService( try { redisLock.lock() - val modelDetail = buildDetailService.get(projectId, buildId) ?: return + val modelDetail = buildRecordService.getBuildRecord(projectId, pipelineId, buildId) ?: return val alreadyCancelUser = modelDetail.cancelUserId if (BuildStatus.parse(modelDetail.status).isFinish()) { 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 c0b6cf7813f..5ee257c390f 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 @@ -167,7 +182,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) { @@ -219,7 +234,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) { From 62821f68fe7aeff59d3b8c5fba9b22efdedf1c12 Mon Sep 17 00:00:00 2001 From: carlyin <449036249@qq.com> Date: Tue, 16 Jul 2024 15:16:46 +0800 Subject: [PATCH 3/9] =?UTF-8?q?perf:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=97=A7=E6=95=B0=E6=8D=AE=E5=85=BC=E5=AE=B9=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6=20#9522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/pojo/PipelineBuildContainer.kt | 1 + .../pipeline/record/BuildRecordContainer.kt | 1 + .../dao/record/BuildRecordContainerDao.kt | 13 +++++--- .../engine/dao/PipelineBuildContainerDao.kt | 1 + .../service/PipelineContainerService.kt | 8 +++-- .../engine/service/PipelineRuntimeService.kt | 4 +-- .../service/record/TaskBuildRecordService.kt | 32 +++++++++---------- .../com/tencent/devops/process/TestBase.kt | 1 + .../impl/InitializeMatrixGroupStageCmd.kt | 2 ++ .../engine/control/MutexControlTest.kt | 1 + .../devops/process/engine/utils/TestTool.kt | 1 + .../builds/PipelineRetryFacadeService.kt | 19 +++++++---- .../com/tencent/devops/process/TestBase.kt | 1 + 13 files changed, 53 insertions(+), 32 deletions(-) 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 002bb285cf2..bfab44fcdd2 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 matrixGroupFlag: Boolean?, val matrixGroupId: String?, val containerType: 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 2a61c463cb4..658dde6d3ab 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 5cde459c9da..2942bc06c47 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, @@ -219,7 +221,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)) @@ -247,7 +249,7 @@ class BuildRecordContainerDao { .and(MATRIX_GROUP_ID.isNotNull) 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).where(conditions).orderBy(CONTAINER_ID.asc()).fetch() return result.map { record -> @@ -257,8 +259,8 @@ class BuildRecordContainerDao { } private fun TPipelineBuildRecordContainer.generateBuildRecordContainer( - record: Record15 + record: Record16 ) = BuildRecordContainer( buildId = record[BUILD_ID], @@ -273,6 +275,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/engine/dao/PipelineBuildContainerDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildContainerDao.kt index 6376b3e7e94..aa468fa82aa 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 @@ -346,6 +346,7 @@ class PipelineBuildContainerDao { containerType = containerType, containerId = containerId, containerHashId = containerHashId, + containPostTaskFlag = controlOption.containPostTaskFlag, matrixGroupFlag = matrixGroupFlag, matrixGroupId = matrixGroupId, seq = seq, 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 eabad63f7f0..fc64831c86c 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 @@ -395,6 +395,7 @@ class PipelineContainerService @Autowired constructor( containPostTaskFlag = container.containPostTaskFlag, agentReuseMutex = agentReuseMutex ), + containPostTaskFlag = container.containPostTaskFlag, matrixGroupFlag = false, matrixGroupId = matrixGroupId ) @@ -658,6 +659,7 @@ class PipelineContainerService @Autowired constructor( seq = context.containerSeq, status = BuildStatus.QUEUE, controlOption = controlOption, + containPostTaskFlag = container.containPostTaskFlag, matrixGroupFlag = container.matrixGroupFlag, matrixGroupId = null ), @@ -673,9 +675,9 @@ class PipelineContainerService @Autowired constructor( projectId = context.projectId, pipelineId = context.pipelineId, buildId = context.buildId, resourceVersion = context.resourceVersion, stageId = stage.id!!, containerId = container.containerId!!, 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/PipelineRuntimeService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt index ab101070686..bd68c33558f 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 @@ -1146,8 +1146,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 ) ) 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 c1a2b3c8ec9..7dc16536978 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 @@ -265,13 +265,6 @@ class TaskBuildRecordService( executeCount: Int, cancelUser: String ) { - taskBuildDetailService.taskCancel( - projectId = projectId, - buildId = buildId, - containerId = containerId, - taskId = taskId, - cancelUser = cancelUser // fix me: 是否要直接更新取消人,暂时维护原有逻辑 - ) updateTaskRecord( projectId = projectId, pipelineId = pipelineId, @@ -298,14 +291,6 @@ class TaskBuildRecordService( executeCount: Int, element: Element? ) { - taskBuildDetailService.taskContinue( - projectId = projectId, - buildId = buildId, - stageId = stageId, - containerId = containerId, - taskId = taskId, - element = element - ) // #7983 此处需要保持Container状态独立刷新,不能放进更新task的并发锁 containerBuildRecordService.updateContainerStatus( projectId = projectId, @@ -420,8 +405,23 @@ class TaskBuildRecordService( ) } } + val pipelineTaskStatusInfos = mutableListOf() + val buildRecordContainer = containerBuildRecordService.getRecord( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + containerId = taskBuildEndParam.containerId, + executeCount = executeCount + ) + buildRecordContainer?.let { + val containPostTaskFlag = buildRecordContainer.containPostTaskFlag + // 判断取消的task任务对应的container是否包含post任务 + val cancelTaskPostFlag = buildStatus == BuildStatus.CANCELED && containPostTaskFlag == true + if (cancelTaskPostFlag) { - return taskBuildDetailService.taskEnd(taskBuildEndParam) + } + } + return pipelineTaskStatusInfos } fun updateTaskRecord( 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 8cc552ce599..ef60f996e37 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 @@ -333,6 +333,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/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 b8cdb21f636..b7eb0019cdf 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 @@ -366,6 +366,7 @@ class InitializeMatrixGroupStageCmd( containerId = newContainer.containerId!!, containerType = recordContainer.containerType, executeCount = context.executeCount, + containPostTaskFlag = newContainer.containPostTaskFlag, matrixGroupFlag = false, matrixGroupId = matrixGroupId, containerVar = containerVar, @@ -482,6 +483,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/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 6c36b7c22f1..5f7a53c19b5 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 @@ -70,6 +70,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 15857d4ed1d..4d53390b067 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 @@ -75,6 +75,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/service/builds/PipelineRetryFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineRetryFacadeService.kt index 2d9142367a0..63ae68fd5a2 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 e7e5b83f05e..dd47b14f1e4 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 @@ -231,6 +231,7 @@ open class TestBase { mutexGroup = null ), cost = containerCost, + containPostTaskFlag = null, matrixGroupId = null, matrixGroupFlag = false, containerHashId = containerHashId From 8948c771c8f7b283228da00daccb480ada0c9009 Mon Sep 17 00:00:00 2001 From: carlyin <449036249@qq.com> Date: Wed, 17 Jul 2024 17:45:07 +0800 Subject: [PATCH 4/9] =?UTF-8?q?perf:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=97=A7=E6=95=B0=E6=8D=AE=E5=85=BC=E5=AE=B9=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6=20#9522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/dao/record/BuildRecordTaskDao.kt | 11 +- .../engine/dao/PipelineBuildTaskDao.kt | 6 +- .../engine/service/PipelineTaskService.kt | 2 - .../service/record/BaseBuildRecordService.kt | 3 +- .../record/ContainerBuildRecordService.kt | 5 +- .../record/PipelineBuildRecordService.kt | 5 +- .../service/record/StageBuildRecordService.kt | 5 +- .../service/record/TaskBuildRecordService.kt | 163 ++++++++++++++---- .../record/PipelineRecordModelService.kt | 2 +- .../engine/control/BuildStartControl.kt | 2 - .../impl/StartActionTaskContainerCmd.kt | 4 - .../listener/run/PipelineTaskPauseListener.kt | 9 +- 12 files changed, 150 insertions(+), 67 deletions(-) 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 277aceea870..3e7a72a1999 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 @@ -169,7 +169,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 +180,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/PipelineBuildTaskDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildTaskDao.kt index 5a1b3c922d0..10a9d2ddb73 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 @@ -274,7 +274,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) @@ -283,6 +285,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/PipelineTaskService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineTaskService.kt index 6c4993375a3..409d0fd449d 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 @@ -650,8 +650,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 c338ab07c39..d5f2de4c3dd 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 @@ -81,8 +81,7 @@ open class BaseBuildRecordService( 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( 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 bcf80d77cc2..9223a430913 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,7 +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.utils.ContainerUtils import com.tencent.devops.process.pojo.VmInfo import com.tencent.devops.process.pojo.pipeline.record.BuildRecordContainer @@ -70,7 +69,6 @@ class ContainerBuildRecordService( pipelineResourceDao: PipelineResourceDao, pipelineBuildDao: PipelineBuildDao, pipelineResourceVersionDao: PipelineResourceVersionDao, - pipelineElementService: PipelineElementService, stageTagService: StageTagService, buildRecordModelDao: BuildRecordModelDao, pipelineEventDispatcher: PipelineEventDispatcher, @@ -84,8 +82,7 @@ class ContainerBuildRecordService( recordModelService = recordModelService, pipelineResourceDao = pipelineResourceDao, pipelineBuildDao = pipelineBuildDao, - pipelineResourceVersionDao = pipelineResourceVersionDao, - pipelineElementService = pipelineElementService + pipelineResourceVersionDao = pipelineResourceVersionDao ) { fun getRecord( 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 0e7ab4e3895..7523c3c6df1 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 @@ -69,7 +69,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.PipelineElementService import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.utils.ContainerUtils import com.tencent.devops.process.pojo.BuildStageStatus @@ -114,7 +113,6 @@ class PipelineBuildRecordService @Autowired constructor( pipelineResourceDao: PipelineResourceDao, pipelineBuildDao: PipelineBuildDao, pipelineResourceVersionDao: PipelineResourceVersionDao, - pipelineElementService: PipelineElementService, redisOperation: RedisOperation, stageTagService: StageTagService, pipelineEventDispatcher: PipelineEventDispatcher @@ -127,8 +125,7 @@ class PipelineBuildRecordService @Autowired constructor( recordModelService = recordModelService, pipelineResourceDao = pipelineResourceDao, pipelineBuildDao = pipelineBuildDao, - pipelineResourceVersionDao = pipelineResourceVersionDao, - pipelineElementService = pipelineElementService + pipelineResourceVersionDao = pipelineResourceVersionDao ) { @Value("\${pipeline.build.retry.limit_days:21}") 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 7d9c699bff9..505f2274924 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,7 +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.pojo.BuildStageStatus import com.tencent.devops.process.service.StageTagService import com.tencent.devops.process.service.record.PipelineRecordModelService @@ -65,7 +64,6 @@ class StageBuildRecordService( recordModelService: PipelineRecordModelService, pipelineResourceDao: PipelineResourceDao, pipelineResourceVersionDao: PipelineResourceVersionDao, - pipelineElementService: PipelineElementService, stageTagService: StageTagService, buildRecordModelDao: BuildRecordModelDao, pipelineEventDispatcher: PipelineEventDispatcher, @@ -79,8 +77,7 @@ class StageBuildRecordService( recordModelService = recordModelService, pipelineResourceDao = pipelineResourceDao, pipelineBuildDao = pipelineBuildDao, - pipelineResourceVersionDao = pipelineResourceVersionDao, - pipelineElementService = pipelineElementService + pipelineResourceVersionDao = pipelineResourceVersionDao ) { fun updateStageStatus( 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 7dc16536978..878976cb083 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 @@ -30,9 +30,11 @@ package com.tencent.devops.process.engine.service.record import com.tencent.devops.common.api.constant.INIT_VERSION import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher +import com.tencent.devops.common.pipeline.container.NormalContainer 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,11 +46,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.pojo.pipeline.record.BuildRecordTask import com.tencent.devops.process.pojo.task.TaskBuildEndParam import com.tencent.devops.process.service.BuildVariableService @@ -75,12 +78,12 @@ class TaskBuildRecordService( private val buildVariableService: BuildVariableService, private val dslContext: DSLContext, private val recordTaskDao: BuildRecordTaskDao, + private val pipelineBuildTaskDao: PipelineBuildTaskDao, private val containerBuildRecordService: ContainerBuildRecordService, recordModelService: PipelineRecordModelService, pipelineResourceDao: PipelineResourceDao, pipelineBuildDao: PipelineBuildDao, pipelineResourceVersionDao: PipelineResourceVersionDao, - pipelineElementService: PipelineElementService, stageTagService: StageTagService, buildRecordModelDao: BuildRecordModelDao, pipelineEventDispatcher: PipelineEventDispatcher, @@ -94,16 +97,13 @@ 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, @@ -214,8 +214,6 @@ class TaskBuildRecordService( projectId: String, pipelineId: String, buildId: String, - stageId: String, - containerId: String, taskId: String, executeCount: Int ) { @@ -259,11 +257,8 @@ class TaskBuildRecordService( projectId: String, pipelineId: String, buildId: String, - stageId: String, - containerId: String, taskId: String, - executeCount: Int, - cancelUser: String + executeCount: Int ) { updateTaskRecord( projectId = projectId, @@ -285,11 +280,9 @@ class TaskBuildRecordService( projectId: String, pipelineId: String, buildId: String, - stageId: String, containerId: String, taskId: String, - executeCount: Int, - element: Element? + executeCount: Int ) { // #7983 此处需要保持Container状态独立刷新,不能放进更新task的并发锁 containerBuildRecordService.updateContainerStatus( @@ -306,8 +299,6 @@ class TaskBuildRecordService( projectId = projectId, pipelineId = pipelineId, buildId = buildId, - stageId = stageId, - containerId = containerId, taskId = taskId, executeCount = executeCount, buildStatus = BuildStatus.QUEUE, @@ -325,14 +316,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, @@ -341,19 +344,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() @@ -405,6 +395,10 @@ class TaskBuildRecordService( ) } } + if (buildStatus?.isCancel() != true && buildStatus?.isSkip() != true) { + // 如果状态不是取消状态或者跳过状态,无需处理后续更新task状态的逻辑 + return emptyList() + } val pipelineTaskStatusInfos = mutableListOf() val buildRecordContainer = containerBuildRecordService.getRecord( projectId = projectId, @@ -414,16 +408,119 @@ class TaskBuildRecordService( executeCount = executeCount ) buildRecordContainer?.let { + val buildTask = pipelineBuildTaskDao.get( + dslContext = dslContext, projectId = projectId, buildId = buildId, taskId = taskId, stepId = null + ) ?: return@let + val runCondition = buildTask.additionalOptions?.runCondition val containPostTaskFlag = buildRecordContainer.containPostTaskFlag + val containerId = buildRecordContainer.containerId + val containerType = buildRecordContainer.containerType // 判断取消的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 + val parentTaskSeq = if (containerType == NormalContainer.classType) { + parentElementJobIndex + 1 + } else { + 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 + ) + ) } } return pipelineTaskStatusInfos } + 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 taskId = taskBuildEndParam.taskId + val executeCount = taskBuildEndParam.executeCount + // 把post任务和取消任务之间的任务置为UNEXEC状态 + val buildTasks = pipelineBuildTaskDao.getTasksInCondition( + dslContext = dslContext, + projectId = projectId, + buildId = buildId, + containerId = containerId, + statusSet = null, + startTaskSeq = startTaskSeq, + endTaskSeq = endTaskSeq + ) + buildTasks.forEach { pipelineBuildTask -> + val additionalOptions = pipelineBuildTask.additionalOptions + if (!pipelineBuildTask.status.isFinish() && additionalOptions?.elementPostInfo == null) { + val unExecBuildStatus = BuildStatus.UNEXEC + pipelineTaskStatusInfos.add( + PipelineTaskStatusInfo( + taskId = taskId, + containerHashId = containerId, + buildStatus = unExecBuildStatus, + executeCount = executeCount, + message = "Do not meet the run conditions, ignored.", + stepId = pipelineBuildTask.stepId + ) + ) + } + } + } + fun updateTaskRecord( projectId: String, pipelineId: String, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/record/PipelineRecordModelService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/record/PipelineRecordModelService.kt index dc87346d51a..971ca262f6e 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/record/PipelineRecordModelService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/record/PipelineRecordModelService.kt @@ -442,7 +442,7 @@ class PipelineRecordModelService @Autowired constructor( // 如果跳过的是矩阵类task,则需要生成完整的model对象以便合并 taskVarMap["@type"] = MatrixStatusElement.classType taskVarMap[MatrixStatusElement::originClassType.name] = - taskBaseMap[MatrixStatusElement::classType.name].toString() + taskBaseMap[MatrixStatusElement.classType].toString() taskVarMap[MatrixStatusElement::originAtomCode.name] = taskBaseMap[KEY_ATOM_CODE].toString() taskVarMap[MatrixStatusElement::originTaskAtom.name] = taskBaseMap[KEY_TASK_ATOM].toString() taskVarMap = ModelUtils.generateBuildModelDetail(taskBaseMap.deepCopy(), taskVarMap) 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 68e90628935..327c4dbd25d 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 @@ -515,8 +515,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, 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 a546476b1ec..9b5dc2040a7 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 @@ -392,8 +392,6 @@ class StartActionTaskContainerCmd( projectId = projectId, pipelineId = pipelineId, buildId = buildId, - stageId = stageId, - containerId = containerId, taskId = taskId, executeCount = executeCount ?: 1, buildStatus = BuildStatus.FAILED, @@ -623,8 +621,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 7b8d9323749..312f70c43cc 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 @@ -126,11 +126,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( @@ -179,11 +177,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( From 7b670d90a920dc796232fb727d84b3d5f63769ff Mon Sep 17 00:00:00 2001 From: carlyin <449036249@qq.com> Date: Mon, 12 Aug 2024 14:59:41 +0800 Subject: [PATCH 5/9] =?UTF-8?q?perf:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=97=A7=E6=95=B0=E6=8D=AE=E5=85=BC=E5=AE=B9=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6=20#9522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/control/BuildCancelControl.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 8e250b83ec6..e48b8be210d 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 @@ -226,7 +226,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 } @@ -243,7 +243,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 ?: "" @@ -255,7 +255,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( From c591e8037250c2cb8b21f5de464ed18a7accdb49 Mon Sep 17 00:00:00 2001 From: carlyin <449036249@qq.com> Date: Wed, 14 Aug 2024 15:34:41 +0800 Subject: [PATCH 6/9] =?UTF-8?q?perf:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=97=A7=E6=95=B0=E6=8D=AE=E5=85=BC=E5=AE=B9=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6=20#9522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/dao/record/BuildRecordTaskDao.kt | 4 +- .../service/record/TaskBuildRecordService.kt | 40 ++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) 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 3e7a72a1999..73237baf047 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() } } 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 878976cb083..e7031808f07 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 @@ -30,7 +30,6 @@ package com.tencent.devops.process.engine.service.record import com.tencent.devops.common.api.constant.INIT_VERSION import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher -import com.tencent.devops.common.pipeline.container.NormalContainer 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 @@ -414,7 +413,6 @@ class TaskBuildRecordService( val runCondition = buildTask.additionalOptions?.runCondition val containPostTaskFlag = buildRecordContainer.containPostTaskFlag val containerId = buildRecordContainer.containerId - val containerType = buildRecordContainer.containerType // 判断取消的task任务对应的container是否包含post任务 val cancelTaskPostFlag = buildStatus == BuildStatus.CANCELED && containPostTaskFlag == true val currentTaskSeq = recordTask.taskSeq @@ -436,12 +434,9 @@ class TaskBuildRecordService( var endTaskSeq = startTaskSeq recordPostTasks.forEach { recordPostTask -> // 计算post父任务序号 - val parentElementJobIndex = recordPostTask.elementPostInfo!!.parentElementJobIndex - val parentTaskSeq = if (containerType == NormalContainer.classType) { - parentElementJobIndex + 1 - } else { - parentElementJobIndex + 2 - } + val parentElementJobIndex = + recordPostTask.elementPostInfo?.parentElementJobIndex ?: return@forEach + val parentTaskSeq = parentElementJobIndex + 2 // 判断父任务的序号是否在取消任务之后 if (parentTaskSeq <= currentTaskSeq) { endTaskSeq = recordPostTask.taskSeq - 1 @@ -474,6 +469,15 @@ class TaskBuildRecordService( stepId = buildTask.stepId ) ) + updateTaskStatus( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + taskId = taskId, + executeCount = executeCount, + buildStatus = buildStatus, + operation = "taskSkip#$taskId" + ) } } return pipelineTaskStatusInfos @@ -485,13 +489,12 @@ class TaskBuildRecordService( endTaskSeq: Int, pipelineTaskStatusInfos: MutableList ) { - if (endTaskSeq <= startTaskSeq) { + if (endTaskSeq < startTaskSeq) { return } val projectId = taskBuildEndParam.projectId val containerId = taskBuildEndParam.containerId val buildId = taskBuildEndParam.buildId - val taskId = taskBuildEndParam.taskId val executeCount = taskBuildEndParam.executeCount // 把post任务和取消任务之间的任务置为UNEXEC状态 val buildTasks = pipelineBuildTaskDao.getTasksInCondition( @@ -503,10 +506,16 @@ class TaskBuildRecordService( 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, @@ -519,6 +528,17 @@ class TaskBuildRecordService( ) } } + if (!unExecTaskIds.isNullOrEmpty()) { + recordTaskDao.updateRecordStatus( + dslContext = dslContext, + projectId = projectId, + pipelineId = taskBuildEndParam.pipelineId, + buildId = buildId, + executeCount = executeCount, + buildStatus = BuildStatus.UNEXEC, + taskIds = unExecTaskIds + ) + } } fun updateTaskRecord( From 0326f8e7160dc1bcd2bdd6b8b1af50d8e1f482fb Mon Sep 17 00:00:00 2001 From: carlyin <449036249@qq.com> Date: Wed, 14 Aug 2024 17:03:26 +0800 Subject: [PATCH 7/9] =?UTF-8?q?perf:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=97=A7=E6=95=B0=E6=8D=AE=E5=85=BC=E5=AE=B9=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6=20#9522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/common/pipeline/enums/BuildStatus.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/BuildStatus.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/BuildStatus.kt index 08bbfbf0272..6cf05ea5fdd 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/BuildStatus.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/BuildStatus.kt @@ -73,7 +73,7 @@ enum class BuildStatus( fun isNeverRun(): Boolean = this == UNEXEC || this == TRIGGER_REVIEWING - fun isFinish(): Boolean = isFailure() || isSuccess() || isCancel() + fun isFinish(): Boolean = isFailure() || isSuccess() || isCancel() || this == UNEXEC fun isFailure(): Boolean = this == FAILED || isPassiveStop() || isTimeout() || this == QUOTA_FAILED From 3a1b6f8e888cceff7fd0566cd553685eeaf0752c Mon Sep 17 00:00:00 2001 From: carlyin Date: Wed, 25 Sep 2024 11:14:30 +0800 Subject: [PATCH 8/9] =?UTF-8?q?perf:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=97=A7=E6=95=B0=E6=8D=AE=E5=85=BC=E5=AE=B9=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6=20#9522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/common/pipeline/enums/BuildStatus.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/BuildStatus.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/BuildStatus.kt index 6cf05ea5fdd..08bbfbf0272 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/BuildStatus.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/BuildStatus.kt @@ -73,7 +73,7 @@ enum class BuildStatus( fun isNeverRun(): Boolean = this == UNEXEC || this == TRIGGER_REVIEWING - fun isFinish(): Boolean = isFailure() || isSuccess() || isCancel() || this == UNEXEC + fun isFinish(): Boolean = isFailure() || isSuccess() || isCancel() fun isFailure(): Boolean = this == FAILED || isPassiveStop() || isTimeout() || this == QUOTA_FAILED From 152221ce4a9ecc3b7028f10d2a29264c0d7b8d66 Mon Sep 17 00:00:00 2001 From: carlyin Date: Thu, 26 Sep 2024 16:44:57 +0800 Subject: [PATCH 9/9] =?UTF-8?q?perf:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=97=A7=E6=95=B0=E6=8D=AE=E5=85=BC=E5=AE=B9=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6=20#9522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/engine/service/record/BaseBuildRecordService.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 2461c370037..7d0154759a7 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 @@ -57,7 +57,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.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 @@ -169,7 +168,7 @@ open class BaseBuildRecordService( errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID, params = arrayOf(buildId) ) - buildInfo.executeCount ?: 1 + buildInfo.executeCount } else { executeCount }