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:
parent
3d99170369
commit
bfd855f52e
@ -31,4 +31,6 @@ public interface SentinelDataSourceConstants {
|
||||
|
||||
String NACOS_DATASOURCE_ENDPOINT = PROPERTY_PREFIX + ".nacos.config.endpoint";
|
||||
|
||||
String PROJECT_NAME = PROPERTY_PREFIX + ".nacos.config.project-name";
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,25 @@ public class DataSourcePropertiesConfiguration {
|
||||
|
||||
private ApolloDataSourceProperties apollo;
|
||||
|
||||
public DataSourcePropertiesConfiguration() {
|
||||
}
|
||||
|
||||
public DataSourcePropertiesConfiguration(FileDataSourceProperties file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public DataSourcePropertiesConfiguration(NacosDataSourceProperties nacos) {
|
||||
this.nacos = nacos;
|
||||
}
|
||||
|
||||
public DataSourcePropertiesConfiguration(ZookeeperDataSourceProperties zk) {
|
||||
this.zk = zk;
|
||||
}
|
||||
|
||||
public DataSourcePropertiesConfiguration(ApolloDataSourceProperties apollo) {
|
||||
this.apollo = apollo;
|
||||
}
|
||||
|
||||
public FileDataSourceProperties getFile() {
|
||||
return file;
|
||||
}
|
||||
|
@ -101,4 +101,31 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties {
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public static NacosDataSourceProperties buildFlowByEDAS() {
|
||||
return buildByEDAS("flow");
|
||||
}
|
||||
|
||||
public static NacosDataSourceProperties buildDegradeByEDAS() {
|
||||
return buildByEDAS("degrade");
|
||||
}
|
||||
|
||||
public static NacosDataSourceProperties buildByEDAS(String type) {
|
||||
NacosDataSourceProperties result = new NacosDataSourceProperties();
|
||||
result.setFactoryBeanName(
|
||||
NacosDataSourceWithAuthorizationFactoryBean.class.getName());
|
||||
result.setEndpoint(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT));
|
||||
result.setNamespace(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_NAMESPACE));
|
||||
result.setAccessKey(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_AK));
|
||||
result.setSecretKey(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_SK));
|
||||
result.setDataType("json");
|
||||
result.setDataId(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.PROJECT_NAME) + "-" + type);
|
||||
result.setGroupId("nacos-sentinel");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -27,6 +27,7 @@ public interface Constants {
|
||||
String NACOS_DATASOURCE_SK = PROPERTY_PREFIX + ".nacos.config.secret-key";
|
||||
String NACOS_DATASOURCE_NAMESPACE = PROPERTY_PREFIX + ".nacos.config.namespace";
|
||||
String NACOS_DATASOURCE_ENDPOINT = PROPERTY_PREFIX + ".nacos.config.endpoint";
|
||||
String PROJECT_NAME = PROPERTY_PREFIX + ".nacos.config.project-name";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,8 @@ public class SentinelAliCloudListener
|
||||
edasChangeOrderConfiguration.getDauthAccessKey());
|
||||
System.getProperties().setProperty(Constants.Sentinel.NACOS_DATASOURCE_SK,
|
||||
edasChangeOrderConfiguration.getDauthSecretKey());
|
||||
System.getProperties().setProperty(Constants.Sentinel.PROJECT_NAME,
|
||||
edasChangeOrderConfiguration.getProjectName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user