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

sentinel commercialization feature

This commit is contained in:
fangjian0423
2018-12-19 22:54:25 +08:00
parent c300ffbbc6
commit 8af824dc2f
7 changed files with 89 additions and 7 deletions

View File

@@ -23,4 +23,9 @@ public interface SentinelConstants {
String PROPERTY_PREFIX = "spring.cloud.sentinel";
// commercialization
String FLOW_DATASOURCE_NAME = "edas-flow";
String DEGRADE_DATASOURCE_NAME = "edas-degrade";
}

View File

@@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.stream.Collectors;
import org.slf4j.Logger;
@@ -16,8 +17,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.context.event.ApplicationStartedEvent;
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.context.event.EventListener;
@@ -73,6 +78,27 @@ public class SentinelDataSourceHandler {
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) event
.getApplicationContext().getAutowireCapableBeanFactory();
// 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) -> {
List<String> validFields = dataSourceProperties.getValidField();