1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00
This commit is contained in:
fangjian0423
2018-12-06 16:02:18 +08:00
parent 0af67df3e3
commit cd6f79b16b
6 changed files with 51 additions and 9 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}