1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryAutoConfiguration.java
#	spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryProperties.java
#	spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/config/NacosDataSourceProperties.java
#	spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelDataSourceHandler.java
This commit is contained in:
mercyblitz
2019-02-01 22:08:21 +08:00
107 changed files with 5467 additions and 561 deletions

View File

@@ -1,35 +1,29 @@
package org.springframework.cloud.alibaba.sentinel.custom;
import com.alibaba.csp.sentinel.datasource.AbstractDataSource;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import com.alibaba.csp.sentinel.slots.block.AbstractRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.cloud.alibaba.sentinel.SentinelConstants;
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
import org.springframework.cloud.alibaba.sentinel.datasource.SentinelDataSourceConstants;
import org.springframework.cloud.alibaba.sentinel.datasource.config.AbstractDataSourceProperties;
import org.springframework.cloud.alibaba.sentinel.datasource.config.DataSourcePropertiesConfiguration;
import org.springframework.cloud.alibaba.sentinel.datasource.config.NacosDataSourceProperties;
import org.springframework.cloud.alibaba.sentinel.datasource.converter.JsonConverter;
import org.springframework.cloud.alibaba.sentinel.datasource.converter.XmlConverter;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
import org.springframework.cloud.alibaba.sentinel.datasource.config.AbstractDataSourceProperties;
import org.springframework.cloud.alibaba.sentinel.datasource.converter.JsonConverter;
import org.springframework.cloud.alibaba.sentinel.datasource.converter.XmlConverter;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import com.alibaba.csp.sentinel.datasource.AbstractDataSource;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import com.alibaba.csp.sentinel.slots.block.AbstractRule;
/**
* Sentinel {@link ReadableDataSource} Handler Handle the configurations of
@@ -62,27 +56,6 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
@Override
public void afterSingletonsInstantiated() {
// commercialization
if (!StringUtils.isEmpty(System.getProperties()
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT))) {
Map<String, DataSourcePropertiesConfiguration> newDataSourceMap = new TreeMap<>(
String.CASE_INSENSITIVE_ORDER);
for (Map.Entry<String, DataSourcePropertiesConfiguration> entry : sentinelProperties
.getDatasource().entrySet()) {
if (entry.getValue().getValidDataSourceProperties()
.getClass() != NacosDataSourceProperties.class) {
newDataSourceMap.put(entry.getKey(), entry.getValue());
}
}
newDataSourceMap.put(SentinelConstants.FLOW_DATASOURCE_NAME,
new DataSourcePropertiesConfiguration(
NacosDataSourceProperties.buildFlowByEDAS()));
newDataSourceMap.put(SentinelConstants.DEGRADE_DATASOURCE_NAME,
new DataSourcePropertiesConfiguration(
NacosDataSourceProperties.buildDegradeByEDAS()));
sentinelProperties.setDatasource(newDataSourceMap);
}
sentinelProperties.getDatasource()
.forEach((dataSourceName, dataSourceProperties) -> {
try {
@@ -213,17 +186,6 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
// register property in RuleManager
dataSourceProperties.postRegister(newDataSource);
// commercialization
if (!StringUtils.isEmpty(System.getProperties()
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT))) {
if (dataSourceName.contains(SentinelConstants.FLOW_DATASOURCE_NAME)) {
FlowRuleManager.register2Property(newDataSource.getProperty());
}
else if (dataSourceName.contains(SentinelConstants.DEGRADE_DATASOURCE_NAME)) {
DegradeRuleManager.register2Property(newDataSource.getProperty());
}
}
}
private void logAndCheckRuleType(AbstractDataSource dataSource, String dataSourceName,