From cff6466223a2320a21c97485c138fe1f45b62a15 Mon Sep 17 00:00:00 2001 From: lepdou Date: Wed, 30 Mar 2022 19:11:40 +0800 Subject: [PATCH] 1. optimize pom dependency 2. optimize demo --- .../pom.xml | 14 ++--- .../pom.xml | 15 ++---- .../polaris/config/ConfigurationModifier.java | 22 ++++---- .../config/PolarisConfigProperties.java | 28 +++++----- ...itional-spring-configuration-metadata.json | 4 +- .../pom.xml | 7 +-- ...s.java => PolarisDiscoveryProperties.java} | 30 ++--------- .../PolarisDiscoveryAutoConfiguration.java | 8 +-- .../discovery/PolarisDiscoveryHandler.java | 11 ++-- .../polaris/registry/PolarisRegistration.java | 30 +++++------ .../registry/PolarisServiceRegistry.java | 34 ++++++------ ...larisServiceRegistryAutoConfiguration.java | 15 +++--- ...itional-spring-configuration-metadata.json | 6 --- .../cloud/polaris/PolarisPropertiesTest.java | 9 ++-- ...PolarisDiscoveryAutoConfigurationTest.java | 5 +- .../pom.xml | 7 +-- .../pom.xml | 17 +++--- spring-cloud-tencent-commons/pom.xml | 12 +---- .../feign/MetadataFirstFeignInterceptor.java | 3 +- spring-cloud-tencent-dependencies/pom.xml | 32 +++++------- .../src/main/resources/bootstrap.yml | 3 +- .../src/main/resources/bootstrap.yml | 3 +- .../polaris-config-example/pom.xml | 7 --- .../src/main/resources/bootstrap.yml | 4 +- .../src/main/resources/log4j.properties | 15 ------ .../src/main/resources/logback-spring.xml | 28 ---------- .../discovery-callee-service/pom.xml | 4 +- .../src/main/resources/bootstrap.yml | 7 +-- .../src/main/resources/polaris.yml | 16 ------ .../src/main/resources/bootstrap.yml | 3 +- .../src/main/resources/application.yml | 9 ---- .../src/main/resources/bootstrap.yml | 10 ++++ .../{application.yml => bootstrap.yml} | 3 +- .../{application.yml => bootstrap.yml} | 3 +- .../ratelimit-callee-service/pom.xml | 6 +-- .../src/main/resources/bootstrap.yml | 5 +- spring-cloud-tencent-polaris-context/pom.xml | 5 -- .../polaris/context/InetUtilsProperties.java | 52 ------------------- .../context/PolarisContextConfiguration.java | 6 +-- .../context/PolarisContextProperties.java | 27 ++++++---- .../spring-configuration-metadata.json | 7 +++ .../context/PolarisContextGetHostTest.java | 4 ++ .../src/test/resources/bootstrap.yml | 3 +- 43 files changed, 184 insertions(+), 355 deletions(-) rename spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/{PolarisProperties.java => PolarisDiscoveryProperties.java} (87%) delete mode 100644 spring-cloud-tencent-examples/polaris-config-example/src/main/resources/log4j.properties delete mode 100644 spring-cloud-tencent-examples/polaris-config-example/src/main/resources/logback-spring.xml delete mode 100644 spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml delete mode 100644 spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/application.yml create mode 100644 spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/bootstrap.yml rename spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/{application.yml => bootstrap.yml} (78%) rename spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/{application.yml => bootstrap.yml} (67%) delete mode 100644 spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/InetUtilsProperties.java diff --git a/spring-cloud-starter-tencent-metadata-transfer/pom.xml b/spring-cloud-starter-tencent-metadata-transfer/pom.xml index 6d86c3352..212bd2b29 100644 --- a/spring-cloud-starter-tencent-metadata-transfer/pom.xml +++ b/spring-cloud-starter-tencent-metadata-transfer/pom.xml @@ -33,6 +33,12 @@ true + + org.springframework.cloud + spring-cloud-starter-openfeign + true + + org.springframework.boot spring-boot-starter-test @@ -45,12 +51,6 @@ test - - org.springframework.cloud - spring-cloud-starter-openfeign - true - - org.powermock @@ -66,4 +66,4 @@ - \ No newline at end of file + diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml b/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml index 414a90738..14b825713 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml @@ -14,11 +14,6 @@ - - com.tencent.cloud - spring-cloud-tencent-commons - - com.tencent.cloud spring-cloud-tencent-polaris-context @@ -40,11 +35,13 @@ org.springframework.cloud spring-cloud-loadbalancer + true org.springframework.cloud spring-cloud-starter-openfeign + true @@ -53,16 +50,10 @@ test - - org.springframework.cloud - spring-cloud-openfeign-core - true - - org.springframework.boot spring-boot-starter-test test - \ No newline at end of file + diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConfigurationModifier.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConfigurationModifier.java index a02d090ae..6c46f3c89 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConfigurationModifier.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConfigurationModifier.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. * */ @@ -43,13 +43,13 @@ public class ConfigurationModifier implements PolarisConfigModifier { public void modify(ConfigurationImpl configuration) { configuration.getConfigFile().getServerConnector().setConnectorType("polaris"); - if (StringUtils.isEmpty(polarisConfigProperties.getAddresses())) { + if (StringUtils.isEmpty(polarisConfigProperties.getAddress())) { return; } // override polaris config server address List addresses = AddressUtils - .parseAddressList(polarisConfigProperties.getAddresses()); + .parseAddressList(polarisConfigProperties.getAddress()); configuration.getConfigFile().getServerConnector().setAddresses(addresses); } diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/config/PolarisConfigProperties.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/config/PolarisConfigProperties.java index 8ef592616..6ddc49f5f 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/config/PolarisConfigProperties.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/config/PolarisConfigProperties.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.config; @@ -37,7 +37,7 @@ public class PolarisConfigProperties { /** * Configuration center service address list. */ - private String addresses; + private String address; /** * Whether to automatically update to the spring context when the configuration file. @@ -58,12 +58,12 @@ public class PolarisConfigProperties { this.enabled = enabled; } - public String getAddresses() { - return addresses; + public String getAddress() { + return address; } - public void setAddresses(String addresses) { - this.addresses = addresses; + public void setAddress(String address) { + this.address = address; } public boolean isAutoRefresh() { diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json index d2461eb78..152d24d64 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -8,10 +8,10 @@ "sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties" }, { - "name": "spring.cloud.polaris.config.addresses", + "name": "spring.cloud.polaris.config.address", "type": "java.lang.String", "defaultValue": "", - "description": "The polaris configuration server addresses.", + "description": "The polaris configuration server address.", "sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties" }, { diff --git a/spring-cloud-starter-tencent-polaris-discovery/pom.xml b/spring-cloud-starter-tencent-polaris-discovery/pom.xml index d11f1f599..4fca20c46 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/pom.xml +++ b/spring-cloud-starter-tencent-polaris-discovery/pom.xml @@ -15,11 +15,6 @@ - - com.tencent.cloud - spring-cloud-tencent-commons - - com.tencent.cloud spring-cloud-tencent-polaris-context @@ -86,4 +81,4 @@ test - \ No newline at end of file + diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisProperties.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryProperties.java similarity index 87% rename from spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisProperties.java rename to spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryProperties.java index f387cf145..35f397217 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisProperties.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/PolarisDiscoveryProperties.java @@ -13,6 +13,7 @@ * 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; @@ -24,7 +25,6 @@ import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.cloud.commons.util.InetUtils; import org.springframework.core.env.Environment; /** @@ -33,7 +33,7 @@ import org.springframework.core.env.Environment; * @author Haotian Zhang, Andrew Shan, Jie Cheng */ @ConfigurationProperties("spring.cloud.polaris.discovery") -public class PolarisProperties { +public class PolarisDiscoveryProperties { /** * The polaris authentication token. @@ -75,11 +75,6 @@ public class PolarisProperties { @Value("${server.port:}") private int port; - /** - * Ip address to be registered. - */ - private String ipAddress; - /** * If instance registered. */ @@ -101,12 +96,6 @@ public class PolarisProperties { @Autowired private Environment environment; - public PolarisProperties(InetUtils inetUtils) { - if (inetUtils != null) { - this.ipAddress = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); - } - } - /** * Init properties. */ @@ -201,14 +190,6 @@ public class PolarisProperties { this.port = port; } - public String getIpAddress() { - return ipAddress; - } - - public void setIpAddress(String ipAddress) { - this.ipAddress = ipAddress; - } - public String getHealthCheckUrl() { return healthCheckUrl; } @@ -222,10 +203,9 @@ public class PolarisProperties { return "PolarisProperties{" + "token='" + token + '\'' + ", namespace='" + namespace + '\'' + ", service='" + service + '\'' + ", weight=" + weight + ", version='" + version + '\'' + ", protocol='" + protocol + '\'' - + ", port=" + port + ", ipAddress='" + ipAddress + '\'' - + ", registerEnabled=" + registerEnabled + ", heartbeatEnabled=" - + heartbeatEnabled + ", healthCheckUrl=" + healthCheckUrl - + ", environment=" + environment + '}'; + + ", port=" + port + '\'' + ", registerEnabled=" + registerEnabled + + ", heartbeatEnabled=" + heartbeatEnabled + ", healthCheckUrl=" + + healthCheckUrl + ", environment=" + environment + '}'; } } diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryAutoConfiguration.java index 5369929cf..34551aaf6 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryAutoConfiguration.java @@ -13,11 +13,12 @@ * 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.discovery; -import com.tencent.cloud.polaris.PolarisProperties; +import com.tencent.cloud.polaris.PolarisDiscoveryProperties; import com.tencent.cloud.polaris.discovery.reactive.PolarisReactiveDiscoveryClientConfiguration; import com.tencent.cloud.polaris.extend.consul.ConsulContextProperties; import com.tencent.polaris.api.core.ConsumerAPI; @@ -27,7 +28,6 @@ import com.tencent.polaris.client.api.SDKContext; import com.tencent.polaris.factory.api.DiscoveryAPIFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.cloud.commons.util.InetUtils; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -46,8 +46,8 @@ public class PolarisDiscoveryAutoConfiguration { @Bean @ConditionalOnMissingBean - public PolarisProperties polarisDiscoveryProperties(InetUtils inetUtils) { - return new PolarisProperties(inetUtils); + public PolarisDiscoveryProperties polarisDiscoveryProperties() { + return new PolarisDiscoveryProperties(); } @Bean(name = "polarisProvider") diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java index 167c029b6..fd8b878e2 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java @@ -13,6 +13,7 @@ * 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.discovery; @@ -22,7 +23,7 @@ import java.util.Map; import com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey; import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContextHolder; -import com.tencent.cloud.polaris.PolarisProperties; +import com.tencent.cloud.polaris.PolarisDiscoveryProperties; import com.tencent.polaris.api.core.ConsumerAPI; import com.tencent.polaris.api.core.ProviderAPI; import com.tencent.polaris.api.pojo.ServiceInfo; @@ -45,7 +46,7 @@ import org.springframework.stereotype.Component; public class PolarisDiscoveryHandler { @Autowired - private PolarisProperties polarisProperties; + private PolarisDiscoveryProperties polarisDiscoveryProperties; @Autowired private ProviderAPI providerAPI; @@ -59,7 +60,7 @@ public class PolarisDiscoveryHandler { * @return list of instances */ public InstancesResponse getFilteredInstances(String service) { - String namespace = polarisProperties.getNamespace(); + String namespace = polarisDiscoveryProperties.getNamespace(); GetInstancesRequest getInstancesRequest = new GetInstancesRequest(); getInstancesRequest.setNamespace(namespace); getInstancesRequest.setService(service); @@ -87,7 +88,7 @@ public class PolarisDiscoveryHandler { * @return list of instances */ public InstancesResponse getInstances(String service) { - String namespace = polarisProperties.getNamespace(); + String namespace = polarisDiscoveryProperties.getNamespace(); GetAllInstancesRequest request = new GetAllInstancesRequest(); request.setNamespace(namespace); request.setService(service); @@ -103,7 +104,7 @@ public class PolarisDiscoveryHandler { * @return service list */ public ServicesResponse GetServices() { - String namespace = polarisProperties.getNamespace(); + String namespace = polarisDiscoveryProperties.getNamespace(); GetServicesRequest request = new GetServicesRequest(); request.setNamespace(namespace); return polarisConsumer.getServices(request); 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 8ceb155b5..38fedcb0b 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 @@ -13,6 +13,7 @@ * 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.registry; @@ -21,7 +22,7 @@ import java.net.URI; import java.util.Map; import com.tencent.cloud.common.metadata.MetadataContextHolder; -import com.tencent.cloud.polaris.PolarisProperties; +import com.tencent.cloud.polaris.PolarisDiscoveryProperties; import com.tencent.polaris.client.api.SDKContext; import org.apache.commons.lang.StringUtils; @@ -36,40 +37,39 @@ import org.springframework.cloud.client.serviceregistry.Registration; */ public class PolarisRegistration implements Registration, ServiceInstance { - private final PolarisProperties polarisProperties; + private final PolarisDiscoveryProperties polarisDiscoveryProperties; private final SDKContext polarisContext; - public PolarisRegistration(PolarisProperties polarisProperties, SDKContext context) { - this.polarisProperties = polarisProperties; + public PolarisRegistration(PolarisDiscoveryProperties polarisDiscoveryProperties, + SDKContext context) { + this.polarisDiscoveryProperties = polarisDiscoveryProperties; this.polarisContext = context; } @Override public String getServiceId() { - return polarisProperties.getService(); + return polarisDiscoveryProperties.getService(); } @Override public String getHost() { - if (StringUtils.isNotBlank(polarisProperties.getIpAddress())) { - return polarisProperties.getIpAddress(); - } return polarisContext.getConfig().getGlobal().getAPI().getBindIP(); } @Override public int getPort() { - return polarisProperties.getPort(); + return polarisDiscoveryProperties.getPort(); } public void setPort(int port) { - this.polarisProperties.setPort(port); + this.polarisDiscoveryProperties.setPort(port); } @Override public boolean isSecure() { - return StringUtils.equalsIgnoreCase(polarisProperties.getProtocol(), "https"); + return StringUtils.equalsIgnoreCase(polarisDiscoveryProperties.getProtocol(), + "https"); } @Override @@ -82,14 +82,14 @@ public class PolarisRegistration implements Registration, ServiceInstance { return MetadataContextHolder.get().getAllSystemMetadata(); } - public PolarisProperties getPolarisProperties() { - return polarisProperties; + public PolarisDiscoveryProperties getPolarisProperties() { + return polarisDiscoveryProperties; } @Override public String toString() { - return "PolarisRegistration{" + "polarisProperties=" + polarisProperties - + ", polarisContext=" + polarisContext + '}'; + return "PolarisRegistration{" + "polarisDiscoveryProperties=" + + polarisDiscoveryProperties + ", polarisContext=" + polarisContext + '}'; } } diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java index d15966820..7e72a075d 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java @@ -13,6 +13,7 @@ * 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.registry; @@ -22,7 +23,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; -import com.tencent.cloud.polaris.PolarisProperties; +import com.tencent.cloud.polaris.PolarisDiscoveryProperties; import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler; import com.tencent.cloud.polaris.util.OkHttpUtil; import com.tencent.polaris.api.core.ProviderAPI; @@ -56,7 +57,7 @@ public class PolarisServiceRegistry implements ServiceRegistry { private static final int ttl = 5; - private final PolarisProperties polarisProperties; + private final PolarisDiscoveryProperties polarisDiscoveryProperties; private final PolarisDiscoveryHandler polarisDiscoveryHandler; @@ -64,13 +65,13 @@ public class PolarisServiceRegistry implements ServiceRegistry { private final ScheduledExecutorService heartbeatExecutor; - public PolarisServiceRegistry(PolarisProperties polarisProperties, + public PolarisServiceRegistry(PolarisDiscoveryProperties polarisDiscoveryProperties, PolarisDiscoveryHandler polarisDiscoveryHandler, MetadataLocalProperties metadataLocalProperties) { - this.polarisProperties = polarisProperties; + this.polarisDiscoveryProperties = polarisDiscoveryProperties; this.polarisDiscoveryHandler = polarisDiscoveryHandler; this.metadataLocalProperties = metadataLocalProperties; - if (polarisProperties.isHeartbeatEnabled()) { + if (polarisDiscoveryProperties.isHeartbeatEnabled()) { ScheduledThreadPoolExecutor heartbeatExecutor = new ScheduledThreadPoolExecutor( 0, new NamedThreadFactory("spring-cloud-heartbeat")); heartbeatExecutor.setMaximumPoolSize(1); @@ -90,24 +91,24 @@ public class PolarisServiceRegistry implements ServiceRegistry { } // Register instance. InstanceRegisterRequest instanceRegisterRequest = new InstanceRegisterRequest(); - instanceRegisterRequest.setNamespace(polarisProperties.getNamespace()); + instanceRegisterRequest.setNamespace(polarisDiscoveryProperties.getNamespace()); instanceRegisterRequest.setService(registration.getServiceId()); instanceRegisterRequest.setHost(registration.getHost()); instanceRegisterRequest.setPort(registration.getPort()); - instanceRegisterRequest.setToken(polarisProperties.getToken()); + instanceRegisterRequest.setToken(polarisDiscoveryProperties.getToken()); if (null != heartbeatExecutor) { instanceRegisterRequest.setTtl(ttl); } instanceRegisterRequest.setMetadata(metadataLocalProperties.getContent()); - instanceRegisterRequest.setProtocol(polarisProperties.getProtocol()); - instanceRegisterRequest.setVersion(polarisProperties.getVersion()); + instanceRegisterRequest.setProtocol(polarisDiscoveryProperties.getProtocol()); + instanceRegisterRequest.setVersion(polarisDiscoveryProperties.getVersion()); try { ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI(); providerClient.register(instanceRegisterRequest); log.info("polaris registry, {} {} {}:{} {} register finished", - polarisProperties.getNamespace(), registration.getServiceId(), - registration.getHost(), registration.getPort(), - metadataLocalProperties.getContent()); + polarisDiscoveryProperties.getNamespace(), + registration.getServiceId(), registration.getHost(), + registration.getPort(), metadataLocalProperties.getContent()); if (null != heartbeatExecutor) { InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest(); @@ -134,8 +135,8 @@ public class PolarisServiceRegistry implements ServiceRegistry { } InstanceDeregisterRequest deRegisterRequest = new InstanceDeregisterRequest(); - deRegisterRequest.setToken(polarisProperties.getToken()); - deRegisterRequest.setNamespace(polarisProperties.getNamespace()); + deRegisterRequest.setToken(polarisDiscoveryProperties.getToken()); + deRegisterRequest.setNamespace(polarisDiscoveryProperties.getNamespace()); deRegisterRequest.setService(registration.getServiceId()); deRegisterRequest.setHost(registration.getHost()); deRegisterRequest.setPort(registration.getPort()); @@ -177,7 +178,7 @@ public class PolarisServiceRegistry implements ServiceRegistry { } for (Instance instance : instances) { if (instance.getHost().equalsIgnoreCase(registration.getHost()) - && instance.getPort() == polarisProperties.getPort()) { + && instance.getPort() == polarisDiscoveryProperties.getPort()) { return instance.isHealthy() ? "UP" : "DOWN"; } } @@ -191,7 +192,8 @@ public class PolarisServiceRegistry implements ServiceRegistry { public void heartbeat(InstanceHeartbeatRequest heartbeatRequest) { heartbeatExecutor.scheduleWithFixedDelay(() -> { try { - String healthCheckEndpoint = polarisProperties.getHealthCheckUrl(); + String healthCheckEndpoint = polarisDiscoveryProperties + .getHealthCheckUrl(); // First determine whether health-check-url is configured. // If configured, the service instance health check needs to be executed // first. diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistryAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistryAutoConfiguration.java index bee238321..7a07bae39 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistryAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistryAutoConfiguration.java @@ -13,12 +13,13 @@ * 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.registry; import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; -import com.tencent.cloud.polaris.PolarisProperties; +import com.tencent.cloud.polaris.PolarisDiscoveryProperties; import com.tencent.cloud.polaris.discovery.ConditionalOnPolarisDiscoveryEnabled; import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration; import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler; @@ -51,18 +52,18 @@ public class PolarisServiceRegistryAutoConfiguration { @Bean public PolarisServiceRegistry polarisServiceRegistry( - PolarisProperties polarisProperties, + PolarisDiscoveryProperties polarisDiscoveryProperties, PolarisDiscoveryHandler polarisDiscoveryHandler, MetadataLocalProperties metadataLocalProperties) { - return new PolarisServiceRegistry(polarisProperties, polarisDiscoveryHandler, - metadataLocalProperties); + return new PolarisServiceRegistry(polarisDiscoveryProperties, + polarisDiscoveryHandler, metadataLocalProperties); } @Bean @ConditionalOnBean(AutoServiceRegistrationProperties.class) - public PolarisRegistration polarisRegistration(PolarisProperties polarisProperties, - SDKContext context) { - return new PolarisRegistration(polarisProperties, context); + public PolarisRegistration polarisRegistration( + PolarisDiscoveryProperties polarisDiscoveryProperties, SDKContext context) { + return new PolarisRegistration(polarisDiscoveryProperties, context); } @Bean diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 3755cd6ef..89021b3d2 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -42,12 +42,6 @@ "defaultValue": "${spring.cloud.polaris.version}", "description": "polaris discovery service's username to authenticate." }, - { - "name": "spring.cloud.polaris.discovery.ip-address", - "type": "java.lang.String", - "defaultValue": "", - "description": "ip address to be registered to polaris discovery server." - }, { "name": "spring.cloud.polaris.protocol", "type": "java.lang.String", diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/PolarisPropertiesTest.java b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/PolarisPropertiesTest.java index d140c8a8d..518797e2c 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/PolarisPropertiesTest.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/PolarisPropertiesTest.java @@ -13,22 +13,20 @@ * 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.junit.Test; -import org.springframework.cloud.commons.util.InetUtils; -import org.springframework.cloud.commons.util.InetUtilsProperties; - import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST; import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; /** - * Test for {@link PolarisProperties} + * Test for {@link PolarisDiscoveryProperties} * * @author Haotian Zhang */ @@ -36,8 +34,7 @@ public class PolarisPropertiesTest { @Test public void testInitAndGetSet() { - PolarisProperties temp = new PolarisProperties( - new InetUtils(new InetUtilsProperties())); + PolarisDiscoveryProperties temp = new PolarisDiscoveryProperties(); try { temp.setNamespace(NAMESPACE_TEST); assertThat(temp.getNamespace()).isEqualTo(NAMESPACE_TEST); diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryAutoConfigurationTest.java b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryAutoConfigurationTest.java index 9c864be98..517c7e464 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryAutoConfigurationTest.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryAutoConfigurationTest.java @@ -13,11 +13,12 @@ * 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.discovery; -import com.tencent.cloud.polaris.PolarisProperties; +import com.tencent.cloud.polaris.PolarisDiscoveryProperties; import com.tencent.cloud.polaris.context.PolarisContextConfiguration; import com.tencent.polaris.api.core.ConsumerAPI; import com.tencent.polaris.api.core.ProviderAPI; @@ -71,7 +72,7 @@ public class PolarisDiscoveryAutoConfigurationTest { this.contextRunner.run(context -> { assertThat(context).hasSingleBean(ProviderAPI.class); assertThat(context).hasSingleBean(ConsumerAPI.class); - assertThat(context).hasSingleBean(PolarisProperties.class); + assertThat(context).hasSingleBean(PolarisDiscoveryProperties.class); assertThat(context).hasSingleBean(PolarisServiceDiscovery.class); }); } diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml b/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml index 282c82097..e3886ecf2 100644 --- a/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml +++ b/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml @@ -15,11 +15,6 @@ - - com.tencent.cloud - spring-cloud-tencent-commons - - com.tencent.cloud spring-cloud-tencent-polaris-context @@ -81,4 +76,4 @@ test - \ No newline at end of file + diff --git a/spring-cloud-starter-tencent-polaris-router/pom.xml b/spring-cloud-starter-tencent-polaris-router/pom.xml index 48c14a357..cffa4f084 100644 --- a/spring-cloud-starter-tencent-polaris-router/pom.xml +++ b/spring-cloud-starter-tencent-polaris-router/pom.xml @@ -15,11 +15,6 @@ - - com.tencent.cloud - spring-cloud-tencent-commons - - com.tencent.cloud spring-cloud-tencent-polaris-context @@ -32,6 +27,11 @@ polaris-router-factory + + org.springframework.cloud + spring-cloud-starter-netflix-ribbon + + com.tencent.polaris polaris-test-common @@ -39,11 +39,6 @@ - - org.springframework.cloud - spring-cloud-starter-netflix-ribbon - - org.springframework.boot spring-boot-starter-test @@ -51,4 +46,4 @@ - \ No newline at end of file + diff --git a/spring-cloud-tencent-commons/pom.xml b/spring-cloud-tencent-commons/pom.xml index 6e16264a0..8f3ad8e84 100644 --- a/spring-cloud-tencent-commons/pom.xml +++ b/spring-cloud-tencent-commons/pom.xml @@ -47,16 +47,6 @@ spring-cloud-commons - - com.netflix.ribbon - ribbon-loadbalancer - - - - com.google.guava - guava - - commons-collections commons-collections @@ -100,4 +90,4 @@ - \ No newline at end of file + diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/interceptor/feign/MetadataFirstFeignInterceptor.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/interceptor/feign/MetadataFirstFeignInterceptor.java index 01df01711..18f5390ab 100644 --- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/interceptor/feign/MetadataFirstFeignInterceptor.java +++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/interceptor/feign/MetadataFirstFeignInterceptor.java @@ -43,7 +43,8 @@ public class MetadataFirstFeignInterceptor implements RequestInterceptor, Ordere MetadataContext metadataContext = MetadataContextHolder.get(); // TODO The peer namespace is temporarily the same as the local namespace - metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_NAMESPACE, + metadataContext.putSystemMetadata( + MetadataConstant.SystemMetadataKey.PEER_NAMESPACE, MetadataContext.LOCAL_NAMESPACE); metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE, requestTemplate.feignTarget().name()); diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index c20150a2e..3e87e058d 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -64,7 +64,6 @@ 1.2.0-Hoxton.SR9-SNAPSHOT 1.3.0-SNAPSHOT - 10.0.0-M6 2.0.0 @@ -84,18 +83,25 @@ import - - org.apache.tomcat.embed - tomcat-embed-websocket - ${tomcat.version} - - com.tencent.cloud spring-cloud-tencent-commons ${revision} + + com.tencent.cloud + spring-cloud-tencent-polaris-context + ${revision} + + + + com.tencent.cloud + spring-cloud-starter-tencent-metadata-transfer + ${revision} + + + com.tencent.cloud spring-cloud-starter-tencent-polaris-ratelimit @@ -120,18 +126,6 @@ ${revision} - - com.tencent.cloud - spring-cloud-tencent-polaris-context - ${revision} - - - - com.tencent.cloud - spring-cloud-starter-tencent-metadata-transfer - ${revision} - - com.tencent.cloud spring-cloud-starter-tencent-polaris-discovery 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 0a482fbae..7f5835916 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,8 @@ spring: name: polaris-circuitbreaker-example-a cloud: polaris: - address: grpc://127.0.0.1:8091 + address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + namespace: default feign: hystrix: enabled: true 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 15e9fe79e..34a198a00 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,5 +5,6 @@ spring: name: polaris-circuitbreaker-example-b cloud: polaris: - address: grpc://127.0.0.1:8091 + address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + namespace: default is-throw-runtime-exception: false diff --git a/spring-cloud-tencent-examples/polaris-config-example/pom.xml b/spring-cloud-tencent-examples/polaris-config-example/pom.xml index d782d5d8f..cef91e5a3 100644 --- a/spring-cloud-tencent-examples/polaris-config-example/pom.xml +++ b/spring-cloud-tencent-examples/polaris-config-example/pom.xml @@ -19,18 +19,11 @@ spring-boot-starter-web - - org.springframework.boot - spring-boot-starter-test - test - - com.tencent.cloud spring-cloud-starter-tencent-polaris-config - 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 613370cc1..92da7031c 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 @@ -5,9 +5,9 @@ spring: name: polaris-config-example cloud: polaris: - namespace: dev + namespace: default config: - addresses: grpc://127.0.0.1:8093 # the address of polaris config server + address: grpc://159.75.195.18:8093 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 auto-refresh: true # auto refresh when config file changed groups: - name: ${spring.application.name} # group name diff --git a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/log4j.properties b/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/log4j.properties deleted file mode 100644 index b0b20e729..000000000 --- a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/log4j.properties +++ /dev/null @@ -1,15 +0,0 @@ -log4j.rootLogger=DEBUG,console,FILE - -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.threshold=INFO -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} [%5p] - %c -%F(%L) -%m%n - -log4j.appender.FILE=org.apache.log4j.RollingFileAppender -log4j.appender.FILE.Append=true - -log4j.appender.FILE.File=applog/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log -log4j.appender.FILE.Threshold=INFO -log4j.appender.FILE.layout=org.apache.log4j.PatternLayout -log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} [%5p] - %c -%F(%L) -%m%n -log4j.appender.FILE.MaxFileSize=10MB diff --git a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/logback-spring.xml b/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/logback-spring.xml deleted file mode 100644 index 0f47f0c1c..000000000 --- a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - logback - - - %d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n - - - - - true - - - applog/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log - - - - - %d{yyyy-MM-dd HH:mm:ss} -%msg%n - - - - - - - - - diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/pom.xml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/pom.xml index 49f58dccd..235ed173a 100644 --- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/pom.xml +++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/pom.xml @@ -15,8 +15,8 @@ - spring-cloud-starter-tencent-polaris-discovery com.tencent.cloud + spring-cloud-starter-tencent-polaris-discovery @@ -57,4 +57,4 @@ - \ No newline at end of file + 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 cc7b8178f..aab8f3b91 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,11 +5,8 @@ spring: name: DiscoveryCalleeService cloud: polaris: - address: grpc://127.0.0.1:8091 - discovery: - ip-address: 127.0.0.1 - inetutils: - default-ip-address: 198.1.1.1 + address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + namespace: default # consul: # port: 8500 # host: 127.0.0.1 diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml deleted file mode 100644 index 8be155671..000000000 --- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml +++ /dev/null @@ -1,16 +0,0 @@ -global: - system: - discoverCluster: - sameAsBuiltin: true - healthCheckCluster: - sameAsBuiltin: true -#global: -# system: -# discoverCluster: -# sameAsBuiltin: false -# namespace: Polaris -# service: polaris.discover -# healthCheckCluster: -# sameAsBuiltin: false -# namespace: Polaris -# service: polaris.healthcheck 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 25306f562..0004dc49b 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,8 @@ spring: name: DiscoveryCallerService cloud: polaris: - address: grpc://127.0.0.1:8091 + address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + namespace: default discovery: heartbeat: enabled: true diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/application.yml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/application.yml deleted file mode 100644 index 29ab597bf..000000000 --- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/application.yml +++ /dev/null @@ -1,9 +0,0 @@ -server: - session-timeout: 1800 - port: 48081 -spring: - application: - name: GatewayCalleeService - cloud: - polaris: - address: grpc://127.0.0.1:8091 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 new file mode 100644 index 000000000..5c68e3d30 --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/bootstrap.yml @@ -0,0 +1,10 @@ +server: + session-timeout: 1800 + port: 48081 +spring: + application: + 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 + namespace: default diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/application.yml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/bootstrap.yml similarity index 78% rename from spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/application.yml rename to spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/bootstrap.yml index 103112ec6..d6b83f018 100644 --- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/application.yml +++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/bootstrap.yml @@ -12,7 +12,8 @@ spring: transitive: - a polaris: - address: grpc://127.0.0.1:8091 + address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + namespace: default gateway: discovery: locator: diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/application.yml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/bootstrap.yml similarity index 67% rename from spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/application.yml rename to spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/bootstrap.yml index c191c5e4b..624830b65 100644 --- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/application.yml +++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/bootstrap.yml @@ -6,7 +6,8 @@ spring: name: GatewayZuulService cloud: polaris: - address: grpc://127.0.0.1:8091 + address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + namespace: default tencent: metadata: content: diff --git a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/pom.xml b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/pom.xml index abace2991..6f19d1ad5 100644 --- a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/pom.xml +++ b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/pom.xml @@ -28,9 +28,5 @@ spring-cloud-starter-tencent-polaris-ratelimit - - org.springframework.boot - spring-boot-actuator-autoconfigure - - \ No newline at end of file + 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 5017624e1..9ad52fcb2 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,6 +5,5 @@ spring: name: RateLimitCalleeService cloud: polaris: - address: grpc://127.0.0.1:8091 - discovery: - namespace: Test + address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18 + namespace: default diff --git a/spring-cloud-tencent-polaris-context/pom.xml b/spring-cloud-tencent-polaris-context/pom.xml index a6fe5ac91..a11dc5aec 100644 --- a/spring-cloud-tencent-polaris-context/pom.xml +++ b/spring-cloud-tencent-polaris-context/pom.xml @@ -93,11 +93,6 @@ - - org.springframework.cloud - spring-cloud-commons - - org.springframework.boot spring-boot-starter-test diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/InetUtilsProperties.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/InetUtilsProperties.java deleted file mode 100644 index cad84c34a..000000000 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/InetUtilsProperties.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * Because polaris-context is initialized in the bootstrap phase, the initialization of - * InetUtilsProperties is required. The impact on user usage is that - * spring.cloud.inetutils.defaultIpAddress needs to be configured in bootstrap.yml to take - * effect. - * - * @see org.springframework.cloud.commons.util.InetUtilsProperties - */ -@ConfigurationProperties(InetUtilsProperties.PREFIX) -public class InetUtilsProperties { - - /** - * Prefix for the Inet Utils properties. - */ - public static final String PREFIX = "spring.cloud.inetutils"; - - /** - * The default IP address. Used in case of errors. - */ - private String defaultIpAddress = "127.0.0.1"; - - String getDefaultIpAddress() { - return defaultIpAddress; - } - - void setDefaultIpAddress(String defaultIpAddress) { - this.defaultIpAddress = defaultIpAddress; - } - -} 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 e54768eb3..e495ef033 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 @@ -13,6 +13,7 @@ * 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; @@ -36,8 +37,7 @@ import org.springframework.context.annotation.Bean; * * @author Haotian Zhang */ -@EnableConfigurationProperties({ PolarisContextProperties.class, - InetUtilsProperties.class }) +@EnableConfigurationProperties({ PolarisContextProperties.class }) public class PolarisContextConfiguration { @Bean(name = "polarisContext", initMethod = "init", destroyMethod = "destroy") @@ -49,7 +49,7 @@ public class PolarisContextConfiguration { @Bean @ConditionalOnMissingBean - public PolarisConfigModifier polarisConfigModifier() { + public ModifyAddress polarisConfigModifier() { return new ModifyAddress(); } diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextProperties.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextProperties.java index a3cce9e47..9bc28682a 100644 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextProperties.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextProperties.java @@ -13,6 +13,7 @@ * 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; @@ -29,7 +30,6 @@ import com.tencent.polaris.factory.config.ConfigurationImpl; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.core.env.Environment; import org.springframework.util.CollectionUtils; @@ -48,13 +48,14 @@ public class PolarisContextProperties { private String address; /** - * polaris namespace. + * current server local ip address. */ - @Value("${spring.cloud.polaris.namespace:#{'default'}}") - private String namespace; + private String localIpAddress; - @Autowired - private InetUtilsProperties inetUtilsProperties; + /** + * polaris namespace. + */ + private String namespace = "default"; @Autowired private Environment environment; @@ -81,10 +82,8 @@ public class PolarisContextProperties { } private String getHost() { - String defaultIpAddress = inetUtilsProperties.getDefaultIpAddress(); - if (!StringUtils.isBlank(defaultIpAddress) - && !defaultIpAddress.equals("127.0.0.1")) { - return defaultIpAddress; + if (StringUtils.isNotBlank(localIpAddress)) { + return localIpAddress; } return environment.getProperty("spring.cloud.client.ip-address"); } @@ -97,6 +96,14 @@ public class PolarisContextProperties { this.address = address; } + String getLocalIpAddress() { + return localIpAddress; + } + + void setLocalIpAddress(String localIpAddress) { + this.localIpAddress = localIpAddress; + } + public String getNamespace() { return namespace; } diff --git a/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/spring-configuration-metadata.json b/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/spring-configuration-metadata.json index 7274683da..75fbdd4f4 100644 --- a/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/spring-configuration-metadata.json @@ -17,7 +17,14 @@ "name": "spring.cloud.polaris.namespace", "type": "java.lang.String", "description": "polaris namespace", + "default": "default", "sourceType": "com.tencent.cloud.polaris.context.PolarisContextProperties" + }, + { + "name": "spring.cloud.polaris.local-ip-address", + "type": "java.lang.String", + "defaultValue": "", + "description": "current server local ip address." } ], "hints": [] diff --git a/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/PolarisContextGetHostTest.java b/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/PolarisContextGetHostTest.java index dce225302..be28008e0 100644 --- a/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/PolarisContextGetHostTest.java +++ b/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/PolarisContextGetHostTest.java @@ -37,11 +37,15 @@ public class PolarisContextGetHostTest { @Autowired private SDKContext polarisContext; + @Autowired + private PolarisContextProperties polarisContextProperties; + @Test public void testGetConfigHost() { String bindIP = polarisContext.getConfig().getGlobal().getAPI().getBindIP(); Assert.assertFalse(StringUtils.isBlank(bindIP)); Assert.assertEquals(bindIP, "192.168.1.1"); + Assert.assertEquals(polarisContextProperties.getNamespace(), "dev"); } } diff --git a/spring-cloud-tencent-polaris-context/src/test/resources/bootstrap.yml b/spring-cloud-tencent-polaris-context/src/test/resources/bootstrap.yml index f85882ee2..7b2284774 100644 --- a/spring-cloud-tencent-polaris-context/src/test/resources/bootstrap.yml +++ b/spring-cloud-tencent-polaris-context/src/test/resources/bootstrap.yml @@ -1,7 +1,6 @@ spring: cloud: polaris: + local-ip-address: 192.168.1.1 address: grpc://127.0.0.1:8091 namespace: dev - inetutils: - defaultIpAddress: 192.168.1.1