Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pref:nodejs安装包下载地址域名支持按部署环境返回 #11327 #11329

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ const val AUTH_HEADER_DEVOPS_STORE_CODE: String = "X-DEVOPS-STORE-CODE"
const val AUTH_HEADER_DEVOPS_STORE_TYPE: String = "X-DEVOPS-STORE-TYPE"
const val AUTH_HEADER_DEVOPS_STORE_VERSION: String = "X-DEVOPS-STORE-VERSION"
const val AUTH_HEADER_DEVOPS_SIGN_FILE_NAME: String = "X-DEVOPS-SIGN-FILE-NAME"
const val AUTH_HEADER_DEVOPS_ENV: String = "X-DEVOPS-ENV"
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package com.tencent.devops.store.api.common

import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BUILD_ID
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_ENV
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_VM_SEQ_ID
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.store.pojo.common.sensitive.SensitiveConfResp
Expand Down Expand Up @@ -73,6 +74,9 @@ interface BuildStoreResource {
@GET
@Path("/pkg/envs/types/{storeType}/languages/{language}/versions/{runtimeVersion}/get")
fun getStorePkgRunEnvInfo(
@Parameter(description = "环境信息", required = false)
@HeaderParam(AUTH_HEADER_DEVOPS_ENV)
devopsEnv: String? = null,
@Parameter(description = "组件类型", required = true)
@PathParam("storeType")
storeType: StoreTypeEnum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data class StorePkgRunEnvInfo(
@get:Schema(title = "安装包名称", required = true)
val pkgName: String,
@get:Schema(title = "安装包下载路径", required = true)
val pkgDownloadPath: String,
var pkgDownloadPath: String,
@get:Schema(title = "是否为默认安装包", required = true)
val defaultFlag: Boolean,
@get:Schema(title = "添加用户", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class BuildStoreResourceImpl @Autowired constructor(
}

override fun getStorePkgRunEnvInfo(
devopsEnv: String?,
storeType: StoreTypeEnum,
language: String,
runtimeVersion: String,
Expand All @@ -70,6 +71,7 @@ class BuildStoreResourceImpl @Autowired constructor(
): Result<StorePkgRunEnvInfo?> {
return Result(
storePkgRunEnvInfoService.getStorePkgRunEnvInfo(
devopsEnv = devopsEnv,
userId = "",
storeType = storeType,
language = language,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.service

abstract class AbstractDomainService {

/**
* 转换url域名
* @param url url地址
* @return 转换域名后的url地址
*/
abstract fun convertDomain(url: String): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ interface StorePkgRunEnvInfoService {

/**
* 获取安装包运行时环境信息
* @param devopsEnv 环境信息
* @param userId userId
* @param storeType 组件类型
* @param language 开发语言
Expand All @@ -79,6 +80,7 @@ interface StorePkgRunEnvInfoService {
* @return 安装包运行时环境信息
*/
fun getStorePkgRunEnvInfo(
devopsEnv: String? = null,
userId: String,
storeType: StoreTypeEnum,
language: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
package com.tencent.devops.store.common.service.impl

import com.github.benmanes.caffeine.cache.Caffeine
import com.tencent.devops.store.common.dao.StorePkgRunEnvInfoDao
import com.tencent.devops.common.service.utils.SpringContextUtil
import com.tencent.devops.store.atom.factory.AtomBusHandleFactory
import com.tencent.devops.store.common.dao.StorePkgRunEnvInfoDao
import com.tencent.devops.store.common.service.AbstractDomainService
import com.tencent.devops.store.common.service.StorePkgRunEnvInfoService
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import com.tencent.devops.store.pojo.common.env.StorePkgRunEnvInfo
import com.tencent.devops.store.pojo.common.env.StorePkgRunEnvRequest
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import com.tencent.devops.store.common.service.StorePkgRunEnvInfoService
import org.jooq.DSLContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -70,6 +72,7 @@ class StorePkgRunEnvInfoServiceImpl @Autowired constructor(
}

override fun getStorePkgRunEnvInfo(
devopsEnv: String?,
userId: String,
storeType: StoreTypeEnum,
language: String,
Expand All @@ -88,7 +91,7 @@ class StorePkgRunEnvInfoServiceImpl @Autowired constructor(
val atomBusHandleService = AtomBusHandleFactory.createAtomBusHandleService(language)
val finalOsName = atomBusHandleService.handleOsName(osName)
val finalOsArch = atomBusHandleService.handleOsArch(osName, osArch)
val key = "PkgRunEnvInfo:$storeType:$language:$finalOsName:$finalOsArch:$convertRuntimeVersion"
val key = "PkgRunEnvInfo:$devopsEnv:$storeType:$language:$finalOsName:$finalOsArch:$convertRuntimeVersion"
var storePkgRunEnvInfo = pkgRunEnvInfoCache.getIfPresent(key)
if (storePkgRunEnvInfo != null) {
// 缓存中取到了安装包运行时环境信息则直接返回
Expand All @@ -113,6 +116,14 @@ class StorePkgRunEnvInfoServiceImpl @Autowired constructor(
null
} else {
storePkgRunEnvInfo = storePkgRunEnvInfoDao.convert(storePkgRunEnvInfoRecord)
if (!devopsEnv.isNullOrBlank()) {
// 转换域名
val beanName = "${devopsEnv.uppercase()}_DOMAIN_SERVICE"
if (SpringContextUtil.isBeanExist(beanName)) {
val domainService = SpringContextUtil.getBean(AbstractDomainService::class.java, beanName)
storePkgRunEnvInfo.pkgDownloadPath = domainService.convertDomain(storePkgRunEnvInfo.pkgDownloadPath)
}
}
// 把安装包运行时环境信息放入缓存
pkgRunEnvInfoCache.put(key, storePkgRunEnvInfo)
storePkgRunEnvInfo
Expand Down