Skip to content

Commit

Permalink
Merge pull request #10757 from mingshewhe/bug_v3.0_template
Browse files Browse the repository at this point in the history
修复3.0模板一些bug
  • Loading branch information
bkci-bot authored Aug 7, 2024
2 parents e31f1f8 + c306839 commit a383495
Show file tree
Hide file tree
Showing 29 changed files with 573 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,34 @@
package com.tencent.devops.common.db.utils

import com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException
import java.math.BigDecimal
import java.sql.Timestamp
import org.jooq.DatePart
import org.jooq.Field
import org.jooq.Record
import org.jooq.SelectOptionStep
import org.jooq.SelectUnionStep
import org.jooq.exception.DataAccessException
import org.jooq.impl.DSL
import org.springframework.dao.DeadlockLoserDataAccessException
import java.math.BigDecimal
import java.sql.Timestamp

object JooqUtils {

const val JooqDeadLockMessage = "Deadlock found when trying to get lock; try restarting transaction"

fun <T> retryWhenDeadLock(action: () -> T): T {
fun <T> retryWhenDeadLock(retryTime: Int = 1, action: () -> T): T {
return try {
action()
} catch (dae: DataAccessException) {
if (dae.isDeadLock()) action() else throw dae
if (retryTime - 1 < 0) {
throw dae
}
if (dae.isDeadLock()) retryWhenDeadLock(retryTime - 1, action) else throw dae
} catch (dae: DeadlockLoserDataAccessException) {
if (retryTime - 1 < 0) {
throw dae
}
retryWhenDeadLock(retryTime - 1, action)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tencent.devops.common.db.utils

import org.jooq.exception.DataAccessException
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

class JooqUtilsTest {
Expand All @@ -18,6 +19,19 @@ class JooqUtilsTest {
Assertions.assertEquals(expect, actual)
}

@Test
@DisplayName("重试多次")
fun retryWhenDeadLock_2() {
var actual = 0
JooqUtils.retryWhenDeadLock(3) {
if (actual++ < 3) {
throw DataAccessException("mock sql dead lock; ${JooqUtils.JooqDeadLockMessage}")
}
}
val expect = 4 // retry
Assertions.assertEquals(expect, actual)
}

@Test
fun assertThrowsRetryWhenDeadLock() {
var actual = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ data class TriggerContainer(
@get:Schema(title = "参数化构建", required = false)
var params: List<BuildFormProperty> = listOf(),
@get:Schema(title = "模板参数构建", required = false)
val templateParams: List<BuildFormProperty>? = null,
var templateParams: List<BuildFormProperty>? = null,
@get:Schema(title = "构建版本号", required = false)
var buildNo: BuildNo? = null,
@get:Schema(title =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ class GitlabWebhookElementParams : ScmWebhookElementParams<CodeGitlabWebHookTrig
} else {
EnvUtils.parseEnv(element.excludeUsers!!.joinToString(","), variables)
}
if (element.branchName == null) {
return null
}
params.version = element.version
when {
// action上线后【流水线配置层面】兼容存量merge_request_accept和push事件
Expand Down Expand Up @@ -103,7 +100,7 @@ class GitlabWebhookElementParams : ScmWebhookElementParams<CodeGitlabWebHookTrig
params.includePushAction = WebhookUtils.joinToString(element.includePushAction)
}
}
params.branchName = EnvUtils.parseEnv(element.branchName!!, variables)
params.branchName = EnvUtils.parseEnv(element.branchName ?: "", variables)
params.codeType = CodeType.GITLAB
params.eventType = element.eventType
params.block = element.block ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@ interface ApigwBuildResourceV4 {
)
@QueryParam("updateTimeDesc")
updateTimeDesc: Boolean? = null,
@Parameter(description = "代码库别名", required = false)
@Parameter(description = "源材料代码库别名", required = false)
@QueryParam("materialAlias")
materialAlias: List<String>?,
@Parameter(description = "代码库URL", required = false)
@QueryParam("materialUrl")
materialUrl: String?,
@Parameter(description = "分支", required = false)
@Parameter(description = "源材料分支", required = false)
@QueryParam("materialBranch")
materialBranch: List<String>?,
@Parameter(description = "commitId", required = false)
@Parameter(description = "源材料commitId", required = false)
@QueryParam("materialCommitId")
materialCommitId: String?,
@Parameter(description = "commitMessage", required = false)
@Parameter(description = "源材料commitMessage", required = false)
@QueryParam("materialCommitMessage")
materialCommitMessage: String?,
@Parameter(description = "状态", required = false)
Expand Down Expand Up @@ -296,7 +296,13 @@ interface ApigwBuildResourceV4 {
startUser: List<String>?,
@Parameter(description = "是否查询归档数据", required = false)
@QueryParam("archiveFlag")
archiveFlag: Boolean? = false
archiveFlag: Boolean? = false,
@Parameter(description = "触发代码库", required = false)
@QueryParam("triggerAlias")
triggerAlias: List<String>? = null,
@Parameter(description = "触发分支", required = false)
@QueryParam("triggerBranch")
triggerBranch: List<String>? = null
): Result<BuildHistoryPage<BuildHistory>>

@Operation(summary = "获取流水线手动启动参数", tags = ["v4_app_build_startInfo", "v4_user_build_startInfo"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ class ApigwBuildResourceV4Impl @Autowired constructor(
buildNoEnd: Int?,
buildMsg: String?,
startUser: List<String>?,
archiveFlag: Boolean?
archiveFlag: Boolean?,
triggerAlias: List<String>?,
triggerBranch: List<String>?
): Result<BuildHistoryPage<BuildHistory>> {
logger.info(
"OPENAPI_BUILD_V4|$userId|get history build|$projectId|$pipelineId|$page|$pageSize" +
Expand Down Expand Up @@ -165,7 +167,9 @@ class ApigwBuildResourceV4Impl @Autowired constructor(
buildNoEnd = buildNoEnd,
buildMsg = buildMsg,
startUser = startUser,
archiveFlag = archiveFlag
archiveFlag = archiveFlag,
triggerAlias = triggerAlias,
triggerBranch = triggerBranch
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ interface AppPipelineBuildResource {
buildMsg: String?,
@Parameter(description = "查看指定版本调试数据", required = false, example = "false")
@QueryParam("version")
customVersion: Int? = null
customVersion: Int? = null,
@Parameter(description = "触发代码库", required = false)
@QueryParam("triggerAlias")
triggerAlias: List<String>?,
@Parameter(description = "触发分支", required = false)
@QueryParam("triggerBranch")
triggerBranch: List<String>?
): Result<BuildHistoryPage<BuildHistory>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,13 @@ interface ServiceBuildResource {
archiveFlag: Boolean? = false,
@Parameter(description = "查看指定版本调试数据", required = false, example = "false")
@QueryParam("version")
customVersion: Int? = null
customVersion: Int? = null,
@Parameter(description = "触发代码库", required = false)
@QueryParam("triggerAlias")
triggerAlias: List<String>? = null,
@Parameter(description = "触发分支", required = false)
@QueryParam("triggerBranch")
triggerBranch: List<String>? = null
): Result<BuildHistoryPage<BuildHistory>>

@Operation(summary = "获取构建详情")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.tencent.devops.common.pipeline.pojo.BuildParameters
import com.tencent.devops.common.pipeline.pojo.StageReviewRequest
import com.tencent.devops.common.pipeline.pojo.element.Element
import com.tencent.devops.common.web.annotation.BkField
import com.tencent.devops.process.enums.HistorySearchType
import com.tencent.devops.process.pojo.BuildHistory
import com.tencent.devops.process.pojo.BuildHistoryRemark
import com.tencent.devops.process.pojo.BuildId
Expand Down Expand Up @@ -400,13 +401,13 @@ interface UserBuildResource {
@Parameter(description = "每页多少条", required = false, example = "20")
@QueryParam("pageSize")
pageSize: Int?,
@Parameter(description = "代码库别名", required = false)
@Parameter(description = "源材料代码库别名", required = false)
@QueryParam("materialAlias")
materialAlias: List<String>?,
@Parameter(description = "代码库URL", required = false)
@QueryParam("materialUrl")
materialUrl: String?,
@Parameter(description = "分支", required = false)
@Parameter(description = "源材料分支", required = false)
@QueryParam("materialBranch")
materialBranch: List<String>?,
@Parameter(description = "commitId", required = false)
Expand Down Expand Up @@ -462,7 +463,13 @@ interface UserBuildResource {
archiveFlag: Boolean? = false,
@Parameter(description = "查看指定版本调试数据", required = false, example = "false")
@QueryParam("version")
customVersion: Int? = null
customVersion: Int? = null,
@Parameter(description = "触发代码库", required = false)
@QueryParam("triggerAlias")
triggerAlias: List<String>?,
@Parameter(description = "触发分支", required = false)
@QueryParam("triggerBranch")
triggerBranch: List<String>?
): Result<BuildHistoryPage<BuildHistory>>

@Operation(summary = "修改流水线备注")
Expand Down Expand Up @@ -534,7 +541,13 @@ interface UserBuildResource {
pipelineId: String,
@Parameter(description = "查看指定版本调试数据", required = false, example = "false")
@QueryParam("version")
debugVersion: Int? = null
debugVersion: Int? = null,
@Parameter(description = "搜索分支关键字", required = false)
@QueryParam("search")
search: String?,
@Parameter(description = "搜索类型, 触发/源材料", required = false)
@QueryParam("type")
type: HistorySearchType?
): Result<List<String>>

@Operation(summary = "获取流水线构建中的查询条件-分支")
Expand All @@ -556,7 +569,13 @@ interface UserBuildResource {
alias: List<String>?,
@Parameter(description = "查看指定版本调试数据", required = false, example = "false")
@QueryParam("debugVersion")
debugVersion: Int? = null
debugVersion: Int? = null,
@Parameter(description = "搜索分支关键字", required = false)
@QueryParam("search")
search: String?,
@Parameter(description = "搜索类型,触发/源材料", required = false)
@QueryParam("type")
type: HistorySearchType?
): Result<List<String>>

@Operation(summary = "触发审核")
Expand Down
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.process.enums

/**
* 构建历史搜索类型
*/
enum class HistorySearchType {
// 触发器
TRIGGER,

// 源材料
MATERIAL
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ data class PipelineDetail(
val instanceFromTemplate: Boolean,
@get:Schema(title = "当前模板的ID", required = false)
var templateId: String?,
@get:Schema(title = "关联模板版本", required = false)
var templateVersion: Long?,
@get:Schema(title = "草稿或最新的发布版本")
val version: Int,
@get:Schema(title = "草稿或最新的发布版本名称")
Expand Down
Loading

0 comments on commit a383495

Please sign in to comment.