Skip to content

Commit

Permalink
feat:新建/编辑流水线时支持调试流水线 TencentBlueKing#8164 版本写入
Browse files Browse the repository at this point in the history
  • Loading branch information
royalhuang committed Oct 20, 2023
1 parent 2601ffd commit 386df6f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.tencent.devops.process.pojo.setting

import com.tencent.devops.common.api.pojo.PipelineAsCodeSettings
import com.tencent.devops.common.pipeline.pojo.setting.PipelineRunLockType
import com.tencent.devops.common.pipeline.pojo.setting.PipelineSetting
import com.tencent.devops.common.pipeline.pojo.setting.Subscription
import com.tencent.devops.common.pipeline.utils.PIPELINE_SETTING_CONCURRENCY_GROUP_DEFAULT
import com.tencent.devops.common.pipeline.utils.PIPELINE_SETTING_MAX_QUEUE_SIZE_DEFAULT
Expand Down Expand Up @@ -77,4 +78,8 @@ data class PipelineSettingVersion(
var concurrencyCancelInProgress: Boolean = false,
@ApiModelProperty("YAML流水线特殊配置", required = false)
var pipelineAsCodeSettings: PipelineAsCodeSettings? = PipelineAsCodeSettings()
)
) {
companion object {
fun convertFromSetting(setting: PipelineSetting) = PipelineSettingVersion()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import org.jooq.Record1
import org.jooq.Record4
import org.jooq.RecordMapper
import org.jooq.Result
import org.jooq.types.UInteger
import org.springframework.stereotype.Repository

@Suppress("ALL")
Expand All @@ -68,7 +67,7 @@ class PipelineSettingDao {
maxPipelineResNum: Int? = PIPELINE_RES_NUM_MIN,
pipelineAsCodeSettings: PipelineAsCodeSettings?,
settingVersion: Int
): Int {
): PipelineSetting? {
with(TPipelineSetting.T_PIPELINE_SETTING) {
val successType = successNotifyTypes.split(",").filter { i -> i.isNotBlank() }
.map { type -> PipelineSubscriptionType.valueOf(type) }.toSet()
Expand All @@ -86,7 +85,7 @@ class PipelineSettingDao {
users = "\${$PIPELINE_START_USER_NAME}",
content = NotifyTemplateUtils.getCommonShutdownFailureContent()
)
return dslContext.insertInto(
val result = dslContext.insertInto(
this,
PROJECT_ID,
PIPELINE_ID,
Expand All @@ -109,33 +108,32 @@ class PipelineSettingDao {
SUCCESS_SUBSCRIPTION,
FAILURE_SUBSCRIPTION,
VERSION
)
.values(
projectId,
pipelineId,
pipelineName,
PipelineRunLockType.toValue(PipelineRunLockType.MULTIPLE),
"",
successSubscription.users,
failSubscription.users,
"",
"",
successNotifyTypes,
failNotifyTypes,
successSubscription.content,
failSubscription.content,
DateTimeUtil.minuteToSecond(PIPELINE_SETTING_WAIT_QUEUE_TIME_MINUTE_DEFAULT),
PIPELINE_SETTING_MAX_QUEUE_SIZE_DEFAULT,
isTemplate,
maxPipelineResNum,
pipelineAsCodeSettings?.let { self ->
JsonUtil.toJson(self, false)
},
JsonUtil.toJson(listOf(successSubscription), false),
JsonUtil.toJson(listOf(failSubscription), false),
settingVersion
)
.execute()
).values(
projectId,
pipelineId,
pipelineName,
PipelineRunLockType.toValue(PipelineRunLockType.MULTIPLE),
"",
successSubscription.users,
failSubscription.users,
"",
"",
successNotifyTypes,
failNotifyTypes,
successSubscription.content,
failSubscription.content,
DateTimeUtil.minuteToSecond(PIPELINE_SETTING_WAIT_QUEUE_TIME_MINUTE_DEFAULT),
PIPELINE_SETTING_MAX_QUEUE_SIZE_DEFAULT,
isTemplate,
maxPipelineResNum,
pipelineAsCodeSettings?.let { self ->
JsonUtil.toJson(self, false)
},
JsonUtil.toJson(listOf(successSubscription), false),
JsonUtil.toJson(listOf(failSubscription), false),
settingVersion
).returning().fetchOne()
return mapper.map(result)
}
}

Expand Down Expand Up @@ -180,7 +178,6 @@ class PipelineSettingDao {
CONCURRENCY_GROUP,
CONCURRENCY_CANCEL_IN_PROGRESS,
CLEAN_VARIABLES_WHEN_RETRY,
PIPELINE_AS_CODE_SETTINGS,
SUCCESS_SUBSCRIPTION,
FAILURE_SUBSCRIPTION,
VERSION
Expand Down Expand Up @@ -215,7 +212,6 @@ class PipelineSettingDao {
setting.concurrencyGroup,
setting.concurrencyCancelInProgress,
setting.cleanVariablesWhenRetry,
setting.pipelineAsCodeSettings?.let { self -> JsonUtil.toJson(self, false) },
JsonUtil.toJson(successSubscriptionList, false),
JsonUtil.toJson(failSubscriptionList, false),
setting.version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.fasterxml.jackson.core.type.TypeReference
import com.tencent.devops.common.api.pojo.PipelineAsCodeSettings
import com.tencent.devops.common.api.util.DateTimeUtil
import com.tencent.devops.common.api.util.JsonUtil
import com.tencent.devops.common.notify.enums.NotifyType
import com.tencent.devops.common.pipeline.pojo.setting.PipelineRunLockType
import com.tencent.devops.model.process.tables.TPipelineSettingVersion
import com.tencent.devops.model.process.tables.records.TPipelineSettingVersionRecord
Expand All @@ -46,40 +45,6 @@ import org.springframework.stereotype.Repository
@Repository
class PipelineSettingVersionDao {

// 新流水线创建的时候,设置默认的通知配置。
fun insertNewSetting(
dslContext: DSLContext,
projectId: String,
pipelineId: String,
pipelineName: String,
settingVersion: Int,
isTemplate: Boolean = false,
successNotifyTypes: String = "",
failNotifyTypes: String = "${NotifyType.EMAIL.name},${NotifyType.RTX.name}",
id: Long? = null
): Int {
with(TPipelineSettingVersion.T_PIPELINE_SETTING_VERSION) {
return dslContext.insertInto(
this,
PROJECT_ID,
PIPELINE_ID,
NAME,
IS_TEMPLATE,
VERSION,
ID
)
.values(
projectId,
pipelineId,
pipelineName,
isTemplate,
settingVersion,
id
)
.execute()
}
}

fun saveSetting(
dslContext: DSLContext,
setting: PipelineSetting,
Expand All @@ -90,29 +55,55 @@ class PipelineSettingVersionDao {
val successSubscriptionList = setting.successSubscriptionList ?: listOf(setting.successSubscription)
val failSubscriptionList = setting.failSubscriptionList ?: listOf(setting.failSubscription)
with(TPipelineSettingVersion.T_PIPELINE_SETTING_VERSION) {
return dslContext.insertInto(
val insert = dslContext.insertInto(
this,
ID,
PROJECT_ID,
PIPELINE_ID,
NAME,
DESC,
RUN_LOCK_TYPE,
WAIT_QUEUE_TIME_SECOND,
MAX_QUEUE_SIZE,
IS_TEMPLATE,
VERSION,
ID,
BUILD_NUM_RULE,
CONCURRENCY_GROUP,
CONCURRENCY_CANCEL_IN_PROGRESS,
SUCCESS_SUBSCRIPTION,
FAILURE_SUBSCRIPTION
FAILURE_SUBSCRIPTION,
VERSION
).values(
id,
setting.projectId,
setting.pipelineId,
setting.pipelineName,
setting.desc,
PipelineRunLockType.toValue(setting.runLockType),
DateTimeUtil.minuteToSecond(setting.waitQueueTimeMinute),
setting.maxQueueSize,
isTemplate,
version,
id,
setting.buildNumRule,
setting.concurrencyGroup,
setting.concurrencyCancelInProgress,
JsonUtil.toJson(successSubscriptionList, false),
JsonUtil.toJson(failSubscriptionList, false)
JsonUtil.toJson(failSubscriptionList, false),
version
).onDuplicateKeyUpdate()
.set(NAME, setting.pipelineName)
.set(DESC, setting.desc)
.set(RUN_LOCK_TYPE, PipelineRunLockType.toValue(setting.runLockType))
.set(WAIT_QUEUE_TIME_SECOND, DateTimeUtil.minuteToSecond(setting.waitQueueTimeMinute))
.set(MAX_QUEUE_SIZE, setting.maxQueueSize)
.set(BUILD_NUM_RULE, setting.buildNumRule)
.set(CONCURRENCY_GROUP, setting.concurrencyGroup)
.set(CONCURRENCY_CANCEL_IN_PROGRESS, setting.concurrencyCancelInProgress)
.set(SUCCESS_SUBSCRIPTION, JsonUtil.toJson(successSubscriptionList, false))
.set(FAILURE_SUBSCRIPTION, JsonUtil.toJson(failSubscriptionList, false))
.execute()
// pipelineAsCodeSettings 默认传空不更新
setting.pipelineAsCodeSettings?.let { self ->
insert.set(PIPELINE_AS_CODE_SETTINGS, JsonUtil.toJson(self, false))
}
return insert.execute()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,17 +689,15 @@ class PipelineRepositoryService constructor(
null
},
settingVersion = settingVersion
)
pipelineSettingVersionDao.insertNewSetting(
dslContext = transactionContext,
projectId = projectId,
pipelineId = pipelineId,
pipelineName = model.name,
failNotifyTypes = notifyTypes,
id = client.get(ServiceAllocIdResource::class)
.generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME).data,
settingVersion = settingVersion
)
)?.let { setting ->
pipelineSettingVersionDao.saveSetting(
dslContext = transactionContext,
setting = setting,
id = client.get(ServiceAllocIdResource::class)
.generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME).data,
version = settingVersion
)
}
}
} else {
pipelineSettingDao.updateSetting(
Expand Down

0 comments on commit 386df6f

Please sign in to comment.