diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/SubPipelineRefDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/SubPipelineRefDao.kt index 6a43416f431..8b48c50794d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/SubPipelineRefDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/SubPipelineRefDao.kt @@ -27,8 +27,8 @@ package com.tencent.devops.process.dao -import com.tencent.devops.model.process.tables.TSubPipelineRef -import com.tencent.devops.model.process.tables.records.TSubPipelineRefRecord +import com.tencent.devops.model.process.tables.TPipelineSubRef +import com.tencent.devops.model.process.tables.records.TPipelineSubRefRecord import com.tencent.devops.process.pojo.pipeline.SubPipelineRef import org.jooq.DSLContext import org.jooq.Result @@ -45,7 +45,7 @@ class SubPipelineRefDao { return } - with(TSubPipelineRef.T_SUB_PIPELINE_REF) { + with(TPipelineSubRef.T_PIPELINE_SUB_REF) { dslContext.batch( subPipelineRefList.map { dslContext.insertInto( @@ -90,8 +90,8 @@ class SubPipelineRefDao { dslContext: DSLContext, projectId: String, pipelineId: String - ): Result { - return with(TSubPipelineRef.T_SUB_PIPELINE_REF) { + ): Result { + return with(TPipelineSubRef.T_PIPELINE_SUB_REF) { dslContext.selectFrom(this).where( PROJECT_ID.eq(projectId).and( PIPELINE_ID.eq(pipelineId) @@ -105,7 +105,7 @@ class SubPipelineRefDao { projectId: String, pipelineId: String ): Int { - return with(TSubPipelineRef.T_SUB_PIPELINE_REF) { + return with(TPipelineSubRef.T_PIPELINE_SUB_REF) { dslContext.deleteFrom(this).where( PROJECT_ID.eq(projectId).and( PIPELINE_ID.eq(pipelineId) @@ -114,6 +114,23 @@ class SubPipelineRefDao { } } + fun delete( + dslContext: DSLContext, + projectId: String, + pipelineId: String, + taskId: String + ): Int { + return with(TPipelineSubRef.T_PIPELINE_SUB_REF) { + dslContext.deleteFrom(this).where( + listOf( + PROJECT_ID.eq(projectId), + PIPELINE_ID.eq(pipelineId), + TASK_ID.eq(taskId) + ) + ).execute() + } + } + fun batchDelete( dslContext: DSLContext, ids: List @@ -121,7 +138,7 @@ class SubPipelineRefDao { if (ids.isEmpty()) { return } - with(TSubPipelineRef.T_SUB_PIPELINE_REF) { + with(TPipelineSubRef.T_PIPELINE_SUB_REF) { dslContext.deleteFrom(this).where( ID.`in`(ids) ).execute() diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineCreateListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineCreateListener.kt index caaeacb6898..216a39bf6eb 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineCreateListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineCreateListener.kt @@ -37,7 +37,6 @@ import com.tencent.devops.process.engine.service.AgentPipelineRefService import com.tencent.devops.process.engine.service.PipelineAtomStatisticsService import com.tencent.devops.process.engine.service.RepoPipelineRefService import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.service.pipeline.SubPipelineRefService import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @@ -54,7 +53,6 @@ class MQPipelineCreateListener @Autowired constructor( private val callBackControl: CallBackControl, private val agentPipelineRefService: AgentPipelineRefService, private val repoPipelineRefService: RepoPipelineRefService, - private val subPipelineRefService: SubPipelineRefService, pipelineEventDispatcher: PipelineEventDispatcher ) : BaseListener(pipelineEventDispatcher) { @@ -94,12 +92,6 @@ class MQPipelineCreateListener @Autowired constructor( } } - watcher.safeAround("saveSubPipelineRef") { - with(event) { - subPipelineRefService.updateSubPipelineRef(userId, projectId, pipelineId) - } - } - LogUtils.printCostTimeWE(watcher = watcher) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineRestoreListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineRestoreListener.kt index 78add796006..20a02f52078 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineRestoreListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineRestoreListener.kt @@ -36,7 +36,6 @@ import com.tencent.devops.process.engine.pojo.event.PipelineRestoreEvent import com.tencent.devops.process.engine.service.AgentPipelineRefService import com.tencent.devops.process.engine.service.PipelineAtomStatisticsService import com.tencent.devops.process.engine.service.RepoPipelineRefService -import com.tencent.devops.process.service.pipeline.SubPipelineRefService import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @@ -51,7 +50,6 @@ class MQPipelineRestoreListener @Autowired constructor( private val pipelineAtomStatisticsService: PipelineAtomStatisticsService, private val callBackControl: CallBackControl, private val repoPipelineRefService: RepoPipelineRefService, - private val subPipelineRefService: SubPipelineRefService, pipelineEventDispatcher: PipelineEventDispatcher ) : BaseListener(pipelineEventDispatcher) { @@ -76,8 +74,6 @@ class MQPipelineRestoreListener @Autowired constructor( callBackControl.pipelineRestoreEvent(projectId = event.projectId, pipelineId = event.pipelineId) with(event) { repoPipelineRefService.updateRepoPipelineRef(userId, "restore_pipeline", projectId, pipelineId) - // 更新子流水线关联关系 - subPipelineRefService.updateSubPipelineRef(userId, projectId, pipelineId) } } finally { watcher.stop() diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineUpdateListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineUpdateListener.kt index 685457cf226..167cf1cf2bb 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineUpdateListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/listener/pipeline/MQPipelineUpdateListener.kt @@ -38,7 +38,6 @@ import com.tencent.devops.process.engine.service.PipelineAtomStatisticsService import com.tencent.devops.process.engine.service.RepoPipelineRefService import com.tencent.devops.process.engine.service.PipelineRuntimeService import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.service.pipeline.SubPipelineRefService import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @@ -55,7 +54,6 @@ class MQPipelineUpdateListener @Autowired constructor( private val agentPipelineRefService: AgentPipelineRefService, private val pipelineWebhookService: PipelineWebhookService, private val repoPipelineRefService: RepoPipelineRefService, - private val subPipelineRefService: SubPipelineRefService, pipelineEventDispatcher: PipelineEventDispatcher ) : BaseListener(pipelineEventDispatcher) { @@ -100,13 +98,6 @@ class MQPipelineUpdateListener @Autowired constructor( } } - watcher.safeAround("updateSubPipelineRef") { - with(event) { - // 更新子流水线关联关系 - subPipelineRefService.updateSubPipelineRef(userId, projectId, pipelineId) - } - } - LogUtils.printCostTimeWE(watcher) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/pipeline/SubPipelineRefService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/pipeline/SubPipelineRefService.kt index 725a4efd549..080bf4f3f71 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/pipeline/SubPipelineRefService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/pipeline/SubPipelineRefService.kt @@ -29,6 +29,7 @@ package com.tencent.devops.process.service.pipeline import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.exception.ErrorCodeException +import com.tencent.devops.common.api.exception.OperationException import com.tencent.devops.common.api.util.EnvUtils import com.tencent.devops.common.pipeline.Model import com.tencent.devops.common.pipeline.container.Stage @@ -41,6 +42,9 @@ import com.tencent.devops.common.pipeline.pojo.element.atom.SubPipelineType import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement import com.tencent.devops.common.util.ThreadPoolUtil +import com.tencent.devops.common.web.utils.I18nUtil +import com.tencent.devops.model.process.tables.TPipelineSubRef +import com.tencent.devops.model.process.tables.records.TPipelineSubRefRecord import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.dao.SubPipelineRefDao import com.tencent.devops.process.engine.dao.PipelineInfoDao @@ -295,6 +299,15 @@ class SubPipelineRefService @Autowired constructor( return PipelineVarUtil.fillVariableMap(paramsMap.mapValues { it.value.defaultValue.toString() }) } +// fun getContextMap(projectId: String,pipelineId: String): Map { +// val triggerContainer = (triggerStage.containers.getOrNull(0) ?: throw ErrorCodeException( +// errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NEED_JOB +// )) as TriggerContainer +// // 检查触发容器 +// val paramsMap = PipelineUtils.checkPipelineParams(triggerContainer.params) +// return PipelineVarUtil.fillVariableMap(paramsMap.mapValues { it.value.defaultValue.toString() }) +// } + private fun resolveSubPipelineCall( projectId: String, element: SubPipelineCallElement, @@ -395,17 +408,21 @@ class SubPipelineRefService @Autowired constructor( fun checkCircularDependency( projectId: String, pipelineId: String, - existsPipeline: List + existsPipeline: MutableMap ): ElementCheckResult { // :TODO 递归校验 // val subPipelineList = subPipelineRefDao.list(dslContext, projectId, pipelineId) -// val intersect = existsPipeline.intersect(subPipelineList) -// if (intersect.isNotEmpty()) { -// return ElementCheckResult( -// result = false, -// errorTitle = "", -// errorMessage = "" -// ) +// subPipelineList.forEach { +// val pipelineItem = "${it.projectId}_${it.pipelineId}" +// if (existsPipeline.contains(pipelineItem)){ +// throw OperationException( +// I18nUtil.getCodeLanMessage( +// messageCode = ProcessMessageCode.ERROR_SUB_PIPELINE_NOT_ALLOWED_CIRCULAR_CALL, +// params = arrayOf(projectId, pipelineId) +// ) +// ) +// } +// checkCircularDependency(it.projectId,it.pipelineId,existsPipeline) // } return ElementCheckResult(result = true) }