From 64259ea34cebec1b84f73aba9b2f09e9401fa1c2 Mon Sep 17 00:00:00 2001 From: lepdou Date: Thu, 31 Mar 2022 16:09:27 +0800 Subject: [PATCH] 1. rollback init polaris-context to application phase 2. set example polaris server address to 127.0.0.1 --- CHANGELOG.md | 1 + ...larisConfigBootstrapAutoConfiguration.java | 21 ++++--- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/polaris.yml | 6 -- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../cloud/polaris/context/ModifyAddress.java | 57 +++++++++++++++++++ .../context/PolarisContextConfiguration.java | 32 ----------- .../main/resources/META-INF/spring.factories | 2 +- 15 files changed, 80 insertions(+), 57 deletions(-) delete mode 100644 spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/polaris.yml create mode 100644 spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/ModifyAddress.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 093d63f8b..c55e24688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,5 +14,6 @@ - [feat:optimize metadata module.](https://github.com/Tencent/spring-cloud-tencent/pull/70) - [feat: optimize pom dependency and demo](https://github.com/Tencent/spring-cloud-tencent/pull/71) - [feat:upgrade polaris version to 1.3.0.](https://github.com/Tencent/spring-cloud-tencent/pull/72) +- [feat:rollback init polaris-context to application phase](https://github.com/Tencent/spring-cloud-tencent/pull/73) 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 8ca4ad980..296793d0a 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 @@ -1,18 +1,18 @@ /* * 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. + * 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 + * 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 + * 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. + * 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; @@ -20,6 +20,7 @@ package com.tencent.cloud.polaris.config; import com.tencent.cloud.polaris.config.adapter.PolarisConfigFileLocator; import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager; import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; +import com.tencent.cloud.polaris.context.PolarisContextConfiguration; import com.tencent.cloud.polaris.context.PolarisContextProperties; import com.tencent.polaris.client.api.SDKContext; import com.tencent.polaris.configuration.api.core.ConfigFileService; @@ -28,6 +29,7 @@ import com.tencent.polaris.configuration.factory.ConfigFileServiceFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; /** * polaris config module auto configuration at bootstrap phase. @@ -37,6 +39,7 @@ import org.springframework.context.annotation.Configuration; @Configuration(proxyBeanMethods = false) @ConditionalOnProperty(value = "spring.cloud.polaris.config.enabled", matchIfMissing = true) +@Import(PolarisContextConfiguration.class) public class PolarisConfigBootstrapAutoConfiguration { @Bean diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/bootstrap.yml index 7f5835916..08b117235 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/bootstrap.yml @@ -5,7 +5,7 @@ spring: name: polaris-circuitbreaker-example-a cloud: polaris: - address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + address: grpc://127.0.0.1:8091 namespace: default feign: hystrix: diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/resources/bootstrap.yml index 34a198a00..ee986b845 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/resources/bootstrap.yml @@ -5,6 +5,6 @@ spring: name: polaris-circuitbreaker-example-b cloud: polaris: - address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + address: grpc://127.0.0.1:8091 namespace: default is-throw-runtime-exception: false diff --git a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml index 92da7031c..b8ab4e08a 100644 --- a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ spring: polaris: namespace: default config: - address: grpc://159.75.195.18:8093 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + address: grpc://127.0.0.1:8093 auto-refresh: true # auto refresh when config file changed groups: - name: ${spring.application.name} # group name diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml index aab8f3b91..991d77a34 100644 --- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml @@ -5,7 +5,7 @@ spring: name: DiscoveryCalleeService cloud: polaris: - address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + address: grpc://127.0.0.1:8091 namespace: default # consul: # port: 8500 diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml index 0004dc49b..d0cb0ec1e 100644 --- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml @@ -6,7 +6,7 @@ spring: name: DiscoveryCallerService cloud: polaris: - address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + address: grpc://127.0.0.1:8091 namespace: default discovery: heartbeat: diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/polaris.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/polaris.yml deleted file mode 100644 index 8e0b95dc3..000000000 --- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/polaris.yml +++ /dev/null @@ -1,6 +0,0 @@ -global: - system: - discoverCluster: - sameAsBuiltin: true - healthCheckCluster: - sameAsBuiltin: true diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/bootstrap.yml index 5c68e3d30..c23ece6d7 100644 --- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/bootstrap.yml @@ -6,5 +6,5 @@ spring: name: GatewayCalleeService cloud: polaris: - address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + address: grpc://127.0.0.1:8091 namespace: default diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/bootstrap.yml index d6b83f018..d41fcf960 100644 --- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/bootstrap.yml @@ -12,7 +12,7 @@ spring: transitive: - a polaris: - address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + address: grpc://127.0.0.1:8091 namespace: default gateway: discovery: diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/bootstrap.yml index 624830b65..332041060 100644 --- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/bootstrap.yml @@ -6,7 +6,7 @@ spring: name: GatewayZuulService cloud: polaris: - address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + address: grpc://127.0.0.1:8091 namespace: default tencent: metadata: diff --git a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml index 9ad52fcb2..6b8ba88a0 100644 --- a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml @@ -5,5 +5,5 @@ spring: name: RateLimitCalleeService cloud: polaris: - address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + address: grpc://127.0.0.1:8091 namespace: default diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/ModifyAddress.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/ModifyAddress.java new file mode 100644 index 000000000..6d3dcf4b9 --- /dev/null +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/ModifyAddress.java @@ -0,0 +1,57 @@ +/* + * 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.context; + +import java.util.List; + +import com.tencent.cloud.common.constant.ContextConstant; +import com.tencent.cloud.common.util.AddressUtils; +import com.tencent.polaris.factory.config.ConfigurationImpl; +import org.apache.commons.lang.StringUtils; + +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Modify polaris server address. + * + * @author lepdou 2022-03-10 + */ +public class ModifyAddress implements PolarisConfigModifier { + + @Autowired + private PolarisContextProperties properties; + + @Override + public void modify(ConfigurationImpl configuration) { + if (StringUtils.isBlank(properties.getAddress())) { + return; + } + + List addresses = AddressUtils + .parseAddressList(properties.getAddress()); + + configuration.getGlobal().getServerConnector().setAddresses(addresses); + } + + @Override + public int getOrder() { + return ContextConstant.ModifierOrder.FIRST; + } + + } diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextConfiguration.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextConfiguration.java index e495ef033..63ddd97e8 100644 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextConfiguration.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextConfiguration.java @@ -18,16 +18,9 @@ package com.tencent.cloud.polaris.context; -import java.util.List; - -import com.tencent.cloud.common.constant.ContextConstant.ModifierOrder; -import com.tencent.cloud.common.util.AddressUtils; import com.tencent.polaris.api.exception.PolarisException; import com.tencent.polaris.client.api.SDKContext; -import com.tencent.polaris.factory.config.ConfigurationImpl; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -52,29 +45,4 @@ public class PolarisContextConfiguration { public ModifyAddress polarisConfigModifier() { return new ModifyAddress(); } - - private static class ModifyAddress implements PolarisConfigModifier { - - @Autowired - private PolarisContextProperties properties; - - @Override - public void modify(ConfigurationImpl configuration) { - if (StringUtils.isBlank(properties.getAddress())) { - return; - } - - List addresses = AddressUtils - .parseAddressList(properties.getAddress()); - - configuration.getGlobal().getServerConnector().setAddresses(addresses); - } - - @Override - public int getOrder() { - return ModifierOrder.FIRST; - } - - } - } diff --git a/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/spring.factories b/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/spring.factories index 609b809d7..5b3b188e7 100644 --- a/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/spring.factories @@ -1 +1 @@ -org.springframework.cloud.bootstrap.BootstrapConfiguration=com.tencent.cloud.polaris.context.PolarisContextConfiguration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.tencent.cloud.polaris.context.PolarisContextConfiguration