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

sentinel commercialization feature for 1.x branch

This commit is contained in:
fangjian0423
2018-12-19 21:59:40 +08:00
parent 3d99170369
commit bfd855f52e
7 changed files with 82 additions and 1 deletions

View File

@@ -21,6 +21,11 @@ package org.springframework.cloud.alibaba.sentinel;
*/
public interface SentinelConstants {
String PROPERTY_PREFIX = "spring.cloud.sentinel";
String PROPERTY_PREFIX = "spring.cloud.sentinel";
// commercialized
String FLOW_DATASOURCE_NAME = "edas-flow";
String DEGRADE_DATASOURCE_NAME = "edas-degrade";
}

View File

@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,9 +31,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.ApplicationReadyEvent;
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;
@@ -90,6 +94,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);
}
for (Map.Entry<String, DataSourcePropertiesConfiguration> entry : sentinelProperties
.getDatasource().entrySet()) {
String dataSourceName = entry.getKey();