From 531b181059875e19c47002e8a81e9079e47bef0c Mon Sep 17 00:00:00 2001 From: greysonfang Date: Wed, 14 Jun 2023 15:40:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8C=87=E5=AE=9A=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=89=93=E5=8C=85=E6=8F=92=E4=BB=B6=20#8672?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/common/client/Client.kt | 39 +++++++++---------- .../client/MutilJarServiceMapConfiguration.kt | 10 +++++ .../main/resources/META-INF/spring.factories | 3 +- 3 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 src/backend/ci/core/common/common-client/src/main/kotlin/com/tencent/devops/common/client/MutilJarServiceMapConfiguration.kt diff --git a/src/backend/ci/core/common/common-client/src/main/kotlin/com/tencent/devops/common/client/Client.kt b/src/backend/ci/core/common/common-client/src/main/kotlin/com/tencent/devops/common/client/Client.kt index 455526e3441..7b3efc54d25 100644 --- a/src/backend/ci/core/common/common-client/src/main/kotlin/com/tencent/devops/common/client/Client.kt +++ b/src/backend/ci/core/common/common-client/src/main/kotlin/com/tencent/devops/common/client/Client.kt @@ -52,6 +52,13 @@ import feign.jackson.JacksonEncoder import feign.jaxrs.JAXRSContract import feign.okhttp.OkHttpClient import feign.spring.SpringContract +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value +import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient +import org.springframework.context.annotation.DependsOn +import org.springframework.core.annotation.AnnotationUtils +import org.springframework.stereotype.Component import java.lang.reflect.Method import java.security.cert.CertificateException import java.util.concurrent.ConcurrentHashMap @@ -60,13 +67,6 @@ import javax.net.ssl.SSLContext import javax.net.ssl.SSLSocketFactory import javax.net.ssl.TrustManager import javax.net.ssl.X509TrustManager -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value -import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient -import org.springframework.context.annotation.DependsOn -import org.springframework.core.annotation.AnnotationUtils -import org.springframework.stereotype.Component import kotlin.reflect.KClass /** @@ -81,6 +81,7 @@ class Client @Autowired constructor( private val clientErrorDecoder: ClientErrorDecoder, private val commonConfig: CommonConfig, private val bkTag: BkTag, + private val mutilJarServiceMapConfiguration: MutilJarServiceMapConfiguration, objectMapper: ObjectMapper ) { @@ -90,8 +91,6 @@ class Client @Autowired constructor( private const val connectTimeoutSeconds = 5L private const val CACHE_SIZE = 1000L private val longTimeOptions = Request.Options(10L, TimeUnit.SECONDS, 30L, TimeUnit.MINUTES, true) - private val accessoriesServiceList = listOf("experience,support,image,lambda,monitoring") - private const val accessoriesName = "accessories" } private val beanCaches: LoadingCache, *> = Caffeine.newBuilder() @@ -296,7 +295,7 @@ class Client @Autowired constructor( if (!assemblyServiceName.isNullOrBlank()) { return assemblyServiceName } - var serviceName = interfaces.getOrPut(clz) { + val serviceName = interfaces.getOrPut(clz) { val serviceInterface = AnnotationUtils.findAnnotation(clz.java, ServiceInterface::class.java) if (serviceInterface != null && serviceInterface.value.isNotBlank()) { serviceInterface.value @@ -311,22 +310,20 @@ class Client @Autowired constructor( matches.groupValues[1] } } - // 得加一个标识,如果为集成的,才这么操作 - if (isAccessoriesService(serviceName)) { - logger.info("findServiceName:serviceName({})", serviceName) - serviceName = accessoriesName - } + return generateServiceName(serviceName) + } + + private fun generateServiceName(serviceName: String): String { + val mutilJarServiceMap = mutilJarServiceMapConfiguration.propertiesMap + val finalServiceName = mutilJarServiceMap[serviceName] ?: serviceName + logger.info("findServiceName:serviceName({})", finalServiceName) return if (serviceSuffix.isNullOrBlank() || KubernetesUtils.inContainer()) { - serviceName + finalServiceName } else { - "$serviceName$serviceSuffix" + "$finalServiceName$serviceSuffix" } } - private fun isAccessoriesService(serviceName: String): Boolean { - return accessoriesServiceList.contains(serviceName) - } - private fun buildGatewayUrl(path: String, gatewayType: GatewayType = GatewayType.IDC): String { return if (path.startsWith("http://") || path.startsWith("https://")) { diff --git a/src/backend/ci/core/common/common-client/src/main/kotlin/com/tencent/devops/common/client/MutilJarServiceMapConfiguration.kt b/src/backend/ci/core/common/common-client/src/main/kotlin/com/tencent/devops/common/client/MutilJarServiceMapConfiguration.kt new file mode 100644 index 00000000000..5f59507cf18 --- /dev/null +++ b/src/backend/ci/core/common/common-client/src/main/kotlin/com/tencent/devops/common/client/MutilJarServiceMapConfiguration.kt @@ -0,0 +1,10 @@ +package com.tencent.devops.common.client + +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.context.annotation.Configuration + +@Configuration +@ConfigurationProperties(prefix = "mutiljar.service.map") +class MutilJarServiceMapConfiguration { + val propertiesMap: Map = mutableMapOf() +} diff --git a/src/backend/ci/core/common/common-client/src/main/resources/META-INF/spring.factories b/src/backend/ci/core/common/common-client/src/main/resources/META-INF/spring.factories index 9239c595c45..aa57898d083 100644 --- a/src/backend/ci/core/common/common-client/src/main/resources/META-INF/spring.factories +++ b/src/backend/ci/core/common/common-client/src/main/resources/META-INF/spring.factories @@ -1,2 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.tencent.devops.common.client.ClientAutoConfiguration \ No newline at end of file +com.tencent.devops.common.client.ClientAutoConfiguration,\ +com.tencent.devops.common.client.MutilJarServiceMapConfiguration