From e1d1de96c8f9fa335e5915ce5efa40b172dcfb26 Mon Sep 17 00:00:00 2001 From: royalhuang Date: Sun, 8 Aug 2021 21:57:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20stage=E6=94=AF=E6=8C=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F=E7=BA=A2=E7=BA=BF=E7=9A=84=E5=87=86=E5=85=A5=E5=87=86?= =?UTF-8?q?=E5=87=BA=20#4732=20=E5=A2=9E=E5=8A=A0=E5=87=86=E5=85=A5?= =?UTF-8?q?=E8=B4=A8=E9=87=8F=E7=BA=A2=E7=BA=BF=E6=8E=A7=E5=88=B6=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/dao/PipelineBuildStageDao.kt | 17 +++++++++++++ .../engine/service/PipelineStageService.kt | 24 ++++++++++++++++++- .../service/detail/StageBuildDetailService.kt | 5 +++- .../stage/impl/CheckPauseReviewStageCmd.kt | 2 +- .../impl/UpdateStateForStageCmdFinally.kt | 5 ++-- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildStageDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildStageDao.kt index 4050f902fe6..d1c2ffb5256 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildStageDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildStageDao.kt @@ -260,6 +260,23 @@ class PipelineBuildStageDao { } } + fun updateOptions( + dslContext: DSLContext, + buildId: String, + stageId: String, + controlOption: PipelineBuildStageControlOption, + checkIn: StagePauseCheck? = null, + checkOut: StagePauseCheck? = null + ): Int { + return with(T_PIPELINE_BUILD_STAGE) { + val update = dslContext.update(this) + .set(CONDITIONS, JsonUtil.toJson(controlOption)) + if (checkIn != null) update.set(CHECK_IN, JsonUtil.toJson(checkIn)) + if (checkOut != null) update.set(CHECK_OUT, JsonUtil.toJson(checkOut)) + update.where(BUILD_ID.eq(buildId)).and(STAGE_ID.eq(stageId)).execute() + } + } + fun update( dslContext: DSLContext, buildId: String, 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 a92fcc8fe24..65ab8d28c7e 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 @@ -36,7 +36,6 @@ import com.tencent.devops.common.pipeline.pojo.StageReviewRequest 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_STAGE_CANCELED_END_SOURCE -import com.tencent.devops.process.engine.common.BS_STAGE_QUALITY_CHECK_FAIL_END_SOURCE import com.tencent.devops.process.engine.dao.PipelineBuildDao import com.tencent.devops.process.engine.dao.PipelineBuildStageDao import com.tencent.devops.process.engine.dao.PipelineBuildSummaryDao @@ -137,6 +136,29 @@ class PipelineStageService @Autowired constructor( } } + fun checkQualityFailStage(userId: String, buildStage: PipelineBuildStage) { + with(buildStage) { + val allStageStatus = stageBuildDetailService.stageCheckQualityFail(buildId = buildId, stageId = stageId) + dslContext.transaction { configuration -> + val context = DSL.using(configuration) + pipelineBuildStageDao.updateOptions( + dslContext = context, buildId = buildId, + stageId = stageId, controlOption = controlOption!!, + checkIn = checkIn, checkOut = checkOut + ) + pipelineBuildDao.updateBuildStageStatus( + dslContext = context, buildId = buildId, stageStatus = allStageStatus + ) + } + pipelineEventDispatcher.dispatch( + PipelineBuildWebSocketPushEvent( + source = "checkQualityFailStage", projectId = projectId, pipelineId = pipelineId, + userId = userId, buildId = buildId, refreshTypes = RefreshType.HISTORY.binary + ) + ) + } + } + fun pauseStage(userId: String, buildStage: PipelineBuildStage) { with(buildStage) { // TODO 暂时只处理准入逻辑,后续和checkOut保持逻辑一致 diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/detail/StageBuildDetailService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/detail/StageBuildDetailService.kt index 5da39d1bf7f..3b0522d7c4a 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/detail/StageBuildDetailService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/detail/StageBuildDetailService.kt @@ -190,8 +190,9 @@ class StageBuildDetailService( controlOption: PipelineBuildStageControlOption, checkIn: StagePauseCheck?, checkOut: StagePauseCheck? - ) { + ): List { logger.info("[$buildId]|stage_cancel|stageId=$stageId") + var allStageStatus: List? = null update(buildId, object : ModelInterface { var update = false @@ -203,6 +204,7 @@ class StageBuildDetailService( stage.stageControlOption = controlOption.stageControlOption stage.checkIn = checkIn stage.checkOut = checkOut + allStageStatus = fetchHistoryStageStatus(model) return Traverse.BREAK } return Traverse.CONTINUE @@ -212,6 +214,7 @@ class StageBuildDetailService( return update } }, BuildStatus.FAILED) + return allStageStatus ?: emptyList() } fun stageReview( diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/CheckPauseReviewStageCmd.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/CheckPauseReviewStageCmd.kt index de4d6d0ef58..be87abcbd57 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/CheckPauseReviewStageCmd.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/CheckPauseReviewStageCmd.kt @@ -86,7 +86,7 @@ class CheckPauseReviewStageCmd( commandContext.stage.checkIn?.status = BuildStatus.QUALITY_CHECK_FAIL.name commandContext.buildStatus = BuildStatus.QUALITY_CHECK_FAIL commandContext.latestSummary = "s(${stage.stageId}) failed with QUALITY_CHECK_IN" - commandContext.cmdFlowState = CmdFlowState.CONTINUE + commandContext.cmdFlowState = CmdFlowState.FINALLY return } 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 824fa8d729b..deafebf054a 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 @@ -89,6 +89,8 @@ class UpdateStateForStageCmdFinally( } else if (commandContext.buildStatus.isFinish()) { // 当前Stage结束 if (commandContext.buildStatus == BuildStatus.SKIP) { // 跳过 pipelineStageService.skipStage(userId = event.userId, buildStage = stage) + } else if (commandContext.buildStatus == BuildStatus.QUALITY_CHECK_FAIL) { + pipelineStageService.checkQualityFailStage(userId = event.userId, buildStage = stage) } nextOrFinish(event, stage, commandContext) sendStageEndCallBack(stage, event) @@ -112,8 +114,7 @@ class UpdateStateForStageCmdFinally( val gotoFinal = commandContext.buildStatus.isFailure() || commandContext.buildStatus.isCancel() || commandContext.fastKill || - event.source == BS_STAGE_CANCELED_END_SOURCE || - event.source == BS_STAGE_QUALITY_CHECK_FAIL_END_SOURCE + event.source == BS_STAGE_CANCELED_END_SOURCE if (gotoFinal) { nextStage = pipelineStageService.getLastStage(buildId = event.buildId)