diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineAtomService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineAtomService.kt index 33750f2cc74..82850c24f58 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineAtomService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineAtomService.kt @@ -374,7 +374,11 @@ class PipelineAtomService @Autowired constructor( private fun validateUserAtomPermission(atomCode: String, userId: String) { val validateResult = - client.get(ServiceStoreResource::class).isStoreMember(atomCode, StoreTypeEnum.ATOM, userId) + client.get(ServiceStoreResource::class).validatePipelineUserAtomPermission( + storeCode = atomCode, + storeType = StoreTypeEnum.ATOM, + userId = userId + ) if (validateResult.isNotOk()) { throw ErrorCodeException( errorCode = validateResult.status.toString(), diff --git a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/OpStoreResource.kt b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/OpStoreResource.kt new file mode 100644 index 00000000000..3dda6c57b12 --- /dev/null +++ b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/OpStoreResource.kt @@ -0,0 +1,68 @@ +/* + * 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.store.api.common + +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 com.tencent.devops.store.pojo.common.enums.StoreTypeEnum +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.Parameter +import io.swagger.v3.oas.annotations.tags.Tag +import javax.ws.rs.Consumes +import javax.ws.rs.DELETE +import javax.ws.rs.HeaderParam +import javax.ws.rs.Path +import javax.ws.rs.Produces +import javax.ws.rs.QueryParam +import javax.ws.rs.core.MediaType + +@Tag(name = "OP_STORE", description = "OP-商店") +@Path("/op/store") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +interface OpStoreResource { + + @Operation(summary = "删除组件内置流水线") + @DELETE + @Path("/inner/pipeline/delete") + fun deleteStoreInnerPipeline( + @Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @Parameter(description = "组件类型", required = false) + @QueryParam("storeType") + storeType: StoreTypeEnum? = null, + @Parameter(description = "组件标识", required = false) + @QueryParam("storeCode") + storeCode: String? = null, + @Parameter(description = "需排除的项目", required = false) + @QueryParam("excludeProjectCode") + excludeProjectCode: String? = null + ): Result +} diff --git a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/ServiceStoreResource.kt b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/ServiceStoreResource.kt index 5e7a2ab0350..626c2af6949 100644 --- a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/ServiceStoreResource.kt +++ b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/ServiceStoreResource.kt @@ -109,6 +109,21 @@ interface ServiceStoreResource { userId: String ): Result + @Operation(summary = "校验流水线用户访问插件信息权限") + @GET + @Path("/codes/{storeCode}/pipeline/user/validate") + fun validatePipelineUserAtomPermission( + @Parameter(description = "标识", required = true) + @PathParam("storeCode") + storeCode: String, + @Parameter(description = "类型", required = true) + @QueryParam("storeType") + storeType: StoreTypeEnum, + @Parameter(description = "用户ID", required = true) + @QueryParam("userId") + userId: String + ): Result + @Operation(summary = "判断错误码是否合规") @POST @Path("/codes/{storeCode}/errorCode/compliance") diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/AtomCommonDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/AtomCommonDao.kt index 7682cd6f102..83203a309a6 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/AtomCommonDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/AtomCommonDao.kt @@ -44,6 +44,7 @@ import com.tencent.devops.store.pojo.common.KEY_CREATOR import com.tencent.devops.store.pojo.common.KEY_LANGUAGE 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.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 @@ -193,4 +194,10 @@ class AtomCommonDao : AbstractStoreCommonDao() { .fetchAny()?.into(String::class.java) } } + + override fun getStoreCodeById(dslContext: DSLContext, storeId: String): String? { + return with(TAtom.T_ATOM) { + dslContext.select(ATOM_CODE).from(this).where(ID.eq(storeId)).fetchOne(0, String::class.java) + } + } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/MarketAtomEnvInfoDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/MarketAtomEnvInfoDao.kt index e5b66c191f1..c12bb55b84f 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/MarketAtomEnvInfoDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/MarketAtomEnvInfoDao.kt @@ -102,7 +102,8 @@ class MarketAtomEnvInfoDao { atomCode: String, version: String, atomDefaultFlag: Boolean, - atomStatusList: List? + atomStatusList: List?, + queryProjectFlag: Boolean = true ): Record? { val tAtom = TAtom.T_ATOM val tStoreProjectRel = TStoreProjectRel.T_STORE_PROJECT_REL @@ -115,17 +116,21 @@ class MarketAtomEnvInfoDao { atomStatusList = atomStatusList )).orderBy(tAtom.CREATE_TIME.desc()).limit(1).fetchOne() } else { - getAtomBaseInfoStep(dslContext, tAtom) - .join(tStoreProjectRel) - .on(tAtom.ATOM_CODE.eq(tStoreProjectRel.STORE_CODE)) - .where(queryNormalAtomCondition( + val baseStep = getAtomBaseInfoStep(dslContext, tAtom) + if (queryProjectFlag) { + baseStep.join(tStoreProjectRel).on(tAtom.ATOM_CODE.eq(tStoreProjectRel.STORE_CODE)) + } + baseStep.where( + queryNormalAtomCondition( tAtom = tAtom, tStoreProjectRel = tStoreProjectRel, projectCode = projectCode, atomCode = atomCode, version = version, - atomStatusList = atomStatusList - )).orderBy(tAtom.CREATE_TIME.desc()).limit(1).fetchOne() + atomStatusList = atomStatusList, + queryProjectFlag = queryProjectFlag + ) + ).orderBy(tAtom.CREATE_TIME.desc()).limit(1).fetchOne() } } @@ -164,7 +169,7 @@ class MarketAtomEnvInfoDao { val conditions = mutableListOf() conditions.add(tAtom.ATOM_CODE.eq(atomCode)) conditions.add(tAtom.VERSION.like(VersionUtils.generateQueryVersion(version))) - if (atomStatusList != null && atomStatusList.isNotEmpty()) { + if (!atomStatusList.isNullOrEmpty()) { conditions.add(tAtom.ATOM_STATUS.`in`(atomStatusList)) } return conditions @@ -187,12 +192,15 @@ class MarketAtomEnvInfoDao { projectCode: String, atomCode: String, version: String, - atomStatusList: List? + atomStatusList: List?, + queryProjectFlag: Boolean = true ): MutableList { val conditions = getBaseQueryCondition(tAtom, atomCode, version, atomStatusList) conditions.add(tAtom.DEFAULT_FLAG.eq(false)) // 查普通插件 - conditions.add(tStoreProjectRel.PROJECT_CODE.eq(projectCode)) - conditions.add(tStoreProjectRel.STORE_TYPE.eq(StoreTypeEnum.ATOM.type.toByte())) + if (queryProjectFlag) { + conditions.add(tStoreProjectRel.PROJECT_CODE.eq(projectCode)) + conditions.add(tStoreProjectRel.STORE_TYPE.eq(StoreTypeEnum.ATOM.type.toByte())) + } return conditions } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomHandleBuildResultServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomHandleBuildResultServiceImpl.kt index 43d8013f937..4e6f387247c 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomHandleBuildResultServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomHandleBuildResultServiceImpl.kt @@ -34,14 +34,14 @@ import com.tencent.devops.common.redis.RedisLock import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.store.atom.dao.MarketAtomDao -import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum -import com.tencent.devops.store.pojo.common.ATOM_POST_VERSION_TEST_FLAG_KEY_PREFIX -import com.tencent.devops.store.pojo.common.STORE_LATEST_TEST_FLAG_KEY_PREFIX -import com.tencent.devops.store.pojo.common.publication.StoreBuildResultRequest import com.tencent.devops.store.atom.service.AtomReleaseService import com.tencent.devops.store.atom.service.MarketAtomService import com.tencent.devops.store.common.service.AbstractStoreHandleBuildResultService import com.tencent.devops.store.common.utils.VersionUtils +import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum +import com.tencent.devops.store.pojo.common.ATOM_POST_VERSION_TEST_FLAG_KEY_PREFIX +import com.tencent.devops.store.pojo.common.STORE_LATEST_TEST_FLAG_KEY_PREFIX +import com.tencent.devops.store.pojo.common.publication.StoreBuildResultRequest import org.jooq.DSLContext import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/MarketAtomEnvServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/MarketAtomEnvServiceImpl.kt index 958f018f5c3..529e17bf0d4 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/MarketAtomEnvServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/MarketAtomEnvServiceImpl.kt @@ -46,6 +46,7 @@ import com.tencent.devops.store.atom.factory.AtomBusHandleFactory import com.tencent.devops.store.atom.service.AtomService import com.tencent.devops.store.atom.service.MarketAtomCommonService import com.tencent.devops.store.atom.service.MarketAtomEnvService +import com.tencent.devops.store.common.configuration.StoreInnerPipelineConfig import com.tencent.devops.store.common.dao.ClassifyDao import com.tencent.devops.store.common.dao.StoreProjectRelDao import com.tencent.devops.store.common.service.StoreI18nMessageService @@ -63,8 +64,8 @@ import com.tencent.devops.store.pojo.common.ATOM_POST_ENTRY_PARAM import com.tencent.devops.store.pojo.common.ATOM_POST_FLAG import com.tencent.devops.store.pojo.common.ATOM_POST_NORMAL_PROJECT_FLAG_KEY_PREFIX import com.tencent.devops.store.pojo.common.ATOM_POST_VERSION_TEST_FLAG_KEY_PREFIX -import com.tencent.devops.store.pojo.common.version.StoreVersion import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum +import com.tencent.devops.store.pojo.common.version.StoreVersion import java.time.LocalDateTime import org.jooq.DSLContext import org.slf4j.LoggerFactory @@ -88,7 +89,8 @@ class MarketAtomEnvServiceImpl @Autowired constructor( private val atomService: AtomService, private val marketAtomCommonService: MarketAtomCommonService, private val storeI18nMessageService: StoreI18nMessageService, - private val redisOperation: RedisOperation + private val redisOperation: RedisOperation, + private val storeInnerPipelineConfig: StoreInnerPipelineConfig ) : MarketAtomEnvService { private val logger = LoggerFactory.getLogger(MarketAtomEnvServiceImpl::class.java) @@ -263,12 +265,15 @@ class MarketAtomEnvServiceImpl @Autowired constructor( AtomStatusEnum.UNDERCARRIAGING.status.toByte(), AtomStatusEnum.UNDERCARRIAGED.status.toByte() ) + val buildingFlag = + projectCode == storeInnerPipelineConfig.innerPipelineProject && atomStatus == AtomStatusEnum.BUILDING.status.toByte() val atomStatusList = getAtomStatusList( atomStatus = atomStatus, version = version, normalStatusList = normalStatusList, atomCode = atomCode, - projectCode = projectCode + projectCode = projectCode, + queryTestFlag = buildingFlag ) val atomDefaultFlag = marketAtomCommonService.isPublicAtom(atomCode) val atomBaseInfoRecord = marketAtomEnvInfoDao.getProjectAtomBaseInfo( @@ -277,7 +282,8 @@ class MarketAtomEnvServiceImpl @Autowired constructor( atomCode = atomCode, version = version, atomDefaultFlag = atomDefaultFlag, - atomStatusList = atomStatusList + atomStatusList = atomStatusList, + queryProjectFlag = !buildingFlag ) ?: throw ErrorCodeException( errorCode = CommonMessageCode.PARAMETER_IS_INVALID, params = arrayOf("[project($projectCode)-plugin($atomCode)]") @@ -414,7 +420,8 @@ class MarketAtomEnvServiceImpl @Autowired constructor( version: String, normalStatusList: List, atomCode: String, - projectCode: String + projectCode: String, + queryTestFlag: Boolean ): List { return if (atomStatus != null) { mutableListOf(atomStatus) @@ -428,7 +435,13 @@ class MarketAtomEnvServiceImpl @Autowired constructor( this.add(AtomStatusEnum.RELEASED.status.toByte()) } } - val flag = storeProjectRelDao.isTestProjectCode(dslContext, atomCode, StoreTypeEnum.ATOM, projectCode) + val flag = queryTestFlag || + storeProjectRelDao.isTestProjectCode( + dslContext = dslContext, + storeCode = atomCode, + storeType = StoreTypeEnum.ATOM, + projectCode = projectCode + ) if (flag) { // 初始化项目或者调试项目有权查处于测试中、审核中的插件 this.addAll( diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/configuration/StoreInnerPipelineConfig.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/configuration/StoreInnerPipelineConfig.kt index a4655934671..fab7880dec7 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/configuration/StoreInnerPipelineConfig.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/configuration/StoreInnerPipelineConfig.kt @@ -38,4 +38,10 @@ class StoreInnerPipelineConfig { @Value("\${store.innerPipeline.user:}") val innerPipelineUser: String = "" + + @Value("\${store.innerPipeline.gray.project:}") + val innerPipelineGrayProject: String = "" + + @Value("\${store.innerPipeline.gray.user:}") + val innerPipelineGrayUser: String = "" } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/AbstractStoreCommonDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/AbstractStoreCommonDao.kt index 2321e79dff1..528524b1e82 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/AbstractStoreCommonDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/AbstractStoreCommonDao.kt @@ -77,4 +77,9 @@ abstract class AbstractStoreCommonDao { ): StoreBaseInfo? abstract fun getStoreRepoHashIdByCode(dslContext: DSLContext, storeCode: String): String? + + abstract fun getStoreCodeById( + dslContext: DSLContext, + storeId: String + ): String? } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StorePipelineRelDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StorePipelineRelDao.kt index 3ac547fff81..82248cc78e1 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StorePipelineRelDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StorePipelineRelDao.kt @@ -32,9 +32,11 @@ import com.tencent.devops.model.store.tables.TStorePipelineRel import com.tencent.devops.model.store.tables.records.TStorePipelineRelRecord import com.tencent.devops.store.pojo.common.enums.StorePipelineBusTypeEnum import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum +import java.time.LocalDateTime +import org.jooq.Condition import org.jooq.DSLContext +import org.jooq.Result import org.springframework.stereotype.Repository -import java.time.LocalDateTime @Repository class StorePipelineRelDao { @@ -92,6 +94,30 @@ class StorePipelineRelDao { } } + fun getStorePipelineRelByStoreCode( + dslContext: DSLContext, + storeCode: String, + storeType: StoreTypeEnum + ): TStorePipelineRelRecord? { + with(TStorePipelineRel.T_STORE_PIPELINE_REL) { + return dslContext.selectFrom(this) + .where(STORE_CODE.eq(storeCode)) + .and(STORE_TYPE.eq(storeType.type.toByte())) + .orderBy(UPDATE_TIME.desc()) + .fetchOne() + } + } + + fun getStoreTypeByLatestPipelineId(dslContext: DSLContext, pipelineId: String): Byte? { + with(TStorePipelineRel.T_STORE_PIPELINE_REL) { + return dslContext.select(STORE_TYPE).from(this) + .where(PIPELINE_ID.eq(pipelineId)) + .orderBy(UPDATE_TIME.desc()) + .limit(1) + .fetchOne(0, Byte::class.java) + } + } + fun deleteStorePipelineRel(dslContext: DSLContext, storeCode: String, storeType: Byte) { with(TStorePipelineRel.T_STORE_PIPELINE_REL) { dslContext.deleteFrom(this) @@ -115,6 +141,23 @@ class StorePipelineRelDao { } } + fun updateStorePipelineProject( + dslContext: DSLContext, + storeCode: String, + storeType: StoreTypeEnum, + pipelineId: String, + projectCode: String + ) { + with(TStorePipelineRel.T_STORE_PIPELINE_REL) { + dslContext.update(this) + .set(PROJECT_CODE, projectCode) + .set(PIPELINE_ID, pipelineId) + .set(UPDATE_TIME, LocalDateTime.now()) + .where(STORE_CODE.eq(storeCode).and(STORE_TYPE.eq(storeType.type.toByte()))) + .execute() + } + } + fun deleteStorePipelineRelById(dslContext: DSLContext, id: String) { with(TStorePipelineRel.T_STORE_PIPELINE_REL) { dslContext.deleteFrom(this) @@ -122,4 +165,27 @@ class StorePipelineRelDao { .execute() } } + + fun getStorePipelineRelRecords( + dslContext: DSLContext, + limit: Int, + offset: Int, + storeType: StoreTypeEnum? = null, + storeCode: String? = null + ): Result? { + return with(TStorePipelineRel.T_STORE_PIPELINE_REL) { + val conditions = mutableListOf() + storeType?.let { + conditions.add(STORE_TYPE.eq(storeType.type.toByte())) + } + storeCode?.let { + conditions.add(STORE_CODE.eq(storeCode)) + } + dslContext.selectFrom(this) + .where(conditions) + .orderBy(CREATE_TIME.asc(), ID.asc()) + .limit(limit).offset(offset) + .fetch() + } + } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StoreProjectRelDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StoreProjectRelDao.kt index a4c2a4833dc..4465f1d76e1 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StoreProjectRelDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StoreProjectRelDao.kt @@ -611,4 +611,24 @@ class StoreProjectRelDao { .fetchOne() } } + + /** + * 判断组件是否被用户安装 + */ + fun isInstalledByUser( + dslContext: DSLContext, + userId: String, + storeCode: String, + storeType: Byte + ): Boolean { + with(TStoreProjectRel.T_STORE_PROJECT_REL) { + return dslContext.selectCount() + .from(this) + .where(CREATOR.eq(userId)) + .and(STORE_CODE.eq(storeCode)) + .and(STORE_TYPE.eq(storeType)) + .and(TYPE.eq(StoreProjectTypeEnum.COMMON.type.toByte())) + .fetchOne(0, Long::class.java) != 0L + } + } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/OpStoreResourceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/OpStoreResourceImpl.kt new file mode 100644 index 00000000000..8257089585b --- /dev/null +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/OpStoreResourceImpl.kt @@ -0,0 +1,57 @@ +/* + * 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.store.common.resources + +import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.web.RestResource +import com.tencent.devops.store.api.common.OpStoreResource +import com.tencent.devops.store.common.service.StorePipelineService +import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum +import org.springframework.beans.factory.annotation.Autowired + +@RestResource +class OpStoreResourceImpl @Autowired constructor( + private val storePipelineService: StorePipelineService +) : OpStoreResource { + + override fun deleteStoreInnerPipeline( + userId: String, + storeType: StoreTypeEnum?, + storeCode: String?, + excludeProjectCode: String? + ): Result { + return Result( + storePipelineService.deleteStoreInnerPipeline( + userId = userId, + storeType = storeType, + storeCode = storeCode, + excludeProjectCode = excludeProjectCode + ) + ) + } +} diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/ServiceStoreResourceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/ServiceStoreResourceImpl.kt index 949c443ed93..75f6d784bf7 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/ServiceStoreResourceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/ServiceStoreResourceImpl.kt @@ -30,6 +30,7 @@ package com.tencent.devops.store.common.resources import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.web.RestResource import com.tencent.devops.store.api.common.ServiceStoreResource +import com.tencent.devops.store.common.configuration.StoreInnerPipelineConfig import com.tencent.devops.store.common.service.ClassifyService import com.tencent.devops.store.common.service.StoreBuildService import com.tencent.devops.store.common.service.StoreComponentManageService @@ -53,7 +54,8 @@ class ServiceStoreResourceImpl @Autowired constructor( private val storeErrorCodeService: StoreErrorCodeService, private val storeMemberService: StoreMemberService, private val classifyService: ClassifyService, - private val storeComponentManageService: StoreComponentManageService + private val storeComponentManageService: StoreComponentManageService, + private val storeInnerPipelineConfig: StoreInnerPipelineConfig ) : ServiceStoreResource { override fun uninstall(storeCode: String, storeType: StoreTypeEnum, projectCode: String): Result { @@ -80,6 +82,18 @@ class ServiceStoreResourceImpl @Autowired constructor( ) } + override fun validatePipelineUserAtomPermission( + storeCode: String, + storeType: StoreTypeEnum, + userId: String + ): Result { + return Result( + storeInnerPipelineConfig.innerPipelineUser == userId || storeMemberService.isStoreMember( + userId, storeCode, storeType.type.toByte() + ) + ) + } + override fun isComplianceErrorCode( storeCode: String, storeType: StoreTypeEnum, diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StoreCommonService.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StoreCommonService.kt index d667307c6e3..785cf6a2af6 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StoreCommonService.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StoreCommonService.kt @@ -27,12 +27,12 @@ package com.tencent.devops.store.common.service -import com.tencent.devops.store.pojo.common.publication.ReleaseProcessItem -import com.tencent.devops.store.pojo.common.publication.StoreProcessInfo -import com.tencent.devops.store.pojo.common.version.StoreShowVersionInfo import com.tencent.devops.store.pojo.common.enums.ReleaseTypeEnum import com.tencent.devops.store.pojo.common.enums.StoreStatusEnum import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum +import com.tencent.devops.store.pojo.common.publication.ReleaseProcessItem +import com.tencent.devops.store.pojo.common.publication.StoreProcessInfo +import com.tencent.devops.store.pojo.common.version.StoreShowVersionInfo import com.tencent.devops.store.pojo.common.version.VersionModel import org.jooq.DSLContext @@ -50,6 +50,14 @@ interface StoreCommonService { storeType: StoreTypeEnum ): String + /** + * 根据ID获取组件名称 + */ + fun getStoreCodeById( + storeId: String, + storeType: StoreTypeEnum + ): String + /** * 根据标识获取组件公共标识 */ diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StorePipelineService.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StorePipelineService.kt index 9d4ed6c26a1..5fbe0098418 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StorePipelineService.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StorePipelineService.kt @@ -29,6 +29,7 @@ package com.tencent.devops.store.common.service import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.store.pojo.common.UpdateStorePipelineModelRequest +import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum import com.tencent.devops.store.pojo.common.publication.StoreRunPipelineParam interface StorePipelineService { @@ -50,4 +51,26 @@ interface StorePipelineService { fun runPipeline( storeRunPipelineParam: StoreRunPipelineParam ): Boolean + + // 创建组件内置流水线 + fun creatStorePipelineByStoreCode( + storeCode: String? = null, + storeType: String, + grayFlag: Boolean = false + ): String + + /** + * 删除组件内置流水线 + * @param userId 用户ID + * @param storeType 组件类型 + * @param storeCode 组件标识 + * @param excludeProjectCode 需排除的项目 + * @return 布尔值 + */ + fun deleteStoreInnerPipeline( + userId: String, + storeType: StoreTypeEnum? = null, + storeCode: String? = null, + excludeProjectCode: String? = null + ): Boolean } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreBuildServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreBuildServiceImpl.kt index 9dcc4176a84..2248b945883 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreBuildServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreBuildServiceImpl.kt @@ -34,10 +34,10 @@ import com.tencent.devops.common.service.utils.SpringContextUtil import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.store.common.dao.StorePipelineBuildRelDao import com.tencent.devops.store.common.dao.StorePipelineRelDao -import com.tencent.devops.store.pojo.common.publication.StoreBuildResultRequest -import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum import com.tencent.devops.store.common.service.AbstractStoreHandleBuildResultService import com.tencent.devops.store.common.service.StoreBuildService +import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum +import com.tencent.devops.store.pojo.common.publication.StoreBuildResultRequest import org.jooq.DSLContext import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -60,15 +60,23 @@ class StoreBuildServiceImpl @Autowired constructor( ): Result { logger.info("handleStoreBuildResult params:[$pipelineId|$buildId|$storeBuildResultRequest]") // 查看该次构建流水线属于研发商店哪个组件类型 - val storePipelineRelRecord = storePipelineRelDao.getStorePipelineRelByPipelineId(dslContext, pipelineId) - ?: return I18nUtil.generateResponseDataObject( + val storeBuildInfoRecord = storePipelineBuildRelDao.getStorePipelineBuildRelByBuildId(dslContext, buildId) + logger.info("handleStoreBuildResult pipelineId:${storeBuildInfoRecord?.pipelineId}") + if (storeBuildInfoRecord == null) { + return I18nUtil.generateResponseDataObject( messageCode = CommonMessageCode.PARAMETER_IS_INVALID, params = arrayOf(pipelineId), language = I18nUtil.getLanguage(I18nUtil.getRequestUserId()) ) - val storeType = storePipelineRelRecord.storeType + } + val storeType = storeBuildInfoRecord.pipelineId?.let { + storePipelineRelDao.getStoreTypeByLatestPipelineId( + dslContext = dslContext, + pipelineId = it + ) + } val storeHandleBuildResultService = - getStoreHandleBuildResultService(StoreTypeEnum.getStoreType(storeType.toInt())) + getStoreHandleBuildResultService(StoreTypeEnum.getStoreType(storeType!!.toInt())) val result = storeHandleBuildResultService.handleStoreBuildResult(pipelineId, buildId, storeBuildResultRequest) logger.info("handleStoreBuildResult result is:$result") if (result.isNotOk() || result.data != true) { diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreCommonServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreCommonServiceImpl.kt index 0f713da6198..87d35f322fa 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreCommonServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreCommonServiceImpl.kt @@ -301,9 +301,10 @@ abstract class StoreCommonServiceImpl : StoreCommonService { val storeBuildInfoRecord = storePipelineBuildRelDao.getStorePipelineBuildRel(dslContext, storeId) if (null != storeBuildInfoRecord) { val pipelineId = storeBuildInfoRecord.pipelineId - val storePipelineRelRecord = storePipelineRelDao.getStorePipelineRelByPipelineId( + val storePipelineRelRecord = storePipelineRelDao.getStorePipelineRelByStoreCode( dslContext = dslContext, - pipelineId = pipelineId + storeType = storeType, + storeCode = storeCode ) var projectCode = storePipelineRelRecord?.projectCode if (projectCode.isNullOrBlank()) { @@ -532,4 +533,16 @@ abstract class StoreCommonServiceImpl : StoreCommonService { val currentNum = if (status == StoreStatusEnum.RELEASED) 1 else 0 return releaseTotalNum > currentNum } + + override fun getStoreCodeById( + storeId: String, + storeType: StoreTypeEnum + ): String { + var code = storeBaseQueryDao.getComponentById(dslContext, storeId)?.storeCode + if (code == null) { + val storeCommonDao = getStoreCommonDao(storeType.name) + code = storeCommonDao.getStoreCodeById(dslContext, storeId) + } + return code ?: "" + } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreLogServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreLogServiceImpl.kt index bf619636973..dc2cd5def5c 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreLogServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreLogServiceImpl.kt @@ -34,7 +34,8 @@ import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.log.api.ServiceLogResource import com.tencent.devops.store.common.configuration.StoreInnerPipelineConfig import com.tencent.devops.store.common.dao.StoreMemberDao -import com.tencent.devops.store.common.dao.StorePipelineRelDao +import com.tencent.devops.store.common.dao.StorePipelineBuildRelDao +import com.tencent.devops.store.common.service.StoreCommonService import com.tencent.devops.store.common.service.StoreLogService import com.tencent.devops.store.constant.StoreMessageCode.GET_INFO_NO_PERMISSION import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum @@ -51,9 +52,10 @@ import org.springframework.stereotype.Service class StoreLogServiceImpl @Autowired constructor( private val client: Client, private val dslContext: DSLContext, - private val storePipelineRelDao: StorePipelineRelDao, + private val storePipelineBuildRelDao: StorePipelineBuildRelDao, private val storeMemberDao: StoreMemberDao, - private val storeInnerPipelineConfig: StoreInnerPipelineConfig + private val storeInnerPipelineConfig: StoreInnerPipelineConfig, + private val storeCommonService: StoreCommonService ) : StoreLogService { override fun getInitLogs( @@ -66,7 +68,7 @@ class StoreLogServiceImpl @Autowired constructor( tag: String?, executeCount: Int? ): Result { - val validateResult = validateUserQueryPermission(storeType, pipelineId, userId) + val validateResult = validateUserQueryPermission(storeType, buildId, userId) if (validateResult.isNotOk()) { return Result(status = validateResult.status, message = validateResult.message, data = null) } @@ -101,7 +103,7 @@ class StoreLogServiceImpl @Autowired constructor( tag: String?, executeCount: Int? ): Result { - val validateResult = validateUserQueryPermission(storeType, pipelineId, userId) + val validateResult = validateUserQueryPermission(storeType, buildId, userId) if (validateResult.isNotOk()) { return Result(status = validateResult.status, message = validateResult.message, data = null) } @@ -140,7 +142,7 @@ class StoreLogServiceImpl @Autowired constructor( tag: String?, executeCount: Int? ): Result { - val validateResult = validateUserQueryPermission(storeType, pipelineId, userId) + val validateResult = validateUserQueryPermission(storeType, buildId, userId) if (validateResult.isNotOk()) { return Result(status = validateResult.status, message = validateResult.message, data = null) } @@ -170,27 +172,28 @@ class StoreLogServiceImpl @Autowired constructor( private fun validateUserQueryPermission( storeType: StoreTypeEnum, - pipelineId: String, + buildId: String, userId: String ): Result { // 查询是否是插件的成员,只有插件的成员才能看日志 - val storePipelineRelRecord = storePipelineRelDao.getStorePipelineRelByPipelineId(dslContext, pipelineId) + val storeBuildInfoRecord = storePipelineBuildRelDao.getStorePipelineBuildRelByBuildId(dslContext, buildId) ?: return I18nUtil.generateResponseDataObject( messageCode = CommonMessageCode.PARAMETER_IS_INVALID, - params = arrayOf(pipelineId), + params = arrayOf(buildId), language = I18nUtil.getLanguage(userId) ) + val storeCode = storeCommonService.getStoreCodeById(storeBuildInfoRecord.storeId, storeType) val flag = storeMemberDao.isStoreMember( dslContext = dslContext, userId = userId, - storeCode = storePipelineRelRecord.storeCode, + storeCode = storeCode, storeType = storeType.type.toByte() ) if (!flag) { return I18nUtil.generateResponseDataObject( messageCode = GET_INFO_NO_PERMISSION, language = I18nUtil.getLanguage(userId), - params = arrayOf(storePipelineRelRecord.storeCode) + params = arrayOf(storeCode) ) } return Result(true) diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreMemberServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreMemberServiceImpl.kt index 179f3d631c8..87ab505d195 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreMemberServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreMemberServiceImpl.kt @@ -36,6 +36,7 @@ import com.tencent.devops.common.client.Client import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.model.store.tables.records.TStoreMemberRecord import com.tencent.devops.project.api.service.ServiceProjectResource +import com.tencent.devops.store.common.configuration.StoreInnerPipelineConfig import com.tencent.devops.store.constant.StoreMessageCode import com.tencent.devops.store.constant.StoreMessageCode.GET_INFO_NO_PERMISSION import com.tencent.devops.store.constant.StoreMessageCode.NO_COMPONENT_ADMIN_PERMISSION @@ -69,6 +70,8 @@ abstract class StoreMemberServiceImpl : StoreMemberService { lateinit var storeProjectRelDao: StoreProjectRelDao @Autowired lateinit var storeNotifyService: StoreNotifyService + @Autowired + lateinit var storeInnerPipelineConfig: StoreInnerPipelineConfig private val executorService = Executors.newFixedThreadPool(5) diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StorePipelineServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StorePipelineServiceImpl.kt index 2c1c4ae8ab6..879acada1a9 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StorePipelineServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StorePipelineServiceImpl.kt @@ -35,20 +35,22 @@ import com.tencent.devops.common.api.constant.KEY_SCRIPT import com.tencent.devops.common.api.constant.KEY_VERSION import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.api.util.UUIDUtil import com.tencent.devops.common.client.Client +import com.tencent.devops.common.pipeline.Model import com.tencent.devops.common.pipeline.enums.BuildStatus import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.enums.StartType -import com.tencent.devops.common.pipeline.pojo.StoreInitPipelineReq +import com.tencent.devops.common.redis.RedisLock import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.gray.Gray import com.tencent.devops.common.service.utils.SpringContextUtil import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.model.store.tables.TStoreProjectRel import com.tencent.devops.process.api.service.ServiceBuildResource -import com.tencent.devops.process.api.service.ServicePipelineInitResource +import com.tencent.devops.process.api.service.ServicePipelineResource import com.tencent.devops.process.api.service.ServicePipelineSettingResource import com.tencent.devops.process.pojo.setting.PipelineModelVersion import com.tencent.devops.process.pojo.setting.UpdatePipelineModelRequest @@ -74,17 +76,18 @@ 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.OperationLogCreateRequest import com.tencent.devops.store.pojo.common.UpdateStorePipelineModelRequest +import com.tencent.devops.store.pojo.common.config.BusinessConfigRequest import com.tencent.devops.store.pojo.common.enums.ScopeTypeEnum import com.tencent.devops.store.pojo.common.enums.StoreOperationTypeEnum import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum import com.tencent.devops.store.pojo.common.publication.StoreRunPipelineParam import com.tencent.devops.store.pojo.common.publication.UpdateStoreBaseDataPO +import java.util.concurrent.Executors import org.apache.commons.lang3.StringEscapeUtils import org.jooq.DSLContext import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service -import java.util.concurrent.Executors @Suppress("ALL") @Service @@ -118,7 +121,6 @@ class StorePipelineServiceImpl @Autowired constructor( userId: String, updateStorePipelineModelRequest: UpdateStorePipelineModelRequest ): Result { - val taskId = UUIDUtil.generate() val scopeType = updateStorePipelineModelRequest.scopeType val storeType = updateStorePipelineModelRequest.storeType val storeCodeList = updateStorePipelineModelRequest.storeCodeList @@ -144,37 +146,39 @@ class StorePipelineServiceImpl @Autowired constructor( pipelineModel = updatePipelineModel grayPipelineModel = updatePipelineModel } + val innerPipelineUser = storeInnerPipelineConfig.innerPipelineUser + val innerPipelineGrayUser = storeInnerPipelineConfig.innerPipelineGrayUser when (scopeType) { ScopeTypeEnum.ALL.name -> { - handleStorePipelineModel( + handleStorePublicPipelineModel( storeType = storeType, - taskId = taskId, - userId = userId, - pipelineModel = grayPipelineModel, - grayFlag = true - ) - handleStorePipelineModel( - storeType = storeType, - taskId = taskId, - userId = userId, + storeCode = null, + userId = innerPipelineUser, pipelineModel = pipelineModel, grayFlag = false ) + handleStorePublicPipelineModel( + storeType = storeType, + storeCode = null, + userId = innerPipelineGrayUser, + pipelineModel = grayPipelineModel, + grayFlag = true + ) } ScopeTypeEnum.GRAY.name -> { - handleStorePipelineModel( + handleStorePublicPipelineModel( storeType = storeType, - taskId = taskId, - userId = userId, + storeCode = null, + userId = innerPipelineGrayUser, pipelineModel = grayPipelineModel, grayFlag = true ) } ScopeTypeEnum.NO_GRAY.name -> { - handleStorePipelineModel( + handleStorePublicPipelineModel( storeType = storeType, - taskId = taskId, - userId = userId, + storeCode = null, + userId = innerPipelineUser, pipelineModel = pipelineModel, grayFlag = false ) @@ -187,15 +191,15 @@ class StorePipelineServiceImpl @Autowired constructor( language = I18nUtil.getLanguage(userId) ) } - updatePipelineModel( - storeType = storeType, - storeCodeList = storeCodeList, - userId = userId, - taskId = taskId, - defaultPipelineModel = pipelineModel, - checkGrayFlag = true, - grayPipelineModel = grayPipelineModel - ) + storeCodeList.forEach { + handleStorePublicPipelineModel( + storeType = storeType, + storeCode = it, + userId = storeInnerPipelineConfig.innerPipelineUser, + pipelineModel = pipelineModel, + grayFlag = false + ) + } } } return Result(true) @@ -214,62 +218,20 @@ class StorePipelineServiceImpl @Autowired constructor( ) val innerPipelineProject = storeInnerPipelineConfig.innerPipelineProject val innerPipelineUser = storeInnerPipelineConfig.innerPipelineUser + val pipelineId: String // 生成流水线启动参数 val startParams = storeReleaseSpecBusService.getStoreRunPipelineStartParams(storeRunPipelineParam) if (null == storePipelineRelRecord) { - val pipelineModelConfig = businessConfigDao.get( + pipelineId = creatStorePipelineByStoreCode(storeType = storeType.name) + storePipelineRelDao.add( dslContext = dslContext, - business = storeType.name, - feature = "initBuildPipeline", - businessValue = "PIPELINE_MODEL" - ) - var pipelineModel = pipelineModelConfig!!.configValue - val pipelineName = "am-$storeType-$storeCode-${UUIDUtil.generate()}" - val paramMap = mapOf( - KEY_PIPELINE_NAME to pipelineName - ) - // 将流水线模型中的变量替换成具体的值 - paramMap.forEach { (key, value) -> - pipelineModel = pipelineModel.replace("#{$key}", value) - } - val storeInitPipelineReq = StoreInitPipelineReq( - pipelineModel = pipelineModel, - startParams = startParams + storeCode = storeCode, + storeType = storeType, + pipelineId = pipelineId, + projectCode = innerPipelineProject ) - val storeInitPipelineResp = client.get(ServicePipelineInitResource::class) - .initStorePipeline(innerPipelineUser, innerPipelineProject, storeInitPipelineReq).data - logger.info("runStorePipeline storeInitPipelineResp is:$storeInitPipelineResp") - if (null != storeInitPipelineResp) { - val pipelineId = storeInitPipelineResp.pipelineId - storePipelineRelDao.add( - dslContext = dslContext, - storeCode = storeCode, - storeType = storeType, - pipelineId = pipelineId, - projectCode = innerPipelineProject - ) - val buildId = storeInitPipelineResp.buildId - if (!buildId.isNullOrBlank()) { - storePipelineBuildRelDao.add( - dslContext = dslContext, - storeId = storeId, - pipelineId = pipelineId, - buildId = buildId - ) - } - val storeStatus = storeReleaseSpecBusService.getStoreRunPipelineStatus(buildId) - storeStatus?.let { - storeBaseManageDao.updateStoreBaseInfo( - dslContext = dslContext, - updateStoreBaseDataPO = UpdateStoreBaseDataPO( - id = storeId, - status = storeStatus, - modifier = userId - ) - ) - } - } } else { + pipelineId = storePipelineRelRecord.pipelineId val buildInfoRecord = storePipelineBuildRelDao.getStorePipelineBuildRel(dslContext, storeId) // 判断插件版本最近一次的构建是否完成 val buildResult = if (buildInfoRecord != null) { @@ -293,37 +255,88 @@ class StorePipelineServiceImpl @Autowired constructor( ) } } - // 触发执行流水线 - val pipelineId = storePipelineRelRecord.pipelineId - val buildIdObj = client.get(ServiceBuildResource::class).manualStartupNew( - userId = innerPipelineUser, - projectId = innerPipelineProject, + } + // 触发执行流水线 + val buildIdObj = client.get(ServiceBuildResource::class).manualStartupNew( + userId = innerPipelineUser, + projectId = innerPipelineProject, + pipelineId = pipelineId, + values = startParams, + channelCode = ChannelCode.AM, + startType = StartType.SERVICE + ).data + var buildId: String? = null + if (null != buildIdObj) { + buildId = buildIdObj.id + storePipelineBuildRelDao.add( + dslContext = dslContext, + storeId = storeId, pipelineId = pipelineId, - values = startParams, - channelCode = ChannelCode.AM, - startType = StartType.SERVICE - ).data - var buildId: String? = null - if (null != buildIdObj) { - buildId = buildIdObj.id - storePipelineBuildRelDao.add( - dslContext = dslContext, - storeId = storeId, - pipelineId = pipelineId, - buildId = buildId + buildId = buildId + ) + } + val storeStatus = storeReleaseSpecBusService.getStoreRunPipelineStatus(buildId) + storeStatus?.let { + storeBaseManageDao.updateStoreBaseInfo( + dslContext = dslContext, + updateStoreBaseDataPO = UpdateStoreBaseDataPO( + id = storeId, + status = storeStatus, + modifier = userId ) - } - val storeStatus = storeReleaseSpecBusService.getStoreRunPipelineStatus(buildId) - storeStatus?.let { - storeBaseManageDao.updateStoreBaseInfo( + ) + } + return true + } + + override fun deleteStoreInnerPipeline( + userId: String, + storeType: StoreTypeEnum?, + storeCode: String?, + excludeProjectCode: String? + ): Boolean { + Executors.newFixedThreadPool(1).submit { + logger.info("begin deleteStoreInnerPipeline!!") + var offset = 0 + do { + // 查询组件内置流水线信息记录 + val storePipelineRelRecords = storePipelineRelDao.getStorePipelineRelRecords( dslContext = dslContext, - updateStoreBaseDataPO = UpdateStoreBaseDataPO( - id = storeId, - status = storeStatus, - modifier = userId - ) + offset = offset, + limit = pageSize, + storeType = storeType, + storeCode = storeCode ) - } + storePipelineRelRecords?.forEach { storePipelineRelRecord -> + var initProjectCode = storePipelineRelRecord.projectCode + if (excludeProjectCode == initProjectCode) { + // 如果内置流水线的项目属于要排除的项目,则不删除该内置流水线 + return@forEach + } + storePipelineBuildRelDao.deleteStorePipelineBuildRelByPipelineId( + dslContext, + storePipelineRelRecord.pipelineId + ) + storePipelineRelDao.deleteStorePipelineRelById(dslContext, storePipelineRelRecord.id) + if (initProjectCode.isNullOrBlank()) { + initProjectCode = storeProjectRelDao.getInitProjectCodeByStoreCode( + dslContext = dslContext, + storeCode = storePipelineRelRecord.storeCode, + storeType = storePipelineRelRecord.storeType + ) + } + // 调接口删除内置流水线 + client.get(ServicePipelineResource::class).delete( + userId = userId, + pipelineId = storePipelineRelRecord.pipelineId, + channelCode = ChannelCode.AM, + projectId = initProjectCode, + checkFlag = false + ) + } + offset += pageSize + } while (storePipelineRelRecords?.size == pageSize) + logger.info("end deleteStoreInnerPipeline!!") } return true } @@ -381,6 +394,185 @@ class StorePipelineServiceImpl @Autowired constructor( } } + private fun handleStorePublicPipelineModel( + storeType: String, + userId: String, + pipelineModel: String, + storeCode: String? = null, + grayFlag: Boolean + ) { + val str = "#{$KEY_PIPELINE_NAME}" + var model = pipelineModel + val suffix = storeCode ?: "PUBLIC" + var pipelineName = "$storeType-PIPELINE-BUILD:$suffix" + val projectCode = if (!grayFlag) { + storeInnerPipelineConfig.innerPipelineProject + } else { + pipelineName = "GRAY-$pipelineName" + storeInnerPipelineConfig.innerPipelineGrayProject + } + if (pipelineModel.contains(str)) { + model = pipelineModel.replace( + "#{$KEY_PIPELINE_NAME}", + pipelineName + ) + } + var publicPipelineId = redisOperation.get("$storeType-PIPELINE-BUILD:PUBLIC") + if (publicPipelineId.isNullOrBlank()) { + publicPipelineId = creatStorePipelineByStoreCode( + storeType = storeType, + grayFlag = grayFlag + ) + } + var pipelineId = if (storeCode != null) { + storePipelineRelDao.getStorePipelineRelByStoreCode( + dslContext = dslContext, + storeCode = storeCode, + storeType = StoreTypeEnum.valueOf(storeType) + )?.pipelineId + } else { + publicPipelineId + } + pipelineId ?: throw ErrorCodeException( + errorCode = CommonMessageCode.ERROR_INVALID_PARAM_, + params = arrayOf(storeCode ?: "$storeType-PIPELINE-BUILD:PUBLIC") + ) + logger.info("handleStorePublicPipelineModel pipelineId:$pipelineId|publicPipelineId:$publicPipelineId") + // 对已托管给公共项目的组件刷新内置流水线model时则给组件在公共项目下创建单独的流水线 + if (storeCode != null && pipelineId == publicPipelineId) { + pipelineId = creatStorePipelineByStoreCode( + storeCode = storeCode, + storeType = storeType, + grayFlag = grayFlag + ) + + val pipelineRelRecord = storePipelineRelDao.getStorePipelineRel( + dslContext = dslContext, + storeCode = storeCode, + storeType = StoreTypeEnum.valueOf(storeType) + ) + if (pipelineRelRecord == null) { + storePipelineRelDao.add( + dslContext = dslContext, + storeCode = storeCode, + storeType = StoreTypeEnum.valueOf(storeType), + pipelineId = pipelineId, + projectCode = storeInnerPipelineConfig.innerPipelineProject + ) + } else { + storePipelineRelDao.updateStorePipelineProject( + dslContext = dslContext, + storeCode = storeCode, + storeType = StoreTypeEnum.valueOf(storeType), + projectCode = storeInnerPipelineConfig.innerPipelineProject, + pipelineId = pipelineId + ) + } + } + val flag = client.get(ServicePipelineSettingResource::class).getPipelineSetting( + projectId = projectCode, + pipelineId = pipelineId, + channelCode = ChannelCode.AM + ).data != null + // 公共项目直接更新 + if (flag) { + client.get(ServicePipelineSettingResource::class) + .updatePipelineModel( + userId = userId, + updatePipelineModelRequest = UpdatePipelineModelRequest( + pipelineModelVersionList = listOf( + PipelineModelVersion( + projectId = projectCode, + pipelineId = pipelineId, + creator = storeInnerPipelineConfig.innerPipelineUser, + model = model + ) + ) + ) + ) + } + } + + override fun creatStorePipelineByStoreCode( + storeCode: String?, + storeType: String, + grayFlag: Boolean + ): String { + val suffix = storeCode ?: "PUBLIC" + var pipelineName = "$storeType-PIPELINE-BUILD:$suffix" + var key = "CREAT-$pipelineName" + if (grayFlag) { + key = "GRAY-$key" + } + storeCode?.let { key += "-$storeCode" } + val lock = RedisLock(redisOperation, key, 60L) + try { + lock.lock() + if (grayFlag) { + pipelineName = "GRAY-$pipelineName" + } + val innerPipelineUser = if (!grayFlag) { + storeInnerPipelineConfig.innerPipelineUser + } else { + storeInnerPipelineConfig.innerPipelineGrayUser + } + val innerPipelineProject = if (!grayFlag) { + storeInnerPipelineConfig.innerPipelineProject + } else { + storeInnerPipelineConfig.innerPipelineGrayProject + } + val businessValue = if (!grayFlag) "PIPELINE" else "GRAY_PIPELINE" + // 获取已创建的公共流水线 + val pipelineIdConfig = businessConfigDao.get( + dslContext = dslContext, + business = StoreTypeEnum.valueOf(storeType).name, + feature = "initBuildPipeline", + businessValue = "${businessValue}_ID" + ) + pipelineIdConfig?.let { + return it.configValue + } + val pipelineModelConfig = businessConfigDao.get( + dslContext = dslContext, + business = StoreTypeEnum.valueOf(storeType).name, + feature = "initBuildPipeline", + businessValue = if (!grayFlag) "${businessValue}_MODEL" else "${businessValue}_MODEL" + ) + val pipelineModel = pipelineModelConfig!!.configValue.replace( + "#{$KEY_PIPELINE_NAME}", + pipelineName + ) + val model = JsonUtil.to(pipelineModel, Model::class.java) + val pipelineId = client.get(ServicePipelineResource::class).create( + userId = innerPipelineUser, + projectId = innerPipelineProject, + pipeline = model, + channelCode = ChannelCode.AM + ).data!!.id + if (storeCode == null) { + redisOperation.set( + key = pipelineName, + value = pipelineId, + expired = false + ) + // 持久化公共组件内置流水线 + businessConfigDao.add( + dslContext = dslContext, + request = BusinessConfigRequest( + business = StoreTypeEnum.valueOf(storeType).name, + feature = "initBuildPipeline", + businessValue = "${businessValue}_ID", + configValue = pipelineId, + description = "${StoreTypeEnum.valueOf(storeType).name} init build pipeline id" + ) + ) + } + return pipelineId + } finally { + lock.unlock() + } + } + private fun updatePipelineModel( storeType: String, storeCodeList: List, diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreProjectServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreProjectServiceImpl.kt index 5fe6e8d04fd..395b1a95063 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreProjectServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreProjectServiceImpl.kt @@ -38,7 +38,6 @@ import com.tencent.devops.common.redis.RedisLock import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.utils.LogUtils import com.tencent.devops.common.web.utils.I18nUtil -import com.tencent.devops.process.api.service.ServicePipelineResource import com.tencent.devops.project.api.service.ServiceProjectResource import com.tencent.devops.repository.api.ServiceRepositoryResource import com.tencent.devops.store.common.dao.StorePipelineBuildRelDao @@ -372,12 +371,6 @@ class StoreProjectServiceImpl @Autowired constructor( override fun updateStoreInitProject(userId: String, storeProjectInfo: StoreProjectInfo): Boolean { dslContext.transaction { configuration -> val context = DSL.using(configuration) - // 获取组件当前初始化项目 - val initProjectInfo = storeProjectRelDao.getInitProjectInfoByStoreCode( - dslContext = context, - storeCode = storeProjectInfo.storeCode, - storeType = storeProjectInfo.storeType.type.toByte() - )!! // 更新组件关联初始化项目 storeProjectRelDao.updateStoreInitProject(context, userId, storeProjectInfo) val testProjectInfo = storeProjectRelDao.getUserTestProjectRelByStoreCode( @@ -404,22 +397,6 @@ class StoreProjectServiceImpl @Autowired constructor( type = StoreProjectTypeEnum.TEST.type.toByte() ) } - val storePipelineRel = storePipelineRelDao.getStorePipelineRel( - dslContext = context, - storeCode = storeProjectInfo.storeCode, - storeType = storeProjectInfo.storeType - ) - storePipelineRel?.let { - storePipelineRelDao.deleteStorePipelineRelById(context, storePipelineRel.id) - storePipelineBuildRelDao.deleteStorePipelineBuildRelByPipelineId(context, storePipelineRel.pipelineId) - client.get(ServicePipelineResource::class).delete( - userId = userId, - pipelineId = it.pipelineId, - channelCode = ChannelCode.AM, - projectId = initProjectInfo.projectCode, - checkFlag = false - ) - } val storeRepoHashId = storeCommonService.getStoreRepoHashIdByCode(storeProjectInfo.storeCode, storeProjectInfo.storeType) storeRepoHashId?.let { diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/dao/ImageCommonDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/dao/ImageCommonDao.kt index 252e07d262b..08f3055972a 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/dao/ImageCommonDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/dao/ImageCommonDao.kt @@ -159,4 +159,10 @@ class ImageCommonDao : AbstractStoreCommonDao() { override fun getStoreRepoHashIdByCode(dslContext: DSLContext, storeCode: String): String? { return null } + + override fun getStoreCodeById(dslContext: DSLContext, storeId: String): String? { + return with(TImage.T_IMAGE) { + dslContext.select(IMAGE_CODE).from(this).where(ID.eq(storeId)).fetchOne(0, String::class.java) + } + } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/service/ImageReleaseService.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/service/ImageReleaseService.kt index e19ca843104..7dc0f088eb8 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/service/ImageReleaseService.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/service/ImageReleaseService.kt @@ -42,15 +42,14 @@ import com.tencent.devops.common.api.util.UUIDUtil import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.enums.StartType -import com.tencent.devops.common.pipeline.pojo.StoreInitPipelineReq import com.tencent.devops.common.pipeline.type.BuildType import com.tencent.devops.common.pipeline.type.docker.ImageType import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.image.api.ServiceImageResource import com.tencent.devops.model.store.tables.records.TImageRecord import com.tencent.devops.process.api.service.ServiceBuildResource -import com.tencent.devops.process.api.service.ServicePipelineInitResource import com.tencent.devops.project.api.service.ServiceProjectResource +import com.tencent.devops.store.common.configuration.StoreInnerPipelineConfig import com.tencent.devops.store.common.dao.BusinessConfigDao import com.tencent.devops.store.common.dao.StoreMemberDao import com.tencent.devops.store.common.dao.StorePipelineBuildRelDao @@ -59,6 +58,7 @@ import com.tencent.devops.store.common.dao.StoreProjectRelDao import com.tencent.devops.store.common.dao.StoreReleaseDao import com.tencent.devops.store.common.dao.StoreStatisticTotalDao import com.tencent.devops.store.common.service.StoreCommonService +import com.tencent.devops.store.common.service.StorePipelineService import com.tencent.devops.store.common.utils.VersionUtils import com.tencent.devops.store.constant.StoreMessageCode import com.tencent.devops.store.constant.StoreMessageCode.IMAGE_ADD_NO_PROJECT_MEMBER @@ -94,13 +94,13 @@ import com.tencent.devops.store.pojo.image.request.MarketImageRelRequest import com.tencent.devops.store.pojo.image.request.MarketImageUpdateRequest import com.tencent.devops.store.pojo.image.response.ImageAgentTypeInfo import com.tencent.devops.ticket.api.ServiceCredentialResource +import java.time.LocalDateTime +import java.util.Base64 import org.jooq.DSLContext import org.jooq.impl.DSL import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value -import java.time.LocalDateTime -import java.util.Base64 @Suppress("ALL") abstract class ImageReleaseService { @@ -161,9 +161,15 @@ abstract class ImageReleaseService { @Autowired lateinit var imageNotifyService: ImageNotifyService + @Autowired + lateinit var storePipelineService: StorePipelineService + @Autowired lateinit var client: Client + @Autowired + lateinit var storeInnerPipelineConfig: StoreInnerPipelineConfig + private val logger = LoggerFactory.getLogger(ImageReleaseService::class.java) @Value("\${store.imageApproveSwitch:close}") @@ -620,11 +626,12 @@ abstract class ImageReleaseService { val imageCode = imageRecord.imageCode val version = imageRecord.version val imagePipelineRelRecord = storePipelineRelDao.getStorePipelineRel(context, imageCode, StoreTypeEnum.IMAGE) + // 查找新增镜像时关联的项目 val projectCode = storeProjectRelDao.getInitProjectCodeByStoreCode( - context, - imageCode, - StoreTypeEnum.IMAGE.type.toByte() - ) // 查找新增镜像时关联的项目 + dslContext = context, + storeCode = imageCode, + storeType = StoreTypeEnum.IMAGE.type.toByte() + ) ?: throw ErrorCodeException(errorCode = CommonMessageCode.SYSTEM_ERROR) val ticketId = imageRecord.ticketId var userName: String? = null var password: String? = null @@ -633,7 +640,7 @@ abstract class ImageReleaseService { val encoder = Base64.getEncoder() val decoder = Base64.getDecoder() val credentialResult = client.get(ServiceCredentialResource::class).get( - projectCode!!, ticketId, + projectCode, ticketId, encoder.encodeToString(pair.publicKey) ) if (credentialResult.isNotOk() || credentialResult.data == null) { @@ -672,84 +679,51 @@ abstract class ImageReleaseService { userName?.let { startParams["registryUser"] = it } password?.let { startParams["registryPwd"] = it } imageRepoUrl?.let { startParams["registryHost"] = it } + val pipelineId: String? if (null == imagePipelineRelRecord) { - val pipelineModelConfig = businessConfigDao.get( + pipelineId = storePipelineService.creatStorePipelineByStoreCode(storeType = StoreTypeEnum.IMAGE.name) + storePipelineRelDao.add( dslContext = context, - business = StoreTypeEnum.IMAGE.name, - feature = "initBuildPipeline", - businessValue = "PIPELINE_MODEL" - ) - var pipelineModel = pipelineModelConfig!!.configValue - val pipelineName = "am-$imageCode-${UUIDUtil.generate()}" - val paramMap = mapOf("pipelineName" to pipelineName) - // 将流水线模型中的变量替换成具体的值 - paramMap.forEach { (key, value) -> - pipelineModel = pipelineModel.replace("#{$key}", value) - } - val storeInitPipelineReq = StoreInitPipelineReq( - pipelineModel = pipelineModel, - startParams = startParams + storeCode = imageCode, + storeType = StoreTypeEnum.IMAGE, + pipelineId = pipelineId, + projectCode = storeInnerPipelineConfig.innerPipelineProject ) - val storeInitPipelineResp = client.get(ServicePipelineInitResource::class) - .initStorePipeline(userId, projectCode!!, storeInitPipelineReq).data - logger.info("runCheckImagePipeline storeInitPipelineResp is:$storeInitPipelineResp") - if (null != storeInitPipelineResp) { - storePipelineRelDao.add( - dslContext = context, - storeCode = imageCode, - storeType = StoreTypeEnum.IMAGE, - pipelineId = storeInitPipelineResp.pipelineId, - projectCode = projectCode - ) - val buildId = storeInitPipelineResp.buildId - val imageStatus = if (buildId.isNullOrBlank()) { - ImageStatusEnum.CHECK_FAIL - } else { - storePipelineBuildRelDao.add( - dslContext = context, - storeId = imageId, - pipelineId = storeInitPipelineResp.pipelineId, - buildId = buildId - ) - ImageStatusEnum.CHECKING - } - marketImageDao.updateImageStatusById( - dslContext = context, - imageId = imageId, - imageStatus = imageStatus.status.toByte(), - userId = userId, - msg = null - ) - } } else { - // 触发执行流水线 - val buildIdObj = client.get(ServiceBuildResource::class).manualStartupNew( + pipelineId = imagePipelineRelRecord.pipelineId + } + // 触发执行流水线 + val startProjectCode = if (imagePipelineRelRecord == null) { + storeInnerPipelineConfig.innerPipelineProject + } else { + imagePipelineRelRecord.projectCode + } + val buildIdObj = client.get(ServiceBuildResource::class).manualStartupNew( + userId = if (imagePipelineRelRecord != null) userId else storeInnerPipelineConfig.innerPipelineUser, + projectId = startProjectCode, + pipelineId = pipelineId!!, + values = startParams, + channelCode = ChannelCode.AM, + startType = StartType.SERVICE + ).data + logger.info("the buildIdObj is:$buildIdObj") + if (null != buildIdObj) { + storePipelineBuildRelDao.add(context, imageId, pipelineId, buildIdObj.id) + marketImageDao.updateImageStatusById( + dslContext = context, + imageId = imageId, + imageStatus = ImageStatusEnum.CHECKING.status.toByte(), userId = userId, - projectId = projectCode!!, - pipelineId = imagePipelineRelRecord.pipelineId, - values = startParams, - channelCode = ChannelCode.AM, - startType = StartType.SERVICE - ).data - logger.info("the buildIdObj is:$buildIdObj") - if (null != buildIdObj) { - storePipelineBuildRelDao.add(context, imageId, imagePipelineRelRecord.pipelineId, buildIdObj.id) - marketImageDao.updateImageStatusById( - dslContext = context, - imageId = imageId, - imageStatus = ImageStatusEnum.CHECKING.status.toByte(), - userId = userId, - msg = null - ) // 验证中 - } else { - marketImageDao.updateImageStatusById( - dslContext = context, - imageId = imageId, - imageStatus = ImageStatusEnum.CHECK_FAIL.status.toByte(), - userId = userId, - msg = null - ) // 验证失败 - } + msg = null + ) // 验证中 + } else { + marketImageDao.updateImageStatusById( + dslContext = context, + imageId = imageId, + imageStatus = ImageStatusEnum.CHECK_FAIL.status.toByte(), + userId = userId, + msg = null + ) // 验证失败 } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/template/dao/TemplateCommonDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/template/dao/TemplateCommonDao.kt index 55ca642492b..39e8f54d847 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/template/dao/TemplateCommonDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/template/dao/TemplateCommonDao.kt @@ -142,4 +142,10 @@ class TemplateCommonDao : AbstractStoreCommonDao() { } } } + + override fun getStoreCodeById(dslContext: DSLContext, storeId: String): String? { + return with(TTemplate.T_TEMPLATE) { + dslContext.select(TEMPLATE_CODE).from(this).where(ID.eq(storeId)).fetchOne(0, String::class.java) + } + } }