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:定时触发器支持设置启动变量 #10617 #11372

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ca3702d
feat:定时触发器支持设置启动变量 #10617
hejieehe Nov 21, 2024
d2f86c8
feat:定时触发器支持设置启动变量 #10617
hejieehe Nov 29, 2024
f75da4a
feat:定时触发器支持设置启动变量 #10617
hejieehe Nov 29, 2024
937bd12
feat:定时触发器支持设置启动变量 #10617
hejieehe Dec 2, 2024
95780da
feat:定时触发器支持设置启动变量 #10617
hejieehe Dec 2, 2024
08dedf7
feat:定时触发器支持设置启动变量 #10617
hejieehe Dec 2, 2024
722a08b
feat:定时触发器支持设置启动变量 #10617
hejieehe Dec 2, 2024
e47338b
feat:定时触发器支持设置启动变量 #10617
hejieehe Dec 3, 2024
8296349
feat:定时触发器支持设置启动变量 #10617 补充SQL
hejieehe Dec 3, 2024
132556e
feat:定时触发器支持设置启动变量 #10617
hejieehe Dec 3, 2024
c401bf7
feat:定时触发器支持设置启动变量 #10617
hejieehe Dec 4, 2024
71dcd8f
feat:定时触发器支持设置启动变量 #10617
hejieehe Dec 4, 2024
2e96ce4
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
hejieehe Dec 23, 2024
be00061
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
hejieehe Jan 6, 2025
3a44dfa
Merge branch 'feat_10617' of https://github.com/hejieehe/bk-ci into f…
hejieehe Jan 6, 2025
305d787
feat:定时触发器支持设置启动变量 #10617
hejieehe Jan 6, 2025
0888691
feat:定时触发器支持设置启动变量 #10617
hejieehe Jan 6, 2025
0a23a7b
feat:定时触发器支持设置启动变量 #10617
hejieehe Jan 7, 2025
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
Expand Up @@ -182,7 +182,8 @@ class ElementTransfer @Autowired(required = false) constructor(
repoName = repoName,
branches = element.branches,
always = (element.noScm != true).nullIfDefault(false),
enable = element.elementEnabled().nullIfDefault(true)
enable = element.elementEnabled().nullIfDefault(true),
startParams = element.startParams
)
)
return@forEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,8 @@ class TriggerTransfer @Autowired(required = false) constructor(
branches = timer.branches,
newExpression = timer.newExpression,
advanceExpression = timer.advanceExpression,
noScm = timer.always != true
noScm = timer.always != true,
startParams = timer.startParams
).checkTriggerElementEnable(timer.enable)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ data class SchedulesRule(
@JsonIgnore
var newExpression: List<String>? = null,
@JsonIgnore
var advanceExpression: List<String>? = null
var advanceExpression: List<String>? = null,
@get:Schema(title = "start-params")
@JsonProperty("start-params")
val startParams: Map<String, String>? = null
) {
data class Interval(
val week: List<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@
},
"always" : {
"type" : "boolean"
},
"start-params" : {
"type" : "object"
}
}
}
Expand Down Expand Up @@ -374,6 +377,9 @@
},
"always" : {
"type" : "boolean"
},
"start-params" : {
"type" : "object"
}
}
} ]
Expand Down Expand Up @@ -1009,6 +1015,9 @@
},
"always" : {
"type" : "boolean"
},
"start-params" : {
"type" : "object"
}
}
}
Expand Down Expand Up @@ -1065,6 +1074,9 @@
},
"always" : {
"type" : "boolean"
},
"start-params" : {
"type" : "object"
}
}
} ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ data class TimerTriggerElement(
@get:Schema(title = "代码库HashId", required = false)
val repoHashId: String? = null,
@get:Schema(title = "指定代码库别名", required = false)
val repoName: String? = null
val repoName: String? = null,
@get:Schema(title = "定时启动参数", required = false)
val startParams: Map<String, String>? = null
) : Element(name, id, status) {
companion object {
const val classType = "timerTrigger"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.process.api.op

import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID
import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE
import com.tencent.devops.common.api.pojo.Result
import io.swagger.v3.oas.annotations.tags.Tag
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import javax.ws.rs.Consumes
import javax.ws.rs.HeaderParam
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.core.MediaType

@Tag(name = "OP_PIPELINE_AGENT_REF", description = "OP-流水线-更新流水线定时触发信息")
@Path("/op/pipeline/timer")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
interface OpPipelineTimerResource {

@Operation(summary = "更新定时触发器信息")
@POST
@Path("/update")
fun updatePipelineTimerInfo(
@Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@Parameter(description = "项目ID", required = false)
@QueryParam("projectId")
projectId: String?,
@Parameter(description = "流水线id", required = false)
@QueryParam("pipelineId")
pipelineId: String?
): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ data class PipelineTimer(
val channelCode: ChannelCode,
val repoHashId: String?,
val branchs: List<String>?,
val noScm: Boolean?
val noScm: Boolean?,
val taskId: String,
val startParam: Map<String, String>?
)
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,17 @@ class PipelineRepositoryService constructor(
).map { it.key to str2model(it.value, it.key) }.toMap()
}

/**
* 批量获取model
*/
fun getModel(projectId: String, pipelineId: String): Model? {
return pipelineResourceDao.getLatestVersionModelString(
dslContext = dslContext,
projectId = projectId,
pipelineId = pipelineId
)?.let { str2model(it, pipelineId) }
}

/**
* 获取编排版本的通用方法
* 1 如果指定了[version]则一定按照version号查询版本
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.process.api.op

import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.web.RestResource
import com.tencent.devops.process.plugin.trigger.service.PipelineTimerUpgradeService
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import java.util.concurrent.Executors
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit

@RestResource
class OpPipelineTimerResourceImpl @Autowired constructor(
val timerUpgradeService: PipelineTimerUpgradeService
) : OpPipelineTimerResource {
override fun updatePipelineTimerInfo(userId: String, projectId: String?, pipelineId: String?): Result<Boolean> {
val startTime = System.currentTimeMillis()
val threadPoolExecutor = ThreadPoolExecutor(
1,
1,
0,
TimeUnit.SECONDS,
LinkedBlockingQueue(1),
Executors.defaultThreadFactory(),
ThreadPoolExecutor.AbortPolicy()
)
threadPoolExecutor.submit {
logger.info("Start to update pipeline timer|projectId=$projectId|pipelineId=$pipelineId")
try {
timerUpgradeService.upgrade(
userId = userId,
targetPipelineId = pipelineId,
targetProjectId = projectId
)
} catch (ignored: Exception) {
logger.warn("Failed to update pipeline timer", ignored)
} finally {
logger.info("Finish to update pipeline timer|${System.currentTimeMillis() - startTime}")
threadPoolExecutor.shutdown()
}
}
return Result(true)
}

companion object {
private val logger = LoggerFactory.getLogger(OpPipelineTimerResourceImpl::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.tencent.devops.common.db.utils.skipCheck
import com.tencent.devops.common.pipeline.enums.ChannelCode
import com.tencent.devops.model.process.Tables.T_PIPELINE_TIMER
import com.tencent.devops.model.process.tables.records.TPipelineTimerRecord
import org.jooq.Condition
import org.jooq.DSLContext
import org.jooq.Result
import org.springframework.stereotype.Repository
Expand All @@ -49,7 +50,9 @@ open class PipelineTimerDao {
channelCode: ChannelCode,
repoHashId: String?,
branchs: String?,
noScm: Boolean?
noScm: Boolean?,
startParam: String?,
taskId: String
): Int {
return with(T_PIPELINE_TIMER) {
dslContext.insertInto(
Expand All @@ -62,7 +65,9 @@ open class PipelineTimerDao {
CHANNEL,
REPO_HASH_ID,
BRANCHS,
NO_SCM
NO_SCM,
START_PARAM,
TASK_ID
).values(
projectId,
pipelineId,
Expand All @@ -72,24 +77,28 @@ open class PipelineTimerDao {
channelCode.name,
repoHashId,
branchs,
noScm
noScm,
startParam,
taskId
)
.onDuplicateKeyUpdate()
.set(TASK_ID, taskId)
.set(CREATE_TIME, LocalDateTime.now())
.set(CREATOR, userId)
.set(CRONTAB, crontabExpression)
.set(CHANNEL, channelCode.name)
.set(REPO_HASH_ID, repoHashId)
.set(BRANCHS, branchs)
.set(NO_SCM, noScm)
.set(START_PARAM, startParam)
.execute()
}
}

open fun get(dslContext: DSLContext, projectId: String, pipelineId: String): TPipelineTimerRecord? {
open fun get(dslContext: DSLContext, projectId: String, pipelineId: String, taskId: String): TPipelineTimerRecord? {
return with(T_PIPELINE_TIMER) {
dslContext.selectFrom(this)
.where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId)))
.where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId).and(TASK_ID.eq(taskId))))
.fetchAny()
}
}
Expand All @@ -102,9 +111,75 @@ open class PipelineTimerDao {
}
}

open fun delete(dslContext: DSLContext, projectId: String, pipelineId: String, taskId: String): Int {
return with(T_PIPELINE_TIMER) {
dslContext.delete(this)
.where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId).and(TASK_ID.eq(taskId))))
.execute()
}
}

open fun list(dslContext: DSLContext, offset: Int, limit: Int): Result<TPipelineTimerRecord> {
return with(T_PIPELINE_TIMER) {
dslContext.selectFrom(this).limit(offset, limit).skipCheck().fetch()
}
}

fun list(dslContext: DSLContext, projectId: String, pipelineId: String): Result<TPipelineTimerRecord> {
return with(T_PIPELINE_TIMER) {
dslContext.selectFrom(this).where(
PROJECT_ID.eq(projectId).and(PIPELINE_ID.eq(pipelineId))
).fetch()
}
}

fun listPipeline(
dslContext: DSLContext,
projectId: String?,
pipelineId: String?,
offset: Int,
limit: Int
): List<Pair<String, String>> {
return with(T_PIPELINE_TIMER) {
val conditions = mutableListOf<Condition>()
if (!projectId.isNullOrBlank()) {
conditions.add(PROJECT_ID.eq(projectId))
}
if (!pipelineId.isNullOrBlank()) {
conditions.add(PIPELINE_ID.eq(pipelineId))
}
dslContext.select(PROJECT_ID, PIPELINE_ID)
.from(this)
.where(conditions)
.groupBy(PROJECT_ID, PIPELINE_ID)
.orderBy(PROJECT_ID, PIPELINE_ID)
.limit(offset, limit)
.skipCheck()
.fetch()
.map {
it.value1() to it.value2()
}
}
}

fun update(
dslContext: DSLContext,
projectId: String,
pipelineId: String,
taskId: String,
startParam: String?
): Int {
return with(T_PIPELINE_TIMER) {
dslContext.update(this)
.set(TASK_ID, taskId)
.let {
if (!startParam.isNullOrBlank()) {
it.set(START_PARAM, startParam)
}
it
}
.where(PROJECT_ID.eq(projectId).and(PIPELINE_ID.eq(pipelineId)))
.execute()
}
}
}
Loading
Loading