diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b501ed5d..96704775e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ --- - [Optimize: remove discovery module useless code](https://github.com/Tencent/spring-cloud-tencent/pull/596) +- [Optimize: optimize configuration conditional & optimize config data tips"](https://github.com/Tencent/spring-cloud-tencent/pull/604) diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/ConditionalOnPolarisCircuitBreakerEnabled.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/ConditionalOnPolarisCircuitBreakerEnabled.java new file mode 100644 index 000000000..cb1e915a8 --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/ConditionalOnPolarisCircuitBreakerEnabled.java @@ -0,0 +1,38 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. 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 java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +/** + * Condition if Polaris circuit breaker is enabled. + * @author lepdou 2022-09-23 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@ConditionalOnPolarisEnabled +@ConditionalOnProperty(name = "spring.cloud.polaris.circuitbreaker.enabled", matchIfMissing = true) +public @interface ConditionalOnPolarisCircuitBreakerEnabled { +} diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java index ef13caa31..3736a45d3 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java @@ -18,7 +18,6 @@ package com.tencent.cloud.polaris.circuitbreaker.config; import com.tencent.cloud.common.constant.ContextConstant; -import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.cloud.polaris.context.PolarisConfigModifier; import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementAutoConfiguration; import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties; @@ -27,7 +26,6 @@ import com.tencent.polaris.factory.config.ConfigurationImpl; import com.tencent.polaris.plugins.router.healthy.RecoverRouterConfig; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -37,8 +35,7 @@ import org.springframework.context.annotation.Configuration; * @author lepdou 2022-03-29 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnPolarisEnabled -@ConditionalOnProperty(value = "spring.cloud.polaris.circuitbreaker.enabled", havingValue = "true", matchIfMissing = true) +@ConditionalOnPolarisCircuitBreakerEnabled @AutoConfigureAfter(RpcEnhancementAutoConfiguration.class) public class PolarisCircuitBreakerAutoConfiguration { diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConditionalOnPolarisConfigEnabled.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConditionalOnPolarisConfigEnabled.java new file mode 100644 index 000000000..3cf6bdb20 --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConditionalOnPolarisConfigEnabled.java @@ -0,0 +1,38 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. 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.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +/** + * Condition if Polaris configuration is enabled. + * @author lepdou 2022-09-23 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@ConditionalOnPolarisEnabled +@ConditionalOnProperty(value = "spring.cloud.polaris.config.enabled", matchIfMissing = true) +public @interface ConditionalOnPolarisConfigEnabled { +} diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java index a040eb042..aa3198435 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java @@ -30,11 +30,9 @@ import com.tencent.cloud.polaris.config.listener.PolarisConfigChangeEventListene 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.ConditionalOnPolarisEnabled; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans; import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder; @@ -48,8 +46,7 @@ import org.springframework.context.annotation.Configuration; * @author lepdou 2022-03-28 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnPolarisEnabled -@ConditionalOnProperty(value = "spring.cloud.polaris.config.enabled", matchIfMissing = true) +@ConditionalOnPolarisConfigEnabled public class PolarisConfigAutoConfiguration { @Bean diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigBootstrapAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigBootstrapAutoConfiguration.java index 235afb773..237533c64 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigBootstrapAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigBootstrapAutoConfiguration.java @@ -23,7 +23,6 @@ import com.tencent.cloud.polaris.config.adapter.PolarisConfigFileLocator; import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager; import com.tencent.cloud.polaris.config.condition.ConditionalOnReflectRefreshType; import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; -import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration; import com.tencent.cloud.polaris.context.config.PolarisContextProperties; import com.tencent.polaris.client.api.SDKContext; @@ -31,7 +30,6 @@ import com.tencent.polaris.configuration.api.core.ConfigFileService; import com.tencent.polaris.configuration.factory.ConfigFileServiceFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans; import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder; @@ -46,8 +44,7 @@ import org.springframework.core.env.Environment; * @author lepdou 2022-03-10 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnPolarisEnabled -@ConditionalOnProperty(value = "spring.cloud.polaris.config.enabled", matchIfMissing = true) +@ConditionalOnPolarisConfigEnabled @Import(PolarisContextAutoConfiguration.class) public class PolarisConfigBootstrapAutoConfiguration { diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointAutoConfiguration.java index ecef5313b..815d5798e 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointAutoConfiguration.java @@ -17,6 +17,7 @@ package com.tencent.cloud.polaris.config.endpoint; +import com.tencent.cloud.polaris.config.ConditionalOnPolarisConfigEnabled; import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager; import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; @@ -24,7 +25,6 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.condition.Conditi import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -35,8 +35,7 @@ import org.springframework.context.annotation.Configuration; **/ @Configuration(proxyBeanMethods = false) @ConditionalOnClass(Endpoint.class) -@ConditionalOnProperty(value = "spring.cloud.polaris.config.enabled", - matchIfMissing = true) +@ConditionalOnPolarisConfigEnabled public class PolarisConfigEndpointAutoConfiguration { @Bean diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryClientConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryClientConfiguration.java index 6b1ef7118..1f6b8f710 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryClientConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryClientConfiguration.java @@ -33,6 +33,7 @@ import org.springframework.context.annotation.Configuration; */ @Configuration(proxyBeanMethods = false) @ConditionalOnBlockingDiscoveryEnabled +@ConditionalOnPolarisDiscoveryEnabled @AutoConfigureBefore({SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class}) @AutoConfigureAfter(PolarisDiscoveryAutoConfiguration.class) public class PolarisDiscoveryClientConfiguration { diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisRegistration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisRegistration.java index 3d6a818fc..a127dc276 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisRegistration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisRegistration.java @@ -19,7 +19,6 @@ package com.tencent.cloud.polaris.registry; import java.net.URI; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -54,7 +53,7 @@ public class PolarisRegistration implements Registration { private Map metadata; - private final String host; + private String host; public PolarisRegistration( PolarisDiscoveryProperties polarisDiscoveryProperties, @@ -78,6 +77,10 @@ public class PolarisRegistration implements Registration { return host; } + public void setHost(String host) { + this.host = host; + } + @Override public int getPort() { return polarisDiscoveryProperties.getPort(); @@ -108,7 +111,7 @@ public class PolarisRegistration implements Registration { instanceMetadata.putAll(staticMetadataManager.getMergedStaticMetadata()); - this.metadata = Collections.unmodifiableMap(instanceMetadata); + this.metadata = instanceMetadata; } return metadata; } diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/ConditionalOnPolarisRateLimitEnabled.java b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/ConditionalOnPolarisRateLimitEnabled.java new file mode 100644 index 000000000..75dc47760 --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/ConditionalOnPolarisRateLimitEnabled.java @@ -0,0 +1,38 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. 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 java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +/** + * Condition if Polaris rate limit is enabled. + * @author lepdou 2022-09-23 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@ConditionalOnPolarisEnabled +@ConditionalOnProperty(name = "spring.cloud.polaris.ratelimit.enabled", matchIfMissing = true) +public @interface ConditionalOnPolarisRateLimitEnabled { +} diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/PolarisRateLimitAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/PolarisRateLimitAutoConfiguration.java index a9dd140e5..c74ffa66b 100644 --- a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/PolarisRateLimitAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/PolarisRateLimitAutoConfiguration.java @@ -18,7 +18,6 @@ package com.tencent.cloud.polaris.ratelimit.config; -import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.cloud.polaris.context.ServiceRuleManager; import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration; import com.tencent.cloud.polaris.ratelimit.RateLimitRuleLabelResolver; @@ -33,7 +32,6 @@ import com.tencent.polaris.ratelimit.factory.LimitAPIFactory; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; @@ -53,9 +51,8 @@ import static javax.servlet.DispatcherType.REQUEST; * @author Haotian Zhang */ @Configuration(proxyBeanMethods = false) -@ConditionalOnPolarisEnabled @AutoConfigureAfter(PolarisContextAutoConfiguration.class) -@ConditionalOnProperty(name = "spring.cloud.polaris.ratelimit.enabled", matchIfMissing = true) +@ConditionalOnPolarisRateLimitEnabled public class PolarisRateLimitAutoConfiguration { @Bean diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/PolarisRateLimitPropertiesAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/PolarisRateLimitPropertiesAutoConfiguration.java index 672a1dae2..ebb9d7553 100644 --- a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/PolarisRateLimitPropertiesAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/config/PolarisRateLimitPropertiesAutoConfiguration.java @@ -17,8 +17,6 @@ package com.tencent.cloud.polaris.ratelimit.config; -import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; - import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -30,8 +28,8 @@ import org.springframework.context.annotation.Configuration; * @author Haotian Zhang */ @Configuration(proxyBeanMethods = false) -@ConditionalOnPolarisEnabled @EnableConfigurationProperties(PolarisRateLimitProperties.class) +@ConditionalOnPolarisRateLimitEnabled public class PolarisRateLimitPropertiesAutoConfiguration { @Bean diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java index e3acf9fda..54068f453 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java @@ -96,7 +96,7 @@ public class PolarisRouterServiceInstanceListSupplier extends DelegatingServiceI // 2. filter by router DefaultRequestContext requestContext = (DefaultRequestContext) request.getContext(); - PolarisRouterContext key = null; + PolarisRouterContext key; if (requestContext instanceof RequestDataContext) { key = buildRouterContext(((RequestDataContext) requestContext).getClientRequest().getHeaders()); } @@ -104,6 +104,11 @@ public class PolarisRouterServiceInstanceListSupplier extends DelegatingServiceI key = buildRouterContext(((PolarisLoadBalancerRequest) requestContext.getClientRequest()).getRequest() .getHeaders()); } + else { + // return all servers if router context is null. + return allServers; + } + return doRouter(allServers, key); } diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/ConditionalOnPolarisRouterEnabled.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/ConditionalOnPolarisRouterEnabled.java new file mode 100644 index 000000000..b11193e64 --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/ConditionalOnPolarisRouterEnabled.java @@ -0,0 +1,38 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. 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 java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +/** + * Condition if Polaris router is enabled. + * @author lepdou 2022-09-23 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@ConditionalOnPolarisEnabled +@ConditionalOnProperty(name = "spring.cloud.polaris.router.enabled", matchIfMissing = true) +public @interface ConditionalOnPolarisRouterEnabled { +} diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/FeignAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/FeignAutoConfiguration.java index 5775b6841..8a90289df 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/FeignAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/FeignAutoConfiguration.java @@ -31,6 +31,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.lang.Nullable; @Configuration(proxyBeanMethods = false) +@ConditionalOnPolarisRouterEnabled @ConditionalOnClass(name = {"feign.RequestInterceptor"}) public class FeignAutoConfiguration { diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java index 8dc41be3a..1ed979c03 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java @@ -43,6 +43,7 @@ import org.springframework.core.annotation.Order; * @author lepdou 2022-05-17 */ @Configuration(proxyBeanMethods = false) +@ConditionalOnPolarisRouterEnabled @ConditionalOnDiscoveryEnabled public class LoadBalancerConfiguration { diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/RouterAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/RouterAutoConfiguration.java index 8947e864f..39ca6fd85 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/RouterAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/RouterAutoConfiguration.java @@ -45,6 +45,7 @@ import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE; * @author lepdou 2022-05-11 */ @Configuration(proxyBeanMethods = false) +@ConditionalOnPolarisRouterEnabled @LoadBalancerClients(defaultConfiguration = LoadBalancerConfiguration.class) @Import({PolarisNearByRouterProperties.class, PolarisMetadataRouterProperties.class, PolarisRuleBasedRouterProperties.class}) public class RouterAutoConfiguration { diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-starter-tencent-polaris-router/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 4f248b727..0c935af6e 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-starter-tencent-polaris-router/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -17,6 +17,12 @@ "type": "java.lang.Boolean", "defaultValue": true, "description": "the switch for rule based router." + }, + { + "name": "spring.cloud.polaris.router.enabled", + "type": "java.lang.Boolean", + "defaultValue": true, + "description": "the switch for router module." } ] } diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index b9ec84412..f3f6a8d02 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -73,7 +73,7 @@ 1.8.0-2020.0.5-SNAPSHOT - 1.8.0-SNAPSHOT + 1.8.0 1.2.11 4.5.1 1.12.10 diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-featureenv-plugin/src/main/java/com/tencent/cloud/plugin/featureenv/FeatureEnvAutoConfiguration.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-featureenv-plugin/src/main/java/com/tencent/cloud/plugin/featureenv/FeatureEnvAutoConfiguration.java index d341ba345..d5eb240ac 100644 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-featureenv-plugin/src/main/java/com/tencent/cloud/plugin/featureenv/FeatureEnvAutoConfiguration.java +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-featureenv-plugin/src/main/java/com/tencent/cloud/plugin/featureenv/FeatureEnvAutoConfiguration.java @@ -18,6 +18,8 @@ package com.tencent.cloud.plugin.featureenv; +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; + import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -27,6 +29,7 @@ import org.springframework.context.annotation.Configuration; * @author lepdou 2022-07-06 */ @Configuration +@ConditionalOnPolarisEnabled @ConditionalOnProperty(value = "spring.cloud.tencent.plugin.router.feature-env.enabled", matchIfMissing = true) public class FeatureEnvAutoConfiguration { diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-gateway-plugin/src/main/java/com/tencent/cloud/plugin/gateway/SCGPluginsAutoConfiguration.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-gateway-plugin/src/main/java/com/tencent/cloud/plugin/gateway/SCGPluginsAutoConfiguration.java index f0daf20a8..1d33cfb49 100644 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-gateway-plugin/src/main/java/com/tencent/cloud/plugin/gateway/SCGPluginsAutoConfiguration.java +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-gateway-plugin/src/main/java/com/tencent/cloud/plugin/gateway/SCGPluginsAutoConfiguration.java @@ -27,6 +27,8 @@ import com.tencent.cloud.plugin.gateway.staining.rule.RuleStainingExecutor; import com.tencent.cloud.plugin.gateway.staining.rule.RuleStainingProperties; import com.tencent.cloud.plugin.gateway.staining.rule.RuleTrafficStainer; import com.tencent.cloud.plugin.gateway.staining.rule.StainingRuleManager; +import com.tencent.cloud.polaris.config.ConditionalOnPolarisConfigEnabled; +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.polaris.configuration.api.core.ConfigFileService; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -38,6 +40,7 @@ import org.springframework.context.annotation.Configuration; * @author lepdou 2022-07-06 */ @Configuration +@ConditionalOnPolarisEnabled @ConditionalOnProperty(value = "spring.cloud.tencent.plugin.scg.enabled", matchIfMissing = true) public class SCGPluginsAutoConfiguration { @@ -52,6 +55,7 @@ public class SCGPluginsAutoConfiguration { @Configuration @ConditionalOnProperty(value = "spring.cloud.tencent.plugin.scg.staining.rule-staining.enabled", matchIfMissing = true) + @ConditionalOnPolarisConfigEnabled public static class RuleStainingPluginConfiguration { @Bean diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextPostConfiguration.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextPostConfiguration.java index 85ea11727..36b8664ce 100644 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextPostConfiguration.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextPostConfiguration.java @@ -19,6 +19,7 @@ package com.tencent.cloud.polaris.context.config; import com.tencent.cloud.common.metadata.StaticMetadataManager; +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.cloud.polaris.context.PostInitPolarisSDKContext; import com.tencent.polaris.client.api.SDKContext; @@ -31,6 +32,7 @@ import org.springframework.context.annotation.Configuration; * @author lepdou 2022-06-28 */ @Configuration(proxyBeanMethods = false) +@ConditionalOnPolarisEnabled public class PolarisContextPostConfiguration { @Bean diff --git a/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/config/PolarisLoadBalancerClientConfiguration.java b/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/config/PolarisLoadBalancerClientConfiguration.java index 1169c9be2..4510a5f97 100644 --- a/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/config/PolarisLoadBalancerClientConfiguration.java +++ b/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/config/PolarisLoadBalancerClientConfiguration.java @@ -17,6 +17,7 @@ package com.tencent.cloud.polaris.loadbalancer.config; +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancer; import com.tencent.cloud.polaris.loadbalancer.PolarisServiceInstanceListSupplier; import com.tencent.polaris.router.api.core.RouterAPI; @@ -45,6 +46,7 @@ import org.springframework.core.env.Environment; * @author liaochuntao */ @Configuration(proxyBeanMethods = false) +@ConditionalOnPolarisEnabled @ConditionalOnDiscoveryEnabled public class PolarisLoadBalancerClientConfiguration { diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java index 3352362d7..46d24fa9d 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java @@ -20,6 +20,7 @@ package com.tencent.cloud.rpc.enhancement.config; import java.util.Collections; import java.util.List; +import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration; import com.tencent.cloud.rpc.enhancement.feign.DefaultEnhancedFeignPluginRunner; import com.tencent.cloud.rpc.enhancement.feign.EnhancedFeignBeanPostProcessor; @@ -54,6 +55,7 @@ import org.springframework.web.client.RestTemplate; * @author Palmer.Xu 2022-06-29 */ @Configuration(proxyBeanMethods = false) +@ConditionalOnPolarisEnabled @ConditionalOnProperty(value = "spring.cloud.tencent.rpc-enhancement.enabled", havingValue = "true", matchIfMissing = true) @EnableConfigurationProperties(RpcEnhancementReporterProperties.class) @AutoConfigureAfter(PolarisContextAutoConfiguration.class)