Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 新增插件修改回调事件 #9566 #9589

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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

/**
Expand Down Expand Up @@ -84,4 +85,15 @@ interface ModelCheckPlugin {
*/
@Throws(ErrorCodeException::class)
fun checkJobCondition(container: Container, finallyStage: Boolean, contextMap: Map<String, String>)

/**
* 在添加element后做的一些处理
* @param existModel 目标Model(要修改的Model)
* @param sourceModel 源要比较的Model
*/
fun afterCreateElementInExistsModel(
existModel: Model,
sourceModel: Model? = null,
param: AfterCreateParam
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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("容器")
var container: Container? = null,
@ApiModelProperty("插件配置")
var element: Element = EmptyElement(),
@ApiModelProperty("旧插件配置")
var oldElement: Element = EmptyElement()
) : AtomChangeEventParam
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

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.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

Expand All @@ -43,18 +43,31 @@ class MarketBuildAtomElementBizPlugin : ElementBizPlugin<MarketBuildAtomElement>

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<String, Any>
MarketBuildUtils.changeAction(
inputMap = inputMap,
atomCode = element.getAtomCode(),
atomVersion = element.version,
param = param,
action = if (param.create) {
AtomChangeAction.CREATE
} else {
AtomChangeAction.UPDATE
}
)
}

override fun beforeDelete(element: MarketBuildAtomElement, param: BeforeDeleteParam) {
val inputMap = element.data["input"] as Map<String, Any>
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 check(element: MarketBuildAtomElement, appearedCnt: Int) = Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

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.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

Expand All @@ -41,20 +41,30 @@ class MarketBuildLessAtomElementBizPlugin : ElementBizPlugin<MarketBuildLessAtom
return MarketBuildLessAtomElement::class.java
}

override fun afterCreate(
element: MarketBuildLessAtomElement,
projectId: String,
pipelineId: String,
pipelineName: String,
userId: String,
channelCode: ChannelCode,
create: Boolean,
container: Container
) = Unit
override fun afterCreate(element: MarketBuildLessAtomElement, param: AfterCreateParam) {
val inputMap = element.data["input"] as Map<String, Any>
MarketBuildUtils.changeAction(
inputMap = inputMap,
atomCode = element.getAtomCode(),
atomVersion = element.version,
param = param,
action = if (param.create) {
AtomChangeAction.CREATE
} else {
AtomChangeAction.UPDATE
}
)
}

override fun beforeDelete(element: MarketBuildLessAtomElement, param: BeforeDeleteParam) {
val inputMap = element.data["input"] as Map<String, Any>
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 check(element: MarketBuildLessAtomElement, appearedCnt: Int) = Unit
Expand Down
Loading