refactor:optimize auto configuration. (#1740)

Signed-off-by: Haotian Zhang <928016560@qq.com>
pull/1742/head
Haotian Zhang 1 month ago committed by GitHub
parent c553ccd164
commit 7414328883
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,3 +2,4 @@
---
- [feat: upgrade springdoc to 1.8.0.](https://github.com/Tencent/spring-cloud-tencent/pull/1737)
- [refactor:optimize auto configuration.](https://github.com/Tencent/spring-cloud-tencent/pull/1740)

@ -21,9 +21,7 @@ import com.tencent.cloud.common.constant.OrderConstant;
import com.tencent.cloud.polaris.auth.filter.AuthReactiveFilter;
import com.tencent.cloud.polaris.auth.filter.AuthServletFilter;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
@ -43,7 +41,6 @@ import static javax.servlet.DispatcherType.REQUEST;
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(PolarisContextAutoConfiguration.class)
public class PolarisAuthAutoConfiguration {
/**

@ -1,34 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.auth.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Autoconfiguration of auth at bootstrap phase.
*
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(PolarisAuthPropertiesAutoConfiguration.class)
public class PolarisAuthPropertiesBootstrapConfiguration {
}

@ -1,5 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.auth.config.PolarisAuthPropertiesAutoConfiguration,\
com.tencent.cloud.polaris.auth.config.PolarisAuthAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.auth.config.PolarisAuthPropertiesBootstrapConfiguration

@ -1,38 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.circuitbreaker.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Autoconfiguration at bootstrap phase.
*
* @author lepdou 2022-03-29
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import({
PolarisCircuitBreakerAutoConfiguration.class,
PolarisCircuitBreakerFeignClientAutoConfiguration.class,
GatewayPolarisCircuitBreakerAutoConfiguration.class
})
public class PolarisCircuitBreakerBootstrapConfiguration {
}

@ -3,5 +3,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerFeignClientAutoConfiguration,\
com.tencent.cloud.polaris.circuitbreaker.config.GatewayPolarisCircuitBreakerAutoConfiguration,\
com.tencent.cloud.polaris.circuitbreaker.endpoint.PolarisCircuitBreakerEndpointAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerBootstrapConfiguration

@ -1,61 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.circuitbreaker.config;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementAutoConfiguration;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementPropertiesAutoConfiguration;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for {@link PolarisCircuitBreakerBootstrapConfiguration}.
*
* @author Haotian Zhang
*/
public class PolarisCircuitBreakerBootstrapConfigurationTest {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
PolarisContextAutoConfiguration.class,
RpcEnhancementPropertiesAutoConfiguration.class,
RpcEnhancementAutoConfiguration.class,
LoadBalancerAutoConfiguration.class,
PolarisCircuitBreakerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.polaris.enabled=true")
.withPropertyValues("spring.cloud.polaris.circuitbreaker.enabled=true");
@BeforeAll
static void beforeAll() {
PolarisSDKContextManager.innerDestroy();
}
@Test
public void testDefaultInitialization() {
this.contextRunner.run(context -> {
assertThat(context).hasSingleBean(PolarisCircuitBreakerAutoConfiguration.class);
assertThat(context).hasSingleBean(PolarisCircuitBreakerFeignClientAutoConfiguration.class);
});
}
}

@ -17,17 +17,21 @@
package com.tencent.cloud.polaris.config;
import java.util.List;
import com.tencent.cloud.polaris.config.adapter.AffectedConfigurationPropertiesRebinder;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigFileLocator;
import com.tencent.cloud.polaris.config.condition.ConditionalOnReflectRefreshType;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.config.PolarisCryptoConfigProperties;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
import com.tencent.cloud.polaris.context.config.PolarisContextPropertiesAutoConfiguration;
import com.tencent.polaris.api.exception.PolarisException;
import com.tencent.polaris.configuration.api.core.ConfigFileService;
import com.tencent.polaris.configuration.factory.ConfigFileServiceFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans;
@ -45,27 +49,37 @@ import org.springframework.core.env.Environment;
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnPolarisConfigEnabled
@Import(PolarisContextAutoConfiguration.class)
@Import(PolarisContextPropertiesAutoConfiguration.class)
public class PolarisConfigBootstrapAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public PolarisConfigProperties polarisProperties() {
return new PolarisConfigProperties();
}
@Bean
@ConditionalOnMissingBean
public PolarisCryptoConfigProperties polarisCryptoConfigProperties() {
return new PolarisCryptoConfigProperties();
}
@Bean
@ConditionalOnMissingBean
public PolarisConfigSDKContextManager polarisConfigSDKContextManager(PolarisContextProperties properties, Environment environment, ObjectProvider<List<PolarisConfigModifier>> modifierListProvider) throws PolarisException {
return new PolarisConfigSDKContextManager(properties, environment, modifierListProvider);
}
@Bean
@ConditionalOnConnectRemoteServerEnabled
public ConfigFileService configFileService(PolarisSDKContextManager polarisSDKContextManager) {
return ConfigFileServiceFactory.createConfigFileService(polarisSDKContextManager.getConfigSDKContext());
@ConditionalOnMissingBean
public ConfigFileService configFileService(PolarisConfigSDKContextManager polarisConfigSDKContextManager) {
return ConfigFileServiceFactory.createConfigFileService(polarisConfigSDKContextManager.getConfigSDKContext());
}
@Bean
@ConditionalOnConnectRemoteServerEnabled
@ConditionalOnMissingBean
public PolarisConfigFileLocator polarisConfigFileLocator(
PolarisConfigProperties polarisConfigProperties,
PolarisContextProperties polarisContextProperties,
@ -77,6 +91,7 @@ public class PolarisConfigBootstrapAutoConfiguration {
@Bean
@ConditionalOnConnectRemoteServerEnabled
@ConditionalOnMissingBean
public ConfigurationModifier configurationModifier(PolarisConfigProperties polarisConfigProperties,
PolarisCryptoConfigProperties polarisCryptoConfigProperties,
PolarisContextProperties polarisContextProperties) {

@ -0,0 +1,124 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.config;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.cloud.polaris.context.PolarisConfigurationConfigModifier;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
import com.tencent.polaris.api.config.Configuration;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.client.api.SDKContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.core.env.Environment;
/**
* Manager for static Polaris Config SDK context.
*
* @author Haotian Zhang
*/
public class PolarisConfigSDKContextManager {
private static final Logger LOG = LoggerFactory.getLogger(PolarisConfigSDKContextManager.class);
private volatile static SDKContext configSDKContext;
private final PolarisContextProperties properties;
private final Environment environment;
private final ObjectProvider<List<PolarisConfigModifier>> modifierListProvider;
public PolarisConfigSDKContextManager(PolarisContextProperties properties, Environment environment, ObjectProvider<List<PolarisConfigModifier>> modifierListProvider) {
this.properties = properties;
this.environment = environment;
this.modifierListProvider = modifierListProvider;
}
/**
* Used for config data.
*/
public static SDKContext innerGetConfigSDKContext() {
if (configSDKContext == null) {
throw new IllegalArgumentException("configSDKContext is not initialized.");
}
return configSDKContext;
}
public static void innerConfigDestroy() {
try {
if (Objects.nonNull(configSDKContext)) {
configSDKContext.destroy();
configSDKContext = null;
}
LOG.info("Polaris SDK config context is destroyed.");
}
catch (Throwable throwable) {
LOG.info("Polaris SDK config context is destroyed failed.", throwable);
}
}
public SDKContext getConfigSDKContext() {
initConfig();
return configSDKContext;
}
/**
* Used for config data.
*/
public static void setConfigSDKContext(SDKContext context) {
if (configSDKContext == null) {
configSDKContext = context;
// add shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(PolarisConfigSDKContextManager::innerConfigDestroy));
LOG.info("create Polaris config SDK context successfully.");
}
}
public void initConfig() {
// get modifiers for configuration.
List<PolarisConfigModifier> modifierList = modifierListProvider.getIfAvailable(ArrayList::new);
List<PolarisConfigModifier> configModifierList = new ArrayList<>();
for (PolarisConfigModifier modifier : modifierList) {
if (modifier instanceof PolarisConfigurationConfigModifier) {
configModifierList.add(modifier);
}
}
if (null == configSDKContext && CollectionUtils.isNotEmpty(configModifierList)) {
try {
// init config SDKContext
Configuration configuration = properties.configuration(configModifierList,
() -> environment.getProperty("spring.cloud.client.ip-address"),
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0));
configSDKContext = SDKContext.initContextByConfig(configuration);
configSDKContext.init();
// add shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(PolarisConfigSDKContextManager::innerConfigDestroy));
LOG.info("create Polaris config SDK context successfully. properties: {}, configuration: {}", properties, configuration);
}
catch (Throwable throwable) {
LOG.error("create Polaris config SDK context failed. properties: {}, ", properties, throwable);
throw throwable;
}
}
}
}

@ -22,12 +22,12 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import com.tencent.cloud.polaris.config.PolarisConfigSDKContextManager;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigCustomExtensionLayer;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigFilePuller;
import com.tencent.cloud.polaris.config.adapter.PolarisServiceLoaderUtil;
import com.tencent.cloud.polaris.config.config.ConfigFileGroup;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.polaris.client.api.SDKContext;
import com.tencent.polaris.configuration.api.core.ConfigFileService;
import com.tencent.polaris.configuration.factory.ConfigFileServiceFactory;
@ -97,7 +97,7 @@ public class PolarisConfigDataLoader implements ConfigDataLoader<PolarisConfigDa
PolarisConfigDataResource resource) {
CompositePropertySource compositePropertySource = new CompositePropertySource(
POLARIS_CONFIG_PROPERTY_SOURCE_NAME);
SDKContext sdkContext = PolarisSDKContextManager.innerGetConfigSDKContext();
SDKContext sdkContext = PolarisConfigSDKContextManager.innerGetConfigSDKContext();
if (null == this.configFileService) {
this.configFileService = ConfigFileServiceFactory.createConfigFileService(sdkContext);
}

@ -23,11 +23,11 @@ import java.util.List;
import java.util.Objects;
import com.tencent.cloud.polaris.config.ConfigurationModifier;
import com.tencent.cloud.polaris.config.PolarisConfigSDKContextManager;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.config.PolarisCryptoConfigProperties;
import com.tencent.cloud.polaris.context.ModifyAddress;
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.client.api.SDKContext;
@ -280,7 +280,7 @@ public class PolarisConfigDataLocationResolver implements
((ConfigurationImpl) sdkContext.getConfig()).getGlobal().getStatReporter().setEnable(false);
}
sdkContext.init();
PolarisSDKContextManager.setConfigSDKContext(sdkContext);
PolarisConfigSDKContextManager.setConfigSDKContext(sdkContext);
}
}

@ -30,6 +30,7 @@ import com.tencent.cloud.polaris.config.enums.RefreshType;
import com.tencent.cloud.polaris.config.spring.annotation.SpringValueProcessor;
import com.tencent.cloud.polaris.config.spring.property.PlaceholderHelper;
import com.tencent.cloud.polaris.config.spring.property.SpringValueRegistry;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -74,6 +75,7 @@ public class ConditionalOnReflectRefreshTypeTest {
@Test
public void testReflectEnabled() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(PolarisContextAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(PolarisConfigBootstrapAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(PolarisConfigAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
@ -94,6 +96,7 @@ public class ConditionalOnReflectRefreshTypeTest {
@Test
public void testWithoutReflectEnabled() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(PolarisContextAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(PolarisConfigBootstrapAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(PolarisConfigAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))

@ -22,9 +22,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.tencent.cloud.polaris.config.PolarisConfigSDKContextManager;
import com.tencent.cloud.polaris.config.adapter.MockedConfigKVFile;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
import com.tencent.polaris.client.api.SDKContext;
import com.tencent.polaris.configuration.api.core.ConfigFileService;
@ -69,12 +69,12 @@ public class PolarisConfigDataLoaderTest {
@BeforeAll
static void beforeAll() {
PolarisSDKContextManager.setConfigSDKContext(sdkContext);
PolarisConfigSDKContextManager.setConfigSDKContext(sdkContext);
}
@AfterAll
static void afterAll() {
PolarisSDKContextManager.innerGetConfigSDKContext();
PolarisConfigSDKContextManager.innerGetConfigSDKContext();
}
@Test

@ -1,34 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.contract.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Bootstrap configuration for Polaris contract properties.
*
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(PolarisContractPropertiesAutoConfiguration.class)
public class PolarisContractPropertiesBootstrapConfiguration {
}

@ -3,7 +3,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.contract.config.PolarisContractProperties,\
com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesAutoConfiguration,\
com.tencent.cloud.polaris.contract.tsf.TsfSwaggerAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesBootstrapConfiguration
org.springframework.context.ApplicationListener=\
com.tencent.cloud.polaris.contract.PolarisSwaggerApplicationListener

@ -1,34 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Common configuration of discovery.
*
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(DiscoveryPropertiesAutoConfiguration.class)
public class DiscoveryPropertiesBootstrapAutoConfiguration {
}

@ -1,35 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.loadbalancer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Common configuration of loadbalancer.
*
* @author Yuwei Fu
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(PolarisLoadBalancerPropertiesAutoConfiguration.class)
public class PolarisLoadBalancerBootstrapAutoConfiguration {
}

@ -8,6 +8,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.eager.config.PolarisEagerLoadAutoConfiguration,\
com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerPropertiesAutoConfiguration,\
com.tencent.cloud.polaris.registry.nacos.NacosDiscoveryRegistryAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration,\
com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerBootstrapAutoConfiguration

@ -24,7 +24,7 @@ import java.util.Map;
import com.tencent.cloud.common.util.OkHttpUtil;
import com.tencent.cloud.plugin.lossless.config.LosslessAutoConfiguration;
import com.tencent.cloud.plugin.lossless.config.LosslessPropertiesBootstrapConfiguration;
import com.tencent.cloud.plugin.lossless.config.LosslessPropertiesAutoConfiguration;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration;
@ -74,7 +74,7 @@ public class LosslessRegistryAspectTest {
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
LosslessAutoConfiguration.class,
LosslessPropertiesBootstrapConfiguration.class,
LosslessPropertiesAutoConfiguration.class,
PolarisContextAutoConfiguration.class,
PolarisPropertiesConfiguration.class,
PolarisDiscoveryClientConfiguration.class,
@ -95,7 +95,7 @@ public class LosslessRegistryAspectTest {
private final WebApplicationContextRunner contextRunner2 = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
LosslessAutoConfiguration.class,
LosslessPropertiesBootstrapConfiguration.class,
LosslessPropertiesAutoConfiguration.class,
PolarisContextAutoConfiguration.class,
PolarisPropertiesConfiguration.class,
PolarisDiscoveryClientConfiguration.class,
@ -117,7 +117,7 @@ public class LosslessRegistryAspectTest {
.withConfiguration(AutoConfigurations.of(
MockDiscoveryConfiguration.class,
LosslessAutoConfiguration.class,
LosslessPropertiesBootstrapConfiguration.class,
LosslessPropertiesAutoConfiguration.class,
PolarisContextAutoConfiguration.class,
PolarisPropertiesConfiguration.class,
PolarisDiscoveryClientConfiguration.class,

@ -1,47 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for {@link DiscoveryPropertiesBootstrapAutoConfiguration}.
*
* @author Haotian Zhang
*/
public class DiscoveryPropertiesBootstrapAutoConfigurationTest {
@Test
public void testDefaultInitialization() {
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withConfiguration(
AutoConfigurations.of(
PolarisContextAutoConfiguration.class,
DiscoveryPropertiesBootstrapAutoConfiguration.class))
.withPropertyValues("spring.cloud.polaris.enabled=true");
applicationContextRunner.run(context -> {
assertThat(context).hasSingleBean(DiscoveryPropertiesBootstrapAutoConfiguration.class);
assertThat(context).hasSingleBean(DiscoveryPropertiesAutoConfiguration.class);
});
}
}

@ -1,34 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.ratelimit.tsf;
import com.tencent.cloud.common.tsf.ConditionalOnOnlyTsfConsulEnabled;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Bootstrap configuration for TSF rate limit.
*
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnOnlyTsfConsulEnabled
@Import(TsfRateLimitAutoConfiguration.class)
public class TsfRateLimitBootstrapConfiguration {
}

@ -3,6 +3,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitPropertiesAutoConfiguration,\
com.tencent.cloud.polaris.ratelimit.endpoint.PolarisRateLimitRuleEndpointAutoConfiguration,\
com.tencent.cloud.polaris.ratelimit.tsf.TsfRateLimitAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitPropertiesBootstrapConfiguration,\
com.tencent.cloud.polaris.ratelimit.tsf.TsfRateLimitBootstrapConfiguration

@ -1,45 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.ratelimit.config;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for {@link PolarisRateLimitPropertiesBootstrapConfiguration}.
*
* @author Haotian Zhang
*/
public class PolarisRateLimitPropertiesBootstrapConfigurationTest {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(PolarisRateLimitPropertiesBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.polaris.enabled=true");
@Test
public void testDefaultInitialization() {
this.contextRunner.run(context -> {
assertThat(context).hasSingleBean(PolarisRateLimitProperties.class);
assertThat(context).hasSingleBean(RateLimitConfigModifier.class);
});
}
}

@ -1,35 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.router.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* RouterBootstrapAutoConfiguration.
*
* @author sean yu
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(RouterConfigModifierAutoConfiguration.class)
public class RouterBootstrapAutoConfiguration {
}

@ -3,5 +3,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.router.config.RouterAutoConfiguration,\
com.tencent.cloud.polaris.router.config.FeignAutoConfiguration,\
com.tencent.cloud.polaris.router.endpoint.PolarisRouterEndpointAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.router.config.RouterBootstrapAutoConfiguration

@ -42,7 +42,6 @@ public class RouterAutoConfigurationTests {
MetadataAutoConfiguration.class,
RouterAutoConfiguration.class,
RouterConfigModifierAutoConfiguration.class,
RouterBootstrapAutoConfiguration.class,
PolarisContextAutoConfiguration.class,
RouterAutoConfiguration.RouterLabelRestTemplateConfig.class,
ApplicationContextAwareUtils.class

@ -1,67 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.router.config;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import com.tencent.cloud.polaris.router.RouterConfigModifier;
import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementAutoConfiguration;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementPropertiesAutoConfiguration;
import com.tencent.polaris.api.config.Configuration;
import com.tencent.polaris.api.config.consumer.ServiceRouterConfig;
import com.tencent.polaris.factory.ConfigAPIFactory;
import com.tencent.polaris.factory.config.ConfigurationImpl;
import com.tencent.polaris.plugins.router.nearby.NearbyRouterConfig;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* RouterBootstrapAutoConfigurationTest.
*
* @author sean yu
*/
public class RouterBootstrapAutoConfigurationTest {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
PolarisContextAutoConfiguration.class,
PolarisNearByRouterProperties.class,
RpcEnhancementPropertiesAutoConfiguration.class,
RpcEnhancementAutoConfiguration.class,
RouterBootstrapAutoConfiguration.class))
.withPropertyValues("spring.cloud.polaris.enabled=true")
.withPropertyValues("spring.cloud.polaris.router.nearby-router.matchLevel=CAMPUS")
.withPropertyValues("spring.cloud.polaris.circuitbreaker.enabled=true");
@Test
public void testDefaultInitialization() {
this.contextRunner.run(context -> {
assertThat(context).hasSingleBean(RouterConfigModifier.class);
RouterConfigModifier routerConfigModifier = (RouterConfigModifier) context.getBean("routerConfigModifier");
Configuration configuration = ConfigAPIFactory.defaultConfig();
routerConfigModifier.modify((ConfigurationImpl) configuration);
NearbyRouterConfig nearbyRouterConfig = configuration.getConsumer().getServiceRouter().getPluginConfig(
ServiceRouterConfig.DEFAULT_ROUTER_NEARBY, NearbyRouterConfig.class);
assertThat(nearbyRouterConfig.getMatchLevel().name()).isEqualTo("CAMPUS");
});
}
}

@ -28,5 +28,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
</dependencies>
</project>

@ -1,4 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.plugin.discovery.adapter.config.NacosDiscoveryAdapterAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.plugin.discovery.adapter.config.NacosDiscoveryAdapterAutoConfiguration

@ -1,29 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.plugin.trace.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(TraceConfigModifierAutoConfiguration.class)
public class TraceConfigModifierBootstrapAutoConfiguration {
}

@ -1,5 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.plugin.trace.config.TraceConfigModifierAutoConfiguration,\
com.tencent.cloud.plugin.trace.config.TraceEnhancedPluginAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.plugin.trace.config.TraceConfigModifierBootstrapAutoConfiguration

@ -22,6 +22,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("spring.cloud.polaris.lossless")
public class LosslessProperties {
/**
* the switch for lossless plugin.
*/
private boolean enabled = false;
private String healthCheckPath;

@ -1,35 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.plugin.lossless.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* BootstrapConfiguration of lossless properties.
*
* @author Shedfree Wu
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(LosslessPropertiesAutoConfiguration.class)
public class LosslessPropertiesBootstrapConfiguration {
}

@ -1,10 +0,0 @@
{
"properties": [
{
"name": "spring.cloud.polaris.lossless.enabled",
"type": "java.lang.Boolean",
"defaultValue": false,
"description": "the switch for lossless plugin."
}
]
}

@ -1,4 +1,2 @@
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.plugin.lossless.config.LosslessPropertiesBootstrapConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.plugin.lossless.config.LosslessAutoConfiguration

@ -27,7 +27,6 @@ import com.tencent.polaris.api.control.Destroyable;
import com.tencent.polaris.api.core.ConsumerAPI;
import com.tencent.polaris.api.core.LosslessAPI;
import com.tencent.polaris.api.core.ProviderAPI;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.assembly.api.AssemblyAPI;
import com.tencent.polaris.assembly.factory.AssemblyAPIFactory;
import com.tencent.polaris.auth.api.core.AuthAPI;
@ -60,7 +59,6 @@ public class PolarisSDKContextManager {
* Constant for checking before destroy SDK context.
*/
public volatile static boolean isRegistered = false;
private volatile static SDKContext configSDKContext;
private volatile static SDKContext serviceSdkContext;
private volatile static ProviderAPI providerAPI;
private volatile static ConsumerAPI consumerAPI;
@ -153,34 +151,6 @@ public class PolarisSDKContextManager {
}
}
/**
* Used for config data.
*/
public static SDKContext innerGetConfigSDKContext() {
if (configSDKContext == null) {
throw new IllegalArgumentException("configSDKContext is not initialized.");
}
return configSDKContext;
}
public static void innerConfigDestroy() {
try {
if (Objects.nonNull(configSDKContext)) {
configSDKContext.destroy();
configSDKContext = null;
}
LOG.info("Polaris SDK config context is destroyed.");
}
catch (Throwable throwable) {
LOG.info("Polaris SDK config context is destroyed failed.", throwable);
}
}
public void init() {
initService();
initConfig();
}
public SDKContext getSDKContext() {
initService();
return serviceSdkContext;
@ -230,23 +200,6 @@ public class PolarisSDKContextManager {
return assemblyAPI;
}
public SDKContext getConfigSDKContext() {
initConfig();
return configSDKContext;
}
/**
* Used for config data.
*/
public static void setConfigSDKContext(SDKContext context) {
if (configSDKContext == null) {
configSDKContext = context;
// add shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(PolarisSDKContextManager::innerConfigDestroy));
LOG.info("create Polaris config SDK context successfully.");
}
}
public void initService() {
if (null == serviceSdkContext) {
try {
@ -313,32 +266,4 @@ public class PolarisSDKContextManager {
}
}
}
public void initConfig() {
// get modifiers for configuration.
List<PolarisConfigModifier> configModifierList = new ArrayList<>();
for (PolarisConfigModifier modifier : modifierList) {
if (modifier instanceof PolarisConfigurationConfigModifier) {
configModifierList.add(modifier);
}
}
if (null == configSDKContext && CollectionUtils.isNotEmpty(configModifierList)) {
try {
// init config SDKContext
Configuration configuration = properties.configuration(configModifierList,
() -> environment.getProperty("spring.cloud.client.ip-address"),
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0));
configSDKContext = SDKContext.initContextByConfig(configuration);
configSDKContext.init();
// add shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(PolarisSDKContextManager::innerConfigDestroy));
LOG.info("create Polaris config SDK context successfully. properties: {}, configuration: {}", properties, configuration);
}
catch (Throwable throwable) {
LOG.error("create Polaris config SDK context failed. properties: {}, ", properties, throwable);
throw throwable;
}
}
}
}

@ -38,6 +38,7 @@ import com.tencent.polaris.client.api.SDKContext;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
/**
@ -47,16 +48,11 @@ import org.springframework.core.env.Environment;
*/
@ConditionalOnPolarisEnabled
@EnableConfigurationProperties
@Import(PolarisContextPropertiesAutoConfiguration.class)
public class PolarisContextAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public PolarisContextProperties polarisContextProperties() {
return new PolarisContextProperties();
}
@Bean(initMethod = "init")
@ConditionalOnMissingBean
public PolarisSDKContextManager polarisSDKContextManager(PolarisContextProperties properties, Environment environment, List<PolarisConfigModifier> modifierList) throws PolarisException {
return new PolarisSDKContextManager(properties, environment, modifierList);
}

@ -15,20 +15,27 @@
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.ratelimit.config;
package com.tencent.cloud.polaris.context.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled;
import com.tencent.polaris.client.api.SDKContext;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
/**
* Autoconfiguration of rate limit at bootstrap phase.
* Autoconfiguration for Polaris {@link SDKContext}.
*
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(PolarisRateLimitPropertiesAutoConfiguration.class)
public class PolarisRateLimitPropertiesBootstrapConfiguration {
@ConditionalOnPolarisEnabled
@EnableConfigurationProperties
public class PolarisContextPropertiesAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public PolarisContextProperties polarisContextProperties() {
return new PolarisContextProperties();
}
}

@ -28,7 +28,7 @@ import org.springframework.context.annotation.Import;
* @author Haotian Zhang
*/
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(PolarisContextAutoConfiguration.class)
public class PolarisContextBootstrapAutoConfiguration {
@Import(PolarisContextPropertiesAutoConfiguration.class)
public class PolarisContextPropertiesBootstrapAutoConfiguration {
}

@ -18,10 +18,8 @@
package com.tencent.cloud.polaris.context.config.extend.tsf;
import com.tencent.cloud.common.tsf.ConditionalOnOnlyTsfConsulEnabled;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import com.tencent.cloud.polaris.context.config.extend.consul.ConsulProperties;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -32,7 +30,6 @@ import org.springframework.context.annotation.Configuration;
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(PolarisContextAutoConfiguration.class)
@ConditionalOnOnlyTsfConsulEnabled
public class TsfContextAutoConfiguration {

@ -1,32 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.context.config.extend.tsf;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* TSF context bootstrap configuration.
*
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
@Import(TsfContextAutoConfiguration.class)
public class TsfContextBootstrapConfiguration {
}

@ -3,8 +3,7 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.context.config.PolarisContextPostConfiguration,\
com.tencent.cloud.polaris.context.config.extend.tsf.TsfContextAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.context.config.PolarisContextBootstrapAutoConfiguration,\
com.tencent.cloud.polaris.context.config.extend.tsf.TsfContextBootstrapConfiguration
com.tencent.cloud.polaris.context.config.PolarisContextPropertiesBootstrapAutoConfiguration
org.springframework.context.ApplicationListener=\
com.tencent.cloud.polaris.context.logging.PolarisLoggingApplicationListener,\
com.tencent.cloud.polaris.context.listener.FailedEventApplicationListener

@ -1,32 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.rpc.enhancement.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Bootstrap configuration for rpc enhancement.
* @author lepdou 2022-08-24
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(RpcEnhancementPropertiesAutoConfiguration.class)
public class RpcEnhancementPropertiesBootstrapConfiguration {
}

@ -1,34 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.rpc.enhancement.stat.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Autoconfiguration of stat reporter at bootstrap phase.
*
* @author lepdou 2022-03-29
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(PolarisStatPropertiesAutoConfiguration.class)
public class PolarisStatPropertiesBootstrapConfiguration {
}

@ -1,7 +1,3 @@
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatPropertiesBootstrapConfiguration,\
com.tencent.cloud.rpc.enhancement.config.RpcEnhancementBootstrapConfiguration,\
com.tencent.cloud.rpc.enhancement.config.RpcEnhancementPropertiesBootstrapConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.rpc.enhancement.config.RpcEnhancementAutoConfiguration,\
com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatPropertiesAutoConfiguration,\

@ -1,47 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 Tencent. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.rpc.enhancement.stat.config;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for {@link PolarisStatPropertiesBootstrapConfiguration}.
*
* @author Haotian Zhang
*/
public class PolarisStatPropertiesBootstrapConfigurationTest {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(PolarisStatPropertiesBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.polaris.enabled=true");
@Test
public void testDefaultInitialization() {
this.contextRunner.run(context -> {
assertThat(context).hasSingleBean(PolarisStatPropertiesBootstrapConfiguration.class);
assertThat(context).hasSingleBean(PolarisStatPropertiesAutoConfiguration.class);
assertThat(context).hasSingleBean(PolarisStatProperties.class);
assertThat(context).hasSingleBean(StatConfigModifier.class);
});
}
}
Loading…
Cancel
Save