mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
remove sentinel commercialization logic & optimize NacosDataSource
This commit is contained in:
@@ -23,14 +23,4 @@ public interface SentinelDataSourceConstants {
|
||||
|
||||
String PROPERTY_PREFIX = "spring.cloud.sentinel";
|
||||
|
||||
String NACOS_DATASOURCE_AK = PROPERTY_PREFIX + ".nacos.config.access-key";
|
||||
|
||||
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";
|
||||
|
||||
}
|
||||
|
@@ -2,8 +2,6 @@ package org.springframework.cloud.alibaba.sentinel.datasource.config;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import org.springframework.cloud.alibaba.sentinel.datasource.RuleType;
|
||||
import org.springframework.cloud.alibaba.sentinel.datasource.SentinelDataSourceConstants;
|
||||
import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.NacosDataSourceFactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -18,13 +16,11 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties {
|
||||
private String serverAddr;
|
||||
|
||||
@NotEmpty
|
||||
private String groupId;
|
||||
private String groupId = "DEFAULT_GROUP";
|
||||
|
||||
@NotEmpty
|
||||
private String dataId;
|
||||
|
||||
// commercialized usage
|
||||
|
||||
private String endpoint;
|
||||
private String namespace;
|
||||
private String accessKey;
|
||||
@@ -36,17 +32,9 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties {
|
||||
|
||||
@Override
|
||||
public void preCheck(String dataSourceName) {
|
||||
if (!StringUtils.isEmpty(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT))) {
|
||||
this.setServerAddr(null);
|
||||
this.setEndpoint(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT));
|
||||
this.setNamespace(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_NAMESPACE));
|
||||
this.setAccessKey(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_AK));
|
||||
this.setSecretKey(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_SK));
|
||||
if (StringUtils.isEmpty(serverAddr) && acmPropertiesInvalid()) {
|
||||
throw new IllegalArgumentException(
|
||||
"NacosDataSource properties value not correct. serverAddr is empty but there is empty value in accessKey, secretKey, endpoint, namespace property");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,34 +94,9 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public static NacosDataSourceProperties buildFlowByEDAS() {
|
||||
return buildByEDAS("flow");
|
||||
public boolean acmPropertiesInvalid() {
|
||||
return StringUtils.isEmpty(endpoint) || StringUtils.isEmpty(accessKey)
|
||||
|| StringUtils.isEmpty(secretKey) || StringUtils.isEmpty(namespace);
|
||||
}
|
||||
|
||||
public static NacosDataSourceProperties buildDegradeByEDAS() {
|
||||
return buildByEDAS("degrade");
|
||||
}
|
||||
|
||||
public static NacosDataSourceProperties buildByEDAS(String type) {
|
||||
NacosDataSourceProperties result = new NacosDataSourceProperties();
|
||||
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");
|
||||
if (type.equals(RuleType.FLOW.getName())) {
|
||||
result.setRuleType(RuleType.FLOW);
|
||||
}
|
||||
else {
|
||||
result.setRuleType(RuleType.DEGRADE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.cloud.alibaba.sentinel.datasource.SentinelDataSourceConstants;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
@@ -30,16 +29,19 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
||||
|
||||
@Override
|
||||
public NacosDataSource getObject() throws Exception {
|
||||
if (!StringUtils.isEmpty(System.getProperties()
|
||||
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT))) {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(PropertyKeyConst.ACCESS_KEY, this.accessKey);
|
||||
properties.setProperty(PropertyKeyConst.SERVER_ADDR, this.secretKey);
|
||||
properties.setProperty(PropertyKeyConst.ENDPOINT, this.endpoint);
|
||||
properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace);
|
||||
return new NacosDataSource(properties, groupId, dataId, converter);
|
||||
Properties properties = new Properties();
|
||||
if (!StringUtils.isEmpty(this.serverAddr)) {
|
||||
properties.setProperty(PropertyKeyConst.SERVER_ADDR, this.serverAddr);
|
||||
}
|
||||
return new NacosDataSource(serverAddr, groupId, dataId, converter);
|
||||
else {
|
||||
properties.setProperty(PropertyKeyConst.ACCESS_KEY, this.accessKey);
|
||||
properties.setProperty(PropertyKeyConst.SECRET_KEY, this.secretKey);
|
||||
properties.setProperty(PropertyKeyConst.ENDPOINT, this.endpoint);
|
||||
}
|
||||
if (!StringUtils.isEmpty(this.namespace)) {
|
||||
properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace);
|
||||
}
|
||||
return new NacosDataSource(properties, groupId, dataId, converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user