feat:upgrade api circuit breaker. (#1438)
* feat:upgrade api circuit breaker. * update CHANGELOG. * feat:upgrade api circuit breaker. * update junit test.pull/1447/head
parent
b82ff9e08d
commit
c5f318d1d0
@ -1,37 +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.config.tsf;
|
||||
|
||||
import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
|
||||
import com.tencent.cloud.polaris.config.ConditionalOnPolarisConfigEnabled;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author juanyinyang
|
||||
* @Date Jul 23, 2023 3:52:48 PM
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty("spring.cloud.polaris.enabled")
|
||||
@ConditionalOnTsfEnabled
|
||||
@ConditionalOnPolarisConfigEnabled
|
||||
public class PolarisAdaptorTsfConfigBootstrapConfiguration {
|
||||
|
||||
|
||||
}
|
@ -1,78 +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.config.tsf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.tencent.cloud.common.constant.OrderConstant;
|
||||
import com.tencent.cloud.polaris.config.config.ConfigFileGroup;
|
||||
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
|
||||
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
|
||||
import com.tencent.cloud.polaris.context.tsf.config.TsfCoreProperties;
|
||||
import com.tencent.cloud.polaris.context.tsf.consul.TsfConsulProperties;
|
||||
import com.tencent.polaris.factory.config.ConfigurationImpl;
|
||||
|
||||
/**
|
||||
* TSF config modifier.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
public class TsfConfigurationModifier implements PolarisConfigModifier {
|
||||
|
||||
|
||||
private final TsfCoreProperties tsfCoreProperties;
|
||||
|
||||
private final TsfConsulProperties tsfConsulProperties;
|
||||
|
||||
private final PolarisConfigProperties polarisConfigProperties;
|
||||
|
||||
public TsfConfigurationModifier(TsfCoreProperties tsfCoreProperties, TsfConsulProperties tsfConsulProperties, PolarisConfigProperties polarisConfigProperties) {
|
||||
this.tsfCoreProperties = tsfCoreProperties;
|
||||
this.tsfConsulProperties = tsfConsulProperties;
|
||||
this.polarisConfigProperties = polarisConfigProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modify(ConfigurationImpl configuration) {
|
||||
if (polarisConfigProperties != null && tsfCoreProperties != null) {
|
||||
polarisConfigProperties.setEnabled(true);
|
||||
if (!tsfCoreProperties.isTsePolarisEnable()) {
|
||||
polarisConfigProperties.setDataSource("consul");
|
||||
polarisConfigProperties.setAddress("http://" + tsfConsulProperties.getHost() + ":" + tsfConsulProperties.getPort());
|
||||
polarisConfigProperties.setPort(tsfConsulProperties.getPort());
|
||||
polarisConfigProperties.setToken(tsfConsulProperties.getAclToken());
|
||||
List<ConfigFileGroup> groups = new ArrayList<>();
|
||||
polarisConfigProperties.setGroups(groups);
|
||||
groups.clear();
|
||||
ConfigFileGroup tsfGroup = new ConfigFileGroup();
|
||||
tsfGroup.setNamespace("config");
|
||||
tsfGroup.setName("application");
|
||||
List<String> files = new ArrayList<>();
|
||||
tsfGroup.setFiles(files);
|
||||
files.add(tsfCoreProperties.getTsfNamespaceId() + "/");
|
||||
files.add(tsfCoreProperties.getTsfApplicationId() + "/" + tsfCoreProperties.getTsfGroupId() + "/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return OrderConstant.Modifier.CONFIG_ORDER - 1;
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
com.tencent.cloud.polaris.config.tsf.adaptor.PolarisAdaptorTsfConfigExtensionLayer
|
@ -1,26 +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.contract.config;
|
||||
|
||||
/**
|
||||
* Extend contract properties.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
public interface ExtendedContractProperties extends ContractProperties {
|
||||
}
|
@ -1,136 +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.contract.tsf;
|
||||
|
||||
import com.tencent.cloud.polaris.contract.config.ExtendedContractProperties;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Properties for TSF contract.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
@ConfigurationProperties("tsf.swagger")
|
||||
public class TsfContractProperties implements ExtendedContractProperties {
|
||||
|
||||
@Value("${tsf.swagger.basePackage:}")
|
||||
private String basePackage;
|
||||
|
||||
@Value("${tsf.swagger.excludePath:}")
|
||||
private String excludePath;
|
||||
|
||||
@Value("${tsf.swagger.enabled:true}")
|
||||
private boolean enabled;
|
||||
|
||||
@Value("${tsf.swagger.group:polaris}")
|
||||
private String groupName;
|
||||
|
||||
@Value("${tsf.swagger.basePath:/**}")
|
||||
private String basePath;
|
||||
|
||||
@Value("${tsf.swagger.doc.auto-startup:true}")
|
||||
private boolean exposure;
|
||||
|
||||
/**
|
||||
* applicationId 应用Id.
|
||||
*/
|
||||
@Value("${tsf_application_id:}")
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasePackage() {
|
||||
return basePackage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBasePackage(String basePackage) {
|
||||
this.basePackage = basePackage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExcludePath() {
|
||||
return excludePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExcludePath(String excludePath) {
|
||||
this.excludePath = excludePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroup(String group) {
|
||||
this.groupName = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExposure() {
|
||||
return exposure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExposure(boolean exposure) {
|
||||
this.exposure = exposure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReportEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReportEnabled(boolean reportEnabled) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -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.contract.tsf;
|
||||
|
||||
import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Auto configuration for TSF contract properties.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnTsfEnabled
|
||||
public class TsfContractPropertiesAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public TsfContractProperties tsfContractProperties() {
|
||||
return new TsfContractProperties();
|
||||
}
|
||||
}
|
@ -1,35 +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.contract.tsf;
|
||||
|
||||
import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* Bootstrap configuration for TSF contract properties.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnTsfEnabled
|
||||
@Import(TsfContractPropertiesAutoConfiguration.class)
|
||||
public class TsfContractPropertiesBootstrapConfiguration {
|
||||
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesBootstrapConfiguration,\
|
||||
com.tencent.cloud.polaris.contract.tsf.TsfContractPropertiesBootstrapConfiguration
|
||||
com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesBootstrapConfiguration
|
||||
org.springframework.context.ApplicationListener=\
|
||||
com.tencent.cloud.polaris.contract.PolarisSwaggerApplicationListener
|
||||
|
@ -1,4 +1,3 @@
|
||||
com.tencent.cloud.polaris.contract.config.PolarisSwaggerAutoConfiguration
|
||||
com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesAutoConfiguration
|
||||
com.tencent.cloud.polaris.contract.tsf.TsfContractPropertiesAutoConfiguration
|
||||
com.tencent.cloud.polaris.contract.tsf.TsfSwaggerAutoConfiguration
|
||||
|
@ -1,120 +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.extend.consul;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import com.tencent.cloud.common.constant.OrderConstant;
|
||||
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
|
||||
import com.tencent.polaris.api.config.plugin.DefaultPlugins;
|
||||
import com.tencent.polaris.factory.config.ConfigurationImpl;
|
||||
import com.tencent.polaris.factory.config.consumer.DiscoveryConfigImpl;
|
||||
import com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl;
|
||||
import com.tencent.polaris.factory.config.provider.RegisterConfigImpl;
|
||||
import com.tencent.polaris.plugins.connector.common.constant.ConsulConstant;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* @author lingxiao.wlx
|
||||
*/
|
||||
public class ConsulConfigModifier implements PolarisConfigModifier {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConsulConfigModifier.class);
|
||||
|
||||
private static final String ID = "consul";
|
||||
|
||||
private final ConsulContextProperties consulContextProperties;
|
||||
|
||||
public ConsulConfigModifier(ConsulContextProperties consulContextProperties) {
|
||||
this.consulContextProperties = consulContextProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modify(ConfigurationImpl configuration) {
|
||||
if (consulContextProperties != null && consulContextProperties.isEnabled()) {
|
||||
// Check if Consul client Available
|
||||
boolean consulAvailable = false;
|
||||
try {
|
||||
consulAvailable = null != Class.forName("com.ecwid.consul.v1.ConsulClient");
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
|
||||
}
|
||||
if (!consulAvailable) {
|
||||
LOGGER.error("Please import \"connector-consul\" dependency when enabling consul service registration and discovery.\n"
|
||||
+ "Add dependency configuration below to pom.xml:\n"
|
||||
+ "<dependency>\n"
|
||||
+ "\t<groupId>com.tencent.polaris</groupId>\n"
|
||||
+ "\t<artifactId>connector-consul</artifactId>\n"
|
||||
+ "</dependency>");
|
||||
throw new RuntimeException("Dependency \"connector-consul\" not found.");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(configuration.getGlobal().getServerConnectors())) {
|
||||
configuration.getGlobal().setServerConnectors(new ArrayList<>());
|
||||
}
|
||||
if (CollectionUtils.isEmpty(configuration.getGlobal().getServerConnectors())
|
||||
&& null != configuration.getGlobal().getServerConnector()) {
|
||||
configuration.getGlobal().getServerConnectors().add(configuration.getGlobal().getServerConnector());
|
||||
}
|
||||
ServerConnectorConfigImpl serverConnectorConfig = new ServerConnectorConfigImpl();
|
||||
serverConnectorConfig.setId(ID);
|
||||
serverConnectorConfig.setAddresses(
|
||||
Collections.singletonList(consulContextProperties.getHost() + ":" + consulContextProperties.getPort()));
|
||||
serverConnectorConfig.setProtocol(DefaultPlugins.SERVER_CONNECTOR_CONSUL);
|
||||
Map<String, String> metadata = serverConnectorConfig.getMetadata();
|
||||
if (StringUtils.isNotBlank(consulContextProperties.getServiceName())) {
|
||||
metadata.put(ConsulConstant.MetadataMapKey.SERVICE_NAME_KEY, consulContextProperties.getServiceName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(consulContextProperties.getInstanceId())) {
|
||||
metadata.put(ConsulConstant.MetadataMapKey.INSTANCE_ID_KEY, consulContextProperties.getInstanceId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(consulContextProperties.getAclToken())) {
|
||||
serverConnectorConfig.setToken(consulContextProperties.getAclToken());
|
||||
}
|
||||
if (consulContextProperties.isPreferIpAddress()
|
||||
&& StringUtils.isNotBlank(consulContextProperties.getIpAddress())) {
|
||||
metadata.put(ConsulConstant.MetadataMapKey.PREFER_IP_ADDRESS_KEY,
|
||||
String.valueOf(consulContextProperties.isPreferIpAddress()));
|
||||
metadata.put(ConsulConstant.MetadataMapKey.IP_ADDRESS_KEY, consulContextProperties.getIpAddress());
|
||||
}
|
||||
configuration.getGlobal().getServerConnectors().add(serverConnectorConfig);
|
||||
|
||||
DiscoveryConfigImpl discoveryConfig = new DiscoveryConfigImpl();
|
||||
discoveryConfig.setServerConnectorId(ID);
|
||||
discoveryConfig.setEnable(consulContextProperties.isDiscoveryEnabled());
|
||||
configuration.getConsumer().getDiscoveries().add(discoveryConfig);
|
||||
|
||||
RegisterConfigImpl registerConfig = new RegisterConfigImpl();
|
||||
registerConfig.setServerConnectorId(ID);
|
||||
registerConfig.setEnable(consulContextProperties.isRegister());
|
||||
configuration.getProvider().getRegisters().add(registerConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return OrderConstant.Modifier.CONSUL_DISCOVERY_CONFIG_ORDER;
|
||||
}
|
||||
}
|
@ -1,140 +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.extend.consul;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Discovery configuration of Consul.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
@ConfigurationProperties("spring.cloud.consul")
|
||||
public class ConsulContextProperties {
|
||||
|
||||
/**
|
||||
* Host of consul(or consul agent).
|
||||
*/
|
||||
private String host;
|
||||
|
||||
private int port;
|
||||
|
||||
private boolean enabled = false;
|
||||
|
||||
@Value("${spring.cloud.consul.discovery.register:#{'true'}}")
|
||||
private boolean register;
|
||||
|
||||
@Value("${spring.cloud.consul.discovery.enabled:#{'true'}}")
|
||||
private boolean discoveryEnabled;
|
||||
|
||||
@Value("${spring.cloud.consul.discovery.instance-id:}")
|
||||
private String instanceId;
|
||||
|
||||
@Value("${spring.cloud.consul.discovery.service-name:${spring.application.name:}}")
|
||||
private String serviceName;
|
||||
|
||||
@Value("${spring.cloud.consul.discovery.ip-address:}")
|
||||
private String ipAddress;
|
||||
|
||||
@Value("${spring.cloud.consul.discovery.prefer-ip-address:#{'false'}}")
|
||||
private boolean preferIpAddress;
|
||||
|
||||
@Value("${consul.token:${CONSUL_TOKEN:${spring.cloud.consul.token:${SPRING_CLOUD_CONSUL_TOKEN:${spring.cloud.consul.discovery.acl-token:}}}}}")
|
||||
private String aclToken;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isRegister() {
|
||||
return register;
|
||||
}
|
||||
|
||||
public void setRegister(boolean register) {
|
||||
this.register = register;
|
||||
}
|
||||
|
||||
public boolean isDiscoveryEnabled() {
|
||||
return discoveryEnabled;
|
||||
}
|
||||
|
||||
public void setDiscoveryEnabled(boolean discoveryEnabled) {
|
||||
this.discoveryEnabled = discoveryEnabled;
|
||||
}
|
||||
|
||||
public String getInstanceId() {
|
||||
return instanceId;
|
||||
}
|
||||
|
||||
public void setInstanceId(String instanceId) {
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
public void setIpAddress(String ipAddress) {
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
public boolean isPreferIpAddress() {
|
||||
return preferIpAddress;
|
||||
}
|
||||
|
||||
public void setPreferIpAddress(boolean preferIpAddress) {
|
||||
this.preferIpAddress = preferIpAddress;
|
||||
}
|
||||
|
||||
public String getAclToken() {
|
||||
return aclToken;
|
||||
}
|
||||
|
||||
public void setAclToken(String aclToken) {
|
||||
this.aclToken = aclToken;
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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.extend.consul;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import com.tencent.cloud.common.constant.OrderConstant;
|
||||
import com.tencent.cloud.common.util.JacksonUtils;
|
||||
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
|
||||
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
|
||||
import com.tencent.cloud.polaris.context.config.extend.consul.ConsulProperties;
|
||||
import com.tencent.cloud.polaris.context.config.extend.tsf.TsfCoreProperties;
|
||||
import com.tencent.polaris.api.config.plugin.DefaultPlugins;
|
||||
import com.tencent.polaris.api.utils.StringUtils;
|
||||
import com.tencent.polaris.factory.config.ConfigurationImpl;
|
||||
import com.tencent.polaris.factory.config.consumer.DiscoveryConfigImpl;
|
||||
import com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl;
|
||||
import com.tencent.polaris.factory.config.provider.RegisterConfigImpl;
|
||||
import com.tencent.polaris.plugins.connector.common.constant.ConsulConstant;
|
||||
import io.micrometer.common.lang.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Modifier for Consul discovery.
|
||||
*
|
||||
* @author lingxiao.wlx, Haotian Zhang
|
||||
*/
|
||||
public class ConsulDiscoveryConfigModifier implements PolarisConfigModifier {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConsulDiscoveryConfigModifier.class);
|
||||
|
||||
private final PolarisDiscoveryProperties polarisDiscoveryProperties;
|
||||
|
||||
private final ConsulProperties consulProperties;
|
||||
|
||||
private final ConsulDiscoveryProperties consulDiscoveryProperties;
|
||||
|
||||
private final ConsulHeartbeatProperties consulHeartbeatProperties;
|
||||
|
||||
private final ApplicationContext context;
|
||||
|
||||
private final TsfCoreProperties tsfCoreProperties;
|
||||
|
||||
public ConsulDiscoveryConfigModifier(PolarisDiscoveryProperties polarisDiscoveryProperties, ConsulProperties consulProperties,
|
||||
ConsulDiscoveryProperties consulDiscoveryProperties, ConsulHeartbeatProperties consulHeartbeatProperties,
|
||||
@Nullable TsfCoreProperties tsfCoreProperties, ApplicationContext context) {
|
||||
this.polarisDiscoveryProperties = polarisDiscoveryProperties;
|
||||
this.consulProperties = consulProperties;
|
||||
this.consulDiscoveryProperties = consulDiscoveryProperties;
|
||||
this.consulHeartbeatProperties = consulHeartbeatProperties;
|
||||
this.tsfCoreProperties = tsfCoreProperties;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modify(ConfigurationImpl configuration) {
|
||||
// init server connectors.
|
||||
if (CollectionUtils.isEmpty(configuration.getGlobal().getServerConnectors())) {
|
||||
configuration.getGlobal().setServerConnectors(new ArrayList<>());
|
||||
}
|
||||
|
||||
// init consul connector.
|
||||
ServerConnectorConfigImpl serverConnectorConfig = new ServerConnectorConfigImpl();
|
||||
serverConnectorConfig.setId(ConsulDiscoveryUtil.ID);
|
||||
serverConnectorConfig.setAddresses(
|
||||
Collections.singletonList(consulProperties.getHost() + ":" + consulProperties.getPort()));
|
||||
LOGGER.info("Will register to consul server: [" + consulProperties.getHost() + ":" + consulProperties.getPort() + "]");
|
||||
serverConnectorConfig.setProtocol(DefaultPlugins.SERVER_CONNECTOR_CONSUL);
|
||||
// set consul connector metadata.
|
||||
Map<String, String> metadata = serverConnectorConfig.getMetadata();
|
||||
// namespace
|
||||
if (StringUtils.isNotBlank(polarisDiscoveryProperties.getNamespace())) {
|
||||
metadata.put(ConsulConstant.MetadataMapKey.NAMESPACE_KEY, polarisDiscoveryProperties.getNamespace());
|
||||
}
|
||||
// service name
|
||||
String appName = ConsulDiscoveryUtil.getAppName(consulDiscoveryProperties, context.getEnvironment());
|
||||
if (StringUtils.isNotBlank(appName)) {
|
||||
metadata.put(ConsulConstant.MetadataMapKey.SERVICE_NAME_KEY, ConsulDiscoveryUtil.normalizeForDns(appName));
|
||||
}
|
||||
// instance ID
|
||||
String instanceId = ConsulDiscoveryUtil.getInstanceId(consulDiscoveryProperties, context);
|
||||
if (StringUtils.isNotBlank(instanceId)) {
|
||||
metadata.put(ConsulConstant.MetadataMapKey.INSTANCE_ID_KEY, instanceId);
|
||||
}
|
||||
// token
|
||||
if (StringUtils.isNotBlank(consulProperties.getAclToken())) {
|
||||
serverConnectorConfig.setToken(consulProperties.getAclToken());
|
||||
}
|
||||
// default query tag
|
||||
if (StringUtils.isNotBlank(consulDiscoveryProperties.getDefaultQueryTag())) {
|
||||
metadata.put(ConsulConstant.MetadataMapKey.QUERY_TAG_KEY, consulDiscoveryProperties.getDefaultQueryTag());
|
||||
}
|
||||
// query passing
|
||||
metadata.put(ConsulConstant.MetadataMapKey.QUERY_PASSING_KEY, String.valueOf(consulDiscoveryProperties.isQueryPassing()));
|
||||
// prefer ip address
|
||||
if (consulDiscoveryProperties.isPreferIpAddress()
|
||||
&& StringUtils.isNotBlank(consulDiscoveryProperties.getIpAddress())) {
|
||||
metadata.put(ConsulConstant.MetadataMapKey.PREFER_IP_ADDRESS_KEY,
|
||||
String.valueOf(consulDiscoveryProperties.isPreferIpAddress()));
|
||||
metadata.put(ConsulConstant.MetadataMapKey.IP_ADDRESS_KEY, consulDiscoveryProperties.getIpAddress());
|
||||
}
|
||||
// is not prefer agent address
|
||||
if (!consulDiscoveryProperties.isPreferAgentAddress()) {
|
||||
metadata.put(ConsulConstant.MetadataMapKey.PREFER_IP_ADDRESS_KEY,
|
||||
String.valueOf(consulDiscoveryProperties.isPreferIpAddress()));
|
||||
metadata.put(ConsulConstant.MetadataMapKey.IP_ADDRESS_KEY, consulDiscoveryProperties.getHostname());
|
||||
}
|
||||
if (tsfCoreProperties != null) {
|
||||
// tags
|
||||
metadata.put(ConsulConstant.MetadataMapKey.TAGS_KEY, JacksonUtils.serialize2Json(tsfCoreProperties.getTsfTags()));
|
||||
}
|
||||
configuration.getGlobal().getServerConnectors().add(serverConnectorConfig);
|
||||
|
||||
// discovery
|
||||
DiscoveryConfigImpl discoveryConfig = new DiscoveryConfigImpl();
|
||||
discoveryConfig.setServerConnectorId(ConsulDiscoveryUtil.ID);
|
||||
discoveryConfig.setEnable(consulDiscoveryProperties.isEnabled());
|
||||
configuration.getConsumer().getDiscoveries().add(discoveryConfig);
|
||||
|
||||
// register
|
||||
RegisterConfigImpl registerConfig = new RegisterConfigImpl();
|
||||
registerConfig.setServerConnectorId(ConsulDiscoveryUtil.ID);
|
||||
registerConfig.setEnable(consulDiscoveryProperties.isRegister());
|
||||
configuration.getProvider().getRegisters().add(registerConfig);
|
||||
|
||||
// heartbeat
|
||||
polarisDiscoveryProperties.setHeartbeatInterval(Long.valueOf(
|
||||
consulHeartbeatProperties.computeHeartbeatInterval().toStandardDuration().getMillis()).intValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return OrderConstant.Modifier.CONSUL_DISCOVERY_CONFIG_ORDER;
|
||||
}
|
||||
}
|
@ -0,0 +1,679 @@
|
||||
/*
|
||||
* 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.extend.consul;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ecwid.consul.v1.ConsistencyMode;
|
||||
import com.tencent.cloud.common.util.inet.PolarisInetUtils;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.commons.util.InetUtils.HostInfo;
|
||||
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Copy from org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.
|
||||
* Defines configuration for service discovery and registration.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @author Donnabell Dmello
|
||||
* @author Venil Noronha
|
||||
* @author Richard Kettelerij
|
||||
*/
|
||||
@ConfigurationProperties(ConsulDiscoveryProperties.PREFIX)
|
||||
public class ConsulDiscoveryProperties {
|
||||
|
||||
/**
|
||||
* Consul discovery properties prefix.
|
||||
*/
|
||||
public static final String PREFIX = "spring.cloud.consul.discovery";
|
||||
|
||||
protected static final String MANAGEMENT = "management";
|
||||
|
||||
private HostInfo hostInfo;
|
||||
|
||||
/** Tags to use when registering service. */
|
||||
private List<String> tags = new ArrayList<>();
|
||||
|
||||
/** Metadata to use when registering service. */
|
||||
private Map<String, String> metadata = new LinkedHashMap<>();
|
||||
|
||||
/** Enable tag override for the registered service. */
|
||||
private Boolean enableTagOverride;
|
||||
|
||||
/** Is service discovery enabled? */
|
||||
private boolean enabled = true;
|
||||
|
||||
/** Tags to use when registering management service. */
|
||||
private List<String> managementTags = new ArrayList<>();
|
||||
|
||||
/** Enable tag override for the registered management service. */
|
||||
private Boolean managementEnableTagOverride;
|
||||
|
||||
/** Metadata to use when registering management service. */
|
||||
private Map<String, String> managementMetadata;
|
||||
|
||||
/** Alternate server path to invoke for health checking. */
|
||||
private String healthCheckPath = "/actuator/health";
|
||||
|
||||
/** Custom health check url to override default. */
|
||||
private String healthCheckUrl;
|
||||
|
||||
/** Headers to be applied to the Health Check calls. */
|
||||
private Map<String, List<String>> healthCheckHeaders = new HashMap<>();
|
||||
|
||||
/** 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. */
|
||||
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;
|
||||
|
||||
/** Unique service instance id. */
|
||||
private String instanceId;
|
||||
|
||||
/** Service instance zone. */
|
||||
private String instanceZone;
|
||||
|
||||
/** Service instance group. */
|
||||
private String instanceGroup;
|
||||
|
||||
/**
|
||||
* Whether hostname is included into the default instance id when registering service.
|
||||
*/
|
||||
private boolean includeHostnameInInstanceId = false;
|
||||
|
||||
/**
|
||||
* Consistency mode for health service request.
|
||||
*/
|
||||
private ConsistencyMode consistencyMode = ConsistencyMode.DEFAULT;
|
||||
|
||||
/**
|
||||
* Service instance zone comes from metadata. This allows changing the metadata tag
|
||||
* name.
|
||||
*/
|
||||
private String defaultZoneMetadataName = "zone";
|
||||
|
||||
/** Whether to register an http or https service. */
|
||||
private String scheme = "http";
|
||||
|
||||
/** 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 one more tags. Multiple tags can be specified with a comma separated
|
||||
* value.
|
||||
*/
|
||||
private Map<String, String> serverListQueryTags = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Map of serviceId's -> datacenter to query for in server list. This allows looking
|
||||
* up services in another datacenters.
|
||||
*/
|
||||
private Map<String, String> 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.
|
||||
* <p>
|
||||
* 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<String> getTags() {
|
||||
return this.tags;
|
||||
}
|
||||
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public boolean isEnableTagOverride() {
|
||||
return enableTagOverride;
|
||||
}
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public List<String> getManagementTags() {
|
||||
return this.managementTags;
|
||||
}
|
||||
|
||||
public void setManagementTags(List<String> 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<String, List<String>> getHealthCheckHeaders() {
|
||||
return this.healthCheckHeaders;
|
||||
}
|
||||
|
||||
public void setHealthCheckHeaders(Map<String, List<String>> 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<String, String> getServerListQueryTags() {
|
||||
return this.serverListQueryTags;
|
||||
}
|
||||
|
||||
public void setServerListQueryTags(Map<String, String> serverListQueryTags) {
|
||||
this.serverListQueryTags = serverListQueryTags;
|
||||
}
|
||||
|
||||
public Map<String, String> getDatacenters() {
|
||||
return this.datacenters;
|
||||
}
|
||||
|
||||
public void setDatacenters(Map<String, String> 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<String, String> getManagementMetadata() {
|
||||
return this.managementMetadata;
|
||||
}
|
||||
|
||||
public void setManagementMetadata(Map<String, String> 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 + '}';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,3 +1,2 @@
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration,\
|
||||
com.tencent.cloud.polaris.tsf.TsfDiscoveryPropertiesBootstrapConfiguration
|
||||
com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.config.extend.tsf;
|
||||
|
||||
import com.tencent.cloud.common.constant.OrderConstant;
|
||||
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
|
||||
import com.tencent.cloud.polaris.context.config.extend.consul.ConsulProperties;
|
||||
import com.tencent.polaris.api.config.plugin.DefaultPlugins;
|
||||
import com.tencent.polaris.factory.config.ConfigurationImpl;
|
||||
import com.tencent.polaris.plugins.event.tsf.TsfEventReporterConfig;
|
||||
|
||||
/**
|
||||
* Config modifier for TSF.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
public class TsfContextConfigModifier implements PolarisConfigModifier {
|
||||
|
||||
private final TsfCoreProperties tsfCoreProperties;
|
||||
|
||||
private final ConsulProperties consulProperties;
|
||||
|
||||
public TsfContextConfigModifier(TsfCoreProperties tsfCoreProperties, ConsulProperties consulProperties) {
|
||||
this.tsfCoreProperties = tsfCoreProperties;
|
||||
this.consulProperties = consulProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modify(ConfigurationImpl configuration) {
|
||||
configuration.getGlobal().getEventReporter().getReporters().add(DefaultPlugins.TSF_EVENT_REPORTER_TYPE);
|
||||
|
||||
TsfEventReporterConfig tsfEventReporterConfig = new TsfEventReporterConfig();
|
||||
tsfEventReporterConfig.setEventMasterIp(tsfCoreProperties.getEventMasterIp());
|
||||
tsfEventReporterConfig.setEventMasterPort(tsfCoreProperties.getEventMasterPort());
|
||||
tsfEventReporterConfig.setAppId(tsfCoreProperties.getAppId());
|
||||
tsfEventReporterConfig.setRegion(tsfCoreProperties.getTsfRegion());
|
||||
tsfEventReporterConfig.setInstanceId(tsfCoreProperties.getInstanceId());
|
||||
tsfEventReporterConfig.setTsfNamespaceId(tsfCoreProperties.getTsfNamespaceId());
|
||||
tsfEventReporterConfig.setServiceName(tsfCoreProperties.getServiceName());
|
||||
tsfEventReporterConfig.setToken(consulProperties.getAclToken());
|
||||
configuration.getGlobal().getEventReporter()
|
||||
.setPluginConfig(DefaultPlugins.TSF_EVENT_REPORTER_TYPE, tsfEventReporterConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return OrderConstant.Modifier.CIRCUIT_BREAKER_ORDER - 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* 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.config.extend.tsf;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.tencent.polaris.api.utils.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.boot.logging.DeferredLogFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
|
||||
/**
|
||||
* Read TSF env.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
public final class TsfCoreEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
|
||||
|
||||
/**
|
||||
* run before {@link ConfigDataEnvironmentPostProcessor}.
|
||||
*/
|
||||
public static final int ORDER = ConfigDataEnvironmentPostProcessor.ORDER - 1;
|
||||
|
||||
private final Log LOGGER;
|
||||
|
||||
private TsfCoreEnvironmentPostProcessor(DeferredLogFactory logFactory) {
|
||||
this.LOGGER = logFactory.getLog(getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return ORDER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
String tsfAppId = environment.getProperty("tsf_app_id");
|
||||
// TSF deploy
|
||||
if (StringUtils.isNotBlank(tsfAppId)) {
|
||||
Map<String, Object> defaultProperties = new HashMap<>();
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
// tsf_prog_version
|
||||
String tsfProgVersion = environment.getProperty("tsf_prog_version");
|
||||
if (StringUtils.isBlank(tsfProgVersion)) {
|
||||
LOGGER.error("tsf_prog_version is empty");
|
||||
}
|
||||
else {
|
||||
defaultProperties.put("spring.cloud.polaris.discovery.version", tsfProgVersion);
|
||||
}
|
||||
|
||||
// lossless
|
||||
defaultProperties.put("spring.cloud.polaris.lossless.enabled", true);
|
||||
defaultProperties.put("spring.cloud.polaris.lossless.port", environment.getProperty("tsf_sctt_extensions_port", "11134"));
|
||||
|
||||
// state
|
||||
defaultProperties.put("spring.cloud.polaris.stat.port", environment.getProperty("tsf_sctt_extensions_port", "11134"));
|
||||
|
||||
boolean tsfConsulEnable = StringUtils.isNotBlank(tsfConsulIp) && StringUtils.isBlank(tsePolarisAddress);
|
||||
if (tsfConsulEnable) {
|
||||
// tsf_consul_port
|
||||
String tsfConsulPort = environment.getProperty("tsf_consul_port");
|
||||
if (StringUtils.isBlank(tsfConsulPort)) {
|
||||
LOGGER.error("tsf_consul_port is empty");
|
||||
}
|
||||
// tsf_token
|
||||
String tsfConsulToken = environment.getProperty("tsf_token");
|
||||
if (StringUtils.isBlank(tsfConsulToken)) {
|
||||
LOGGER.error("tsf_token is empty");
|
||||
}
|
||||
// tsf_instance_id
|
||||
String tsfInstanceId = environment.getProperty("tsf_instance_id");
|
||||
if (StringUtils.isBlank(tsfInstanceId)) {
|
||||
LOGGER.error("tsf_instance_id is empty");
|
||||
}
|
||||
// tsf_application_id
|
||||
String tsfApplicationId = environment.getProperty("tsf_application_id");
|
||||
if (StringUtils.isBlank(tsfApplicationId)) {
|
||||
LOGGER.error("tsf_application_id is empty");
|
||||
}
|
||||
|
||||
// tsf_group_id
|
||||
String tsfGroupId = environment.getProperty("tsf_group_id");
|
||||
if (StringUtils.isBlank(tsfGroupId)) {
|
||||
LOGGER.error("tsf_group_id is empty");
|
||||
}
|
||||
|
||||
// tsf_namespace_id
|
||||
String tsfNamespaceId = environment.getProperty("tsf_namespace_id");
|
||||
if (StringUtils.isBlank(tsfNamespaceId)) {
|
||||
LOGGER.error("tsf_namespace_id is empty");
|
||||
}
|
||||
else {
|
||||
defaultProperties.put("spring.cloud.polaris.namespace", tsfNamespaceId);
|
||||
}
|
||||
|
||||
// context
|
||||
defaultProperties.put("spring.cloud.polaris.enabled", "true");
|
||||
defaultProperties.put("spring.cloud.polaris.discovery.enabled", "false");
|
||||
defaultProperties.put("spring.cloud.polaris.discovery.register", "false");
|
||||
defaultProperties.put("spring.cloud.consul.enabled", "true");
|
||||
defaultProperties.put("spring.cloud.consul.host", tsfConsulIp);
|
||||
defaultProperties.put("spring.cloud.consul.port", tsfConsulPort);
|
||||
defaultProperties.put("spring.cloud.consul.token", tsfConsulToken);
|
||||
|
||||
// discovery
|
||||
defaultProperties.put("spring.cloud.consul.discovery.enabled", "true");
|
||||
defaultProperties.put("spring.cloud.consul.discovery.register", "true");
|
||||
defaultProperties.put("spring.cloud.consul.discovery.instance-id", tsfInstanceId);
|
||||
defaultProperties.put("spring.cloud.polaris.discovery.instance-id", tsfInstanceId);
|
||||
defaultProperties.put("spring.cloud.polaris.discovery.zero-protection.enabled", "true");
|
||||
defaultProperties.put("spring.cloud.polaris.discovery.zero-protection.is-need-test-connectivity", "true");
|
||||
defaultProperties.put("spring.cloud.discovery.client.health-indicator.enabled", "false");
|
||||
|
||||
// contract
|
||||
defaultProperties.put("spring.cloud.polaris.contract.enabled", environment.getProperty("tsf.swagger.enabled", "true"));
|
||||
if (StringUtils.isNotBlank(environment.getProperty("tsf.swagger.basePackage"))) {
|
||||
defaultProperties.put("spring.cloud.polaris.contract.base-package", environment.getProperty("tsf.swagger.basePackage"));
|
||||
}
|
||||
if (StringUtils.isNotBlank(environment.getProperty("tsf.swagger.excludePath"))) {
|
||||
defaultProperties.put("spring.cloud.polaris.contract.exclude-path", environment.getProperty("tsf.swagger.excludePath"));
|
||||
}
|
||||
defaultProperties.put("spring.cloud.polaris.contract.group", environment.getProperty("tsf.swagger.group", "polaris"));
|
||||
defaultProperties.put("spring.cloud.polaris.contract.base-path", environment.getProperty("tsf.swagger.basePath", "/**"));
|
||||
defaultProperties.put("spring.cloud.polaris.contract.exposure", environment.getProperty("tsf.swagger.doc.auto-startup", "true"));
|
||||
defaultProperties.put("spring.cloud.polaris.contract.report.enabled", environment.getProperty("tsf.swagger.enabled", "true"));
|
||||
defaultProperties.put("spring.cloud.polaris.contract.name", tsfApplicationId);
|
||||
|
||||
// configuration
|
||||
defaultProperties.put("spring.cloud.polaris.config.enabled", "true");
|
||||
defaultProperties.put("spring.cloud.polaris.config.internal-enabled", "false");
|
||||
defaultProperties.put("spring.cloud.polaris.config.data-source", "consul");
|
||||
defaultProperties.put("spring.cloud.polaris.config.address", "http://" + tsfConsulIp + ":" + tsfConsulPort);
|
||||
defaultProperties.put("spring.cloud.polaris.config.port", tsfConsulPort);
|
||||
defaultProperties.put("spring.cloud.polaris.config.token", tsfConsulToken);
|
||||
defaultProperties.put("spring.cloud.polaris.config.groups[0].namespace", "config");
|
||||
defaultProperties.put("spring.cloud.polaris.config.groups[0].name", "application");
|
||||
defaultProperties.put("spring.cloud.polaris.config.groups[0].files[0]", tsfApplicationId + "/" + tsfGroupId + "/");
|
||||
defaultProperties.put("spring.cloud.polaris.config.groups[0].files[1]", tsfNamespaceId + "/");
|
||||
defaultProperties.put("spring.cloud.polaris.config.refresh-type", "refresh_context");
|
||||
|
||||
// router
|
||||
defaultProperties.put("spring.cloud.polaris.router.rule-router.fail-over", "none");
|
||||
defaultProperties.put("spring.cloud.polaris.router.namespace-router.enabled", "true");
|
||||
}
|
||||
|
||||
MapPropertySource propertySource = new MapPropertySource("tsf-polaris-properties", defaultProperties);
|
||||
environment.getPropertySources().addFirst(propertySource);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,80 +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.tsf;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.tencent.cloud.common.util.inet.PolarisInetUtils;
|
||||
import com.tencent.cloud.polaris.context.tsf.config.TsfCoreProperties;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
public final class TsfUtils {
|
||||
|
||||
/**
|
||||
* IPV4.
|
||||
*/
|
||||
public static String TSF_ADDRESS_IPV4 = "TSF_ADDRESS_IPV4";
|
||||
|
||||
/**
|
||||
* IPV6.
|
||||
*/
|
||||
public static String TSF_ADDRESS_IPV6 = "TSF_ADDRESS_IPV6";
|
||||
|
||||
private TsfUtils() {
|
||||
}
|
||||
|
||||
public static List<String> createTags(TsfCoreProperties properties) {
|
||||
List<String> tags = new LinkedList<>(properties.getTags());
|
||||
|
||||
if (StringUtils.hasText(properties.getInstanceZone())) {
|
||||
tags.add(properties.getDefaultZoneMetadataName() + "=" + properties.getInstanceZone());
|
||||
}
|
||||
if (StringUtils.hasText(properties.getInstanceGroup())) {
|
||||
tags.add("group=" + properties.getInstanceGroup());
|
||||
}
|
||||
|
||||
//store the secure flag in the tags so that clients will be able to figure out whether to use http or https automatically
|
||||
tags.add("secure=" + properties.getScheme().equalsIgnoreCase("https"));
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
public static Map<String, String> appendMetaIpAddress(Map<String, String> meta) {
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
String ipv4Address = PolarisInetUtils.getIpString(false);
|
||||
if (ipv4Address != null) {
|
||||
meta.put(TSF_ADDRESS_IPV4, ipv4Address);
|
||||
}
|
||||
|
||||
String ipv6Address = PolarisInetUtils.getIpString(true);
|
||||
if (ipv6Address != null) {
|
||||
meta.put(TSF_ADDRESS_IPV6, ipv6Address);
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
}
|
@ -1,27 +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.tsf.consul;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import({TsfConsulAutoConfiguration.class})
|
||||
public class TsfConsulBootstrapConfiguration {
|
||||
|
||||
}
|
@ -1,138 +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.tsf.env;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.tencent.polaris.api.utils.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.boot.logging.DeferredLogFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
|
||||
/**
|
||||
* Read TSF env.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
public final class TsfCoreEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
|
||||
|
||||
/**
|
||||
* run before {@link ConfigDataEnvironmentPostProcessor}.
|
||||
*/
|
||||
public static final int ORDER = ConfigDataEnvironmentPostProcessor.ORDER - 1;
|
||||
|
||||
private final Log LOGGER;
|
||||
|
||||
private TsfCoreEnvironmentPostProcessor(DeferredLogFactory logFactory) {
|
||||
this.LOGGER = logFactory.getLog(getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return ORDER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
String tsfAppId = environment.getProperty("tsf_app_id");
|
||||
if (StringUtils.isNotBlank(tsfAppId)) {
|
||||
Map<String, Object> defaultProperties = new HashMap<>();
|
||||
// enable polaris as default
|
||||
defaultProperties.put("spring.cloud.polaris.enabled", "true");
|
||||
// tsf_application_id
|
||||
String tsfApplicationId = environment.getProperty("tsf_application_id");
|
||||
if (StringUtils.isBlank(tsfApplicationId)) {
|
||||
LOGGER.error("tsf_application_id is empty");
|
||||
}
|
||||
|
||||
// tsf_group_id
|
||||
String tsfGroupId = environment.getProperty("tsf_group_id");
|
||||
if (StringUtils.isBlank(tsfGroupId)) {
|
||||
LOGGER.error("tsf_group_id is empty");
|
||||
}
|
||||
|
||||
// tsf_namespace_id
|
||||
String tsfNamespaceId = environment.getProperty("tsf_namespace_id");
|
||||
if (StringUtils.isBlank(tsfNamespaceId)) {
|
||||
LOGGER.error("tsf_namespace_id is empty");
|
||||
}
|
||||
else {
|
||||
defaultProperties.put("spring.cloud.polaris.namespace", tsfNamespaceId);
|
||||
}
|
||||
|
||||
// tsf_consul_ip
|
||||
String tsfConsulIp = environment.getProperty("tsf_consul_ip");
|
||||
if (StringUtils.isBlank(tsfConsulIp)) {
|
||||
LOGGER.error("tsf_consul_ip is empty");
|
||||
}
|
||||
|
||||
// tsf_consul_port
|
||||
String tsfConsulPort = environment.getProperty("tsf_consul_port");
|
||||
if (StringUtils.isBlank(tsfConsulPort)) {
|
||||
LOGGER.error("tsf_consul_port is empty");
|
||||
}
|
||||
|
||||
// tsf_token
|
||||
String tsfConsulToken = environment.getProperty("tsf_token");
|
||||
if (StringUtils.isBlank(tsfConsulToken)) {
|
||||
LOGGER.error("tsf_token is empty");
|
||||
}
|
||||
|
||||
// tse_polaris_enable
|
||||
String tsePolarisEnable = environment.getProperty("tse_polaris_enable", "false");
|
||||
if (StringUtils.equals(tsePolarisEnable, "true")) {
|
||||
defaultProperties.put("spring.cloud.polaris.config.enabled", "true");
|
||||
}
|
||||
else {
|
||||
defaultProperties.put("spring.cloud.polaris.contract.report.enabled", "false");
|
||||
defaultProperties.put("spring.cloud.polaris.config.enabled", "true");
|
||||
defaultProperties.put("spring.cloud.polaris.config.internal-enabled", "false");
|
||||
defaultProperties.put("spring.cloud.polaris.config.data-source", "consul");
|
||||
defaultProperties.put("spring.cloud.polaris.config.address", "http://" + tsfConsulIp + ":" + tsfConsulPort);
|
||||
defaultProperties.put("spring.cloud.polaris.config.port", tsfConsulPort);
|
||||
defaultProperties.put("spring.cloud.polaris.config.token", tsfConsulToken);
|
||||
defaultProperties.put("spring.cloud.polaris.config.groups[0].namespace", "config");
|
||||
defaultProperties.put("spring.cloud.polaris.config.groups[0].name", "application");
|
||||
defaultProperties.put("spring.cloud.polaris.config.groups[0].files[0]", tsfApplicationId + "/" + tsfGroupId + "/");
|
||||
defaultProperties.put("spring.cloud.polaris.config.groups[0].files[1]", tsfNamespaceId + "/");
|
||||
}
|
||||
|
||||
// tse_polaris_ip
|
||||
defaultProperties.put("spring.cloud.polaris.address", "grpc://" + environment.getProperty("tse_polaris_ip", "") + ":8091");
|
||||
|
||||
// tsf_sctt_extensions_port
|
||||
defaultProperties.put("spring.cloud.polaris.stat.port", environment.getProperty("tsf_sctt_extensions_port", "11134"));
|
||||
|
||||
// rule based router fail over type
|
||||
defaultProperties.put("spring.cloud.polaris.router.rule-router.fail-over", "none");
|
||||
|
||||
// namespace affinity router
|
||||
defaultProperties.put("spring.cloud.polaris.router.namespace-router.enabled", "true");
|
||||
|
||||
MapPropertySource propertySource = new MapPropertySource("tsf-polaris-properties", defaultProperties);
|
||||
environment.getPropertySources().addFirst(propertySource);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +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.tsf.metadata;
|
||||
|
||||
import com.tencent.cloud.common.spi.InstanceMetadataProvider;
|
||||
import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
|
||||
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
|
||||
import com.tencent.cloud.polaris.context.tsf.config.TsfCoreProperties;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Auto configuration for instanceMetadataProvider for TSF.
|
||||
*
|
||||
* @author Hoatian Zhang
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@AutoConfigureAfter(PolarisContextAutoConfiguration.class)
|
||||
@ConditionalOnTsfEnabled
|
||||
public class TsfInstanceMetadataAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public InstanceMetadataProvider tsfInstanceMetadataProvider(TsfCoreProperties tsfCoreProperties) {
|
||||
return new TsfInstanceMetadataProvider(tsfCoreProperties);
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
com.tencent.cloud.polaris.context.config.PolarisContextBootstrapAutoConfiguration,\
|
||||
com.tencent.cloud.polaris.context.tsf.config.TsfCorePropertiesBootstrapConfiguration,\
|
||||
com.tencent.cloud.polaris.context.tsf.consul.TsfConsulBootstrapConfiguration
|
||||
com.tencent.cloud.polaris.context.config.extend.tsf.TsfContextBootstrapConfiguration
|
||||
org.springframework.context.ApplicationListener=\
|
||||
com.tencent.cloud.polaris.context.logging.PolarisLoggingApplicationListener
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
com.tencent.cloud.polaris.context.tsf.env.TsfCoreEnvironmentPostProcessor
|
||||
com.tencent.cloud.polaris.context.config.extend.tsf.TsfCoreEnvironmentPostProcessor
|
||||
|
@ -1,5 +1,3 @@
|
||||
com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration
|
||||
com.tencent.cloud.polaris.context.config.PolarisContextPostConfiguration
|
||||
com.tencent.cloud.polaris.context.tsf.config.TsfCorePropertiesAutoConfiguration
|
||||
com.tencent.cloud.polaris.context.tsf.consul.TsfConsulAutoConfiguration
|
||||
com.tencent.cloud.polaris.context.tsf.metadata.TsfInstanceMetadataAutoConfiguration
|
||||
com.tencent.cloud.polaris.context.config.extend.tsf.TsfContextAutoConfiguration
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.config.extend.consul;
|
||||
|
||||
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test for {@link ConsulPropertiesTest}.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = ConsulPropertiesTest.TestApplication.class)
|
||||
@ActiveProfiles("test")
|
||||
public class ConsulPropertiesTest {
|
||||
|
||||
@Autowired
|
||||
private ConsulProperties consulProperties;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
PolarisSDKContextManager.innerDestroy();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
PolarisSDKContextManager.innerDestroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultInitialization() {
|
||||
assertThat(consulProperties).isNotNull();
|
||||
assertThat(consulProperties.isEnabled()).isFalse();
|
||||
assertThat(consulProperties.getHost()).isEqualTo("localhost");
|
||||
assertThat(consulProperties.getPort()).isEqualTo(8500);
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
protected static class TestApplication {
|
||||
|
||||
static {
|
||||
PolarisSDKContextManager.innerDestroy();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue