1. optimize pom dependency 2. optimize demo

pull/71/head
lepdou 3 years ago
parent cf6a2bf8f8
commit cff6466223

@ -33,6 +33,12 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
@ -45,12 +51,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<optional>true</optional>
</dependency>
<!-- powermock-module-junit4 --> <!-- powermock-module-junit4 -->
<dependency> <dependency>
<groupId>org.powermock</groupId> <groupId>org.powermock</groupId>

@ -14,11 +14,6 @@
<dependencies> <dependencies>
<!-- Spring Cloud Tencent dependencies start --> <!-- Spring Cloud Tencent dependencies start -->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId> <artifactId>spring-cloud-tencent-polaris-context</artifactId>
@ -40,11 +35,13 @@
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId> <artifactId>spring-cloud-loadbalancer</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId> <artifactId>spring-cloud-starter-openfeign</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
@ -53,12 +50,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

@ -43,13 +43,13 @@ public class ConfigurationModifier implements PolarisConfigModifier {
public void modify(ConfigurationImpl configuration) { public void modify(ConfigurationImpl configuration) {
configuration.getConfigFile().getServerConnector().setConnectorType("polaris"); configuration.getConfigFile().getServerConnector().setConnectorType("polaris");
if (StringUtils.isEmpty(polarisConfigProperties.getAddresses())) { if (StringUtils.isEmpty(polarisConfigProperties.getAddress())) {
return; return;
} }
// override polaris config server address // override polaris config server address
List<String> addresses = AddressUtils List<String> addresses = AddressUtils
.parseAddressList(polarisConfigProperties.getAddresses()); .parseAddressList(polarisConfigProperties.getAddress());
configuration.getConfigFile().getServerConnector().setAddresses(addresses); configuration.getConfigFile().getServerConnector().setAddresses(addresses);
} }

@ -37,7 +37,7 @@ public class PolarisConfigProperties {
/** /**
* Configuration center service address list. * Configuration center service address list.
*/ */
private String addresses; private String address;
/** /**
* Whether to automatically update to the spring context when the configuration file. * Whether to automatically update to the spring context when the configuration file.
@ -58,12 +58,12 @@ public class PolarisConfigProperties {
this.enabled = enabled; this.enabled = enabled;
} }
public String getAddresses() { public String getAddress() {
return addresses; return address;
} }
public void setAddresses(String addresses) { public void setAddress(String address) {
this.addresses = addresses; this.address = address;
} }
public boolean isAutoRefresh() { public boolean isAutoRefresh() {

@ -8,10 +8,10 @@
"sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties" "sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties"
}, },
{ {
"name": "spring.cloud.polaris.config.addresses", "name": "spring.cloud.polaris.config.address",
"type": "java.lang.String", "type": "java.lang.String",
"defaultValue": "", "defaultValue": "",
"description": "The polaris configuration server addresses.", "description": "The polaris configuration server address.",
"sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties" "sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties"
}, },
{ {

@ -15,11 +15,6 @@
<dependencies> <dependencies>
<!-- Spring Cloud Tencent dependencies start --> <!-- Spring Cloud Tencent dependencies start -->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId> <artifactId>spring-cloud-tencent-polaris-context</artifactId>

@ -13,6 +13,7 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris; 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.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
/** /**
@ -33,7 +33,7 @@ import org.springframework.core.env.Environment;
* @author Haotian Zhang, Andrew Shan, Jie Cheng * @author Haotian Zhang, Andrew Shan, Jie Cheng
*/ */
@ConfigurationProperties("spring.cloud.polaris.discovery") @ConfigurationProperties("spring.cloud.polaris.discovery")
public class PolarisProperties { public class PolarisDiscoveryProperties {
/** /**
* The polaris authentication token. * The polaris authentication token.
@ -75,11 +75,6 @@ public class PolarisProperties {
@Value("${server.port:}") @Value("${server.port:}")
private int port; private int port;
/**
* Ip address to be registered.
*/
private String ipAddress;
/** /**
* If instance registered. * If instance registered.
*/ */
@ -101,12 +96,6 @@ public class PolarisProperties {
@Autowired @Autowired
private Environment environment; private Environment environment;
public PolarisProperties(InetUtils inetUtils) {
if (inetUtils != null) {
this.ipAddress = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
}
}
/** /**
* Init properties. * Init properties.
*/ */
@ -201,14 +190,6 @@ public class PolarisProperties {
this.port = port; this.port = port;
} }
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public String getHealthCheckUrl() { public String getHealthCheckUrl() {
return healthCheckUrl; return healthCheckUrl;
} }
@ -222,10 +203,9 @@ public class PolarisProperties {
return "PolarisProperties{" + "token='" + token + '\'' + ", namespace='" return "PolarisProperties{" + "token='" + token + '\'' + ", namespace='"
+ namespace + '\'' + ", service='" + service + '\'' + ", weight=" + weight + namespace + '\'' + ", service='" + service + '\'' + ", weight=" + weight
+ ", version='" + version + '\'' + ", protocol='" + protocol + '\'' + ", version='" + version + '\'' + ", protocol='" + protocol + '\''
+ ", port=" + port + ", ipAddress='" + ipAddress + '\'' + ", port=" + port + '\'' + ", registerEnabled=" + registerEnabled
+ ", registerEnabled=" + registerEnabled + ", heartbeatEnabled=" + ", heartbeatEnabled=" + heartbeatEnabled + ", healthCheckUrl="
+ heartbeatEnabled + ", healthCheckUrl=" + healthCheckUrl + healthCheckUrl + ", environment=" + environment + '}';
+ ", environment=" + environment + '}';
} }
} }

@ -13,11 +13,12 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris.discovery; 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.discovery.reactive.PolarisReactiveDiscoveryClientConfiguration;
import com.tencent.cloud.polaris.extend.consul.ConsulContextProperties; import com.tencent.cloud.polaris.extend.consul.ConsulContextProperties;
import com.tencent.polaris.api.core.ConsumerAPI; 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 com.tencent.polaris.factory.api.DiscoveryAPIFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
@ -46,8 +46,8 @@ public class PolarisDiscoveryAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public PolarisProperties polarisDiscoveryProperties(InetUtils inetUtils) { public PolarisDiscoveryProperties polarisDiscoveryProperties() {
return new PolarisProperties(inetUtils); return new PolarisDiscoveryProperties();
} }
@Bean(name = "polarisProvider") @Bean(name = "polarisProvider")

@ -13,6 +13,7 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris.discovery; 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.constant.MetadataConstant.SystemMetadataKey;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; 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.ConsumerAPI;
import com.tencent.polaris.api.core.ProviderAPI; import com.tencent.polaris.api.core.ProviderAPI;
import com.tencent.polaris.api.pojo.ServiceInfo; import com.tencent.polaris.api.pojo.ServiceInfo;
@ -45,7 +46,7 @@ import org.springframework.stereotype.Component;
public class PolarisDiscoveryHandler { public class PolarisDiscoveryHandler {
@Autowired @Autowired
private PolarisProperties polarisProperties; private PolarisDiscoveryProperties polarisDiscoveryProperties;
@Autowired @Autowired
private ProviderAPI providerAPI; private ProviderAPI providerAPI;
@ -59,7 +60,7 @@ public class PolarisDiscoveryHandler {
* @return list of instances * @return list of instances
*/ */
public InstancesResponse getFilteredInstances(String service) { public InstancesResponse getFilteredInstances(String service) {
String namespace = polarisProperties.getNamespace(); String namespace = polarisDiscoveryProperties.getNamespace();
GetInstancesRequest getInstancesRequest = new GetInstancesRequest(); GetInstancesRequest getInstancesRequest = new GetInstancesRequest();
getInstancesRequest.setNamespace(namespace); getInstancesRequest.setNamespace(namespace);
getInstancesRequest.setService(service); getInstancesRequest.setService(service);
@ -87,7 +88,7 @@ public class PolarisDiscoveryHandler {
* @return list of instances * @return list of instances
*/ */
public InstancesResponse getInstances(String service) { public InstancesResponse getInstances(String service) {
String namespace = polarisProperties.getNamespace(); String namespace = polarisDiscoveryProperties.getNamespace();
GetAllInstancesRequest request = new GetAllInstancesRequest(); GetAllInstancesRequest request = new GetAllInstancesRequest();
request.setNamespace(namespace); request.setNamespace(namespace);
request.setService(service); request.setService(service);
@ -103,7 +104,7 @@ public class PolarisDiscoveryHandler {
* @return service list * @return service list
*/ */
public ServicesResponse GetServices() { public ServicesResponse GetServices() {
String namespace = polarisProperties.getNamespace(); String namespace = polarisDiscoveryProperties.getNamespace();
GetServicesRequest request = new GetServicesRequest(); GetServicesRequest request = new GetServicesRequest();
request.setNamespace(namespace); request.setNamespace(namespace);
return polarisConsumer.getServices(request); return polarisConsumer.getServices(request);

@ -13,6 +13,7 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris.registry; package com.tencent.cloud.polaris.registry;
@ -21,7 +22,7 @@ import java.net.URI;
import java.util.Map; import java.util.Map;
import com.tencent.cloud.common.metadata.MetadataContextHolder; 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 com.tencent.polaris.client.api.SDKContext;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -36,40 +37,39 @@ import org.springframework.cloud.client.serviceregistry.Registration;
*/ */
public class PolarisRegistration implements Registration, ServiceInstance { public class PolarisRegistration implements Registration, ServiceInstance {
private final PolarisProperties polarisProperties; private final PolarisDiscoveryProperties polarisDiscoveryProperties;
private final SDKContext polarisContext; private final SDKContext polarisContext;
public PolarisRegistration(PolarisProperties polarisProperties, SDKContext context) { public PolarisRegistration(PolarisDiscoveryProperties polarisDiscoveryProperties,
this.polarisProperties = polarisProperties; SDKContext context) {
this.polarisDiscoveryProperties = polarisDiscoveryProperties;
this.polarisContext = context; this.polarisContext = context;
} }
@Override @Override
public String getServiceId() { public String getServiceId() {
return polarisProperties.getService(); return polarisDiscoveryProperties.getService();
} }
@Override @Override
public String getHost() { public String getHost() {
if (StringUtils.isNotBlank(polarisProperties.getIpAddress())) {
return polarisProperties.getIpAddress();
}
return polarisContext.getConfig().getGlobal().getAPI().getBindIP(); return polarisContext.getConfig().getGlobal().getAPI().getBindIP();
} }
@Override @Override
public int getPort() { public int getPort() {
return polarisProperties.getPort(); return polarisDiscoveryProperties.getPort();
} }
public void setPort(int port) { public void setPort(int port) {
this.polarisProperties.setPort(port); this.polarisDiscoveryProperties.setPort(port);
} }
@Override @Override
public boolean isSecure() { public boolean isSecure() {
return StringUtils.equalsIgnoreCase(polarisProperties.getProtocol(), "https"); return StringUtils.equalsIgnoreCase(polarisDiscoveryProperties.getProtocol(),
"https");
} }
@Override @Override
@ -82,14 +82,14 @@ public class PolarisRegistration implements Registration, ServiceInstance {
return MetadataContextHolder.get().getAllSystemMetadata(); return MetadataContextHolder.get().getAllSystemMetadata();
} }
public PolarisProperties getPolarisProperties() { public PolarisDiscoveryProperties getPolarisProperties() {
return polarisProperties; return polarisDiscoveryProperties;
} }
@Override @Override
public String toString() { public String toString() {
return "PolarisRegistration{" + "polarisProperties=" + polarisProperties return "PolarisRegistration{" + "polarisDiscoveryProperties="
+ ", polarisContext=" + polarisContext + '}'; + polarisDiscoveryProperties + ", polarisContext=" + polarisContext + '}';
} }
} }

@ -13,6 +13,7 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris.registry; package com.tencent.cloud.polaris.registry;
@ -22,7 +23,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; 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.discovery.PolarisDiscoveryHandler;
import com.tencent.cloud.polaris.util.OkHttpUtil; import com.tencent.cloud.polaris.util.OkHttpUtil;
import com.tencent.polaris.api.core.ProviderAPI; import com.tencent.polaris.api.core.ProviderAPI;
@ -56,7 +57,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
private static final int ttl = 5; private static final int ttl = 5;
private final PolarisProperties polarisProperties; private final PolarisDiscoveryProperties polarisDiscoveryProperties;
private final PolarisDiscoveryHandler polarisDiscoveryHandler; private final PolarisDiscoveryHandler polarisDiscoveryHandler;
@ -64,13 +65,13 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
private final ScheduledExecutorService heartbeatExecutor; private final ScheduledExecutorService heartbeatExecutor;
public PolarisServiceRegistry(PolarisProperties polarisProperties, public PolarisServiceRegistry(PolarisDiscoveryProperties polarisDiscoveryProperties,
PolarisDiscoveryHandler polarisDiscoveryHandler, PolarisDiscoveryHandler polarisDiscoveryHandler,
MetadataLocalProperties metadataLocalProperties) { MetadataLocalProperties metadataLocalProperties) {
this.polarisProperties = polarisProperties; this.polarisDiscoveryProperties = polarisDiscoveryProperties;
this.polarisDiscoveryHandler = polarisDiscoveryHandler; this.polarisDiscoveryHandler = polarisDiscoveryHandler;
this.metadataLocalProperties = metadataLocalProperties; this.metadataLocalProperties = metadataLocalProperties;
if (polarisProperties.isHeartbeatEnabled()) { if (polarisDiscoveryProperties.isHeartbeatEnabled()) {
ScheduledThreadPoolExecutor heartbeatExecutor = new ScheduledThreadPoolExecutor( ScheduledThreadPoolExecutor heartbeatExecutor = new ScheduledThreadPoolExecutor(
0, new NamedThreadFactory("spring-cloud-heartbeat")); 0, new NamedThreadFactory("spring-cloud-heartbeat"));
heartbeatExecutor.setMaximumPoolSize(1); heartbeatExecutor.setMaximumPoolSize(1);
@ -90,24 +91,24 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
} }
// Register instance. // Register instance.
InstanceRegisterRequest instanceRegisterRequest = new InstanceRegisterRequest(); InstanceRegisterRequest instanceRegisterRequest = new InstanceRegisterRequest();
instanceRegisterRequest.setNamespace(polarisProperties.getNamespace()); instanceRegisterRequest.setNamespace(polarisDiscoveryProperties.getNamespace());
instanceRegisterRequest.setService(registration.getServiceId()); instanceRegisterRequest.setService(registration.getServiceId());
instanceRegisterRequest.setHost(registration.getHost()); instanceRegisterRequest.setHost(registration.getHost());
instanceRegisterRequest.setPort(registration.getPort()); instanceRegisterRequest.setPort(registration.getPort());
instanceRegisterRequest.setToken(polarisProperties.getToken()); instanceRegisterRequest.setToken(polarisDiscoveryProperties.getToken());
if (null != heartbeatExecutor) { if (null != heartbeatExecutor) {
instanceRegisterRequest.setTtl(ttl); instanceRegisterRequest.setTtl(ttl);
} }
instanceRegisterRequest.setMetadata(metadataLocalProperties.getContent()); instanceRegisterRequest.setMetadata(metadataLocalProperties.getContent());
instanceRegisterRequest.setProtocol(polarisProperties.getProtocol()); instanceRegisterRequest.setProtocol(polarisDiscoveryProperties.getProtocol());
instanceRegisterRequest.setVersion(polarisProperties.getVersion()); instanceRegisterRequest.setVersion(polarisDiscoveryProperties.getVersion());
try { try {
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI(); ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
providerClient.register(instanceRegisterRequest); providerClient.register(instanceRegisterRequest);
log.info("polaris registry, {} {} {}:{} {} register finished", log.info("polaris registry, {} {} {}:{} {} register finished",
polarisProperties.getNamespace(), registration.getServiceId(), polarisDiscoveryProperties.getNamespace(),
registration.getHost(), registration.getPort(), registration.getServiceId(), registration.getHost(),
metadataLocalProperties.getContent()); registration.getPort(), metadataLocalProperties.getContent());
if (null != heartbeatExecutor) { if (null != heartbeatExecutor) {
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest(); InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
@ -134,8 +135,8 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
} }
InstanceDeregisterRequest deRegisterRequest = new InstanceDeregisterRequest(); InstanceDeregisterRequest deRegisterRequest = new InstanceDeregisterRequest();
deRegisterRequest.setToken(polarisProperties.getToken()); deRegisterRequest.setToken(polarisDiscoveryProperties.getToken());
deRegisterRequest.setNamespace(polarisProperties.getNamespace()); deRegisterRequest.setNamespace(polarisDiscoveryProperties.getNamespace());
deRegisterRequest.setService(registration.getServiceId()); deRegisterRequest.setService(registration.getServiceId());
deRegisterRequest.setHost(registration.getHost()); deRegisterRequest.setHost(registration.getHost());
deRegisterRequest.setPort(registration.getPort()); deRegisterRequest.setPort(registration.getPort());
@ -177,7 +178,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
} }
for (Instance instance : instances) { for (Instance instance : instances) {
if (instance.getHost().equalsIgnoreCase(registration.getHost()) if (instance.getHost().equalsIgnoreCase(registration.getHost())
&& instance.getPort() == polarisProperties.getPort()) { && instance.getPort() == polarisDiscoveryProperties.getPort()) {
return instance.isHealthy() ? "UP" : "DOWN"; return instance.isHealthy() ? "UP" : "DOWN";
} }
} }
@ -191,7 +192,8 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
public void heartbeat(InstanceHeartbeatRequest heartbeatRequest) { public void heartbeat(InstanceHeartbeatRequest heartbeatRequest) {
heartbeatExecutor.scheduleWithFixedDelay(() -> { heartbeatExecutor.scheduleWithFixedDelay(() -> {
try { try {
String healthCheckEndpoint = polarisProperties.getHealthCheckUrl(); String healthCheckEndpoint = polarisDiscoveryProperties
.getHealthCheckUrl();
// First determine whether health-check-url is configured. // First determine whether health-check-url is configured.
// If configured, the service instance health check needs to be executed // If configured, the service instance health check needs to be executed
// first. // first.

@ -13,12 +13,13 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris.registry; package com.tencent.cloud.polaris.registry;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; 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.ConditionalOnPolarisDiscoveryEnabled;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration; import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler; import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
@ -51,18 +52,18 @@ public class PolarisServiceRegistryAutoConfiguration {
@Bean @Bean
public PolarisServiceRegistry polarisServiceRegistry( public PolarisServiceRegistry polarisServiceRegistry(
PolarisProperties polarisProperties, PolarisDiscoveryProperties polarisDiscoveryProperties,
PolarisDiscoveryHandler polarisDiscoveryHandler, PolarisDiscoveryHandler polarisDiscoveryHandler,
MetadataLocalProperties metadataLocalProperties) { MetadataLocalProperties metadataLocalProperties) {
return new PolarisServiceRegistry(polarisProperties, polarisDiscoveryHandler, return new PolarisServiceRegistry(polarisDiscoveryProperties,
metadataLocalProperties); polarisDiscoveryHandler, metadataLocalProperties);
} }
@Bean @Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class) @ConditionalOnBean(AutoServiceRegistrationProperties.class)
public PolarisRegistration polarisRegistration(PolarisProperties polarisProperties, public PolarisRegistration polarisRegistration(
SDKContext context) { PolarisDiscoveryProperties polarisDiscoveryProperties, SDKContext context) {
return new PolarisRegistration(polarisProperties, context); return new PolarisRegistration(polarisDiscoveryProperties, context);
} }
@Bean @Bean

@ -42,12 +42,6 @@
"defaultValue": "${spring.cloud.polaris.version}", "defaultValue": "${spring.cloud.polaris.version}",
"description": "polaris discovery service's username to authenticate." "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", "name": "spring.cloud.polaris.protocol",
"type": "java.lang.String", "type": "java.lang.String",

@ -13,22 +13,20 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris; package com.tencent.cloud.polaris;
import org.junit.Test; 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.NAMESPACE_TEST;
import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER; import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
/** /**
* Test for {@link PolarisProperties} * Test for {@link PolarisDiscoveryProperties}
* *
* @author Haotian Zhang * @author Haotian Zhang
*/ */
@ -36,8 +34,7 @@ public class PolarisPropertiesTest {
@Test @Test
public void testInitAndGetSet() { public void testInitAndGetSet() {
PolarisProperties temp = new PolarisProperties( PolarisDiscoveryProperties temp = new PolarisDiscoveryProperties();
new InetUtils(new InetUtilsProperties()));
try { try {
temp.setNamespace(NAMESPACE_TEST); temp.setNamespace(NAMESPACE_TEST);
assertThat(temp.getNamespace()).isEqualTo(NAMESPACE_TEST); assertThat(temp.getNamespace()).isEqualTo(NAMESPACE_TEST);

@ -13,11 +13,12 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris.discovery; 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.cloud.polaris.context.PolarisContextConfiguration;
import com.tencent.polaris.api.core.ConsumerAPI; import com.tencent.polaris.api.core.ConsumerAPI;
import com.tencent.polaris.api.core.ProviderAPI; import com.tencent.polaris.api.core.ProviderAPI;
@ -71,7 +72,7 @@ public class PolarisDiscoveryAutoConfigurationTest {
this.contextRunner.run(context -> { this.contextRunner.run(context -> {
assertThat(context).hasSingleBean(ProviderAPI.class); assertThat(context).hasSingleBean(ProviderAPI.class);
assertThat(context).hasSingleBean(ConsumerAPI.class); assertThat(context).hasSingleBean(ConsumerAPI.class);
assertThat(context).hasSingleBean(PolarisProperties.class); assertThat(context).hasSingleBean(PolarisDiscoveryProperties.class);
assertThat(context).hasSingleBean(PolarisServiceDiscovery.class); assertThat(context).hasSingleBean(PolarisServiceDiscovery.class);
}); });
} }

@ -15,11 +15,6 @@
<dependencies> <dependencies>
<!-- Spring Cloud Tencent dependencies start --> <!-- Spring Cloud Tencent dependencies start -->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId> <artifactId>spring-cloud-tencent-polaris-context</artifactId>

@ -15,11 +15,6 @@
<dependencies> <dependencies>
<!-- Spring Cloud Tencent dependencies start --> <!-- Spring Cloud Tencent dependencies start -->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId> <artifactId>spring-cloud-tencent-polaris-context</artifactId>
@ -32,6 +27,11 @@
<artifactId>polaris-router-factory</artifactId> <artifactId>polaris-router-factory</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.tencent.polaris</groupId> <groupId>com.tencent.polaris</groupId>
<artifactId>polaris-test-common</artifactId> <artifactId>polaris-test-common</artifactId>
@ -39,11 +39,6 @@
</dependency> </dependency>
<!-- Polaris dependencies end --> <!-- Polaris dependencies end -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

@ -47,16 +47,6 @@
<artifactId>spring-cloud-commons</artifactId> <artifactId>spring-cloud-commons</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency> <dependency>
<groupId>commons-collections</groupId> <groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId> <artifactId>commons-collections</artifactId>

@ -43,7 +43,8 @@ public class MetadataFirstFeignInterceptor implements RequestInterceptor, Ordere
MetadataContext metadataContext = MetadataContextHolder.get(); MetadataContext metadataContext = MetadataContextHolder.get();
// TODO The peer namespace is temporarily the same as the local namespace // 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.LOCAL_NAMESPACE);
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE, metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE,
requestTemplate.feignTarget().name()); requestTemplate.feignTarget().name());

@ -64,7 +64,6 @@
<properties> <properties>
<revision>1.2.0-Hoxton.SR9-SNAPSHOT</revision> <revision>1.2.0-Hoxton.SR9-SNAPSHOT</revision>
<polaris.version>1.3.0-SNAPSHOT</polaris.version> <polaris.version>1.3.0-SNAPSHOT</polaris.version>
<tomcat.version>10.0.0-M6</tomcat.version>
<powermock.version>2.0.0</powermock.version> <powermock.version>2.0.0</powermock.version>
<!-- Maven Plugin Versions --> <!-- Maven Plugin Versions -->
@ -84,12 +83,6 @@
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId> <artifactId>spring-cloud-tencent-commons</artifactId>
@ -98,37 +91,38 @@
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-ratelimit</artifactId> <artifactId>spring-cloud-tencent-polaris-context</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-circuitbreaker</artifactId> <artifactId>spring-cloud-starter-tencent-metadata-transfer</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<!-- polaris starter-->
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-router</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-ratelimit</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-config</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-circuitbreaker</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-router</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-metadata-transfer</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-config</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>

@ -5,7 +5,8 @@ spring:
name: polaris-circuitbreaker-example-a name: polaris-circuitbreaker-example-a
cloud: cloud:
polaris: 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: feign:
hystrix: hystrix:
enabled: true enabled: true

@ -5,5 +5,6 @@ spring:
name: polaris-circuitbreaker-example-b name: polaris-circuitbreaker-example-b
cloud: cloud:
polaris: 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 is-throw-runtime-exception: false

@ -19,18 +19,11 @@
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring Cloud Tencent dependency --> <!-- Spring Cloud Tencent dependency -->
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-config</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-config</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

@ -5,9 +5,9 @@ spring:
name: polaris-config-example name: polaris-config-example
cloud: cloud:
polaris: polaris:
namespace: dev namespace: default
config: 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 auto-refresh: true # auto refresh when config file changed
groups: groups:
- name: ${spring.application.name} # group name - name: ${spring.application.name} # group name

@ -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

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<contextName>logback</contextName>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<Prudent>true</Prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>
applog/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log
</FileNamePattern>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} -%msg%n
</Pattern>
</layout>
</appender>
<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="logFile"/>
</root>
</configuration>

@ -15,8 +15,8 @@
<dependencies> <dependencies>
<dependency> <dependency>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency> </dependency>
<!-- <dependency>--> <!-- <dependency>-->

@ -5,11 +5,8 @@ spring:
name: DiscoveryCalleeService name: DiscoveryCalleeService
cloud: cloud:
polaris: 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
discovery: namespace: default
ip-address: 127.0.0.1
inetutils:
default-ip-address: 198.1.1.1
# consul: # consul:
# port: 8500 # port: 8500
# host: 127.0.0.1 # host: 127.0.0.1

@ -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

@ -6,7 +6,8 @@ spring:
name: DiscoveryCallerService name: DiscoveryCallerService
cloud: cloud:
polaris: 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: discovery:
heartbeat: heartbeat:
enabled: true enabled: true

@ -1,9 +0,0 @@
server:
session-timeout: 1800
port: 48081
spring:
application:
name: GatewayCalleeService
cloud:
polaris:
address: grpc://127.0.0.1:8091

@ -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

@ -12,7 +12,8 @@ spring:
transitive: transitive:
- a - a
polaris: 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: gateway:
discovery: discovery:
locator: locator:

@ -6,7 +6,8 @@ spring:
name: GatewayZuulService name: GatewayZuulService
cloud: cloud:
polaris: 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: tencent:
metadata: metadata:
content: content:

@ -28,9 +28,5 @@
<artifactId>spring-cloud-starter-tencent-polaris-ratelimit</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-ratelimit</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -5,6 +5,5 @@ spring:
name: RateLimitCalleeService name: RateLimitCalleeService
cloud: cloud:
polaris: 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
discovery: namespace: default
namespace: Test

@ -93,11 +93,6 @@
</dependency> </dependency>
<!-- Polaris dependencies end --> <!-- Polaris dependencies end -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

@ -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;
}
}

@ -13,6 +13,7 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris.context; package com.tencent.cloud.polaris.context;
@ -36,8 +37,7 @@ import org.springframework.context.annotation.Bean;
* *
* @author Haotian Zhang * @author Haotian Zhang
*/ */
@EnableConfigurationProperties({ PolarisContextProperties.class, @EnableConfigurationProperties({ PolarisContextProperties.class })
InetUtilsProperties.class })
public class PolarisContextConfiguration { public class PolarisContextConfiguration {
@Bean(name = "polarisContext", initMethod = "init", destroyMethod = "destroy") @Bean(name = "polarisContext", initMethod = "init", destroyMethod = "destroy")
@ -49,7 +49,7 @@ public class PolarisContextConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public PolarisConfigModifier polarisConfigModifier() { public ModifyAddress polarisConfigModifier() {
return new ModifyAddress(); return new ModifyAddress();
} }

@ -13,6 +13,7 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * 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 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*
*/ */
package com.tencent.cloud.polaris.context; 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.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -48,13 +48,14 @@ public class PolarisContextProperties {
private String address; private String address;
/** /**
* polaris namespace. * current server local ip address.
*/ */
@Value("${spring.cloud.polaris.namespace:#{'default'}}") private String localIpAddress;
private String namespace;
@Autowired /**
private InetUtilsProperties inetUtilsProperties; * polaris namespace.
*/
private String namespace = "default";
@Autowired @Autowired
private Environment environment; private Environment environment;
@ -81,10 +82,8 @@ public class PolarisContextProperties {
} }
private String getHost() { private String getHost() {
String defaultIpAddress = inetUtilsProperties.getDefaultIpAddress(); if (StringUtils.isNotBlank(localIpAddress)) {
if (!StringUtils.isBlank(defaultIpAddress) return localIpAddress;
&& !defaultIpAddress.equals("127.0.0.1")) {
return defaultIpAddress;
} }
return environment.getProperty("spring.cloud.client.ip-address"); return environment.getProperty("spring.cloud.client.ip-address");
} }
@ -97,6 +96,14 @@ public class PolarisContextProperties {
this.address = address; this.address = address;
} }
String getLocalIpAddress() {
return localIpAddress;
}
void setLocalIpAddress(String localIpAddress) {
this.localIpAddress = localIpAddress;
}
public String getNamespace() { public String getNamespace() {
return namespace; return namespace;
} }

@ -17,7 +17,14 @@
"name": "spring.cloud.polaris.namespace", "name": "spring.cloud.polaris.namespace",
"type": "java.lang.String", "type": "java.lang.String",
"description": "polaris namespace", "description": "polaris namespace",
"default": "default",
"sourceType": "com.tencent.cloud.polaris.context.PolarisContextProperties" "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": [] "hints": []

@ -37,11 +37,15 @@ public class PolarisContextGetHostTest {
@Autowired @Autowired
private SDKContext polarisContext; private SDKContext polarisContext;
@Autowired
private PolarisContextProperties polarisContextProperties;
@Test @Test
public void testGetConfigHost() { public void testGetConfigHost() {
String bindIP = polarisContext.getConfig().getGlobal().getAPI().getBindIP(); String bindIP = polarisContext.getConfig().getGlobal().getAPI().getBindIP();
Assert.assertFalse(StringUtils.isBlank(bindIP)); Assert.assertFalse(StringUtils.isBlank(bindIP));
Assert.assertEquals(bindIP, "192.168.1.1"); Assert.assertEquals(bindIP, "192.168.1.1");
Assert.assertEquals(polarisContextProperties.getNamespace(), "dev");
} }
} }

@ -1,7 +1,6 @@
spring: spring:
cloud: cloud:
polaris: polaris:
local-ip-address: 192.168.1.1
address: grpc://127.0.0.1:8091 address: grpc://127.0.0.1:8091
namespace: dev namespace: dev
inetutils:
defaultIpAddress: 192.168.1.1

Loading…
Cancel
Save