datacenters = new HashMap<>();
+
+ /**
+ * Tag to query for in service list if one is not listed in serverListQueryTags.
+ * Multiple tags can be specified with a comma separated value.
+ */
+ private String defaultQueryTag;
+
+ /**
+ * Add the 'passing` parameter to /v1/health/service/serviceName. This pushes health
+ * check passing to the server.
+ */
+ private boolean queryPassing = true;
+
+ /** Register as a service in consul. */
+ private boolean register = true;
+
+ /** Disable automatic de-registration of service in consul. */
+ private boolean deregister = true;
+
+ /** Register health check in consul. Useful during development of a service. */
+ private boolean registerHealthCheck = true;
+
+ /**
+ * Throw exceptions during service registration if true, otherwise, log warnings
+ * (defaults to true).
+ */
+ private boolean failFast = true;
+
+ /**
+ * Skips certificate verification during service checks if true, otherwise runs
+ * certificate verification.
+ */
+ private Boolean healthCheckTlsSkipVerify;
+
+ /**
+ * Order of the discovery client used by `CompositeDiscoveryClient` for sorting
+ * available clients.
+ */
+ private int order = 0;
+
+ @SuppressWarnings("unused")
+ private ConsulDiscoveryProperties() {
+ this(new PolarisInetUtils(new InetUtilsProperties()));
+ }
+
+ public ConsulDiscoveryProperties(PolarisInetUtils polarisInetUtils) {
+ this.managementTags.add(MANAGEMENT);
+ this.hostInfo = polarisInetUtils.findFirstNonLoopbackHostInfo();
+ this.ipAddress = this.hostInfo.getIpAddress();
+ this.hostname = this.hostInfo.getHostname();
+ }
+
+ /**
+ * Gets the tag to use when looking up the instances for a particular service. If the
+ * service has an entry in {@link #serverListQueryTags} that will be used. Otherwise
+ * the content of {@link #defaultQueryTag} will be used.
+ * @param serviceId the service whose instances are being looked up
+ * @return the tag to filter the service instances by or null if no tags are
+ * configured for the service and the default query tag is not configured
+ */
+ public String getQueryTagForService(String serviceId) {
+ String tag = this.serverListQueryTags.get(serviceId);
+ return tag != null ? tag : this.defaultQueryTag;
+ }
+
+ /**
+ * Gets the array of tags to use when looking up the instances for a particular
+ * service. If the service has an entry in {@link #serverListQueryTags} that will be
+ * used. Otherwise the content of {@link #defaultQueryTag} will be used. This differs
+ * from {@link #getQueryTagForService(String)} in that it assumes the configured tag
+ * property value may represent multiple tags when separated by commas. When the tag
+ * property is set to a single tag then this method behaves identical to its
+ * aforementioned counterpart except that it returns a single element array with the
+ * single tag value.
+ *
+ * The expected format of the tag property value is {@code tag1,tag2,..,tagN}.
+ * Whitespace will be trimmed off each entry.
+ * @param serviceId the service whose instances are being looked up
+ * @return the array of tags to filter the service instances by - it will be null if
+ * no tags are configured for the service and the default query tag is not configured
+ * or if a single tag is configured and it is the empty string
+ */
+ @Nullable
+ public String[] getQueryTagsForService(String serviceId) {
+ String queryTagStr = getQueryTagForService(serviceId);
+ if (queryTagStr == null || queryTagStr.isEmpty()) {
+ return null;
+ }
+ return StringUtils.tokenizeToStringArray(queryTagStr, ",");
+ }
+
+ public String getHostname() {
+ return this.preferIpAddress ? this.ipAddress : this.hostname;
+ }
+
+ public void setHostname(String hostname) {
+ this.hostname = hostname;
+ this.hostInfo.override = true;
+ }
+
+ private HostInfo getHostInfo() {
+ return this.hostInfo;
+ }
+
+ private void setHostInfo(HostInfo hostInfo) {
+ this.hostInfo = hostInfo;
+ }
+
+ public List getTags() {
+ return this.tags;
+ }
+
+ public void setTags(List tags) {
+ this.tags = tags;
+ }
+
+ public boolean isEnableTagOverride() {
+ return enableTagOverride;
+ }
+
+ public Map getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(Map metadata) {
+ this.metadata = metadata;
+ }
+
+ public boolean isEnabled() {
+ return this.enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public List getManagementTags() {
+ return this.managementTags;
+ }
+
+ public void setManagementTags(List managementTags) {
+ this.managementTags = managementTags;
+ }
+
+ public String getHealthCheckPath() {
+ return this.healthCheckPath;
+ }
+
+ public void setHealthCheckPath(String healthCheckPath) {
+ this.healthCheckPath = healthCheckPath;
+ }
+
+ public String getHealthCheckUrl() {
+ return this.healthCheckUrl;
+ }
+
+ public void setHealthCheckUrl(String healthCheckUrl) {
+ this.healthCheckUrl = healthCheckUrl;
+ }
+
+ public Map> getHealthCheckHeaders() {
+ return this.healthCheckHeaders;
+ }
+
+ public void setHealthCheckHeaders(Map> healthCheckHeaders) {
+ this.healthCheckHeaders = healthCheckHeaders;
+ }
+
+ public String getHealthCheckInterval() {
+ return this.healthCheckInterval;
+ }
+
+ public void setHealthCheckInterval(String healthCheckInterval) {
+ this.healthCheckInterval = healthCheckInterval;
+ }
+
+ public String getHealthCheckTimeout() {
+ return this.healthCheckTimeout;
+ }
+
+ public void setHealthCheckTimeout(String healthCheckTimeout) {
+ this.healthCheckTimeout = healthCheckTimeout;
+ }
+
+ public String getHealthCheckCriticalTimeout() {
+ return this.healthCheckCriticalTimeout;
+ }
+
+ public void setHealthCheckCriticalTimeout(String healthCheckCriticalTimeout) {
+ this.healthCheckCriticalTimeout = healthCheckCriticalTimeout;
+ }
+
+ public String getIpAddress() {
+ return this.ipAddress;
+ }
+
+ public void setIpAddress(String ipAddress) {
+ this.ipAddress = ipAddress;
+ this.hostInfo.override = true;
+ }
+
+ public Integer getPort() {
+ return this.port;
+ }
+
+ public void setPort(Integer port) {
+ this.port = port;
+ }
+
+ public Integer getManagementPort() {
+ return this.managementPort;
+ }
+
+ public void setManagementPort(Integer managementPort) {
+ this.managementPort = managementPort;
+ }
+
+ public Lifecycle getLifecycle() {
+ return this.lifecycle;
+ }
+
+ public void setLifecycle(Lifecycle lifecycle) {
+ this.lifecycle = lifecycle;
+ }
+
+ public boolean isPreferIpAddress() {
+ return this.preferIpAddress;
+ }
+
+ public void setPreferIpAddress(boolean preferIpAddress) {
+ this.preferIpAddress = preferIpAddress;
+ }
+
+ public boolean isPreferAgentAddress() {
+ return this.preferAgentAddress;
+ }
+
+ public void setPreferAgentAddress(boolean preferAgentAddress) {
+ this.preferAgentAddress = preferAgentAddress;
+ }
+
+ public int getCatalogServicesWatchDelay() {
+ return this.catalogServicesWatchDelay;
+ }
+
+ public void setCatalogServicesWatchDelay(int catalogServicesWatchDelay) {
+ this.catalogServicesWatchDelay = catalogServicesWatchDelay;
+ }
+
+ public int getCatalogServicesWatchTimeout() {
+ return this.catalogServicesWatchTimeout;
+ }
+
+ public void setCatalogServicesWatchTimeout(int catalogServicesWatchTimeout) {
+ this.catalogServicesWatchTimeout = catalogServicesWatchTimeout;
+ }
+
+ public String getServiceName() {
+ return this.serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public String getInstanceId() {
+ return this.instanceId;
+ }
+
+ public void setInstanceId(String instanceId) {
+ this.instanceId = instanceId;
+ }
+
+ public String getInstanceZone() {
+ return this.instanceZone;
+ }
+
+ public void setInstanceZone(String instanceZone) {
+ this.instanceZone = instanceZone;
+ }
+
+ public String getInstanceGroup() {
+ return this.instanceGroup;
+ }
+
+ public void setInstanceGroup(String instanceGroup) {
+ this.instanceGroup = instanceGroup;
+ }
+
+ public boolean isIncludeHostnameInInstanceId() {
+ return includeHostnameInInstanceId;
+ }
+
+ public void setIncludeHostnameInInstanceId(boolean includeHostnameInInstanceId) {
+ this.includeHostnameInInstanceId = includeHostnameInInstanceId;
+ }
+
+ public ConsistencyMode getConsistencyMode() {
+ return consistencyMode;
+ }
+
+ public void setConsistencyMode(ConsistencyMode consistencyMode) {
+ this.consistencyMode = consistencyMode;
+ }
+
+ public String getDefaultZoneMetadataName() {
+ return this.defaultZoneMetadataName;
+ }
+
+ public void setDefaultZoneMetadataName(String defaultZoneMetadataName) {
+ this.defaultZoneMetadataName = defaultZoneMetadataName;
+ }
+
+ public String getScheme() {
+ return this.scheme;
+ }
+
+ public void setScheme(String scheme) {
+ this.scheme = scheme;
+ }
+
+ public String getManagementSuffix() {
+ return this.managementSuffix;
+ }
+
+ public void setManagementSuffix(String managementSuffix) {
+ this.managementSuffix = managementSuffix;
+ }
+
+ public Map getServerListQueryTags() {
+ return this.serverListQueryTags;
+ }
+
+ public void setServerListQueryTags(Map serverListQueryTags) {
+ this.serverListQueryTags = serverListQueryTags;
+ }
+
+ public Map getDatacenters() {
+ return this.datacenters;
+ }
+
+ public void setDatacenters(Map datacenters) {
+ this.datacenters = datacenters;
+ }
+
+ public String getDefaultQueryTag() {
+ return this.defaultQueryTag;
+ }
+
+ public void setDefaultQueryTag(String defaultQueryTag) {
+ this.defaultQueryTag = defaultQueryTag;
+ }
+
+ public boolean isQueryPassing() {
+ return this.queryPassing;
+ }
+
+ public void setQueryPassing(boolean queryPassing) {
+ this.queryPassing = queryPassing;
+ }
+
+ public boolean isRegister() {
+ return this.register;
+ }
+
+ public void setRegister(boolean register) {
+ this.register = register;
+ }
+
+ public boolean isDeregister() {
+ return this.deregister;
+ }
+
+ public void setDeregister(boolean deregister) {
+ this.deregister = deregister;
+ }
+
+ public boolean isRegisterHealthCheck() {
+ return this.registerHealthCheck;
+ }
+
+ public void setRegisterHealthCheck(boolean registerHealthCheck) {
+ this.registerHealthCheck = registerHealthCheck;
+ }
+
+ public boolean isFailFast() {
+ return this.failFast;
+ }
+
+ public void setFailFast(boolean failFast) {
+ this.failFast = failFast;
+ }
+
+ public Boolean getHealthCheckTlsSkipVerify() {
+ return this.healthCheckTlsSkipVerify;
+ }
+
+ public void setHealthCheckTlsSkipVerify(Boolean healthCheckTlsSkipVerify) {
+ this.healthCheckTlsSkipVerify = healthCheckTlsSkipVerify;
+ }
+
+ public int getOrder() {
+ return this.order;
+ }
+
+ public void setOrder(int order) {
+ this.order = order;
+ }
+
+ public Map getManagementMetadata() {
+ return this.managementMetadata;
+ }
+
+ public void setManagementMetadata(Map managementMetadata) {
+ this.managementMetadata = managementMetadata;
+ }
+
+ public Boolean getEnableTagOverride() {
+ return this.enableTagOverride;
+ }
+
+ public void setEnableTagOverride(boolean enableTagOverride) {
+ this.enableTagOverride = enableTagOverride;
+ }
+
+ public void setEnableTagOverride(Boolean enableTagOverride) {
+ this.enableTagOverride = enableTagOverride;
+ }
+
+ public Boolean getManagementEnableTagOverride() {
+ return this.managementEnableTagOverride;
+ }
+
+ public void setManagementEnableTagOverride(Boolean managementEnableTagOverride) {
+ this.managementEnableTagOverride = managementEnableTagOverride;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringCreator(this)
+ .append("catalogServicesWatchDelay", this.catalogServicesWatchDelay)
+ .append("catalogServicesWatchTimeout", this.catalogServicesWatchTimeout)
+ .append("consistencyMode", this.consistencyMode)
+ .append("datacenters", this.datacenters)
+ .append("defaultQueryTag", this.defaultQueryTag)
+ .append("defaultZoneMetadataName", this.defaultZoneMetadataName)
+ .append("deregister", this.deregister)
+ .append("enabled", this.enabled)
+ .append("enableTagOverride", this.enableTagOverride)
+ .append("failFast", this.failFast)
+ .append("hostInfo", this.hostInfo)
+ .append("healthCheckCriticalTimeout", this.healthCheckCriticalTimeout)
+ .append("healthCheckHeaders", this.healthCheckHeaders)
+ .append("healthCheckInterval", this.healthCheckInterval)
+ .append("healthCheckPath", this.healthCheckPath)
+ .append("healthCheckTimeout", this.healthCheckTimeout)
+ .append("healthCheckTlsSkipVerify", this.healthCheckTlsSkipVerify)
+ .append("healthCheckUrl", this.healthCheckUrl)
+ .append("hostname", this.hostname)
+ .append("includeHostnameInInstanceId", this.includeHostnameInInstanceId)
+ .append("instanceId", this.instanceId)
+ .append("instanceGroup", this.instanceGroup)
+ .append("instanceZone", this.instanceZone)
+ .append("ipAddress", this.ipAddress)
+ .append("lifecycle", this.lifecycle)
+ .append("metadata", this.metadata)
+ .append("managementEnableTagOverride", this.managementEnableTagOverride)
+ .append("managementMetadata", this.managementMetadata)
+ .append("managementPort", this.managementPort)
+ .append("managementSuffix", this.managementSuffix)
+ .append("managementTags", this.managementTags)
+ .append("order", this.order)
+ .append("port", this.port)
+ .append("preferAgentAddress", this.preferAgentAddress)
+ .append("preferIpAddress", this.preferIpAddress)
+ .append("queryPassing", this.queryPassing)
+ .append("register", this.register)
+ .append("registerHealthCheck", this.registerHealthCheck)
+ .append("scheme", this.scheme)
+ .append("serviceName", this.serviceName)
+ .append("serverListQueryTags", this.serverListQueryTags)
+ .append("tags", this.tags)
+ .toString();
+ }
+
+ /**
+ * Properties releated to the lifecycle.
+ */
+ public static class Lifecycle {
+
+ private boolean enabled = true;
+
+ public boolean isEnabled() {
+ return this.enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public String toString() {
+ return "Lifecycle{" + "enabled=" + this.enabled + '}';
+ }
+
+ }
+}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/util/RegistrationUtil.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulDiscoveryUtil.java
similarity index 71%
rename from spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/util/RegistrationUtil.java
rename to spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulDiscoveryUtil.java
index a9c55b7fb..f7b1bee92 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/util/RegistrationUtil.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulDiscoveryUtil.java
@@ -15,17 +15,16 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.polaris.tsf.util;
+package com.tencent.cloud.polaris.extend.consul;
import java.util.Map;
import com.ecwid.consul.v1.agent.model.NewService;
-import com.tencent.cloud.common.util.AddressUtils;
import com.tencent.cloud.common.util.JacksonUtils;
-import com.tencent.cloud.polaris.context.tsf.config.TsfCoreProperties;
-import com.tencent.cloud.polaris.tsf.TsfDiscoveryProperties;
-import com.tencent.cloud.polaris.tsf.TsfHeartbeatProperties;
+import com.tencent.cloud.polaris.context.config.extend.tsf.TsfCoreProperties;
import com.tencent.polaris.api.config.Configuration;
+import com.tencent.polaris.api.utils.IPAddressUtils;
+import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl;
import com.tencent.polaris.plugins.connector.common.constant.ConsulConstant;
import org.slf4j.Logger;
@@ -39,38 +38,39 @@ import org.springframework.cloud.commons.util.IdUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* TSF registration utils.
*
* @author Haotian Zhang
*/
-public final class RegistrationUtil {
+public final class ConsulDiscoveryUtil {
/**
* - 分隔符.
*/
public static final char SEPARATOR = '-';
+
/**
* Server connector ID.
*/
public static final String ID = "consul";
- private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationUtil.class);
- private RegistrationUtil() {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConsulDiscoveryUtil.class);
+
+ private ConsulDiscoveryUtil() {
}
- public static String getAppName(TsfDiscoveryProperties properties, Environment env) {
+ public static String getAppName(ConsulDiscoveryProperties properties, Environment env) {
String appName = properties.getServiceName();
- if (!StringUtils.isEmpty(appName)) {
+ if (StringUtils.isNotBlank(appName)) {
return appName;
}
return env.getProperty("spring.application.name", "application");
}
- public static String getInstanceId(TsfCoreProperties properties, ApplicationContext context) {
+ public static String getInstanceId(ConsulDiscoveryProperties properties, ApplicationContext context) {
// tsf consul 不支持 dns,所以这里不需要 normalize,并且由于优雅下线,readiness probe 联动都是依赖 service id 的,normalize 后两边对不上,所以需要去掉 normalize
- if (!StringUtils.hasText(properties.getInstanceId())) {
+ if (StringUtils.isBlank(properties.getInstanceId())) {
return IdUtils.getDefaultInstanceId(context.getEnvironment(), false);
}
else {
@@ -78,17 +78,7 @@ public final class RegistrationUtil {
}
}
- // 更新了判断逻辑,仅判断为空的场景
public static String normalizeForDns(String s) {
- // if (s == null || !Character.isLetter(s.charAt(0))
- // || !Character.isLetterOrDigit(s.charAt(s.length()-1))) {
- // throw new IllegalArgumentException("Consul service ids must not be empty,
- // must start with a letter, end with a letter or digit, and have as interior
- // characters only letters, digits, and hyphen");
- // }
-
- // tsf not check consul service instance id start with letter and end with
- // letter or digit
if (s == null) {
throw new IllegalArgumentException("Consul service ids must not be empty");
}
@@ -113,8 +103,8 @@ public final class RegistrationUtil {
}
public static void setCheck(AutoServiceRegistrationProperties autoServiceRegistrationProperties,
- TsfDiscoveryProperties properties, TsfCoreProperties tsfCoreProperties, ApplicationContext context,
- TsfHeartbeatProperties tsfHeartbeatProperties, Registration registration, Configuration configuration) {
+ ConsulDiscoveryProperties properties, TsfCoreProperties tsfCoreProperties, ApplicationContext context,
+ ConsulHeartbeatProperties consulHeartbeatProperties, Registration registration, Configuration configuration) {
if (properties.isRegisterHealthCheck()) {
Integer checkPort;
if (shouldRegisterManagement(autoServiceRegistrationProperties, properties, context)) {
@@ -128,7 +118,7 @@ public final class RegistrationUtil {
for (ServerConnectorConfigImpl config : configuration.getGlobal().getServerConnectors()) {
if (org.apache.commons.lang.StringUtils.equals(config.getId(), ID)) {
Map metadata = config.getMetadata();
- NewService.Check check = createCheck(checkPort, tsfHeartbeatProperties, properties, tsfCoreProperties);
+ NewService.Check check = createCheck(checkPort, consulHeartbeatProperties, properties, tsfCoreProperties);
String checkJson = JacksonUtils.serialize2Json(check);
LOGGER.debug("Check is : {}", checkJson);
metadata.put(ConsulConstant.MetadataMapKey.CHECK_KEY, checkJson);
@@ -138,8 +128,8 @@ public final class RegistrationUtil {
}
}
- public static NewService.Check createCheck(Integer port, TsfHeartbeatProperties ttlConfig,
- TsfDiscoveryProperties properties, TsfCoreProperties tsfCoreProperties) {
+ public static NewService.Check createCheck(Integer port, ConsulHeartbeatProperties ttlConfig,
+ ConsulDiscoveryProperties properties, TsfCoreProperties tsfCoreProperties) {
NewService.Check check = new NewService.Check();
if (ttlConfig.isEnabled()) {
check.setTtl(ttlConfig.getTtl());
@@ -154,12 +144,12 @@ public final class RegistrationUtil {
}
else {
check.setHttp(String.format("%s://%s:%s%s", tsfCoreProperties.getScheme(),
- AddressUtils.getIpCompatible(properties.getHostname()), port,
+ IPAddressUtils.getIpCompatible(properties.getHostname()), port,
properties.getHealthCheckPath()));
}
check.setInterval(properties.getHealthCheckInterval());
check.setTimeout(properties.getHealthCheckTimeout());
- if (StringUtils.hasText(properties.getHealthCheckCriticalTimeout())) {
+ if (StringUtils.isNotBlank(properties.getHealthCheckCriticalTimeout())) {
check.setDeregisterCriticalServiceAfter(properties.getHealthCheckCriticalTimeout());
}
check.setTlsSkipVerify(properties.getHealthCheckTlsSkipVerify());
@@ -169,7 +159,8 @@ public final class RegistrationUtil {
/**
* @return if the management service should be registered with the {@link ServiceRegistry}
*/
- public static boolean shouldRegisterManagement(AutoServiceRegistrationProperties autoServiceRegistrationProperties, TsfDiscoveryProperties properties, ApplicationContext context) {
+ public static boolean shouldRegisterManagement(AutoServiceRegistrationProperties autoServiceRegistrationProperties,
+ ConsulDiscoveryProperties properties, ApplicationContext context) {
return autoServiceRegistrationProperties.isRegisterManagement()
&& getManagementPort(properties, context) != null
&& ManagementServerPortUtils.isDifferent(context);
@@ -178,7 +169,7 @@ public final class RegistrationUtil {
/**
* @return the port of the Management Service
*/
- public static Integer getManagementPort(TsfDiscoveryProperties properties, ApplicationContext context) {
+ public static Integer getManagementPort(ConsulDiscoveryProperties properties, ApplicationContext context) {
// If an alternate external port is specified, use it instead
if (properties.getManagementPort() != null) {
return properties.getManagementPort();
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfHeartbeatProperties.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulHeartbeatProperties.java
similarity index 82%
rename from spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfHeartbeatProperties.java
rename to spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulHeartbeatProperties.java
index e946c5cec..ef709e4ea 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfHeartbeatProperties.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/consul/ConsulHeartbeatProperties.java
@@ -15,25 +15,33 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.polaris.tsf;
+package com.tencent.cloud.polaris.extend.consul;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
-import org.apache.commons.logging.Log;
import org.joda.time.Period;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.style.ToStringCreator;
import org.springframework.validation.annotation.Validated;
-@ConfigurationProperties(prefix = "tsf.discovery.heartbeat")
+/**
+ * Copy from org.springframework.cloud.consul.discovery.HeartbeatProperties.
+ * Properties related to heartbeat verification.
+ *
+ * @author Spencer Gibb
+ * @author Chris Bono
+ */
+@ConfigurationProperties(prefix = "spring.cloud.consul.discovery.heartbeat")
@Validated
-public class TsfHeartbeatProperties {
+public class ConsulHeartbeatProperties {
- private static final Log log = org.apache.commons.logging.LogFactory.getLog(TsfHeartbeatProperties.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConsulHeartbeatProperties.class);
// TODO: change enabled to default to true when I stop seeing messages like
// [WARN] agent: Check 'service:testConsulApp:xtest:8080' missed TTL, is now critical
boolean enabled = true;
@@ -50,7 +58,7 @@ public class TsfHeartbeatProperties {
//TODO: did heartbeatInterval need to be a field?
- protected Period computeHearbeatInterval() {
+ protected Period computeHeartbeatInterval() {
// heartbeat rate at ratio * ttl, but no later than ttl -1s and, (under lesser
// priority), no sooner than 1s from now
double interval = ttlValue * intervalRatio;
@@ -58,7 +66,7 @@ public class TsfHeartbeatProperties {
int ttlMinus1 = ttlValue - 1;
double min = Math.min(ttlMinus1, max);
Period heartbeatInterval = new Period(Math.round(1000 * min));
- log.debug("Computed heartbeatInterval: " + heartbeatInterval);
+ LOGGER.debug("Computed heartbeatInterval: " + heartbeatInterval);
return heartbeatInterval;
}
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 faac451ed..2dfb36404 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
@@ -26,7 +26,7 @@ import java.util.Objects;
import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
-import com.tencent.cloud.polaris.extend.consul.ConsulContextProperties;
+import com.tencent.cloud.polaris.extend.consul.ConsulDiscoveryProperties;
import com.tencent.cloud.polaris.extend.nacos.NacosContextProperties;
import com.tencent.polaris.client.api.SDKContext;
import org.apache.commons.lang.StringUtils;
@@ -72,7 +72,7 @@ public class PolarisRegistration implements Registration {
public PolarisRegistration(
PolarisDiscoveryProperties polarisDiscoveryProperties,
@Nullable PolarisContextProperties polarisContextProperties,
- @Nullable ConsulContextProperties consulContextProperties,
+ @Nullable ConsulDiscoveryProperties consulDiscoveryProperties,
SDKContext context, StaticMetadataManager staticMetadataManager,
@Nullable NacosContextProperties nacosContextProperties,
@Nullable ServletWebServerApplicationContext servletWebServerApplicationContext,
@@ -133,8 +133,8 @@ public class PolarisRegistration implements Registration {
if (null != polarisDiscoveryProperties) {
registerEnabled = polarisDiscoveryProperties.isRegisterEnabled();
}
- if (null != consulContextProperties && consulContextProperties.isEnabled()) {
- registerEnabled |= consulContextProperties.isRegister();
+ if (null != consulDiscoveryProperties) {
+ registerEnabled |= consulDiscoveryProperties.isRegister();
}
if (null != nacosContextProperties && nacosContextProperties.isEnabled()) {
registerEnabled |= nacosContextProperties.isRegisterEnabled();
@@ -143,7 +143,7 @@ public class PolarisRegistration implements Registration {
public static PolarisRegistration registration(PolarisDiscoveryProperties polarisDiscoveryProperties,
@Nullable PolarisContextProperties polarisContextProperties,
- @Nullable ConsulContextProperties consulContextProperties,
+ @Nullable ConsulDiscoveryProperties consulContextProperties,
SDKContext context, StaticMetadataManager staticMetadataManager,
@Nullable NacosContextProperties nacosContextProperties,
@Nullable ServletWebServerApplicationContext servletWebServerApplicationContext,
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 a1588af44..582f80198 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
@@ -142,6 +142,7 @@ public class PolarisServiceRegistry implements ServiceRegistry());
- }
- // 删除可能存在的consul发现配置
- for (DiscoveryConfigImpl dc : configuration.getConsumer().getDiscoveries()) {
- if (StringUtils.equals(dc.getServerConnectorId(), RegistrationUtil.ID)) {
- configuration.getConsumer().getDiscoveries().remove(dc);
- }
- }
- // 删除可能存在的consul注册配置
- for (RegisterConfigImpl rc : configuration.getProvider().getRegisters()) {
- if (StringUtils.equals(rc.getServerConnectorId(), RegistrationUtil.ID)) {
- configuration.getProvider().getRegisters().remove(rc);
- }
- }
-
- // 如果ServerConnectors为空,则把ServerConnector(如有)复制过去
- if (CollectionUtils.isEmpty(configuration.getGlobal().getServerConnectors())
- && null != configuration.getGlobal().getServerConnector()) {
- configuration.getGlobal().getServerConnectors().add(configuration.getGlobal().getServerConnector());
- }
- if (consulEnable) {
- // enable consul
- ServerConnectorConfigImpl serverConnectorConfig = new ServerConnectorConfigImpl();
- serverConnectorConfig.setId(RegistrationUtil.ID);
- serverConnectorConfig.setAddresses(
- Collections.singletonList(tsfConsulProperties.getHost() + ":" + tsfConsulProperties.getPort()));
- LOGGER.info("Will register to consul server: [" + tsfConsulProperties.getHost() + ":" + tsfConsulProperties.getPort() + "]");
- serverConnectorConfig.setProtocol(DefaultPlugins.SERVER_CONNECTOR_CONSUL);
-
- Map metadata = serverConnectorConfig.getMetadata();
- String appName = RegistrationUtil.getAppName(tsfDiscoveryProperties, context.getEnvironment());
- metadata.put(ConsulConstant.MetadataMapKey.SERVICE_NAME_KEY, RegistrationUtil.normalizeForDns(appName));
- metadata.put(ConsulConstant.MetadataMapKey.INSTANCE_ID_KEY, RegistrationUtil.getInstanceId(tsfCoreProperties, context));
- if (StringUtils.isNotBlank(tsfConsulProperties.getAclToken())) {
- serverConnectorConfig.setToken(tsfConsulProperties.getAclToken());
- }
- metadata.put(ConsulConstant.MetadataMapKey.TAGS_KEY, JacksonUtils.serialize2Json(TsfUtils.createTags(tsfCoreProperties)));
- if (StringUtils.isNotBlank(tsfDiscoveryProperties.getDefaultQueryTag())) {
- metadata.put(ConsulConstant.MetadataMapKey.QUERY_TAG_KEY, tsfDiscoveryProperties.getDefaultQueryTag());
- }
- metadata.put(ConsulConstant.MetadataMapKey.QUERY_PASSING_KEY, String.valueOf(tsfDiscoveryProperties.isQueryPassing()));
- if (tsfDiscoveryProperties.isPreferIpAddress()
- && StringUtils.isNotBlank(tsfDiscoveryProperties.getIpAddress())) {
- metadata.put(ConsulConstant.MetadataMapKey.PREFER_IP_ADDRESS_KEY,
- String.valueOf(tsfDiscoveryProperties.isPreferIpAddress()));
- metadata.put(ConsulConstant.MetadataMapKey.IP_ADDRESS_KEY, tsfDiscoveryProperties.getIpAddress());
- }
- if (!tsfDiscoveryProperties.isPreferAgentAddress()) {
- metadata.put(ConsulConstant.MetadataMapKey.PREFER_IP_ADDRESS_KEY,
- String.valueOf(tsfDiscoveryProperties.isPreferIpAddress()));
- metadata.put(ConsulConstant.MetadataMapKey.IP_ADDRESS_KEY, tsfDiscoveryProperties.getHostname());
- }
- configuration.getGlobal().getServerConnectors().add(serverConnectorConfig);
-
- // 添加发现配置
- DiscoveryConfigImpl discoveryConfig = new DiscoveryConfigImpl();
- discoveryConfig.setServerConnectorId(RegistrationUtil.ID);
- discoveryConfig.setEnable(tsfDiscoveryProperties.isEnabled());
- configuration.getConsumer().getDiscoveries().add(discoveryConfig);
-
- // 添加注册配置
- RegisterConfigImpl registerConfig = new RegisterConfigImpl();
- registerConfig.setServerConnectorId(RegistrationUtil.ID);
- registerConfig.setEnable(tsfDiscoveryProperties.isRegister());
- configuration.getProvider().getRegisters().add(registerConfig);
- }
-
- if (polarisDiscoveryProperties != null) {
- if (!polarisEnable) {
- configuration.getGlobal().getAPI().setReportEnable(false);
- for (DiscoveryConfigImpl dc : configuration.getConsumer().getDiscoveries()) {
- if (StringUtils.equals(dc.getServerConnectorId(), "polaris")) {
- dc.setEnable(false);
- }
- }
- for (RegisterConfigImpl rc : configuration.getProvider().getRegisters()) {
- if (StringUtils.equals(rc.getServerConnectorId(), "polaris")) {
- rc.setEnable(false);
- rc.setReportServiceContractEnable(false);
- }
- }
- }
- }
- }
-
- @Override
- public int getOrder() {
- return OrderConstant.Modifier.CONSUL_DISCOVERY_CONFIG_ORDER + 1;
- }
-}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfDiscoveryProperties.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfDiscoveryProperties.java
deleted file mode 100644
index dc308081c..000000000
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfDiscoveryProperties.java
+++ /dev/null
@@ -1,550 +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.tsf;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import com.tencent.cloud.common.util.inet.PolarisInetUtils;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.cloud.commons.util.InetUtils;
-
-/**
- * Defines configuration for service discovery and registration.
- *
- * @author Spencer Gibb
- * @author Donnabell Dmello
- * @author Venil Noronha
- * @author Richard Kettelerij
- */
-@ConfigurationProperties("tsf.discovery")
-public class TsfDiscoveryProperties {
-
- protected static final String MANAGEMENT = "management";
-
- private InetUtils.HostInfo hostInfo;
-
- /**
- * If service discovery enabled.
- */
- private boolean enabled = true;
-
- /**
- * Tags to use when registering management service.
- */
- private List managementTags = new ArrayList<>();
-
- /**
- * Alternate server path to invoke for health checking .
- */
- private String healthCheckPath = "/actuator/health";
-
- /**
- * Custom health check url to override default.
- */
- private String healthCheckUrl;
-
- /**
- * How often to perform the health check (e.g. 10s), defaults to 10s.
- */
- private String healthCheckInterval = "10s";
-
- /**
- * Timeout for health check (e.g. 10s).
- */
- private String healthCheckTimeout;
-
- /**
- * Timeout to deregister services critical for longer than timeout (e.g. 30m).
- * Requires consul version 7.x or higher.
- */
- private String healthCheckCriticalTimeout;
-
- /**
- * IP address to use when accessing service (must also set preferIpAddress to use).
- */
- private String ipAddress;
-
- /**
- * Hostname to use when accessing server.
- */
- private String hostname;
-
- /**
- * Port to register the service under (defaults to listening port).
- */
- private Integer port;
-
- /**
- * Port to register the management service under (defaults to management port).
- */
- private Integer managementPort;
-
- private Lifecycle lifecycle = new Lifecycle();
-
- /**
- * Use ip address rather than hostname during registration.
- * 默认使用IP地址
- */
- private boolean preferIpAddress = true;
-
- /**
- * Source of how we will determine the address to use.
- */
- private boolean preferAgentAddress = false;
-
- /**
- * The delay between calls to watch consul catalog in millis, default is 1000.
- */
- private int catalogServicesWatchDelay = 1000;
-
- /**
- * The number of seconds to block while watching consul catalog, default is 2.
- */
- private int catalogServicesWatchTimeout = 55;
-
- /**
- * Service name.
- */
- private String serviceName;
-
- /**
- * Suffix to use when registering management service.
- */
- private String managementSuffix = MANAGEMENT;
-
- /**
- * Map of serviceId's -> tag to query for in server list.
- * This allows filtering services by a single tag.
- */
- private Map serverListQueryTags = new HashMap<>();
-
- /**
- * Map of serviceId's -> datacenter to query for in server list.
- * This allows looking up services in another datacenters.
- */
- private Map datacenters = new HashMap<>();
-
- /**
- * Tag to query for in service list if one is not listed in serverListQueryTags.
- */
- private String defaultQueryTag;
-
- /**
- * Add the 'passing` parameter to /v1/health/service/serviceName.
- * This pushes health check passing to the server.
- */
- private boolean queryPassing = true;
-
- /**
- * Register as a service in consul.
- */
- private boolean register = true;
-
- /**
- * Disable automatic de-registration of service in consul.
- */
- private boolean deregister = true;
-
- /**
- * Register health check in consul. Useful during development of a service.
- */
- private boolean registerHealthCheck = true;
-
- /**
- * Throw exceptions during service registration if true, otherwise, log
- * warnings (defaults to true).
- */
- private boolean failFast = true;
-
- /**
- * Skips certificate verification during service checks if true, otherwise
- * runs certificate verification.
- */
- private Boolean healthCheckTlsSkipVerify;
-
- /**
- * 有状态服务回调的线程池.
- */
- private int callbackPoolSize = 10;
-
- private long callbackInitialDelay = 10 * 1000L;
-
- private long callbackErrorDelay = 30 * 1000L;
-
- /**
- * 是否开启零实例保护,默认开启。开启时如果 consul 返回在线实例为0,用上次的缓存(正常来说线上环境不应该有provider全下线的情况).
- * 定制化双发现时可能需要关闭,此时如果provider下线,则返回空列表。如果 consul 连接不上则用缓存.
- */
- private boolean zeroInstanceProtect = true;
-
- private int testConnectivityTimeout = 5000;
-
- private Map serviceMeta;
-
- @SuppressWarnings("unused")
- private TsfDiscoveryProperties() {
- this.managementTags.add(MANAGEMENT);
- }
-
- public TsfDiscoveryProperties(PolarisInetUtils polarisInetUtils) {
- this();
- this.hostInfo = polarisInetUtils.findFirstNonLoopbackHostInfo();
- this.ipAddress = this.hostInfo.getIpAddress();
- this.hostname = this.hostInfo.getHostname();
- }
-
- /**
- * @param serviceId The service who's filtering tag is being looked up
- * @return The tag the given service id should be filtered by, or null.
- */
- public String getQueryTagForService(String serviceId) {
- String tag = serverListQueryTags.get(serviceId);
- return tag != null ? tag : defaultQueryTag;
- }
-
- public String getHostname() {
- return this.preferIpAddress ? this.ipAddress : this.hostname;
- }
-
- public void setHostname(String hostname) {
- this.hostname = hostname;
- this.hostInfo.override = true;
- }
-
- private InetUtils.HostInfo getHostInfo() {
- return hostInfo;
- }
-
- private void setHostInfo(InetUtils.HostInfo hostInfo) {
- this.hostInfo = hostInfo;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public List getManagementTags() {
- return managementTags;
- }
-
- public void setManagementTags(List managementTags) {
- this.managementTags = managementTags;
- }
-
- public String getHealthCheckPath() {
- return healthCheckPath;
- }
-
- public void setHealthCheckPath(String healthCheckPath) {
- this.healthCheckPath = healthCheckPath;
- }
-
- public String getHealthCheckUrl() {
- return healthCheckUrl;
- }
-
- public void setHealthCheckUrl(String healthCheckUrl) {
- this.healthCheckUrl = healthCheckUrl;
- }
-
- public String getHealthCheckInterval() {
- return healthCheckInterval;
- }
-
- public void setHealthCheckInterval(String healthCheckInterval) {
- this.healthCheckInterval = healthCheckInterval;
- }
-
- public String getHealthCheckTimeout() {
- return healthCheckTimeout;
- }
-
- public void setHealthCheckTimeout(String healthCheckTimeout) {
- this.healthCheckTimeout = healthCheckTimeout;
- }
-
- public String getHealthCheckCriticalTimeout() {
- return healthCheckCriticalTimeout;
- }
-
- public void setHealthCheckCriticalTimeout(String healthCheckCriticalTimeout) {
- this.healthCheckCriticalTimeout = healthCheckCriticalTimeout;
- }
-
- public String getIpAddress() {
- return ipAddress;
- }
-
- public void setIpAddress(String ipAddress) {
- this.ipAddress = ipAddress;
- this.hostInfo.override = true;
- }
-
- public Integer getPort() {
- return port;
- }
-
- public void setPort(Integer port) {
- this.port = port;
- }
-
- public Integer getManagementPort() {
- return managementPort;
- }
-
- public void setManagementPort(Integer managementPort) {
- this.managementPort = managementPort;
- }
-
- public Lifecycle getLifecycle() {
- return lifecycle;
- }
-
- public void setLifecycle(Lifecycle lifecycle) {
- this.lifecycle = lifecycle;
- }
-
- public boolean isPreferIpAddress() {
- return preferIpAddress;
- }
-
- public void setPreferIpAddress(boolean preferIpAddress) {
- this.preferIpAddress = preferIpAddress;
- }
-
- public boolean isPreferAgentAddress() {
- return preferAgentAddress;
- }
-
- public void setPreferAgentAddress(boolean preferAgentAddress) {
- this.preferAgentAddress = preferAgentAddress;
- }
-
- public int getCatalogServicesWatchDelay() {
- return catalogServicesWatchDelay;
- }
-
- public void setCatalogServicesWatchDelay(int catalogServicesWatchDelay) {
- this.catalogServicesWatchDelay = catalogServicesWatchDelay;
- }
-
- public int getCatalogServicesWatchTimeout() {
- return catalogServicesWatchTimeout;
- }
-
- public void setCatalogServicesWatchTimeout(int catalogServicesWatchTimeout) {
- this.catalogServicesWatchTimeout = catalogServicesWatchTimeout;
- }
-
- public String getServiceName() {
- return serviceName;
- }
-
- public void setServiceName(String serviceName) {
- this.serviceName = serviceName;
- }
-
- public String getManagementSuffix() {
- return managementSuffix;
- }
-
- public void setManagementSuffix(String managementSuffix) {
- this.managementSuffix = managementSuffix;
- }
-
- public Map getServerListQueryTags() {
- return serverListQueryTags;
- }
-
- public void setServerListQueryTags(Map serverListQueryTags) {
- this.serverListQueryTags = serverListQueryTags;
- }
-
- public Map getDatacenters() {
- return datacenters;
- }
-
- public void setDatacenters(Map datacenters) {
- this.datacenters = datacenters;
- }
-
- public String getDefaultQueryTag() {
- return defaultQueryTag;
- }
-
- public void setDefaultQueryTag(String defaultQueryTag) {
- this.defaultQueryTag = defaultQueryTag;
- }
-
- public boolean isQueryPassing() {
- return queryPassing;
- }
-
- public void setQueryPassing(boolean queryPassing) {
- this.queryPassing = queryPassing;
- }
-
- public boolean isRegister() {
- return register;
- }
-
- public void setRegister(boolean register) {
- this.register = register;
- }
-
- public boolean isDeregister() {
- return deregister;
- }
-
- public void setDeregister(boolean deregister) {
- this.deregister = deregister;
- }
-
- public boolean isRegisterHealthCheck() {
- return registerHealthCheck;
- }
-
- public void setRegisterHealthCheck(boolean registerHealthCheck) {
- this.registerHealthCheck = registerHealthCheck;
- }
-
- public boolean isFailFast() {
- return failFast;
- }
-
- public void setFailFast(boolean failFast) {
- this.failFast = failFast;
- }
-
- public Boolean getHealthCheckTlsSkipVerify() {
- return healthCheckTlsSkipVerify;
- }
-
- public void setHealthCheckTlsSkipVerify(Boolean healthCheckTlsSkipVerify) {
- this.healthCheckTlsSkipVerify = healthCheckTlsSkipVerify;
- }
-
- public Map getServiceMeta() {
- return serviceMeta;
- }
-
- public void setServiceMeta(final Map serviceMeta) {
- this.serviceMeta = serviceMeta;
- }
-
- public int getCallbackPoolSize() {
- return callbackPoolSize;
- }
-
- public void setCallbackPoolSize(int callbackPoolSize) {
- this.callbackPoolSize = callbackPoolSize;
- }
-
- public long getCallbackInitialDelay() {
- return callbackInitialDelay;
- }
-
- public void setCallbackInitialDelay(long callbackInitialDelay) {
- this.callbackInitialDelay = callbackInitialDelay;
- }
-
- public long getCallbackErrorDelay() {
- return callbackErrorDelay;
- }
-
- public void setCallbackErrorDelay(long callbackErrorDelay) {
- this.callbackErrorDelay = callbackErrorDelay;
- }
-
- public boolean isZeroInstanceProtect() {
- return zeroInstanceProtect;
- }
-
- public void setZeroInstanceProtect(boolean zeroInstanceProtect) {
- this.zeroInstanceProtect = zeroInstanceProtect;
- }
-
- public int getTestConnectivityTimeout() {
- return testConnectivityTimeout;
- }
-
- public void setTestConnectivityTimeout(int testConnectivityTimeout) {
- this.testConnectivityTimeout = testConnectivityTimeout;
- }
-
- @Override
- public String toString() {
- return "ConsulDiscoveryProperties{" +
- "hostInfo=" + hostInfo +
- ", enabled=" + enabled +
- ", managementTags=" + managementTags +
- ", healthCheckPath='" + healthCheckPath + '\'' +
- ", healthCheckUrl='" + healthCheckUrl + '\'' +
- ", healthCheckInterval='" + healthCheckInterval + '\'' +
- ", healthCheckTimeout='" + healthCheckTimeout + '\'' +
- ", healthCheckCriticalTimeout='" + healthCheckCriticalTimeout + '\'' +
- ", ipAddress='" + ipAddress + '\'' +
- ", hostname='" + hostname + '\'' +
- ", port=" + port +
- ", managementPort=" + managementPort +
- ", lifecycle=" + lifecycle +
- ", preferIpAddress=" + preferIpAddress +
- ", preferAgentAddress=" + preferAgentAddress +
- ", catalogServicesWatchDelay=" + catalogServicesWatchDelay +
- ", catalogServicesWatchTimeout=" + catalogServicesWatchTimeout +
- ", serviceName='" + serviceName + '\'' +
- ", managementSuffix='" + managementSuffix + '\'' +
- ", serverListQueryTags=" + serverListQueryTags +
- ", datacenters=" + datacenters +
- ", defaultQueryTag='" + defaultQueryTag + '\'' +
- ", queryPassing=" + queryPassing +
- ", register=" + register +
- ", deregister=" + deregister +
- ", registerHealthCheck=" + registerHealthCheck +
- ", failFast=" + failFast +
- ", healthCheckTlsSkipVerify=" + healthCheckTlsSkipVerify +
- '}';
- }
-
- public static class Lifecycle {
- private boolean enabled = true;
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- @Override
- public String toString() {
- return "Lifecycle{" +
- "enabled=" + enabled +
- '}';
- }
- }
-}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfDiscoveryPropertiesAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfDiscoveryPropertiesAutoConfiguration.java
deleted file mode 100644
index e961b2e28..000000000
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfDiscoveryPropertiesAutoConfiguration.java
+++ /dev/null
@@ -1,83 +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.tsf;
-
-import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
-import com.tencent.cloud.common.util.inet.PolarisInetUtils;
-import com.tencent.cloud.plugin.lossless.config.LosslessProperties;
-import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
-import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
-import com.tencent.cloud.polaris.context.tsf.config.TsfCoreProperties;
-import com.tencent.cloud.polaris.context.tsf.consul.TsfConsulProperties;
-import com.tencent.cloud.polaris.tsf.lossless.TsfLosslessConfigModifier;
-import com.tencent.cloud.polaris.tsf.lossless.TsfLosslessProperties;
-
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Auto configuration for TSF discovery.
- *
- * @author Haotian Zhang
- */
-@Configuration(proxyBeanMethods = false)
-@ConditionalOnTsfEnabled
-public class TsfDiscoveryPropertiesAutoConfiguration {
-
- @Bean
- @ConditionalOnMissingBean
- public TsfDiscoveryProperties tsfDiscoveryProperties(PolarisInetUtils polarisInetUtils) {
- return new TsfDiscoveryProperties(polarisInetUtils);
- }
-
- @Bean
- @ConditionalOnMissingBean
- public TsfHeartbeatProperties tsfHeartbeatProperties() {
- return new TsfHeartbeatProperties();
- }
-
- @Bean
- @ConditionalOnMissingBean
- public TsfLosslessProperties tsfLosslessProperties() {
- return new TsfLosslessProperties();
- }
-
- @Bean
- @ConditionalOnMissingBean
- public TsfDiscoveryConfigModifier tsfDiscoveryConfigModifier(TsfCoreProperties tsfCoreProperties,
- TsfConsulProperties tsfConsulProperties, TsfDiscoveryProperties tsfDiscoveryProperties,
- TsfHeartbeatProperties tsfHeartbeatProperties, PolarisDiscoveryProperties polarisDiscoveryProperties,
- PolarisContextProperties polarisContextProperties, ApplicationContext context) {
- return new TsfDiscoveryConfigModifier(tsfCoreProperties, tsfConsulProperties, tsfDiscoveryProperties,
- tsfHeartbeatProperties, polarisDiscoveryProperties, polarisContextProperties, context);
- }
-
- @Bean
- @ConditionalOnMissingBean
- public TsfZeroProtectionConfigModifier tsfZeroProtectionConfigModifier() {
- return new TsfZeroProtectionConfigModifier();
- }
-
- @Bean
- @ConditionalOnMissingBean
- public TsfLosslessConfigModifier tsfLosslessConfigModifier(LosslessProperties losslessProperties, TsfLosslessProperties tsfLosslessProperties) {
- return new TsfLosslessConfigModifier(losslessProperties, tsfLosslessProperties);
- }
-}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfDiscoveryPropertiesBootstrapConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfDiscoveryPropertiesBootstrapConfiguration.java
deleted file mode 100644
index 4395650d2..000000000
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfDiscoveryPropertiesBootstrapConfiguration.java
+++ /dev/null
@@ -1,39 +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.tsf;
-
-import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
-import com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration;
-
-import org.springframework.cloud.commons.util.UtilAutoConfiguration;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-
-/**
- * Bootstrap configuration for TSF discovery.
- *
- * @author Haotian Zhang
- */
-@Configuration(proxyBeanMethods = false)
-@ConditionalOnTsfEnabled
-@Import({TsfDiscoveryPropertiesAutoConfiguration.class,
- DiscoveryPropertiesAutoConfiguration.class,
- UtilAutoConfiguration.class})
-public class TsfDiscoveryPropertiesBootstrapConfiguration {
-
-}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfZeroProtectionConfigModifier.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfZeroProtectionConfigModifier.java
deleted file mode 100644
index 0a78d1a73..000000000
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/TsfZeroProtectionConfigModifier.java
+++ /dev/null
@@ -1,40 +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.tsf;
-
-import com.tencent.cloud.common.constant.OrderConstant;
-import com.tencent.cloud.polaris.context.PolarisConfigModifier;
-import com.tencent.polaris.factory.config.ConfigurationImpl;
-
-/**
- * Modifier for TSF discovery zero protection.
- *
- * @author Haotian Zhang
- */
-public class TsfZeroProtectionConfigModifier implements PolarisConfigModifier {
- @Override
- public void modify(ConfigurationImpl configuration) {
- configuration.getConsumer().getZeroProtection().setEnable(true);
- configuration.getConsumer().getZeroProtection().setNeedTestConnectivity(true);
- }
-
- @Override
- public int getOrder() {
- return OrderConstant.Modifier.DISCOVERY_ORDER + 1;
- }
-}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/lossless/TsfLosslessConfigModifier.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/lossless/TsfLosslessConfigModifier.java
deleted file mode 100644
index 40a6fda0e..000000000
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/lossless/TsfLosslessConfigModifier.java
+++ /dev/null
@@ -1,50 +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.tsf.lossless;
-
-import com.tencent.cloud.common.constant.OrderConstant;
-import com.tencent.cloud.plugin.lossless.config.LosslessProperties;
-import com.tencent.cloud.polaris.context.PolarisConfigModifier;
-import com.tencent.polaris.factory.config.ConfigurationImpl;
-
-/**
- * Modifier for TSF lossless online offline.
- *
- * @author Haotian Zhang
- */
-public class TsfLosslessConfigModifier implements PolarisConfigModifier {
-
- private final LosslessProperties losslessProperties;
- private final TsfLosslessProperties tsfLosslessProperties;
-
- public TsfLosslessConfigModifier(LosslessProperties losslessProperties, TsfLosslessProperties tsfLosslessProperties) {
- this.losslessProperties = losslessProperties;
- this.tsfLosslessProperties = tsfLosslessProperties;
- }
-
- @Override
- public void modify(ConfigurationImpl configuration) {
- losslessProperties.setEnabled(true);
- losslessProperties.setPort(tsfLosslessProperties.getPort());
- }
-
- @Override
- public int getOrder() {
- return OrderConstant.Modifier.LOSSLESS_ORDER - 1;
- }
-}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/lossless/TsfLosslessProperties.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/lossless/TsfLosslessProperties.java
deleted file mode 100644
index 0be0d5977..000000000
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/lossless/TsfLosslessProperties.java
+++ /dev/null
@@ -1,48 +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.tsf.lossless;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * 优雅上下线的配置.
- *
- * @author Haotian Zhang
- */
-@ConfigurationProperties("tsf.discovery.lossless")
-public class TsfLosslessProperties {
-
- @Value("${tsf.discovery.lossless.port:${tsf_sctt_extensions_port:11134}}")
- private int port = 11134;
-
- public int getPort() {
- return port;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- @Override
- public String toString() {
- return "TsfLosslessProperties{" +
- "port=" + port +
- '}';
- }
-}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/registry/TsfDiscoveryRegistryAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/registry/TsfDiscoveryRegistryAutoConfiguration.java
index 687180bf4..dc4e9caba 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/registry/TsfDiscoveryRegistryAutoConfiguration.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/registry/TsfDiscoveryRegistryAutoConfiguration.java
@@ -18,13 +18,12 @@
package com.tencent.cloud.polaris.tsf.registry;
import javax.servlet.ServletContext;
-import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
+import com.tencent.cloud.common.tsf.ConditionalOnTsfConsulEnabled;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
-import com.tencent.cloud.polaris.context.tsf.config.TsfCoreProperties;
+import com.tencent.cloud.polaris.context.config.extend.tsf.TsfCoreProperties;
+import com.tencent.cloud.polaris.extend.consul.ConsulDiscoveryProperties;
+import com.tencent.cloud.polaris.extend.consul.ConsulHeartbeatProperties;
import com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration;
-import com.tencent.cloud.polaris.tsf.TsfDiscoveryProperties;
-import com.tencent.cloud.polaris.tsf.TsfHeartbeatProperties;
-
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
@@ -42,7 +41,7 @@ import org.springframework.context.annotation.Configuration;
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
-@ConditionalOnTsfEnabled
+@ConditionalOnTsfConsulEnabled
@AutoConfigureBefore(PolarisServiceRegistryAutoConfiguration.class)
public class TsfDiscoveryRegistryAutoConfiguration {
@@ -50,10 +49,10 @@ public class TsfDiscoveryRegistryAutoConfiguration {
@ConditionalOnMissingBean
public TsfPortPolarisRegistrationCustomizer tsfPortPolarisRegistrationCustomizer(
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
- ApplicationContext context, TsfDiscoveryProperties tsfDiscoveryProperties, TsfCoreProperties tsfCoreProperties,
- TsfHeartbeatProperties tsfHeartbeatProperties, PolarisSDKContextManager polarisSDKContextManager) {
+ ApplicationContext context, ConsulDiscoveryProperties consulDiscoveryProperties, TsfCoreProperties tsfCoreProperties,
+ ConsulHeartbeatProperties consulHeartbeatProperties, PolarisSDKContextManager polarisSDKContextManager) {
return new TsfPortPolarisRegistrationCustomizer(autoServiceRegistrationProperties, context,
- tsfDiscoveryProperties, tsfCoreProperties, tsfHeartbeatProperties, polarisSDKContextManager.getSDKContext());
+ consulDiscoveryProperties, tsfCoreProperties, consulHeartbeatProperties, polarisSDKContextManager.getSDKContext());
}
@Bean
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/registry/TsfPortPolarisRegistrationCustomizer.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/registry/TsfPortPolarisRegistrationCustomizer.java
index 8312c2f1b..68a13a365 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/registry/TsfPortPolarisRegistrationCustomizer.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/tsf/registry/TsfPortPolarisRegistrationCustomizer.java
@@ -17,12 +17,12 @@
package com.tencent.cloud.polaris.tsf.registry;
-import com.tencent.cloud.polaris.context.tsf.config.TsfCoreProperties;
+import com.tencent.cloud.polaris.context.config.extend.tsf.TsfCoreProperties;
+import com.tencent.cloud.polaris.extend.consul.ConsulDiscoveryProperties;
+import com.tencent.cloud.polaris.extend.consul.ConsulDiscoveryUtil;
+import com.tencent.cloud.polaris.extend.consul.ConsulHeartbeatProperties;
import com.tencent.cloud.polaris.registry.PolarisRegistration;
import com.tencent.cloud.polaris.registry.PolarisRegistrationCustomizer;
-import com.tencent.cloud.polaris.tsf.TsfDiscoveryProperties;
-import com.tencent.cloud.polaris.tsf.TsfHeartbeatProperties;
-import com.tencent.cloud.polaris.tsf.util.RegistrationUtil;
import com.tencent.polaris.client.api.SDKContext;
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
@@ -37,29 +37,29 @@ public class TsfPortPolarisRegistrationCustomizer implements PolarisRegistration
private final AutoServiceRegistrationProperties autoServiceRegistrationProperties;
private final ApplicationContext context;
- private final TsfDiscoveryProperties tsfDiscoveryProperties;
+ private final ConsulDiscoveryProperties consulDiscoveryProperties;
private final TsfCoreProperties tsfCoreProperties;
- private final TsfHeartbeatProperties tsfHeartbeatProperties;
+ private final ConsulHeartbeatProperties consulHeartbeatProperties;
private final SDKContext sdkContext;
public TsfPortPolarisRegistrationCustomizer(AutoServiceRegistrationProperties autoServiceRegistrationProperties,
- ApplicationContext context, TsfDiscoveryProperties tsfDiscoveryProperties, TsfCoreProperties tsfCoreProperties,
- TsfHeartbeatProperties tsfHeartbeatProperties, SDKContext sdkContext) {
+ ApplicationContext context, ConsulDiscoveryProperties consulDiscoveryProperties, TsfCoreProperties tsfCoreProperties,
+ ConsulHeartbeatProperties consulHeartbeatProperties, SDKContext sdkContext) {
this.autoServiceRegistrationProperties = autoServiceRegistrationProperties;
this.context = context;
- this.tsfDiscoveryProperties = tsfDiscoveryProperties;
+ this.consulDiscoveryProperties = consulDiscoveryProperties;
this.tsfCoreProperties = tsfCoreProperties;
- this.tsfHeartbeatProperties = tsfHeartbeatProperties;
+ this.consulHeartbeatProperties = consulHeartbeatProperties;
this.sdkContext = sdkContext;
}
@Override
public void customize(PolarisRegistration registration) {
- if (tsfDiscoveryProperties.getPort() != null) {
- registration.setPort(tsfDiscoveryProperties.getPort());
+ if (consulDiscoveryProperties.getPort() != null) {
+ registration.setPort(consulDiscoveryProperties.getPort());
}
// we know the port and can set the check
- RegistrationUtil.setCheck(autoServiceRegistrationProperties, tsfDiscoveryProperties, tsfCoreProperties, context,
- tsfHeartbeatProperties, registration, sdkContext.getConfig());
+ ConsulDiscoveryUtil.setCheck(autoServiceRegistrationProperties, consulDiscoveryProperties, tsfCoreProperties, context,
+ consulHeartbeatProperties, registration, sdkContext.getConfig());
}
}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/spring.factories
index 8b0e96f63..63944186e 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/spring.factories
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/spring.factories
@@ -4,8 +4,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration,\
com.tencent.cloud.polaris.endpoint.PolarisDiscoveryEndpointAutoConfiguration,\
com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerAutoConfiguration,\
- com.tencent.cloud.polaris.tsf.TsfDiscoveryPropertiesAutoConfiguration,\
com.tencent.cloud.polaris.tsf.registry.TsfDiscoveryRegistryAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
- com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration,\
- com.tencent.cloud.polaris.tsf.TsfDiscoveryPropertiesBootstrapConfiguration
+ com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/DiscoveryPropertiesAutoConfigurationTest.java b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/DiscoveryPropertiesAutoConfigurationTest.java
index 37a01df72..3dee04d67 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/DiscoveryPropertiesAutoConfigurationTest.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/DiscoveryPropertiesAutoConfigurationTest.java
@@ -19,7 +19,7 @@ package com.tencent.cloud.polaris;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
-import com.tencent.cloud.polaris.extend.consul.ConsulContextProperties;
+import com.tencent.cloud.polaris.extend.consul.ConsulDiscoveryProperties;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
@@ -43,7 +43,7 @@ public class DiscoveryPropertiesAutoConfigurationTest {
applicationContextRunner.run(context -> {
assertThat(context).hasSingleBean(DiscoveryPropertiesAutoConfiguration.class);
assertThat(context).hasSingleBean(PolarisDiscoveryProperties.class);
- assertThat(context).hasSingleBean(ConsulContextProperties.class);
+ assertThat(context).doesNotHaveBean(ConsulDiscoveryProperties.class);
assertThat(context).hasSingleBean(PolarisDiscoveryHandler.class);
assertThat(context).hasSingleBean(DiscoveryConfigModifier.class);
});
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/consul/ConsulContextPropertiesTest.java b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/consul/ConsulDiscoveryPropertiesTest.java
similarity index 81%
rename from spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/consul/ConsulContextPropertiesTest.java
rename to spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/consul/ConsulDiscoveryPropertiesTest.java
index 1d545b4e5..ac096d862 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/consul/ConsulContextPropertiesTest.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/consul/ConsulDiscoveryPropertiesTest.java
@@ -37,21 +37,20 @@ import static com.tencent.polaris.plugins.connector.common.constant.ConsulConsta
import static com.tencent.polaris.plugins.connector.common.constant.ConsulConstant.MetadataMapKey.PREFER_IP_ADDRESS_KEY;
import static com.tencent.polaris.plugins.connector.common.constant.ConsulConstant.MetadataMapKey.SERVICE_NAME_KEY;
import static com.tencent.polaris.test.common.Consts.HOST;
-import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
import static org.assertj.core.api.Assertions.assertThat;
/**
- * Test for {@link ConsulContextProperties}.
+ * Test for {@link ConsulDiscoveryPropertiesTest}.
*
* @author Haotian Zhang
*/
@ExtendWith(SpringExtension.class)
-@SpringBootTest(classes = ConsulContextPropertiesTest.TestApplication.class)
+@SpringBootTest(classes = ConsulDiscoveryPropertiesTest.TestApplication.class)
@ActiveProfiles("test")
-public class ConsulContextPropertiesTest {
+public class ConsulDiscoveryPropertiesTest {
@Autowired
- private ConsulContextProperties consulContextProperties;
+ private ConsulDiscoveryProperties consulDiscoveryProperties;
@Autowired
private PolarisSDKContextManager polarisSDKContextManager;
@@ -63,12 +62,9 @@ public class ConsulContextPropertiesTest {
@Test
public void testDefaultInitialization() {
- assertThat(consulContextProperties).isNotNull();
- assertThat(consulContextProperties.isEnabled()).isTrue();
- assertThat(consulContextProperties.getHost()).isEqualTo("127.0.0.1");
- assertThat(consulContextProperties.getPort()).isEqualTo(8500);
- assertThat(consulContextProperties.isRegister()).isTrue();
- assertThat(consulContextProperties.isDiscoveryEnabled()).isTrue();
+ assertThat(consulDiscoveryProperties).isNotNull();
+ assertThat(consulDiscoveryProperties.isRegister()).isTrue();
+ assertThat(consulDiscoveryProperties.isEnabled()).isTrue();
}
@Test
@@ -84,7 +80,7 @@ public class ConsulContextPropertiesTest {
}
}
assertThat(metadata).isNotNull();
- assertThat(metadata.get(SERVICE_NAME_KEY)).isEqualTo(SERVICE_PROVIDER);
+ assertThat(metadata.get(SERVICE_NAME_KEY)).isEqualTo("java-provider-test");
assertThat(metadata.get(INSTANCE_ID_KEY)).isEqualTo("ins-test");
assertThat(metadata.get(PREFER_IP_ADDRESS_KEY)).isEqualTo("true");
assertThat(metadata.get(IP_ADDRESS_KEY)).isEqualTo(HOST);
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/registry/PolarisRegistrationTest.java b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/registry/PolarisRegistrationTest.java
index 076142014..f9b62d331 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/registry/PolarisRegistrationTest.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/registry/PolarisRegistrationTest.java
@@ -23,7 +23,7 @@ import java.util.Map;
import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
-import com.tencent.cloud.polaris.extend.consul.ConsulContextProperties;
+import com.tencent.cloud.polaris.extend.consul.ConsulDiscoveryProperties;
import com.tencent.cloud.polaris.extend.nacos.NacosContextProperties;
import com.tencent.polaris.api.config.Configuration;
import com.tencent.polaris.api.config.global.APIConfig;
@@ -76,9 +76,8 @@ public class PolarisRegistrationTest {
PolarisContextProperties polarisContextProperties = mock(PolarisContextProperties.class);
doReturn(testLocalPort).when(polarisContextProperties).getLocalPort();
- // mock ConsulContextProperties
- ConsulContextProperties consulContextProperties = mock(ConsulContextProperties.class);
- doReturn(true).when(consulContextProperties).isEnabled();
+ // mock ConsulDiscoveryProperties
+ ConsulDiscoveryProperties consulContextProperties = mock(ConsulDiscoveryProperties.class);
doReturn(true).when(consulContextProperties).isRegister();
// mock NacosContextProperties
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/tsf/ConditionalOnTsfConsulEnabled.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/tsf/ConditionalOnTsfConsulEnabled.java
new file mode 100644
index 000000000..2044bcb01
--- /dev/null
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/tsf/ConditionalOnTsfConsulEnabled.java
@@ -0,0 +1,63 @@
+/*
+ * 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.common.tsf;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import com.tencent.polaris.api.utils.StringUtils;
+
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.core.env.Environment;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+/**
+ * Condition that if Polaris enabled.
+ *
+ * @author Haotian Zhang
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Conditional(ConditionalOnTsfConsulEnabled.OnTsfEnabledCondition.class)
+public @interface ConditionalOnTsfConsulEnabled {
+
+ class OnTsfEnabledCondition implements Condition {
+
+ @Override
+ public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
+ Environment environment = conditionContext.getEnvironment();
+ boolean tsfConsulEnable = false;
+
+ String tsfAppId = environment.getProperty("tsf_app_id", "");
+ if (StringUtils.isNotBlank(tsfAppId)) {
+ String tsfConsulIp = environment.getProperty("tsf_consul_ip");
+ String tsePolarisAddress = environment.getProperty("spring.cloud.polaris.address");
+ if (StringUtils.isBlank(tsePolarisAddress) && StringUtils.isNotBlank(environment.getProperty("tse_polaris_ip"))) {
+ tsePolarisAddress = "grpc://" + environment.getProperty("tse_polaris_ip") + ":8091";
+ }
+ tsfConsulEnable = StringUtils.isNotBlank(tsfConsulIp) && StringUtils.isBlank(tsePolarisAddress);
+ }
+
+ return tsfConsulEnable;
+ }
+ }
+}
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/AddressUtils.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/AddressUtils.java
index 3415cb799..880970499 100644
--- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/AddressUtils.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/AddressUtils.java
@@ -87,16 +87,6 @@ public final class AddressUtils {
return true;
}
- public static String getIpCompatible(String ip) {
- if (StringUtils.isEmpty(ip)) {
- return ip;
- }
- if (ip.contains(":") && !ip.startsWith("[") && !ip.endsWith("]")) {
- return "[" + ip + "]";
- }
- return ip;
- }
-
public static boolean preferIpv6() {
if (Boolean.FALSE.equals(hasIpv6Address)) {
LOGGER.debug("AddressUtils.preferIpv6 hasIpv6Address = false");
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/inet/PolarisInetUtilsAutoConfiguration.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/inet/PolarisInetUtilsAutoConfiguration.java
index b3b4655dc..4160d7bb1 100644
--- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/inet/PolarisInetUtilsAutoConfiguration.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/inet/PolarisInetUtilsAutoConfiguration.java
@@ -17,12 +17,12 @@
package com.tencent.cloud.common.util.inet;
-import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.commons.util.InetUtilsProperties;
+import org.springframework.cloud.commons.util.UtilAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
/**
@@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration;
* @author Haotian Zhang
*/
@Configuration(proxyBeanMethods = false)
-@ConditionalOnTsfEnabled
+@Import(UtilAutoConfiguration.class)
public class PolarisInetUtilsAutoConfiguration {
@Bean
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java
index 9f923950a..a3dac5adb 100644
--- a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java
@@ -61,7 +61,7 @@ public class QuickstartCalleeController {
@Autowired
private DataSourceProperties dataSourceProperties;
private boolean ifBadGateway = true;
- private boolean ifDelay = true;
+ private boolean ifDelay = false;
/**
* Get sum of two value.
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java
index 1dbd829a3..837b5ec0c 100644
--- a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java
@@ -17,6 +17,7 @@
package com.tencent.cloud.quickstart.caller.circuitbreaker;
+import com.tencent.cloud.common.metadata.MetadataContext;
import reactor.core.publisher.Mono;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +29,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient;
@@ -110,7 +113,7 @@ public class CircuitBreakerController {
@GetMapping("/rest")
public String circuitBreakRestTemplate() {
return circuitBreakerFactory
- .create("QuickstartCalleeService#/quickstart/callee/circuitBreak")
+ .create(MetadataContext.LOCAL_NAMESPACE + "#QuickstartCalleeService#/quickstart/callee/circuitBreak#http#GET")
.run(() -> defaultRestTemplate.getForObject("/quickstart/callee/circuitBreak", String.class),
throwable -> "trigger the refuse for service callee."
);
@@ -142,7 +145,12 @@ public class CircuitBreakerController {
*/
@GetMapping("/rest/fallbackFromPolaris")
public ResponseEntity circuitBreakRestTemplateFallbackFromPolaris() {
- return restTemplateFallbackFromPolaris.getForEntity("/quickstart/callee/circuitBreak", String.class);
+ try {
+ return restTemplateFallbackFromPolaris.getForEntity("/quickstart/callee/circuitBreak", String.class);
+ }
+ catch (HttpClientErrorException | HttpServerErrorException httpClientErrorException) {
+ return new ResponseEntity<>(httpClientErrorException.getResponseBodyAsString(), httpClientErrorException.getStatusCode());
+ }
}
/**
@@ -151,7 +159,12 @@ public class CircuitBreakerController {
*/
@GetMapping("/rest/fallbackFromCode")
public ResponseEntity circuitBreakRestTemplateFallbackFromCode() {
- return restTemplateFallbackFromCode.getForEntity("/quickstart/callee/circuitBreak", String.class);
+ try {
+ return restTemplateFallbackFromCode.getForEntity("/quickstart/callee/circuitBreak", String.class);
+ }
+ catch (HttpClientErrorException | HttpServerErrorException httpClientErrorException) {
+ return new ResponseEntity<>(httpClientErrorException.getResponseBodyAsString(), httpClientErrorException.getStatusCode());
+ }
}
/**
@@ -168,7 +181,7 @@ public class CircuitBreakerController {
.bodyToMono(String.class)
.transform(it ->
reactiveCircuitBreakerFactory
- .create("QuickstartCalleeService#/quickstart/callee/circuitBreak")
+ .create(MetadataContext.LOCAL_NAMESPACE + "QuickstartCalleeService#/quickstart/callee/circuitBreak#http#GET")
.run(it, throwable -> Mono.just("fallback: trigger the refuse for service callee"))
);
}
diff --git a/spring-cloud-tencent-examples/tsf-example/consumer-demo/pom.xml b/spring-cloud-tencent-examples/tsf-example/consumer-demo/pom.xml
index 968784284..44abeeb31 100644
--- a/spring-cloud-tencent-examples/tsf-example/consumer-demo/pom.xml
+++ b/spring-cloud-tencent-examples/tsf-example/consumer-demo/pom.xml
@@ -32,6 +32,11 @@
spring-cloud-starter-tencent-polaris-router