Skip to content

Commit

Permalink
feat:流水线模板设置优化 TencentBlueKing#10857
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Aug 22, 2024
1 parent 5fd8da8 commit a85b694
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.tencent.devops.process.dao.PipelineSettingVersionDao
import com.tencent.devops.process.pojo.PipelineDetailInfo
import com.tencent.devops.process.pojo.setting.PipelineSettingVersion
import com.tencent.devops.process.service.label.PipelineGroupService
import com.tencent.devops.process.utils.PipelineVersionUtils
import org.jooq.DSLContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -169,4 +170,22 @@ class PipelineSettingVersionService @Autowired constructor(
context ?: dslContext, projectId, pipelineId
)?.let { PipelineSettingVersion.convertFromSetting(it) }
}

fun getSettingVersionAfterUpdate(
projectId: String,
pipelineId: String,
updateVersion: Boolean,
setting: PipelineSetting
): Int {
return getLatestSettingVersion(
projectId = projectId,
pipelineId = pipelineId
)?.let { latest ->
if (updateVersion) PipelineVersionUtils.getSettingVersion(
currVersion = latest.version,
originSetting = latest,
newSetting = PipelineSettingVersion.convertFromSetting(setting)
) else latest.version
} ?: 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ class PipelineSettingFacadeService @Autowired constructor(
updateLastModifyUser: Boolean? = true,
dispatchPipelineUpdateEvent: Boolean = true,
updateLabels: Boolean = true,
updateVersion: Boolean = true,
isTemplate: Boolean = false
updateVersion: Boolean = true
): PipelineSetting {
if (checkPermission) {
val language = I18nUtil.getLanguage(userId)
Expand All @@ -145,25 +144,20 @@ class PipelineSettingFacadeService @Autowired constructor(
setting.fixSubscriptions()
modelCheckPlugin.checkSettingIntegrity(setting, projectId)
ActionAuditContext.current().setInstance(setting)
val settingVersion = pipelineSettingVersionService.getLatestSettingVersion(
val settingVersion = pipelineSettingVersionService.getSettingVersionAfterUpdate(
projectId = projectId,
pipelineId = pipelineId
)?.let { latest ->
if (updateVersion) PipelineVersionUtils.getSettingVersion(
currVersion = latest.version,
originSetting = latest,
newSetting = PipelineSettingVersion.convertFromSetting(setting)
) else latest.version
} ?: 1

pipelineId = pipelineId,
updateVersion = updateVersion,
setting = setting
)
val pipelineName = pipelineRepositoryService.saveSetting(
context = context,
userId = userId,
setting = setting,
version = settingVersion,
versionStatus = versionStatus,
updateLastModifyUser = updateLastModifyUser,
isTemplate = isTemplate
isTemplate = false
)

if (pipelineName.name != pipelineName.oldName) {
Expand All @@ -178,22 +172,12 @@ class PipelineSettingFacadeService @Autowired constructor(
projectId = setting.projectId
)
)

if (checkPermission) {
if (isTemplate) {
pipelineTemplatePermissionService.modifyResource(
userId = userId,
projectId = projectId,
templateId = setting.pipelineId,
templateName = setting.pipelineName
)
} else {
pipelinePermissionService.modifyResource(
projectId = setting.projectId,
pipelineId = setting.pipelineId,
pipelineName = setting.pipelineName
)
}
pipelinePermissionService.modifyResource(
projectId = setting.projectId,
pipelineId = setting.pipelineId,
pipelineName = setting.pipelineName
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ class TemplateFacadeService @Autowired constructor(
copyTemplateReq.templateName
)
templateSettingService.saveTemplatePipelineSetting(
context, userId, setting, true
context = context,
userId = userId,
setting = setting
)
} else {
templateSettingService.insertTemplateSetting(
Expand Down Expand Up @@ -406,7 +408,9 @@ class TemplateFacadeService @Autowired constructor(
templateName = saveAsTemplateReq.templateName
)
templateSettingService.saveTemplatePipelineSetting(
context, userId, setting, true
context = context,
userId = userId,
setting = setting
)
} else {
templateSettingService.insertTemplateSetting(
Expand Down Expand Up @@ -1584,8 +1588,12 @@ class TemplateFacadeService @Autowired constructor(
pipelineId = pipelineId,
templateName = instance.pipelineName
)
templateSettingService.saveTemplatePipelineSetting(
context, userId, setting
pipelineSettingFacadeService.saveSetting(
context = context,
userId = userId,
projectId = setting.projectId,
pipelineId = setting.pipelineId,
setting = setting
)
} else {
templateSettingService.insertTemplateSetting(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.tencent.devops.process.service.template

import com.tencent.bk.audit.context.ActionAuditContext
import com.tencent.devops.common.api.exception.ErrorCodeException
import com.tencent.devops.common.pipeline.enums.VersionStatus
import com.tencent.devops.common.pipeline.extend.ModelCheckPlugin
import com.tencent.devops.common.pipeline.pojo.setting.PipelineSetting
import com.tencent.devops.common.pipeline.pojo.setting.PipelineSubscriptionType
import com.tencent.devops.common.pipeline.pojo.setting.Subscription
Expand All @@ -9,8 +12,10 @@ import com.tencent.devops.process.engine.dao.PipelineInfoDao
import com.tencent.devops.process.engine.dao.template.TemplateDao
import com.tencent.devops.process.engine.service.PipelineInfoExtService
import com.tencent.devops.process.engine.service.PipelineRepositoryService
import com.tencent.devops.process.permission.template.PipelineTemplatePermissionService
import com.tencent.devops.process.service.label.PipelineGroupService
import com.tencent.devops.process.service.pipeline.PipelineSettingFacadeService
import com.tencent.devops.process.service.pipeline.PipelineSettingVersionService
import com.tencent.devops.process.yaml.utils.NotifyTemplateUtils
import org.jooq.DSLContext
import org.jooq.impl.DSL
Expand All @@ -25,12 +30,13 @@ import org.springframework.stereotype.Service
class TemplateSettingService @Autowired constructor(
private val dslContext: DSLContext,
private val pipelineGroupService: PipelineGroupService,
private val pipelineInfoDao: PipelineInfoDao,
private val pipelineRepositoryService: PipelineRepositoryService,
private val pipelineSettingFacadeService: PipelineSettingFacadeService,
private val pipelineInfoExtService: PipelineInfoExtService,
private val templateCommonService: TemplateCommonService,
private val templateDao: TemplateDao
private val templateDao: TemplateDao,
private val modelCheckPlugin: ModelCheckPlugin,
private val pipelineSettingVersionService: PipelineSettingVersionService,
private val pipelineTemplatePermissionService: PipelineTemplatePermissionService
) {
fun updateTemplateSetting(
projectId: String,
Expand All @@ -55,40 +61,57 @@ class TemplateSettingService @Autowired constructor(
name = setting.pipelineName,
desc = setting.desc
)
saveTemplatePipelineSetting(context, userId, setting, true)
saveTemplatePipelineSetting(
context = context,
userId = userId,
setting = setting
)
}
return true
}

fun saveTemplatePipelineSetting(
context: DSLContext? = null,
userId: String,
setting: PipelineSetting,
isTemplate: Boolean = false
setting: PipelineSetting
): PipelineSetting {
pipelineGroupService.updatePipelineLabel(
userId = userId,
projectId = setting.projectId,
pipelineId = setting.pipelineId,
labelIds = setting.labels
val projectId = setting.projectId
val pipelineId = setting.pipelineId
// 对齐新旧通知配置,统一根据新list数据保存
setting.fixSubscriptions()
modelCheckPlugin.checkSettingIntegrity(setting, projectId)
ActionAuditContext.current().setInstance(setting)
val settingVersion = pipelineSettingVersionService.getSettingVersionAfterUpdate(
projectId = projectId,
pipelineId = pipelineId,
updateVersion = true,
setting = setting
)
pipelineInfoDao.update(
dslContext = dslContext,
projectId = setting.projectId,
pipelineId = setting.pipelineId,
logger.info("Save the template pipeline setting|$pipelineId|settingVersion=$settingVersion|setting=\n$setting")
val templateName = pipelineRepositoryService.saveSetting(
context = context,
userId = userId,
pipelineName = setting.pipelineName,
pipelineDesc = setting.desc
setting = setting,
version = settingVersion,
versionStatus = VersionStatus.RELEASED,
updateLastModifyUser = true,
isTemplate = true
)
logger.info("Save the template pipeline setting - ($setting)")
return pipelineSettingFacadeService.saveSetting(
context = context,
if (templateName.name != templateName.oldName) {
pipelineTemplatePermissionService.modifyResource(
userId = userId,
projectId = projectId,
templateId = setting.pipelineId,
templateName = setting.pipelineName
)
}
pipelineGroupService.updatePipelineLabel(
userId = userId,
projectId = setting.projectId,
pipelineId = setting.pipelineId,
setting = setting,
isTemplate = isTemplate
labelIds = setting.labels
)
return setting.copy(version = settingVersion)
}

fun insertTemplateSetting(
Expand All @@ -112,13 +135,10 @@ class TemplateSettingService @Autowired constructor(
projectId = projectId, pipelineId = templateId, pipelineName = pipelineName,
maxPipelineResNum = null, failSubscription = failSubscription
)
return pipelineSettingFacadeService.saveSetting(
return saveTemplatePipelineSetting(
context = context,
userId = userId,
projectId = projectId,
pipelineId = templateId,
setting = setting,
isTemplate = isTemplate
setting = setting
)
}

Expand Down

0 comments on commit a85b694

Please sign in to comment.