Skip to content

Commit

Permalink
Merge pull request #9683 from carlyin0801/issue_9677_store_inner_pipe…
Browse files Browse the repository at this point in the history
…line_fix

pref:支持刷新研发商店多个组件内置打包流水线 #9677
  • Loading branch information
bkci-bot authored Nov 23, 2023
2 parents 0bfddd6 + c778112 commit 2d14f2a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@
*/
package com.tencent.devops.store.dao.image

import com.tencent.devops.common.api.constant.KEY_VERSION
import com.tencent.devops.model.store.tables.TImage
import com.tencent.devops.model.store.tables.TImageFeature
import com.tencent.devops.model.store.tables.TStorePipelineRel
import com.tencent.devops.model.store.tables.TStoreProjectRel
import com.tencent.devops.process.utils.KEY_PIPELINE_ID
import com.tencent.devops.store.dao.common.AbstractStoreCommonDao
import com.tencent.devops.store.pojo.common.KEY_CREATOR
import com.tencent.devops.store.pojo.common.KEY_PROJECT_CODE
import com.tencent.devops.store.pojo.common.KEY_STORE_CODE
import com.tencent.devops.store.pojo.common.StoreBaseInfo
import com.tencent.devops.store.pojo.common.enums.StoreProjectTypeEnum
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import org.jooq.Condition
import org.jooq.DSLContext
import org.jooq.Record
Expand Down Expand Up @@ -59,7 +68,7 @@ class ImageCommonDao : AbstractStoreCommonDao() {

override fun getStoreCodeListByName(dslContext: DSLContext, storeName: String): Result<out Record>? {
return with(TImage.T_IMAGE) {
dslContext.select(IMAGE_CODE.`as`("storeCode")).from(this)
dslContext.select(IMAGE_CODE.`as`(KEY_STORE_CODE)).from(this)
.where(IMAGE_NAME.contains(storeName))
.groupBy(IMAGE_CODE)
.fetch()
Expand All @@ -85,15 +94,23 @@ class ImageCommonDao : AbstractStoreCommonDao() {
dslContext: DSLContext,
storeCodeList: List<String>
): Result<out Record>? {
return with(TImage.T_IMAGE) {
dslContext.select(
IMAGE_CODE.`as`("storeCode"),
VERSION.`as`("version")
).from(this)
.where(IMAGE_CODE.`in`(storeCodeList))
.and(LATEST_FLAG.eq(true))
.fetch()
}
val ti = TImage.T_IMAGE
val tspr = TStoreProjectRel.T_STORE_PROJECT_REL
val tspir = TStorePipelineRel.T_STORE_PIPELINE_REL
return dslContext.select(
ti.IMAGE_CODE.`as`(KEY_STORE_CODE),
ti.VERSION.`as`(KEY_VERSION),
tspr.PROJECT_CODE.`as`(KEY_PROJECT_CODE),
tspr.CREATOR.`as`(KEY_CREATOR),
tspir.PIPELINE_ID.`as`(KEY_PIPELINE_ID)
).from(ti)
.join(tspr).on(ti.IMAGE_CODE.eq(tspr.STORE_CODE))
.join(tspir).on(ti.IMAGE_CODE.eq(tspir.STORE_CODE).and(tspr.STORE_TYPE.eq(tspir.STORE_TYPE)))
.where(tspr.STORE_TYPE.eq(StoreTypeEnum.ATOM.type.toByte()))
.and(ti.LATEST_FLAG.eq(true))
.and(tspr.TYPE.eq(StoreProjectTypeEnum.INIT.type.toByte()))
.and(ti.IMAGE_CODE.`in`(storeCodeList))
.fetch()
}

override fun getStoreDevLanguages(dslContext: DSLContext, storeCode: String): List<String>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
package com.tencent.devops.store.dao.atom

import com.tencent.devops.common.api.constant.JS
import com.tencent.devops.common.api.constant.KEY_BRANCH
import com.tencent.devops.common.api.constant.KEY_REPOSITORY_HASH_ID
import com.tencent.devops.common.api.constant.KEY_REPOSITORY_PATH
import com.tencent.devops.common.api.constant.KEY_SCRIPT
import com.tencent.devops.common.api.constant.KEY_VERSION
import com.tencent.devops.common.api.enums.FrontendTypeEnum
import com.tencent.devops.model.store.tables.TAtom
import com.tencent.devops.model.store.tables.TAtomEnvInfo
import com.tencent.devops.model.store.tables.TStoreBuildInfo
import com.tencent.devops.model.store.tables.TStorePipelineRel
import com.tencent.devops.model.store.tables.TStoreProjectRel
import com.tencent.devops.process.utils.KEY_PIPELINE_ID
Expand Down Expand Up @@ -92,7 +90,7 @@ class AtomCommonDao : AbstractStoreCommonDao() {

override fun getStoreCodeListByName(dslContext: DSLContext, storeName: String): Result<out Record>? {
return with(TAtom.T_ATOM) {
dslContext.select(ATOM_CODE.`as`("storeCode")).from(this)
dslContext.select(ATOM_CODE.`as`(KEY_STORE_CODE)).from(this)
.where(NAME.contains(storeName))
.groupBy(ATOM_CODE)
.fetch()
Expand All @@ -105,25 +103,22 @@ class AtomCommonDao : AbstractStoreCommonDao() {
): Result<out Record>? {
val ta = TAtom.T_ATOM
val taei = TAtomEnvInfo.T_ATOM_ENV_INFO
val tsbi = TStoreBuildInfo.T_STORE_BUILD_INFO
val tspr = TStoreProjectRel.T_STORE_PROJECT_REL
val tspir = TStorePipelineRel.T_STORE_PIPELINE_REL
return dslContext.select(
ta.ATOM_CODE.`as`(KEY_STORE_CODE),
ta.VERSION.`as`(KEY_VERSION),
ta.REPOSITORY_HASH_ID.`as`(KEY_REPOSITORY_HASH_ID),
ta.CODE_SRC.`as`(KEY_CODE_SRC),
ta.BRANCH.`as`(KEY_BRANCH),
taei.LANGUAGE.`as`(KEY_LANGUAGE),
tsbi.SCRIPT.`as`(KEY_SCRIPT),
tsbi.REPOSITORY_PATH.`as`(KEY_REPOSITORY_PATH),
tspr.PROJECT_CODE.`as`(KEY_PROJECT_CODE),
tspr.CREATOR.`as`(KEY_CREATOR),
tspir.PIPELINE_ID.`as`(KEY_PIPELINE_ID)
).from(ta).leftJoin(taei).on(ta.ID.eq(taei.ATOM_ID))
.join(tsbi).on(taei.LANGUAGE.eq(tsbi.LANGUAGE))
.join(tspr).on(ta.ATOM_CODE.eq(tspr.STORE_CODE).and(tsbi.STORE_TYPE.eq(tspr.STORE_TYPE)))
.join(tspir).on(ta.ATOM_CODE.eq(tspir.STORE_CODE).and(tsbi.STORE_TYPE.eq(tspir.STORE_TYPE)))
.where(tsbi.STORE_TYPE.eq(StoreTypeEnum.ATOM.type.toByte()))
.join(tspr).on(ta.ATOM_CODE.eq(tspr.STORE_CODE))
.join(tspir).on(ta.ATOM_CODE.eq(tspir.STORE_CODE).and(tspr.STORE_TYPE.eq(tspir.STORE_TYPE)))
.where(tspr.STORE_TYPE.eq(StoreTypeEnum.ATOM.type.toByte()))
.and(ta.LATEST_FLAG.eq(true))
.and(tspr.TYPE.eq(StoreProjectTypeEnum.INIT.type.toByte()))
.and(ta.ATOM_CODE.`in`(storeCodeList))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class StoreBuildInfoDao {
dslContext: DSLContext,
language: String,
storeType: StoreTypeEnum
): TStoreBuildInfoRecord {
): TStoreBuildInfoRecord? {
return with(TStoreBuildInfo.T_STORE_BUILD_INFO) {
dslContext.selectFrom(this)
.where(LANGUAGE.eq(language))
.and(STORE_TYPE.eq(storeType.type.toByte()))
.fetchOne()!!
.fetchOne()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@

package com.tencent.devops.store.dao.template

import com.tencent.devops.common.api.constant.KEY_VERSION
import com.tencent.devops.model.store.tables.TTemplate
import com.tencent.devops.store.dao.common.AbstractStoreCommonDao
import com.tencent.devops.store.pojo.common.KEY_STORE_CODE
import com.tencent.devops.store.pojo.common.StoreBaseInfo
import org.jooq.Condition
import org.jooq.DSLContext
Expand Down Expand Up @@ -74,7 +76,7 @@ class TemplateCommonDao : AbstractStoreCommonDao() {

override fun getStoreCodeListByName(dslContext: DSLContext, storeName: String): Result<out Record>? {
return with(TTemplate.T_TEMPLATE) {
dslContext.select(TEMPLATE_CODE.`as`("storeCode")).from(this)
dslContext.select(TEMPLATE_CODE.`as`(KEY_STORE_CODE)).from(this)
.where(TEMPLATE_NAME.contains(storeName))
.groupBy(TEMPLATE_CODE)
.fetch()
Expand All @@ -87,8 +89,8 @@ class TemplateCommonDao : AbstractStoreCommonDao() {
): Result<out Record>? {
return with(TTemplate.T_TEMPLATE) {
dslContext.select(
TEMPLATE_CODE.`as`("storeCode"),
VERSION.`as`("version")
TEMPLATE_CODE.`as`(KEY_STORE_CODE),
VERSION.`as`(KEY_VERSION)
).from(this)
.where(TEMPLATE_CODE.`in`(storeCodeList))
.and(LATEST_FLAG.eq(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package com.tencent.devops.store.service.common.impl

import com.tencent.devops.common.api.constant.CommonMessageCode
import com.tencent.devops.common.api.constant.KEY_BRANCH
import com.tencent.devops.common.api.constant.KEY_REPOSITORY_HASH_ID
import com.tencent.devops.common.api.constant.KEY_REPOSITORY_PATH
import com.tencent.devops.common.api.constant.KEY_SCRIPT
Expand All @@ -50,6 +51,7 @@ import com.tencent.devops.process.utils.KEY_PIPELINE_NAME
import com.tencent.devops.store.dao.common.AbstractStoreCommonDao
import com.tencent.devops.store.dao.common.BusinessConfigDao
import com.tencent.devops.store.dao.common.OperationLogDao
import com.tencent.devops.store.dao.common.StoreBuildInfoDao
import com.tencent.devops.store.dao.common.StoreProjectRelDao
import com.tencent.devops.store.pojo.common.KEY_CREATOR
import com.tencent.devops.store.pojo.common.KEY_LANGUAGE
Expand Down Expand Up @@ -78,6 +80,9 @@ class StorePipelineServiceImpl : StorePipelineService {
@Autowired
private lateinit var businessConfigDao: BusinessConfigDao

@Autowired
private lateinit var storeBuildInfoDao: StoreBuildInfoDao

@Autowired
private lateinit var operationLogDao: OperationLogDao

Expand Down Expand Up @@ -224,7 +229,7 @@ class StorePipelineServiceImpl : StorePipelineService {
)
val grayStoreCodeList =
projectRelRecords?.getValues(TStoreProjectRel.T_STORE_PROJECT_REL.STORE_CODE)
if (grayStoreCodeList != null && grayStoreCodeList.isNotEmpty()) {
if (!grayStoreCodeList.isNullOrEmpty()) {
updatePipelineModel(
storeType = storeType,
storeCodeList = grayStoreCodeList,
Expand Down Expand Up @@ -263,22 +268,37 @@ class StorePipelineServiceImpl : StorePipelineService {
// 获取研发商店组件信息
val storeInfoRecords = storeCommonDao.getLatestStoreInfoListByCodes(dslContext, storeCodeList)
val pipelineModelVersionList = mutableListOf<PipelineModelVersion>()
storeInfoRecords?.forEach { storeInfo ->
val projectCode = storeInfo[KEY_PROJECT_CODE] as String
val storeCode = storeInfo[KEY_STORE_CODE] as String
var pipelineName = "am-$projectCode-$storeCode-${System.currentTimeMillis()}"
if (pipelineName.toCharArray().size > 128) {
pipelineName = "am-$storeCode-${UUIDUtil.generate()}"
}
val paramMap = mapOf(
storeInfoRecords?.forEach { storeInfoRecord ->
val storeInfoMap = storeInfoRecord.intoMap()
val projectCode = storeInfoMap[KEY_PROJECT_CODE]?.toString() ?: ""
val storeCode = storeInfoMap[KEY_STORE_CODE] as String
val pipelineName = "am-$storeCode-${UUIDUtil.generate()}"
val paramMap = mutableMapOf(
KEY_PIPELINE_NAME to pipelineName,
KEY_STORE_CODE to storeCode,
KEY_VERSION to storeInfo[KEY_VERSION],
KEY_LANGUAGE to storeInfo[KEY_LANGUAGE],
KEY_SCRIPT to StringEscapeUtils.escapeJava(storeInfo[KEY_SCRIPT] as String),
KEY_REPOSITORY_HASH_ID to storeInfo[KEY_REPOSITORY_HASH_ID],
KEY_REPOSITORY_PATH to (storeInfo[KEY_REPOSITORY_PATH] ?: "")
KEY_VERSION to storeInfoMap[KEY_VERSION]
)
val language = storeInfoMap[KEY_LANGUAGE]?.toString()
language?.let {
paramMap[KEY_LANGUAGE] = language
val storeBuildInfoRecord = storeBuildInfoDao.getStoreBuildInfoByLanguage(
dslContext = dslContext,
language = language,
storeType = StoreTypeEnum.valueOf(storeType)
)
storeBuildInfoRecord?.let {
paramMap[KEY_SCRIPT] = StringEscapeUtils.escapeJava(storeBuildInfoRecord.script)
paramMap[KEY_REPOSITORY_PATH] = storeBuildInfoRecord.repositoryPath ?: ""
}
}
val repositoryHashId = storeInfoMap[KEY_REPOSITORY_HASH_ID]?.toString()
repositoryHashId?.let {
paramMap[KEY_REPOSITORY_HASH_ID] = repositoryHashId
}
val branch = storeInfoMap[KEY_BRANCH]?.toString()
branch?.let {
paramMap[KEY_BRANCH] = branch
}
// 将流水线模型中的变量替换成具体的值
var convertModel = if (checkGrayFlag) {
val grayProjectSet = gray.grayProjectSet(redisOperation)
Expand All @@ -294,8 +314,8 @@ class StorePipelineServiceImpl : StorePipelineService {
pipelineModelVersionList.add(
PipelineModelVersion(
projectId = projectCode,
pipelineId = storeInfo[KEY_PIPELINE_ID] as String,
creator = storeInfo[KEY_CREATOR] as String,
pipelineId = storeInfoMap[KEY_PIPELINE_ID] as String,
creator = storeInfoMap[KEY_CREATOR] as String,
model = convertModel
)
)
Expand All @@ -308,7 +328,6 @@ class StorePipelineServiceImpl : StorePipelineService {
pipelineModelVersionList = pipelineModelVersionList
)
)
logger.info("updatePipelineModelResult:$updatePipelineModelResult")
if (updatePipelineModelResult.isNotOk()) {
batchAddOperateLogs(storeCodeList, storeType, userId, taskId)
}
Expand Down

0 comments on commit 2d14f2a

Please sign in to comment.