mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Polish #115
This commit is contained in:
parent
0af67df3e3
commit
cd6f79b16b
@ -89,6 +89,11 @@
|
||||
<artifactId>sentinel-core</artifactId>
|
||||
<version>${sentinel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-parameter-flow-control</artifactId>
|
||||
<version>${sentinel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-datasource-extension</artifactId>
|
||||
|
@ -18,6 +18,13 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-datasource-extension</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-parameter-flow-control</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -18,6 +18,7 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@ -32,6 +33,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @see DegradeRule
|
||||
* @see SystemRule
|
||||
* @see AuthorityRule
|
||||
* @see ParamFlowRule
|
||||
* @see ObjectMapper
|
||||
*/
|
||||
public class JsonConverter implements Converter<String, List<AbstractRule>> {
|
||||
@ -48,7 +50,7 @@ public class JsonConverter implements Converter<String, List<AbstractRule>> {
|
||||
public List<AbstractRule> convert(String source) {
|
||||
List<AbstractRule> ruleList = new ArrayList<>();
|
||||
if (StringUtils.isEmpty(source)) {
|
||||
logger.info(
|
||||
logger.warn(
|
||||
"Sentinel JsonConverter can not convert rules because source is empty");
|
||||
return ruleList;
|
||||
}
|
||||
@ -68,7 +70,7 @@ public class JsonConverter implements Converter<String, List<AbstractRule>> {
|
||||
|
||||
List<AbstractRule> rules = Arrays.asList(convertFlowRule(itemJson),
|
||||
convertDegradeRule(itemJson), convertSystemRule(itemJson),
|
||||
convertAuthorityRule(itemJson));
|
||||
convertAuthorityRule(itemJson), convertParamFlowRule(itemJson));
|
||||
|
||||
List<AbstractRule> convertRuleList = rules.stream()
|
||||
.filter(rule -> !ObjectUtils.isEmpty(rule))
|
||||
@ -101,8 +103,6 @@ public class JsonConverter implements Converter<String, List<AbstractRule>> {
|
||||
throw new RuntimeException(
|
||||
"Sentinel JsonConverter convert error: " + e.getMessage(), e);
|
||||
}
|
||||
logger.info("Sentinel JsonConverter convert {} rules: {}", ruleList.size(),
|
||||
ruleList);
|
||||
return ruleList;
|
||||
}
|
||||
|
||||
@ -154,4 +154,15 @@ public class JsonConverter implements Converter<String, List<AbstractRule>> {
|
||||
return rule;
|
||||
}
|
||||
|
||||
private ParamFlowRule convertParamFlowRule(String json) {
|
||||
ParamFlowRule rule = null;
|
||||
try {
|
||||
rule = objectMapper.readValue(json, ParamFlowRule.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@ -32,7 +33,7 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
* @see DegradeRule
|
||||
* @see SystemRule
|
||||
* @see AuthorityRule
|
||||
* @see XmlMapper
|
||||
* @see ParamFlowRule
|
||||
*/
|
||||
public class XmlConverter implements Converter<String, List<AbstractRule>> {
|
||||
|
||||
@ -48,7 +49,7 @@ public class XmlConverter implements Converter<String, List<AbstractRule>> {
|
||||
public List<AbstractRule> convert(String source) {
|
||||
List<AbstractRule> ruleList = new ArrayList<>();
|
||||
if (StringUtils.isEmpty(source)) {
|
||||
logger.info(
|
||||
logger.warn(
|
||||
"Sentinel XmlConverter can not convert rules because source is empty");
|
||||
return ruleList;
|
||||
}
|
||||
@ -68,7 +69,7 @@ public class XmlConverter implements Converter<String, List<AbstractRule>> {
|
||||
|
||||
List<AbstractRule> rules = Arrays.asList(convertFlowRule(itemXml),
|
||||
convertDegradeRule(itemXml), convertSystemRule(itemXml),
|
||||
convertAuthorityRule(itemXml));
|
||||
convertAuthorityRule(itemXml), convertParamFlowRule(itemXml));
|
||||
|
||||
List<AbstractRule> convertRuleList = rules.stream()
|
||||
.filter(rule -> !ObjectUtils.isEmpty(rule))
|
||||
@ -101,8 +102,6 @@ public class XmlConverter implements Converter<String, List<AbstractRule>> {
|
||||
throw new RuntimeException(
|
||||
"Sentinel XmlConverter convert error: " + e.getMessage(), e);
|
||||
}
|
||||
logger.info("Sentinel XmlConverter convert {} rules: {}", ruleList.size(),
|
||||
ruleList);
|
||||
return ruleList;
|
||||
}
|
||||
|
||||
@ -154,4 +153,15 @@ public class XmlConverter implements Converter<String, List<AbstractRule>> {
|
||||
return rule;
|
||||
}
|
||||
|
||||
private ParamFlowRule convertParamFlowRule(String json) {
|
||||
ParamFlowRule rule = null;
|
||||
try {
|
||||
rule = xmlMapper.readValue(json, ParamFlowRule.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,11 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-parameter-flow-control</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-sentinel-datasource</artifactId>
|
||||
|
@ -32,6 +32,8 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
|
||||
|
||||
@ -58,10 +60,12 @@ public class SentinelEndpoint {
|
||||
List<FlowRule> flowRules = FlowRuleManager.getRules();
|
||||
List<DegradeRule> degradeRules = DegradeRuleManager.getRules();
|
||||
List<SystemRule> systemRules = SystemRuleManager.getRules();
|
||||
List<ParamFlowRule> paramFlowRules = ParamFlowRuleManager.getRules();
|
||||
result.put("properties", sentinelProperties);
|
||||
result.put("FlowRules", flowRules);
|
||||
result.put("DegradeRules", degradeRules);
|
||||
result.put("SystemRules", systemRules);
|
||||
result.put("ParamFlowRule", paramFlowRules);
|
||||
result.put("datasources", new HashMap<String, Object>());
|
||||
dataSourceHandler.getDataSourceBeanNameList().forEach(dataSourceBeanName -> {
|
||||
ReadableDataSource dataSource = applicationContext.getBean(dataSourceBeanName,
|
||||
|
Loading…
x
Reference in New Issue
Block a user