From 35407145f1fcf9b4c1d69f8235c622f52cb7742b Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 19 Oct 2023 18:25:47 +0800 Subject: [PATCH 01/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/pipeline/enums/AtomChangeAction.kt | 43 +++++++ .../pipeline/extend/ModelCheckPlugin.kt | 25 ++++ .../pojo/element/atom/AfterCreateParam.kt | 57 +++++++++ .../pojo/element/atom/AtomChangeEventParam.kt | 40 +++++++ .../pojo/element/atom/BeforeDeleteParam.kt | 24 +++- .../pojo/element/atom/BeforeUpdateParam.kt | 53 ++++++++ .../plugin/MarketBuildAtomElementBizPlugin.kt | 43 +++++-- .../MarketBuildLessAtomElementBizPlugin.kt | 44 +++++-- .../engine/atom/plugin/MarketBuildUtils.kt | 113 ++++++++++++++---- .../engine/extend/DefaultModelCheckPlugin.kt | 85 ++++++++++++- .../service/PipelineRepositoryService.kt | 33 ++--- .../devops/process/plugin/ElementBizPlugin.kt | 20 ++-- .../element/TimerTriggerElementBizPlugin.kt | 88 +++++++------- .../service/PipelineInfoFacadeService.kt | 42 +++++-- .../webhook/WebHookTriggerElementBizPlugin.kt | 26 ++-- 15 files changed, 576 insertions(+), 160 deletions(-) create mode 100644 src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/AtomChangeAction.kt create mode 100644 src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt create mode 100644 src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AtomChangeEventParam.kt create mode 100644 src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeUpdateParam.kt diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/AtomChangeAction.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/AtomChangeAction.kt new file mode 100644 index 00000000000..bdc30df05dd --- /dev/null +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/AtomChangeAction.kt @@ -0,0 +1,43 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.common.pipeline.enums + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("插件修改动作枚举") +enum class AtomChangeAction { + @ApiModelProperty("创建") + CREATE, + + @ApiModelProperty("修改") + UPDATE, + + @ApiModelProperty("删除") + DELETE +} \ No newline at end of file diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/extend/ModelCheckPlugin.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/extend/ModelCheckPlugin.kt index 1664370f653..039ed5012cb 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/extend/ModelCheckPlugin.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/extend/ModelCheckPlugin.kt @@ -32,7 +32,9 @@ import com.tencent.devops.common.pipeline.Model import com.tencent.devops.common.pipeline.container.Container import com.tencent.devops.common.pipeline.option.JobControlOption import com.tencent.devops.common.pipeline.pojo.element.Element +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam /** * 对流水线模型中的设置的agent进行检查的扩展点 @@ -84,4 +86,27 @@ interface ModelCheckPlugin { */ @Throws(ErrorCodeException::class) fun checkJobCondition(container: Container, finallyStage: Boolean, contextMap: Map) + + /** + * 在修改element前做的一些处理 + * 对比sourceModel,并清理model中与之不同的Element + * @param existModel 目标Model(要修改的Model) + * @param sourceModel 源要比较的Model + */ + fun beforeUpdateElementInExistsModel( + existModel: Model, + sourceModel: Model? = null, + param: BeforeUpdateParam + ) + + /** + * 在添加element后做的一些处理 + * @param existModel 目标Model(要修改的Model) + * @param sourceModel 源要比较的Model + */ + fun afterCreateElementInExistsModel( + existModel: Model, + sourceModel: Model? = null, + param: AfterCreateParam + ) } diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt new file mode 100644 index 00000000000..19f3c17df76 --- /dev/null +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt @@ -0,0 +1,57 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.common.pipeline.pojo.element.atom + +import com.tencent.devops.common.pipeline.container.Container +import com.tencent.devops.common.pipeline.enums.AtomChangeAction +import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.pojo.element.Element +import com.tencent.devops.common.pipeline.pojo.element.EmptyElement +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("新增插件时的后置操作参数") +data class AfterCreateParam( + @ApiModelProperty("用户名") + override val userId: String, + @ApiModelProperty("项目ID") + override val projectId: String, + @ApiModelProperty("流水线Id") + override val pipelineId: String, + @ApiModelProperty("渠道") + override val channelCode: ChannelCode = ChannelCode.BS, + @ApiModelProperty("动作") + override val action: AtomChangeAction = AtomChangeAction.CREATE, + val pipelineName: String = "", + @ApiModelProperty("是否创建") + val create: Boolean = true, + @ApiModelProperty("容器") + val container: Container? = null, + @ApiModelProperty("插件配置") + var element: Element = EmptyElement() +) : AtomChangeEventParam diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AtomChangeEventParam.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AtomChangeEventParam.kt new file mode 100644 index 00000000000..115daf7e0b6 --- /dev/null +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AtomChangeEventParam.kt @@ -0,0 +1,40 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.common.pipeline.pojo.element.atom + +import com.tencent.devops.common.pipeline.enums.AtomChangeAction +import com.tencent.devops.common.pipeline.enums.ChannelCode + +interface AtomChangeEventParam { + val userId: String + val projectId: String + val pipelineId: String + val channelCode: ChannelCode + val action: AtomChangeAction +} + diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeDeleteParam.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeDeleteParam.kt index 19dedbfd90c..ca280ef3d10 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeDeleteParam.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeDeleteParam.kt @@ -27,11 +27,25 @@ package com.tencent.devops.common.pipeline.pojo.element.atom +import com.tencent.devops.common.pipeline.enums.AtomChangeAction import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.pojo.element.Element +import com.tencent.devops.common.pipeline.pojo.element.EmptyElement +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty +@ApiModel("删除插件时的前置操作参数") data class BeforeDeleteParam( - val userId: String, - val projectId: String, - val pipelineId: String, - val channelCode: ChannelCode = ChannelCode.BS -) + @ApiModelProperty("用户名") + override val userId: String, + @ApiModelProperty("项目ID") + override val projectId: String, + @ApiModelProperty("流水线Id") + override val pipelineId: String, + @ApiModelProperty("渠道") + override val channelCode: ChannelCode = ChannelCode.BS, + @ApiModelProperty("动作") + override val action: AtomChangeAction = AtomChangeAction.DELETE, + @ApiModelProperty("插件配置") + var element: Element = EmptyElement() +) : AtomChangeEventParam diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeUpdateParam.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeUpdateParam.kt new file mode 100644 index 00000000000..2b16efc7143 --- /dev/null +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeUpdateParam.kt @@ -0,0 +1,53 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.common.pipeline.pojo.element.atom + +import com.tencent.devops.common.pipeline.enums.AtomChangeAction +import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.pojo.element.Element +import com.tencent.devops.common.pipeline.pojo.element.EmptyElement +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("修改插件时的前置操作参数") +data class BeforeUpdateParam( + @ApiModelProperty("用户名") + override val userId: String, + @ApiModelProperty("项目ID") + override val projectId: String, + @ApiModelProperty("流水线Id") + override val pipelineId: String, + @ApiModelProperty("渠道") + override val channelCode: ChannelCode = ChannelCode.BS, + @ApiModelProperty("动作") + override val action: AtomChangeAction = AtomChangeAction.UPDATE, + @ApiModelProperty("旧插件配置") + var oldElement: Element = EmptyElement(), + @ApiModelProperty("新插件配置") + var newElement: Element = EmptyElement() +) : AtomChangeEventParam diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildAtomElementBizPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildAtomElementBizPlugin.kt index 125a0b021b1..3bf7658fc55 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildAtomElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildAtomElementBizPlugin.kt @@ -27,10 +27,11 @@ package com.tencent.devops.process.engine.atom.plugin -import com.tencent.devops.common.pipeline.container.Container -import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement +import com.tencent.devops.common.pipeline.enums.AtomChangeAction import com.tencent.devops.process.plugin.ElementBizPlugin import com.tencent.devops.process.plugin.annotation.ElementBiz @@ -43,18 +44,38 @@ class MarketBuildAtomElementBizPlugin : ElementBizPlugin override fun afterCreate( element: MarketBuildAtomElement, - projectId: String, - pipelineId: String, - pipelineName: String, - userId: String, - channelCode: ChannelCode, - create: Boolean, - container: Container - ) = Unit + param: AfterCreateParam + ) { + val inputMap = element.data["input"] as Map + MarketBuildUtils.changeAction( + inputMap = inputMap, + atomCode = element.getAtomCode(), + atomVersion = element.version, + param = param, + action = AtomChangeAction.CREATE + ) + } override fun beforeDelete(element: MarketBuildAtomElement, param: BeforeDeleteParam) { val inputMap = element.data["input"] as Map - MarketBuildUtils.beforeDelete(inputMap, element.getAtomCode(), element.version, param) + MarketBuildUtils.changeAction( + inputMap = inputMap, + atomCode = element.getAtomCode(), + atomVersion = element.version, + param = param, + action = AtomChangeAction.DELETE + ) + } + + override fun beforeUpdate(element: MarketBuildAtomElement, param: BeforeUpdateParam) { + val inputMap = element.data["input"] as Map + MarketBuildUtils.changeAction( + inputMap = inputMap, + atomCode = element.getAtomCode(), + atomVersion = element.version, + param = param, + action = AtomChangeAction.UPDATE + ) } override fun check(element: MarketBuildAtomElement, appearedCnt: Int) = Unit diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildLessAtomElementBizPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildLessAtomElementBizPlugin.kt index c4348f35cbf..779d9fea953 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildLessAtomElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildLessAtomElementBizPlugin.kt @@ -27,10 +27,11 @@ package com.tencent.devops.process.engine.atom.plugin -import com.tencent.devops.common.pipeline.container.Container -import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement +import com.tencent.devops.common.pipeline.enums.AtomChangeAction import com.tencent.devops.process.plugin.ElementBizPlugin import com.tencent.devops.process.plugin.annotation.ElementBiz @@ -41,20 +42,37 @@ class MarketBuildLessAtomElementBizPlugin : ElementBizPlugin + MarketBuildUtils.changeAction( + inputMap = inputMap, + atomCode = element.getAtomCode(), + atomVersion = element.version, + param = param, + action = AtomChangeAction.CREATE + ) + } override fun beforeDelete(element: MarketBuildLessAtomElement, param: BeforeDeleteParam) { val inputMap = element.data["input"] as Map - MarketBuildUtils.beforeDelete(inputMap, element.getAtomCode(), element.version, param) + MarketBuildUtils.changeAction( + inputMap = inputMap, + atomCode = element.getAtomCode(), + atomVersion = element.version, + param = param, + action = AtomChangeAction.DELETE + ) + } + + override fun beforeUpdate(element: MarketBuildLessAtomElement, param: BeforeUpdateParam) { + val inputMap = element.data["input"] as Map + MarketBuildUtils.changeAction( + inputMap = inputMap, + atomCode = element.getAtomCode(), + atomVersion = element.version, + param = param, + action = AtomChangeAction.UPDATE + ) } override fun check(element: MarketBuildLessAtomElement, appearedCnt: Int) = Unit diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildUtils.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildUtils.kt index 05f0362857f..44dace1c149 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildUtils.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildUtils.kt @@ -29,11 +29,13 @@ package com.tencent.devops.process.engine.atom.plugin import com.google.common.cache.CacheBuilder import com.google.common.cache.CacheLoader +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.OkhttpUtils import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.enums.ChannelCode -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.atom.AtomChangeEventParam import com.tencent.devops.common.service.utils.SpringContextUtil +import com.tencent.devops.common.pipeline.enums.AtomChangeAction import com.tencent.devops.store.api.atom.ServiceAtomResource import com.tencent.devops.store.pojo.atom.PipelineAtom import okhttp3.Request @@ -46,9 +48,18 @@ import javax.ws.rs.HttpMethod object MarketBuildUtils { private const val INPUT_PARAM = "input" - private const val BK_ATOM_HOOK_URL = "bk_atom_del_hook_url" - private const val BK_ATOM_HOOK_URL_METHOD = "bk_atom_del_hook_url_method" - private const val BK_ATOM_HOOK_URL_BODY = "bk_atom_del_hook_url_body" + // 插件删除 + private const val BK_ATOM_DEL_HOOK_URL = "bk_atom_del_hook_url" + private const val BK_ATOM_DEL_HOOK_URL_METHOD = "bk_atom_del_hook_url_method" + private const val BK_ATOM_DEL_HOOK_URL_BODY = "bk_atom_del_hook_url_body" + // 插件添加 + private const val BK_ATOM_CREATE_HOOK_URL = "bk_atom_add_hook_url" + private const val BK_ATOM_CREATE_HOOK_URL_METHOD = "bk_atom_add_hook_url_method" + private const val BK_ATOM_CREATE_HOOK_URL_BODY = "bk_atom_add_hook_url_body" + // 插件修改 + private const val BK_ATOM_UPDATE_HOOK_URL = "bk_atom_update_hook_url" + private const val BK_ATOM_UPDATE_HOOK_URL_METHOD = "bk_atom_update_hook_url_method" + private const val BK_ATOM_UPDATE_HOOK_URL_BODY = "bk_atom_update_hook_url_body" private const val PROJECT_ID = "projectId" private const val PIPELINE_ID = "pipelineId" @@ -80,26 +91,46 @@ object MarketBuildUtils { ArrayBlockingQueue(16000) ) - fun beforeDelete(inputMap: Map, atomCode: String, atomVersion: String, param: BeforeDeleteParam) { + fun changeAction( + inputMap: Map, + atomCode: String, + atomVersion: String, + param: AtomChangeEventParam, + action: AtomChangeAction + ) { marketBuildExecutorService.execute { - logger.info("start to do before delete: $atomCode, $atomVersion, $param") + logger.info("start to do [$action]: $atomCode, $atomVersion, $param") val bkAtomHookUrl = inputMap.getOrDefault( - BK_ATOM_HOOK_URL, - getDefaultHookUrl(atomCode = atomCode, atomVersion = atomVersion, channelCode = param.channelCode) + getHookUrl(action), + getDefaultHookUrl( + atomCode = atomCode, + atomVersion = atomVersion, + channelCode = param.channelCode, + hookUrlParamKey = getHookUrl(action) + ) ) as String if (bkAtomHookUrl.isBlank()) { logger.info("bk atom hook url is blank: $atomCode, $atomVersion") return@execute } - + // hook方法 val bkAtomHookUrlMethod = inputMap.getOrDefault( - key = BK_ATOM_HOOK_URL_METHOD, - defaultValue = getDefaultHookMethod(atomCode, atomVersion) + key = getHookMethod(action), + defaultValue = getDefaultHookMethod( + atomCode = atomCode, + atomVersion = atomVersion, + hookUrlMethodParamKey = getHookMethod(action) + ) ) as String + // 请求体 val bkAtomHookBody = inputMap.getOrDefault( - BK_ATOM_HOOK_URL_BODY, - getDefaultHookBody(atomCode, atomVersion) + getHookBody(action), + getDefaultHookBody( + atomCode = atomCode, + atomVersion = atomVersion, + hookUrlMethodBodyKey = getHookBody(action) + ) ) as String doHttp(bkAtomHookUrl, bkAtomHookUrlMethod, bkAtomHookBody, param, inputMap) @@ -110,7 +141,7 @@ object MarketBuildUtils { bkAtomHookUrl: String, bkAtomHookUrlMethod: String, bkAtomHookBody: String, - param: BeforeDeleteParam, + param: AtomChangeEventParam, inputMap: Map ) { val url = resolveParam(bkAtomHookUrl, param, inputMap) @@ -118,17 +149,21 @@ object MarketBuildUtils { .url(url) logger.info("start to market build atom http: $url, $bkAtomHookUrlMethod, $bkAtomHookBody") - + // 没有配置hookBody时,增加默认接口入参 + val requestBody = if (bkAtomHookBody.isBlank()) { + logger.info("the atom hook body config is empty|atomParam[$param]") + JsonUtil.toJson(param,false) + }else{ + resolveParam(bkAtomHookBody, param, inputMap) + } when (bkAtomHookUrlMethod) { HttpMethod.GET -> { request = request.get() } HttpMethod.POST -> { - val requestBody = resolveParam(bkAtomHookBody, param, inputMap) request = request.post(RequestBody.create(OkhttpUtils.jsonMediaType, requestBody)) } HttpMethod.PUT -> { - val requestBody = resolveParam(bkAtomHookBody, param, inputMap) request = request.put(RequestBody.create(OkhttpUtils.jsonMediaType, requestBody)) } HttpMethod.DELETE -> { @@ -143,44 +178,53 @@ object MarketBuildUtils { } @Suppress("ALL") - private fun getDefaultHookUrl(atomCode: String, atomVersion: String, channelCode: ChannelCode): String { + private fun getDefaultHookUrl( + atomCode: String, + atomVersion: String, + channelCode: ChannelCode, + hookUrlParamKey: String + ): String { if (channelCode != ChannelCode.BS) return "" val inputMap = atomCache.get("$atomCode|$atomVersion")?.props?.get(INPUT_PARAM) if (inputMap == null || inputMap !is Map<*, *>) { return "" } - val bkAtomHookUrlItem = inputMap[BK_ATOM_HOOK_URL] + val bkAtomHookUrlItem = inputMap[hookUrlParamKey] if (bkAtomHookUrlItem != null && bkAtomHookUrlItem is Map<*, *>) { return bkAtomHookUrlItem["default"]?.toString() ?: "" } return "" } - private fun getDefaultHookMethod(atomCode: String, atomVersion: String): String { + private fun getDefaultHookMethod( + atomCode: String, + atomVersion: String, + hookUrlMethodParamKey: String + ): String { val inputMap = atomCache.get("$atomCode|$atomVersion")?.props?.get(INPUT_PARAM) if (inputMap == null || inputMap !is Map<*, *>) { return "" } - val bkAtomHookUrlItem = inputMap[BK_ATOM_HOOK_URL_METHOD] + val bkAtomHookUrlItem = inputMap[hookUrlMethodParamKey] if (bkAtomHookUrlItem != null && bkAtomHookUrlItem is Map<*, *>) { - return bkAtomHookUrlItem["default"]?.toString() ?: "GET" + return bkAtomHookUrlItem["default"]?.toString() ?: "POST" } - return "GET" + return "POST" } - private fun getDefaultHookBody(atomCode: String, atomVersion: String): String { + private fun getDefaultHookBody(atomCode: String, atomVersion: String, hookUrlMethodBodyKey: String): String { val inputMap = atomCache.get("$atomCode|$atomVersion")?.props?.get(INPUT_PARAM) if (inputMap == null || inputMap !is Map<*, *>) { return "" } - val bkAtomHookUrlItem = inputMap[BK_ATOM_HOOK_URL_BODY] + val bkAtomHookUrlItem = inputMap[hookUrlMethodBodyKey] if (bkAtomHookUrlItem != null && bkAtomHookUrlItem is Map<*, *>) { return bkAtomHookUrlItem["default"]?.toString() ?: "" } return "" } - private fun resolveParam(str: String, param: BeforeDeleteParam, inputMap: Map): String { + private fun resolveParam(str: String, param: AtomChangeEventParam, inputMap: Map): String { var result = str.replace("{$PROJECT_ID}", param.projectId) .replace("{$PIPELINE_ID}", param.pipelineId) .replace("{$USER_ID}", param.userId) @@ -197,4 +241,21 @@ object MarketBuildUtils { return result.replace(Regex("\\{.*}"), "") .replace(Regex("%7B.*%7D"), "") } + private fun getHookUrl(pluginChangeAction: AtomChangeAction) = when (pluginChangeAction) { + AtomChangeAction.DELETE -> BK_ATOM_DEL_HOOK_URL + AtomChangeAction.UPDATE -> BK_ATOM_UPDATE_HOOK_URL + AtomChangeAction.CREATE -> BK_ATOM_CREATE_HOOK_URL + } + + private fun getHookMethod(pluginChangeAction: AtomChangeAction) = when (pluginChangeAction) { + AtomChangeAction.DELETE -> BK_ATOM_DEL_HOOK_URL_METHOD + AtomChangeAction.UPDATE -> BK_ATOM_UPDATE_HOOK_URL_METHOD + AtomChangeAction.CREATE -> BK_ATOM_CREATE_HOOK_URL_METHOD + } + + private fun getHookBody(pluginChangeAction: AtomChangeAction) = when (pluginChangeAction) { + AtomChangeAction.DELETE -> BK_ATOM_DEL_HOOK_URL_BODY + AtomChangeAction.UPDATE -> BK_ATOM_UPDATE_HOOK_URL_BODY + AtomChangeAction.CREATE -> BK_ATOM_CREATE_HOOK_URL_BODY + } } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index 7de6f06e6a2..f5133476293 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -41,7 +41,10 @@ import com.tencent.devops.common.pipeline.enums.JobRunCondition import com.tencent.devops.common.pipeline.extend.ModelCheckPlugin import com.tencent.devops.common.pipeline.pojo.BuildFormProperty import com.tencent.devops.common.pipeline.pojo.element.Element +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam +import com.tencent.devops.common.pipeline.pojo.element.atom.AtomChangeEventParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement import com.tencent.devops.process.constant.ProcessMessageCode @@ -367,23 +370,41 @@ open class DefaultModelCheckPlugin constructor( return false } + private fun Model.elementFind(originElement: Element): Element? { + stages.forEach { s -> + s.containers.forEach { c -> + val element = loopFindElement(c.elements, originElement) + if (element != null) { + return element + } + } + } + return null + } + + private fun loopFindElement(elements: List, originElement: Element): Element? { + elements.forEach { e -> + if (e.stepId?.let { it == originElement.stepId } == true || e.id == originElement.id) { + return e + } + } + return null + } + override fun beforeDeleteElementInExistsModel( existModel: Model, sourceModel: Model?, param: BeforeDeleteParam ) { - existModel.stages.forEach { s -> - s.containers.forEach { c -> - c.elements.forEach { e -> - deletePrepare(sourceModel, e, param) - } - } + recursiveElement(existModel){ + deletePrepare(sourceModel, it, param) } } private fun deletePrepare(sourceModel: Model?, originElement: Element, param: BeforeDeleteParam) { if (sourceModel == null || !sourceModel.elementExist(originElement)) { logger.info("The element(${originElement.name}/${originElement.id}) is delete") + param.element = originElement ElementBizRegistrar.getPlugin(originElement)?.beforeDelete(originElement, param) } else { logger.info("The element(${originElement.name}/${originElement.id}) is not delete") @@ -485,6 +506,58 @@ open class DefaultModelCheckPlugin constructor( } } + override fun beforeUpdateElementInExistsModel(existModel: Model, sourceModel: Model?, param: BeforeUpdateParam) { + recursiveElement(existModel = existModel) { + updatePrepare(sourceModel, it, param) + } + } + + private fun recursiveElement( + existModel: Model, + action: (element: Element) -> Unit + ) { + existModel.stages.forEach { s -> + s.containers.forEach { c -> + c.elements.forEach { e -> + action.invoke(e) + } + } + } + } + + private fun updatePrepare(sourceModel: Model?, originElement: Element, param: BeforeUpdateParam) { + if (sourceModel != null) { + val oldElement = sourceModel.elementFind(originElement) + if (oldElement != null) { + param.newElement = originElement + param.oldElement = oldElement + logger.info("The element(${originElement.name}/${originElement.id}) is update") + ElementBizRegistrar.getPlugin(originElement)?.beforeUpdate(originElement, param) + } else { + logger.info( + "The element(${originElement.name}/${originElement.id}) is not update," + + "the element cannot be found from the model" + ) + } + } else { + logger.info("The element(${originElement.name}/${originElement.id}) is not update") + } + } + + override fun afterCreateElementInExistsModel(existModel: Model, sourceModel: Model?, param: AfterCreateParam) { + recursiveElement(existModel = existModel) { + createPrepare(sourceModel, it, param) + } + } + + private fun createPrepare(sourceModel: Model?, originElement: Element, param: AfterCreateParam) { + if (sourceModel == null) { + param.element = originElement + logger.info("The element(${originElement.name}/${originElement.id}) is create") + ElementBizRegistrar.getPlugin(originElement)?.afterCreate(originElement, param) + } + } + private val finallyStageJobRunConditionSet = setOf( JobRunCondition.PREVIOUS_STAGE_CANCEL, JobRunCondition.PREVIOUS_STAGE_FAILED, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt index 5fe32d9a445..62586a59be2 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt @@ -48,6 +48,7 @@ import com.tencent.devops.common.pipeline.option.MatrixControlOption import com.tencent.devops.common.pipeline.pojo.BuildNo import com.tencent.devops.common.pipeline.pojo.MatrixPipelineInfo import com.tencent.devops.common.pipeline.pojo.element.SubPipelineCallElement +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.trigger.ManualTriggerElement import com.tencent.devops.common.pipeline.utils.MatrixContextUtils import com.tencent.devops.common.redis.RedisOperation @@ -298,13 +299,15 @@ class PipelineRepositoryService constructor( distIds.add(e.id!!) ElementBizRegistrar.getPlugin(e)?.afterCreate( element = e, - projectId = projectId, - pipelineId = pipelineId, - pipelineName = model.name, - userId = userId, - channelCode = channelCode, - create = create, - container = c + param = AfterCreateParam( + projectId = projectId, + pipelineId = pipelineId, + pipelineName = model.name, + userId = userId, + channelCode = channelCode, + create = create, + container = c + ) ) modelTasks.add( @@ -415,13 +418,15 @@ class PipelineRepositoryService constructor( // 补偿动作--未来拆分出来,针对复杂的东西异步处理 ElementBizRegistrar.getPlugin(e)?.afterCreate( element = e, - projectId = projectId, - pipelineId = pipelineId, - pipelineName = model.name, - userId = userId, - channelCode = channelCode, - create = create, - container = c + param = AfterCreateParam( + projectId = projectId, + pipelineId = pipelineId, + pipelineName = model.name, + userId = userId, + channelCode = channelCode, + create = create, + container = c + ) ) modelTasks.add( diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/plugin/ElementBizPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/plugin/ElementBizPlugin.kt index 369e8822bc5..083166e08b5 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/plugin/ElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/plugin/ElementBizPlugin.kt @@ -27,10 +27,10 @@ package com.tencent.devops.process.plugin -import com.tencent.devops.common.pipeline.container.Container -import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.pojo.element.Element +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam /** * 流水线的Element的编排插件处理器 @@ -48,22 +48,18 @@ interface ElementBizPlugin { * 流水线名称[pipelineName],操作人[userId],还有渠道[channelCode],和是否初次新建[create]标识 * 进行创建后的处理 */ - fun afterCreate( - element: T, - projectId: String, - pipelineId: String, - pipelineName: String, - userId: String, - channelCode: ChannelCode = ChannelCode.BS, - create: Boolean, - container: Container - ) + fun afterCreate(element: T, param: AfterCreateParam) /** * 在删除[element]插件之前,根据[param]参数调用删除前的预处理 */ fun beforeDelete(element: T, param: BeforeDeleteParam) + /** + * 在修改[element]插件之前,根据[param]参数调用修改前的预处理 + */ + fun beforeUpdate(element: T, param: BeforeUpdateParam) + /** * 检查[element]插件以及出现的次数[appearedCnt]是否符合要求 */ diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt index d088703151c..7efa2da378e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt @@ -28,10 +28,10 @@ package com.tencent.devops.process.plugin.trigger.element import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.pipeline.container.Container import com.tencent.devops.common.pipeline.container.TriggerContainer -import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.trigger.TimerTriggerElement import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.plugin.ElementBizPlugin @@ -54,59 +54,55 @@ class TimerTriggerElementBizPlugin constructor( override fun afterCreate( element: TimerTriggerElement, - projectId: String, - pipelineId: String, - pipelineName: String, - userId: String, - channelCode: ChannelCode, - create: Boolean, - container: Container + param: AfterCreateParam ) { - val crontabExpressions = mutableSetOf() - val params = (container as TriggerContainer).params.associate { it.id to it.defaultValue.toString() } - logger.info("[$pipelineId]|$userId| Timer trigger [${element.name}] enable=${element.isElementEnable()}") - if (element.isElementEnable()) { + with(param) { + val crontabExpressions = mutableSetOf() + val params = (container as TriggerContainer).params.associate { it.id to it.defaultValue.toString() } + logger.info("[$pipelineId]|$userId| Timer trigger [${element.name}] enable=${element.isElementEnable()}") + if (element.isElementEnable()) { - val eConvertExpressions = element.convertExpressions(params = params) - if (eConvertExpressions.isEmpty()) { - throw ErrorCodeException( - errorCode = ProcessMessageCode.ILLEGAL_TIMER_CRONTAB - ) - } - eConvertExpressions.forEach { cron -> - if (!CronExpression.isValidExpression(cron)) { + val eConvertExpressions = element.convertExpressions(params = params) + if (eConvertExpressions.isEmpty()) { throw ErrorCodeException( - errorCode = ProcessMessageCode.ILLEGAL_TIMER_CRONTAB, - params = arrayOf(cron) + errorCode = ProcessMessageCode.ILLEGAL_TIMER_CRONTAB ) } - if (!CronExpressionUtils.isValidTimeInterval(cron)) { - throw ErrorCodeException( - errorCode = ProcessMessageCode.ILLEGAL_TIMER_INTERVAL_CRONTAB, - params = arrayOf(cron) - ) + eConvertExpressions.forEach { cron -> + if (!CronExpression.isValidExpression(cron)) { + throw ErrorCodeException( + errorCode = ProcessMessageCode.ILLEGAL_TIMER_CRONTAB, + params = arrayOf(cron) + ) + } + if (!CronExpressionUtils.isValidTimeInterval(cron)) { + throw ErrorCodeException( + errorCode = ProcessMessageCode.ILLEGAL_TIMER_INTERVAL_CRONTAB, + params = arrayOf(cron) + ) + } + crontabExpressions.add(cron) } - crontabExpressions.add(cron) } - } - if (crontabExpressions.isNotEmpty()) { - val result = pipelineTimerService.saveTimer( - projectId = projectId, - pipelineId = pipelineId, - userId = userId, - crontabExpressions = crontabExpressions, - channelCode = channelCode - ) - logger.info("[$pipelineId]|$userId| Update pipeline timer|crontab=$crontabExpressions") - if (result.isNotOk()) { - throw ErrorCodeException( - errorCode = ProcessMessageCode.ILLEGAL_TIMER_CRONTAB + if (crontabExpressions.isNotEmpty()) { + val result = pipelineTimerService.saveTimer( + projectId = projectId, + pipelineId = pipelineId, + userId = userId, + crontabExpressions = crontabExpressions, + channelCode = channelCode ) + logger.info("[$pipelineId]|$userId| Update pipeline timer|crontab=$crontabExpressions") + if (result.isNotOk()) { + throw ErrorCodeException( + errorCode = ProcessMessageCode.ILLEGAL_TIMER_CRONTAB + ) + } + } else { + pipelineTimerService.deleteTimer(projectId, pipelineId, userId) + logger.info("[$pipelineId]|$userId| Delete pipeline timer") } - } else { - pipelineTimerService.deleteTimer(projectId, pipelineId, userId) - logger.info("[$pipelineId]|$userId| Delete pipeline timer") } } @@ -116,6 +112,8 @@ class TimerTriggerElementBizPlugin constructor( } } + override fun beforeUpdate(element: TimerTriggerElement, param: BeforeUpdateParam) = Unit + companion object { private val logger = LoggerFactory.getLogger(TimerTriggerElementBizPlugin::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt index 1d11678a6e9..2245ac21963 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt @@ -49,7 +49,9 @@ import com.tencent.devops.common.pipeline.enums.PipelineInstanceTypeEnum import com.tencent.devops.common.pipeline.extend.ModelCheckPlugin import com.tencent.devops.common.pipeline.pojo.BuildFormProperty import com.tencent.devops.common.pipeline.pojo.BuildNo +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.utils.LogUtils import com.tencent.devops.common.web.utils.I18nUtil @@ -455,13 +457,26 @@ class PipelineInfoFacadeService @Autowired constructor( throw ignored } finally { if (!success) { - val beforeDeleteParam = BeforeDeleteParam( - userId = userId, projectId = projectId, pipelineId = pipelineId ?: "", channelCode = channelCode + modelCheckPlugin.afterCreateElementInExistsModel( + existModel = model, + sourceModel = null, + param = AfterCreateParam( + userId = userId, + projectId = projectId, + pipelineId = pipelineId ?: "", + channelCode = channelCode + ) ) + modelCheckPlugin.beforeDeleteElementInExistsModel( existModel = model, sourceModel = null, - param = beforeDeleteParam + param = BeforeDeleteParam( + userId = userId, + projectId = projectId, + pipelineId = pipelineId ?: "", + channelCode = channelCode + ) ) } } @@ -719,13 +734,22 @@ class PipelineInfoFacadeService @Autowired constructor( errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS ) // 对已经存在的模型做处理 - val param = BeforeDeleteParam( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - channelCode = channelCode + modelCheckPlugin.beforeDeleteElementInExistsModel( + existModel, model, BeforeDeleteParam( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + channelCode = channelCode + ) + ) + modelCheckPlugin.beforeUpdateElementInExistsModel( + existModel, model, BeforeUpdateParam( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + channelCode = channelCode + ) ) - modelCheckPlugin.beforeDeleteElementInExistsModel(existModel, model, param) val deployResult = pipelineRepositoryService.deployPipeline( model = model, projectId = projectId, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt index fba577862ff..60f05862580 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt @@ -30,9 +30,10 @@ package com.tencent.devops.process.webhook import com.tencent.devops.common.api.constant.CommonMessageCode import com.tencent.devops.common.api.enums.RepositoryTypeNew import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.pipeline.container.Container import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitGenericWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement @@ -48,16 +49,7 @@ import com.tencent.devops.process.plugin.annotation.ElementBiz abstract class WebHookTriggerElementBizPlugin constructor( private val pipelineWebhookService: PipelineWebhookService ) : ElementBizPlugin { - override fun afterCreate( - element: T, - projectId: String, - pipelineId: String, - pipelineName: String, - userId: String, - channelCode: ChannelCode, - create: Boolean, - container: Container - ) = Unit + override fun afterCreate(element: T, param: AfterCreateParam) = Unit override fun beforeDelete(element: T, param: BeforeDeleteParam) { if (param.pipelineId.isNotBlank()) { @@ -71,6 +63,8 @@ abstract class WebHookTriggerElementBizPlugin constru } override fun check(element: T, appearedCnt: Int) = Unit + + override fun beforeUpdate(element: T, param: BeforeUpdateParam) = Unit } @ElementBiz @@ -144,16 +138,10 @@ class CodeGitGenericWebHookTriggerElementBizPlugin constructor( override fun afterCreate( element: CodeGitGenericWebHookTriggerElement, - projectId: String, - pipelineId: String, - pipelineName: String, - userId: String, - channelCode: ChannelCode, - create: Boolean, - container: Container + param: AfterCreateParam ) { // 只支持codecc才能自定义hookUrl - if (channelCode != ChannelCode.CODECC && !element.data.input.hookUrl.isNullOrBlank()) { + if (param.channelCode != ChannelCode.CODECC && !element.data.input.hookUrl.isNullOrBlank()) { element.data.input.hookUrl = null } } From fbe3fc8b9f8adcd66b8d2dbbed73a3bc223bd96d Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 23 Oct 2023 09:45:37 +0800 Subject: [PATCH 02/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/extend/DefaultModelCheckPlugin.kt | 5 +- .../element/TimerTriggerElementBizPlugin.kt | 1 + .../service/PipelineInfoFacadeService.kt | 56 +++++++++++++++++-- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index f5133476293..b350140c4f3 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -42,7 +42,6 @@ import com.tencent.devops.common.pipeline.extend.ModelCheckPlugin import com.tencent.devops.common.pipeline.pojo.BuildFormProperty import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam -import com.tencent.devops.common.pipeline.pojo.element.atom.AtomChangeEventParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement @@ -551,10 +550,12 @@ open class DefaultModelCheckPlugin constructor( } private fun createPrepare(sourceModel: Model?, originElement: Element, param: AfterCreateParam) { - if (sourceModel == null) { + if (sourceModel == null || !sourceModel.elementExist(originElement)) { param.element = originElement logger.info("The element(${originElement.name}/${originElement.id}) is create") ElementBizRegistrar.getPlugin(originElement)?.afterCreate(originElement, param) + }else { + logger.info("The element(${originElement.name}/${originElement.id}) is not create") } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt index 7efa2da378e..8946ec30ec6 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt @@ -52,6 +52,7 @@ class TimerTriggerElementBizPlugin constructor( override fun check(element: TimerTriggerElement, appearedCnt: Int) = Unit + @SuppressWarnings("NestedBlockDepth") override fun afterCreate( element: TimerTriggerElement, param: AfterCreateParam diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt index 2245ac21963..ff0465faf19 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt @@ -214,6 +214,16 @@ class PipelineInfoFacadeService @Autowired constructor( checkPermission = true, dispatchPipelineUpdateEvent = false ) + modelCheckPlugin.afterCreateElementInExistsModel( + existModel = model, + sourceModel = null, + param = AfterCreateParam( + userId = userId, + projectId = projectId, + pipelineId = newPipelineId ?: "", + channelCode = ChannelCode.BS + ) + ) return newPipelineId } @@ -497,6 +507,7 @@ class PipelineInfoFacadeService @Autowired constructor( channelCode: ChannelCode ): DeployPipelineResult { val watcher = Watcher(id = "restorePipeline|$pipelineId|$userId") + var model: Model? = null try { watcher.start("isProjectManager") // 判断用户是否为项目管理员 @@ -516,7 +527,7 @@ class PipelineInfoFacadeService @Autowired constructor( } watcher.start("restorePipeline") - val model = pipelineRepositoryService.restorePipeline( + model = pipelineRepositoryService.restorePipeline( projectId = projectId, pipelineId = pipelineId, userId = userId, channelCode = channelCode, days = deletedPipelineStoreDays.toLong() ) @@ -529,6 +540,18 @@ class PipelineInfoFacadeService @Autowired constructor( ) return DeployPipelineResult(pipelineId, pipelineName = model.name, version = model.latestVersion) } finally { + if (model != null) { + modelCheckPlugin.afterCreateElementInExistsModel( + existModel = model, + sourceModel = null, + param = AfterCreateParam( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + channelCode = channelCode + ) + ) + } watcher.stop() LogUtils.printCostTimeWE(watcher) } @@ -552,6 +575,10 @@ class PipelineInfoFacadeService @Autowired constructor( ) logger.info("Start to copy the pipeline $pipelineId") + // 新流水线Id + var newPipelineId: String? = null + // 新流水线Model + var newModel: Model? = null if (checkPermission) { val permission = AuthPermission.EDIT pipelinePermissionService.validPipelinePermission( @@ -612,15 +639,15 @@ class PipelineInfoFacadeService @Autowired constructor( errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS ) try { - val copyMode = Model( + newModel = Model( name = pipelineCopy.name, desc = pipelineCopy.desc ?: model.desc, stages = model.stages, staticViews = pipelineCopy.staticViews, labels = pipelineCopy.labels ) - modelCheckPlugin.clearUpModel(copyMode) - val newPipelineId = createPipeline(userId, projectId, copyMode, channelCode) + modelCheckPlugin.clearUpModel(newModel) + newPipelineId = createPipeline(userId, projectId, newModel, channelCode) val settingInfo = pipelineSettingFacadeService.getSettingInfo(projectId, pipelineId) if (settingInfo != null) { // setting pipeline需替换成新流水线的 @@ -658,6 +685,19 @@ class PipelineInfoFacadeService @Autowired constructor( errorCode = ProcessMessageCode.OPERATE_PIPELINE_FAIL, params = arrayOf(e.message ?: "") ) + } finally { + if (newPipelineId.isNullOrBlank() && newModel != null) { + modelCheckPlugin.afterCreateElementInExistsModel( + existModel = newModel, + sourceModel = null, + param = AfterCreateParam( + userId = userId, + projectId = projectId, + pipelineId = newPipelineId!!, + channelCode = channelCode + ) + ) + } } } @@ -750,6 +790,14 @@ class PipelineInfoFacadeService @Autowired constructor( channelCode = channelCode ) ) + modelCheckPlugin.afterCreateElementInExistsModel( + existModel, model, AfterCreateParam( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + channelCode = channelCode + ) + ) val deployResult = pipelineRepositoryService.deployPipeline( model = model, projectId = projectId, From b0006bb59c5010cfdd89c66045721d4410b87782 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 23 Oct 2023 10:12:17 +0800 Subject: [PATCH 03/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipeline/pojo/element/atom/AtomChangeEventParam.kt | 1 - .../devops/process/engine/atom/plugin/MarketBuildUtils.kt | 7 +++++-- .../process/engine/extend/DefaultModelCheckPlugin.kt | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AtomChangeEventParam.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AtomChangeEventParam.kt index 115daf7e0b6..2d66d192f92 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AtomChangeEventParam.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AtomChangeEventParam.kt @@ -37,4 +37,3 @@ interface AtomChangeEventParam { val channelCode: ChannelCode val action: AtomChangeAction } - diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildUtils.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildUtils.kt index 44dace1c149..b9001e68a6f 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildUtils.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildUtils.kt @@ -152,20 +152,23 @@ object MarketBuildUtils { // 没有配置hookBody时,增加默认接口入参 val requestBody = if (bkAtomHookBody.isBlank()) { logger.info("the atom hook body config is empty|atomParam[$param]") - JsonUtil.toJson(param,false) - }else{ + JsonUtil.toJson(param, false) + } else { resolveParam(bkAtomHookBody, param, inputMap) } when (bkAtomHookUrlMethod) { HttpMethod.GET -> { request = request.get() } + HttpMethod.POST -> { request = request.post(RequestBody.create(OkhttpUtils.jsonMediaType, requestBody)) } + HttpMethod.PUT -> { request = request.put(RequestBody.create(OkhttpUtils.jsonMediaType, requestBody)) } + HttpMethod.DELETE -> { request = request.delete() } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index b350140c4f3..8ed02c2f5aa 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -395,7 +395,7 @@ open class DefaultModelCheckPlugin constructor( sourceModel: Model?, param: BeforeDeleteParam ) { - recursiveElement(existModel){ + recursiveElement(existModel) { deletePrepare(sourceModel, it, param) } } @@ -554,7 +554,7 @@ open class DefaultModelCheckPlugin constructor( param.element = originElement logger.info("The element(${originElement.name}/${originElement.id}) is create") ElementBizRegistrar.getPlugin(originElement)?.afterCreate(originElement, param) - }else { + } else { logger.info("The element(${originElement.name}/${originElement.id}) is not create") } } From 3f5811de5f58acc1216b08f92157b00202c6d499 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 25 Oct 2023 09:42:09 +0800 Subject: [PATCH 04/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/common/pipeline/enums/AtomChangeAction.kt | 2 +- .../plugin/trigger/element/TimerTriggerElementBizPlugin.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/AtomChangeAction.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/AtomChangeAction.kt index bdc30df05dd..d58c28bdee2 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/AtomChangeAction.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/enums/AtomChangeAction.kt @@ -40,4 +40,4 @@ enum class AtomChangeAction { @ApiModelProperty("删除") DELETE -} \ No newline at end of file +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt index 8946ec30ec6..058631f8c43 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt @@ -52,7 +52,7 @@ class TimerTriggerElementBizPlugin constructor( override fun check(element: TimerTriggerElement, appearedCnt: Int) = Unit - @SuppressWarnings("NestedBlockDepth") + @SuppressWarnings("NestedBlockDepth", "ComplexMethod") override fun afterCreate( element: TimerTriggerElement, param: AfterCreateParam From c9b77dc93aa4a17453f352752f134d819ed068c5 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 25 Oct 2023 11:09:18 +0800 Subject: [PATCH 05/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/extend/DefaultModelCheckPlugin.kt | 2 ++ .../engine/service/PipelineRepositoryService.kt | 14 -------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index 8ed02c2f5aa..c37bbb1f6c8 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -550,6 +550,8 @@ open class DefaultModelCheckPlugin constructor( } private fun createPrepare(sourceModel: Model?, originElement: Element, param: AfterCreateParam) { + logger.info("createPrepare The element(${originElement.name}/${originElement.id})," + + "sourceModel|[$sourceModel]") if (sourceModel == null || !sourceModel.elementExist(originElement)) { param.element = originElement logger.info("The element(${originElement.name}/${originElement.id}) is create") diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt index 62586a59be2..00d745c50bd 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt @@ -415,20 +415,6 @@ class PipelineRepositoryService constructor( } } - // 补偿动作--未来拆分出来,针对复杂的东西异步处理 - ElementBizRegistrar.getPlugin(e)?.afterCreate( - element = e, - param = AfterCreateParam( - projectId = projectId, - pipelineId = pipelineId, - pipelineName = model.name, - userId = userId, - channelCode = channelCode, - create = create, - container = c - ) - ) - modelTasks.add( PipelineModelTask( projectId = projectId, From c6abd6ae5ed1fdd159073d404daefa9990352f58 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 25 Oct 2023 11:37:51 +0800 Subject: [PATCH 06/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PipelineRepositoryService.kt | 26 ------------------- .../service/PipelineInfoFacadeService.kt | 10 +++---- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt index 00d745c50bd..a70f7f03001 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt @@ -232,11 +232,7 @@ class PipelineRepositoryService constructor( containerSeqId = containerSeqId, projectId = projectId, pipelineId = pipelineId, - model = model, - userId = userId, modelTasks = modelTasks, - channelCode = channelCode, - create = create, distIds = distinctIdSet ) } else { @@ -246,10 +242,7 @@ class PipelineRepositoryService constructor( containerSeqId = containerSeqId, userId = userId, pipelineId = pipelineId, - model = model, modelTasks = modelTasks, - channelCode = channelCode, - create = create, distIds = distinctIdSet ) } @@ -263,11 +256,7 @@ class PipelineRepositoryService constructor( containerSeqId: AtomicInteger, projectId: String, pipelineId: String, - model: Model, - userId: String, modelTasks: MutableList, - channelCode: ChannelCode, - create: Boolean, distIds: HashSet ) { if (stage.containers.size != 1) { @@ -297,18 +286,6 @@ class PipelineRepositoryService constructor( e.id = modelTaskIdGenerator.getNextId() } distIds.add(e.id!!) - ElementBizRegistrar.getPlugin(e)?.afterCreate( - element = e, - param = AfterCreateParam( - projectId = projectId, - pipelineId = pipelineId, - pipelineName = model.name, - userId = userId, - channelCode = channelCode, - create = create, - container = c - ) - ) modelTasks.add( PipelineModelTask( @@ -336,10 +313,7 @@ class PipelineRepositoryService constructor( containerSeqId: AtomicInteger, userId: String, pipelineId: String, - model: Model, modelTasks: MutableList, - channelCode: ChannelCode, - create: Boolean, distIds: HashSet ) { if (stage.containers.isEmpty()) { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt index ff0465faf19..1c9b19dde57 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt @@ -467,21 +467,21 @@ class PipelineInfoFacadeService @Autowired constructor( throw ignored } finally { if (!success) { - modelCheckPlugin.afterCreateElementInExistsModel( + modelCheckPlugin.beforeDeleteElementInExistsModel( existModel = model, sourceModel = null, - param = AfterCreateParam( + param = BeforeDeleteParam( userId = userId, projectId = projectId, pipelineId = pipelineId ?: "", channelCode = channelCode ) ) - - modelCheckPlugin.beforeDeleteElementInExistsModel( + } else { + modelCheckPlugin.afterCreateElementInExistsModel( existModel = model, sourceModel = null, - param = BeforeDeleteParam( + param = AfterCreateParam( userId = userId, projectId = projectId, pipelineId = pipelineId ?: "", From ed9e519953423b2b78e6b37bc56b531a54763e95 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 25 Oct 2023 11:40:34 +0800 Subject: [PATCH 07/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/service/PipelineRepositoryService.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt index a70f7f03001..3bb7b77c766 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt @@ -48,7 +48,6 @@ import com.tencent.devops.common.pipeline.option.MatrixControlOption import com.tencent.devops.common.pipeline.pojo.BuildNo import com.tencent.devops.common.pipeline.pojo.MatrixPipelineInfo import com.tencent.devops.common.pipeline.pojo.element.SubPipelineCallElement -import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.trigger.ManualTriggerElement import com.tencent.devops.common.pipeline.utils.MatrixContextUtils import com.tencent.devops.common.redis.RedisOperation @@ -76,7 +75,6 @@ import com.tencent.devops.process.engine.pojo.event.PipelineCreateEvent import com.tencent.devops.process.engine.pojo.event.PipelineDeleteEvent import com.tencent.devops.process.engine.pojo.event.PipelineRestoreEvent import com.tencent.devops.process.engine.pojo.event.PipelineUpdateEvent -import com.tencent.devops.process.plugin.load.ElementBizRegistrar import com.tencent.devops.process.pojo.PipelineCollation import com.tencent.devops.process.pojo.PipelineName import com.tencent.devops.process.pojo.PipelineSortType From 56419053298139b0325f9aed44327e7afd893ec4 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 26 Oct 2023 11:27:04 +0800 Subject: [PATCH 08/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/engine/extend/DefaultModelCheckPlugin.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index c37bbb1f6c8..900bd8aed59 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -544,6 +544,15 @@ open class DefaultModelCheckPlugin constructor( } override fun afterCreateElementInExistsModel(existModel: Model, sourceModel: Model?, param: AfterCreateParam) { + val sourceModelStr = if (sourceModel != null) { + JsonUtil.toJson(sourceModel, false) + } else { + "" + } + logger.info( + "afterCreateElementInExistsModel|existModel[${JsonUtil.toJson(existModel, false)}]|" + + "sourceModel[${sourceModelStr}]" + ) recursiveElement(existModel = existModel) { createPrepare(sourceModel, it, param) } From c64c039e265581b547e9d8979b5e2a883b355214 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 26 Oct 2023 11:30:47 +0800 Subject: [PATCH 09/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/extend/DefaultModelCheckPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index 900bd8aed59..e116df8364c 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -551,7 +551,7 @@ open class DefaultModelCheckPlugin constructor( } logger.info( "afterCreateElementInExistsModel|existModel[${JsonUtil.toJson(existModel, false)}]|" + - "sourceModel[${sourceModelStr}]" + "sourceModel[$sourceModelStr]" ) recursiveElement(existModel = existModel) { createPrepare(sourceModel, it, param) From 52d99950bcdbc977972611aedf654e3f2fa34ddd Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 26 Oct 2023 14:14:48 +0800 Subject: [PATCH 10/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/service/PipelineInfoFacadeService.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt index 1c9b19dde57..3374bcc1f43 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt @@ -783,7 +783,7 @@ class PipelineInfoFacadeService @Autowired constructor( ) ) modelCheckPlugin.beforeUpdateElementInExistsModel( - existModel, model, BeforeUpdateParam( + model, existModel, BeforeUpdateParam( userId = userId, projectId = projectId, pipelineId = pipelineId, @@ -791,7 +791,7 @@ class PipelineInfoFacadeService @Autowired constructor( ) ) modelCheckPlugin.afterCreateElementInExistsModel( - existModel, model, AfterCreateParam( + model, existModel, AfterCreateParam( userId = userId, projectId = projectId, pipelineId = pipelineId, From 5b04b6e91f8ca71483ac97d0ea9e41dc92ed0375 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 26 Oct 2023 15:42:27 +0800 Subject: [PATCH 11/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/extend/DefaultModelCheckPlugin.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index e116df8364c..aaf03255dc4 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -403,8 +403,10 @@ open class DefaultModelCheckPlugin constructor( private fun deletePrepare(sourceModel: Model?, originElement: Element, param: BeforeDeleteParam) { if (sourceModel == null || !sourceModel.elementExist(originElement)) { logger.info("The element(${originElement.name}/${originElement.id}) is delete") - param.element = originElement - ElementBizRegistrar.getPlugin(originElement)?.beforeDelete(originElement, param) + ElementBizRegistrar.getPlugin(originElement)?.beforeDelete( + originElement, + param.copy(element = originElement) + ) } else { logger.info("The element(${originElement.name}/${originElement.id}) is not delete") } @@ -507,6 +509,7 @@ open class DefaultModelCheckPlugin constructor( override fun beforeUpdateElementInExistsModel(existModel: Model, sourceModel: Model?, param: BeforeUpdateParam) { recursiveElement(existModel = existModel) { + logger.info("beforeUpdateElementInExistsModel,element[${JsonUtil.toJson(it, false)}]") updatePrepare(sourceModel, it, param) } } @@ -528,10 +531,11 @@ open class DefaultModelCheckPlugin constructor( if (sourceModel != null) { val oldElement = sourceModel.elementFind(originElement) if (oldElement != null) { - param.newElement = originElement - param.oldElement = oldElement logger.info("The element(${originElement.name}/${originElement.id}) is update") - ElementBizRegistrar.getPlugin(originElement)?.beforeUpdate(originElement, param) + ElementBizRegistrar.getPlugin(originElement)?.beforeUpdate( + originElement, + param.copy(oldElement = oldElement, newElement = originElement) + ) } else { logger.info( "The element(${originElement.name}/${originElement.id}) is not update," + @@ -562,9 +566,11 @@ open class DefaultModelCheckPlugin constructor( logger.info("createPrepare The element(${originElement.name}/${originElement.id})," + "sourceModel|[$sourceModel]") if (sourceModel == null || !sourceModel.elementExist(originElement)) { - param.element = originElement logger.info("The element(${originElement.name}/${originElement.id}) is create") - ElementBizRegistrar.getPlugin(originElement)?.afterCreate(originElement, param) + ElementBizRegistrar.getPlugin(originElement)?.afterCreate( + originElement, + param.copy(element = originElement) + ) } else { logger.info("The element(${originElement.name}/${originElement.id}) is not create") } From 43290a6e8351db60e5a73e9405f5b9ca799a9a59 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 26 Oct 2023 16:28:25 +0800 Subject: [PATCH 12/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/engine/extend/DefaultModelCheckPlugin.kt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index aaf03255dc4..28a64f01af7 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -509,7 +509,6 @@ open class DefaultModelCheckPlugin constructor( override fun beforeUpdateElementInExistsModel(existModel: Model, sourceModel: Model?, param: BeforeUpdateParam) { recursiveElement(existModel = existModel) { - logger.info("beforeUpdateElementInExistsModel,element[${JsonUtil.toJson(it, false)}]") updatePrepare(sourceModel, it, param) } } @@ -548,23 +547,12 @@ open class DefaultModelCheckPlugin constructor( } override fun afterCreateElementInExistsModel(existModel: Model, sourceModel: Model?, param: AfterCreateParam) { - val sourceModelStr = if (sourceModel != null) { - JsonUtil.toJson(sourceModel, false) - } else { - "" - } - logger.info( - "afterCreateElementInExistsModel|existModel[${JsonUtil.toJson(existModel, false)}]|" + - "sourceModel[$sourceModelStr]" - ) recursiveElement(existModel = existModel) { createPrepare(sourceModel, it, param) } } private fun createPrepare(sourceModel: Model?, originElement: Element, param: AfterCreateParam) { - logger.info("createPrepare The element(${originElement.name}/${originElement.id})," + - "sourceModel|[$sourceModel]") if (sourceModel == null || !sourceModel.elementExist(originElement)) { logger.info("The element(${originElement.name}/${originElement.id}) is create") ElementBizRegistrar.getPlugin(originElement)?.afterCreate( From ddedbc11d0d06d342d05778e95ab444a0ba123ef Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 13 Nov 2023 14:54:07 +0800 Subject: [PATCH 13/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipeline/extend/ModelCheckPlugin.kt | 13 ----- .../pojo/element/atom/AfterCreateParam.kt | 4 +- .../pojo/element/atom/BeforeUpdateParam.kt | 53 ------------------- .../plugin/MarketBuildAtomElementBizPlugin.kt | 18 ++----- .../MarketBuildLessAtomElementBizPlugin.kt | 18 ++----- .../engine/extend/DefaultModelCheckPlugin.kt | 38 ++++--------- .../service/PipelineRepositoryService.kt | 45 +++++++++++++++- .../devops/process/plugin/ElementBizPlugin.kt | 6 --- .../element/TimerTriggerElementBizPlugin.kt | 3 -- .../service/PipelineInfoFacadeService.kt | 49 +++-------------- .../webhook/WebHookTriggerElementBizPlugin.kt | 3 -- 11 files changed, 72 insertions(+), 178 deletions(-) delete mode 100644 src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeUpdateParam.kt diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/extend/ModelCheckPlugin.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/extend/ModelCheckPlugin.kt index 039ed5012cb..81d298e3b41 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/extend/ModelCheckPlugin.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/extend/ModelCheckPlugin.kt @@ -34,7 +34,6 @@ import com.tencent.devops.common.pipeline.option.JobControlOption import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam /** * 对流水线模型中的设置的agent进行检查的扩展点 @@ -87,18 +86,6 @@ interface ModelCheckPlugin { @Throws(ErrorCodeException::class) fun checkJobCondition(container: Container, finallyStage: Boolean, contextMap: Map) - /** - * 在修改element前做的一些处理 - * 对比sourceModel,并清理model中与之不同的Element - * @param existModel 目标Model(要修改的Model) - * @param sourceModel 源要比较的Model - */ - fun beforeUpdateElementInExistsModel( - existModel: Model, - sourceModel: Model? = null, - param: BeforeUpdateParam - ) - /** * 在添加element后做的一些处理 * @param existModel 目标Model(要修改的Model) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt index 19f3c17df76..ba143b4c98c 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt @@ -53,5 +53,7 @@ data class AfterCreateParam( @ApiModelProperty("容器") val container: Container? = null, @ApiModelProperty("插件配置") - var element: Element = EmptyElement() + var element: Element = EmptyElement(), + @ApiModelProperty("旧插件配置") + var oldElement: Element = EmptyElement() ) : AtomChangeEventParam diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeUpdateParam.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeUpdateParam.kt deleted file mode 100644 index 2b16efc7143..00000000000 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/BeforeUpdateParam.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.common.pipeline.pojo.element.atom - -import com.tencent.devops.common.pipeline.enums.AtomChangeAction -import com.tencent.devops.common.pipeline.enums.ChannelCode -import com.tencent.devops.common.pipeline.pojo.element.Element -import com.tencent.devops.common.pipeline.pojo.element.EmptyElement -import io.swagger.annotations.ApiModel -import io.swagger.annotations.ApiModelProperty - -@ApiModel("修改插件时的前置操作参数") -data class BeforeUpdateParam( - @ApiModelProperty("用户名") - override val userId: String, - @ApiModelProperty("项目ID") - override val projectId: String, - @ApiModelProperty("流水线Id") - override val pipelineId: String, - @ApiModelProperty("渠道") - override val channelCode: ChannelCode = ChannelCode.BS, - @ApiModelProperty("动作") - override val action: AtomChangeAction = AtomChangeAction.UPDATE, - @ApiModelProperty("旧插件配置") - var oldElement: Element = EmptyElement(), - @ApiModelProperty("新插件配置") - var newElement: Element = EmptyElement() -) : AtomChangeEventParam diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildAtomElementBizPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildAtomElementBizPlugin.kt index 3bf7658fc55..990b42ce4d2 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildAtomElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildAtomElementBizPlugin.kt @@ -29,7 +29,6 @@ package com.tencent.devops.process.engine.atom.plugin import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement import com.tencent.devops.common.pipeline.enums.AtomChangeAction import com.tencent.devops.process.plugin.ElementBizPlugin @@ -52,7 +51,11 @@ class MarketBuildAtomElementBizPlugin : ElementBizPlugin atomCode = element.getAtomCode(), atomVersion = element.version, param = param, - action = AtomChangeAction.CREATE + action = if (param.create) { + AtomChangeAction.CREATE + } else { + AtomChangeAction.UPDATE + } ) } @@ -67,16 +70,5 @@ class MarketBuildAtomElementBizPlugin : ElementBizPlugin ) } - override fun beforeUpdate(element: MarketBuildAtomElement, param: BeforeUpdateParam) { - val inputMap = element.data["input"] as Map - MarketBuildUtils.changeAction( - inputMap = inputMap, - atomCode = element.getAtomCode(), - atomVersion = element.version, - param = param, - action = AtomChangeAction.UPDATE - ) - } - override fun check(element: MarketBuildAtomElement, appearedCnt: Int) = Unit } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildLessAtomElementBizPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildLessAtomElementBizPlugin.kt index 779d9fea953..98d6c40f290 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildLessAtomElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/atom/plugin/MarketBuildLessAtomElementBizPlugin.kt @@ -29,7 +29,6 @@ package com.tencent.devops.process.engine.atom.plugin import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement import com.tencent.devops.common.pipeline.enums.AtomChangeAction import com.tencent.devops.process.plugin.ElementBizPlugin @@ -49,7 +48,11 @@ class MarketBuildLessAtomElementBizPlugin : ElementBizPlugin - MarketBuildUtils.changeAction( - inputMap = inputMap, - atomCode = element.getAtomCode(), - atomVersion = element.version, - param = param, - action = AtomChangeAction.UPDATE - ) - } - override fun check(element: MarketBuildLessAtomElement, appearedCnt: Int) = Unit } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index 28a64f01af7..92387f8c976 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -43,7 +43,6 @@ import com.tencent.devops.common.pipeline.pojo.BuildFormProperty import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement import com.tencent.devops.process.constant.ProcessMessageCode @@ -507,12 +506,6 @@ open class DefaultModelCheckPlugin constructor( } } - override fun beforeUpdateElementInExistsModel(existModel: Model, sourceModel: Model?, param: BeforeUpdateParam) { - recursiveElement(existModel = existModel) { - updatePrepare(sourceModel, it, param) - } - } - private fun recursiveElement( existModel: Model, action: (element: Element) -> Unit @@ -526,26 +519,6 @@ open class DefaultModelCheckPlugin constructor( } } - private fun updatePrepare(sourceModel: Model?, originElement: Element, param: BeforeUpdateParam) { - if (sourceModel != null) { - val oldElement = sourceModel.elementFind(originElement) - if (oldElement != null) { - logger.info("The element(${originElement.name}/${originElement.id}) is update") - ElementBizRegistrar.getPlugin(originElement)?.beforeUpdate( - originElement, - param.copy(oldElement = oldElement, newElement = originElement) - ) - } else { - logger.info( - "The element(${originElement.name}/${originElement.id}) is not update," + - "the element cannot be found from the model" - ) - } - } else { - logger.info("The element(${originElement.name}/${originElement.id}) is not update") - } - } - override fun afterCreateElementInExistsModel(existModel: Model, sourceModel: Model?, param: AfterCreateParam) { recursiveElement(existModel = existModel) { createPrepare(sourceModel, it, param) @@ -554,10 +527,17 @@ open class DefaultModelCheckPlugin constructor( private fun createPrepare(sourceModel: Model?, originElement: Element, param: AfterCreateParam) { if (sourceModel == null || !sourceModel.elementExist(originElement)) { - logger.info("The element(${originElement.name}/${originElement.id}) is create") + val oldElement = sourceModel!!.elementFind(originElement) + val elementParam = if (oldElement == null) { + logger.info("The element(${originElement.name}/${originElement.id}) is create") + param.copy(element = originElement) + } else { + logger.info("The element(${originElement.name}/${originElement.id}) is update") + param.copy(element = originElement, oldElement = oldElement, create = false) + } ElementBizRegistrar.getPlugin(originElement)?.afterCreate( originElement, - param.copy(element = originElement) + elementParam ) } else { logger.info("The element(${originElement.name}/${originElement.id}) is not create") diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt index 3bb7b77c766..c3051a44e8f 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt @@ -48,6 +48,7 @@ import com.tencent.devops.common.pipeline.option.MatrixControlOption import com.tencent.devops.common.pipeline.pojo.BuildNo import com.tencent.devops.common.pipeline.pojo.MatrixPipelineInfo import com.tencent.devops.common.pipeline.pojo.element.SubPipelineCallElement +import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.trigger.ManualTriggerElement import com.tencent.devops.common.pipeline.utils.MatrixContextUtils import com.tencent.devops.common.redis.RedisOperation @@ -75,6 +76,7 @@ import com.tencent.devops.process.engine.pojo.event.PipelineCreateEvent import com.tencent.devops.process.engine.pojo.event.PipelineDeleteEvent import com.tencent.devops.process.engine.pojo.event.PipelineRestoreEvent import com.tencent.devops.process.engine.pojo.event.PipelineUpdateEvent +import com.tencent.devops.process.plugin.load.ElementBizRegistrar import com.tencent.devops.process.pojo.PipelineCollation import com.tencent.devops.process.pojo.PipelineName import com.tencent.devops.process.pojo.PipelineSortType @@ -138,7 +140,8 @@ class PipelineRepositoryService constructor( create: Boolean, useTemplateSettings: Boolean? = false, templateId: String? = null, - updateLastModifyUser: Boolean? = true + updateLastModifyUser: Boolean? = true, + existModel: Model? = null ): DeployPipelineResult { // 生成流水线ID,新流水线以p-开头,以区分以前旧数据 @@ -230,7 +233,11 @@ class PipelineRepositoryService constructor( containerSeqId = containerSeqId, projectId = projectId, pipelineId = pipelineId, + model = model, + userId = userId, modelTasks = modelTasks, + channelCode = channelCode, + create = create, distIds = distinctIdSet ) } else { @@ -240,7 +247,10 @@ class PipelineRepositoryService constructor( containerSeqId = containerSeqId, userId = userId, pipelineId = pipelineId, + model = model, modelTasks = modelTasks, + channelCode = channelCode, + create = create, distIds = distinctIdSet ) } @@ -254,7 +264,11 @@ class PipelineRepositoryService constructor( containerSeqId: AtomicInteger, projectId: String, pipelineId: String, + model: Model, + userId: String, modelTasks: MutableList, + channelCode: ChannelCode, + create: Boolean, distIds: HashSet ) { if (stage.containers.size != 1) { @@ -284,6 +298,18 @@ class PipelineRepositoryService constructor( e.id = modelTaskIdGenerator.getNextId() } distIds.add(e.id!!) + ElementBizRegistrar.getPlugin(e)?.afterCreate( + element = e, + param = AfterCreateParam( + projectId = projectId, + pipelineId = pipelineId, + pipelineName = model.name, + userId = userId, + channelCode = channelCode, + create = create, + container = c + ) + ) modelTasks.add( PipelineModelTask( @@ -311,7 +337,10 @@ class PipelineRepositoryService constructor( containerSeqId: AtomicInteger, userId: String, pipelineId: String, + model: Model, modelTasks: MutableList, + channelCode: ChannelCode, + create: Boolean, distIds: HashSet ) { if (stage.containers.isEmpty()) { @@ -387,6 +416,20 @@ class PipelineRepositoryService constructor( } } + // 补偿动作--未来拆分出来,针对复杂的东西异步处理 + ElementBizRegistrar.getPlugin(e)?.afterCreate( + element = e, + param = AfterCreateParam( + projectId = projectId, + pipelineId = pipelineId, + pipelineName = model.name, + userId = userId, + channelCode = channelCode, + create = create, + container = c + ) + ) + modelTasks.add( PipelineModelTask( projectId = projectId, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/plugin/ElementBizPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/plugin/ElementBizPlugin.kt index 083166e08b5..31aa2b086ff 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/plugin/ElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/plugin/ElementBizPlugin.kt @@ -30,7 +30,6 @@ package com.tencent.devops.process.plugin import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam /** * 流水线的Element的编排插件处理器 @@ -55,11 +54,6 @@ interface ElementBizPlugin { */ fun beforeDelete(element: T, param: BeforeDeleteParam) - /** - * 在修改[element]插件之前,根据[param]参数调用修改前的预处理 - */ - fun beforeUpdate(element: T, param: BeforeUpdateParam) - /** * 检查[element]插件以及出现的次数[appearedCnt]是否符合要求 */ diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt index 058631f8c43..c82908fcec3 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/plugin/trigger/element/TimerTriggerElementBizPlugin.kt @@ -31,7 +31,6 @@ import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.pipeline.container.TriggerContainer import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.trigger.TimerTriggerElement import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.plugin.ElementBizPlugin @@ -113,8 +112,6 @@ class TimerTriggerElementBizPlugin constructor( } } - override fun beforeUpdate(element: TimerTriggerElement, param: BeforeUpdateParam) = Unit - companion object { private val logger = LoggerFactory.getLogger(TimerTriggerElementBizPlugin::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt index 3374bcc1f43..1a2851100d1 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineInfoFacadeService.kt @@ -51,7 +51,6 @@ import com.tencent.devops.common.pipeline.pojo.BuildFormProperty import com.tencent.devops.common.pipeline.pojo.BuildNo import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.utils.LogUtils import com.tencent.devops.common.web.utils.I18nUtil @@ -221,7 +220,8 @@ class PipelineInfoFacadeService @Autowired constructor( userId = userId, projectId = projectId, pipelineId = newPipelineId ?: "", - channelCode = ChannelCode.BS + channelCode = ChannelCode.BS, + create = true ) ) return newPipelineId @@ -477,17 +477,6 @@ class PipelineInfoFacadeService @Autowired constructor( channelCode = channelCode ) ) - } else { - modelCheckPlugin.afterCreateElementInExistsModel( - existModel = model, - sourceModel = null, - param = AfterCreateParam( - userId = userId, - projectId = projectId, - pipelineId = pipelineId ?: "", - channelCode = channelCode - ) - ) } } } finally { @@ -540,18 +529,6 @@ class PipelineInfoFacadeService @Autowired constructor( ) return DeployPipelineResult(pipelineId, pipelineName = model.name, version = model.latestVersion) } finally { - if (model != null) { - modelCheckPlugin.afterCreateElementInExistsModel( - existModel = model, - sourceModel = null, - param = AfterCreateParam( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - channelCode = channelCode - ) - ) - } watcher.stop() LogUtils.printCostTimeWE(watcher) } @@ -694,7 +671,8 @@ class PipelineInfoFacadeService @Autowired constructor( userId = userId, projectId = projectId, pipelineId = newPipelineId!!, - channelCode = channelCode + channelCode = channelCode, + create = true ) ) } @@ -782,22 +760,6 @@ class PipelineInfoFacadeService @Autowired constructor( channelCode = channelCode ) ) - modelCheckPlugin.beforeUpdateElementInExistsModel( - model, existModel, BeforeUpdateParam( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - channelCode = channelCode - ) - ) - modelCheckPlugin.afterCreateElementInExistsModel( - model, existModel, AfterCreateParam( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - channelCode = channelCode - ) - ) val deployResult = pipelineRepositoryService.deployPipeline( model = model, projectId = projectId, @@ -805,7 +767,8 @@ class PipelineInfoFacadeService @Autowired constructor( userId = userId, channelCode = channelCode, create = false, - updateLastModifyUser = updateLastModifyUser + updateLastModifyUser = updateLastModifyUser, + existModel = existModel ) if (checkPermission) { pipelinePermissionService.modifyResource(projectId, pipelineId, model.name) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt index 60f05862580..32f286fbb87 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt @@ -33,7 +33,6 @@ import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.pojo.element.atom.AfterCreateParam import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeUpdateParam import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitGenericWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement @@ -63,8 +62,6 @@ abstract class WebHookTriggerElementBizPlugin constru } override fun check(element: T, appearedCnt: Int) = Unit - - override fun beforeUpdate(element: T, param: BeforeUpdateParam) = Unit } @ElementBiz From 97a0675880057b5bdae37a39eafbc12e10a76545 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 14 Nov 2023 17:42:21 +0800 Subject: [PATCH 14/14] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20#9566?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipeline/pojo/element/atom/AfterCreateParam.kt | 2 +- .../engine/extend/DefaultModelCheckPlugin.kt | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt index ba143b4c98c..4cb93ef8234 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/atom/AfterCreateParam.kt @@ -51,7 +51,7 @@ data class AfterCreateParam( @ApiModelProperty("是否创建") val create: Boolean = true, @ApiModelProperty("容器") - val container: Container? = null, + var container: Container? = null, @ApiModelProperty("插件配置") var element: Element = EmptyElement(), @ApiModelProperty("旧插件配置") diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt index 92387f8c976..57041241b08 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/extend/DefaultModelCheckPlugin.kt @@ -394,8 +394,8 @@ open class DefaultModelCheckPlugin constructor( sourceModel: Model?, param: BeforeDeleteParam ) { - recursiveElement(existModel) { - deletePrepare(sourceModel, it, param) + recursiveElement(existModel) { container, element -> + deletePrepare(sourceModel, element, param) } } @@ -508,20 +508,21 @@ open class DefaultModelCheckPlugin constructor( private fun recursiveElement( existModel: Model, - action: (element: Element) -> Unit + action: (container: Container, element: Element) -> Unit ) { existModel.stages.forEach { s -> s.containers.forEach { c -> c.elements.forEach { e -> - action.invoke(e) + action.invoke(c, e) } } } } override fun afterCreateElementInExistsModel(existModel: Model, sourceModel: Model?, param: AfterCreateParam) { - recursiveElement(existModel = existModel) { - createPrepare(sourceModel, it, param) + recursiveElement(existModel = existModel) { container, element -> + param.container = container + createPrepare(sourceModel, element, param) } }