|
|
@ -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.degrade.DegradeRuleManager;
|
|
|
|
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
|
|
|
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.FlowRuleManager;
|
|
|
|
|
|
|
|
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
|
|
|
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
|
|
|
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
@ -32,6 +33,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
* @see DegradeRule
|
|
|
|
* @see DegradeRule
|
|
|
|
* @see SystemRule
|
|
|
|
* @see SystemRule
|
|
|
|
* @see AuthorityRule
|
|
|
|
* @see AuthorityRule
|
|
|
|
|
|
|
|
* @see ParamFlowRule
|
|
|
|
* @see ObjectMapper
|
|
|
|
* @see ObjectMapper
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class JsonConverter implements Converter<String, List<AbstractRule>> {
|
|
|
|
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) {
|
|
|
|
public List<AbstractRule> convert(String source) {
|
|
|
|
List<AbstractRule> ruleList = new ArrayList<>();
|
|
|
|
List<AbstractRule> ruleList = new ArrayList<>();
|
|
|
|
if (StringUtils.isEmpty(source)) {
|
|
|
|
if (StringUtils.isEmpty(source)) {
|
|
|
|
logger.info(
|
|
|
|
logger.warn(
|
|
|
|
"Sentinel JsonConverter can not convert rules because source is empty");
|
|
|
|
"Sentinel JsonConverter can not convert rules because source is empty");
|
|
|
|
return ruleList;
|
|
|
|
return ruleList;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -68,7 +70,7 @@ public class JsonConverter implements Converter<String, List<AbstractRule>> {
|
|
|
|
|
|
|
|
|
|
|
|
List<AbstractRule> rules = Arrays.asList(convertFlowRule(itemJson),
|
|
|
|
List<AbstractRule> rules = Arrays.asList(convertFlowRule(itemJson),
|
|
|
|
convertDegradeRule(itemJson), convertSystemRule(itemJson),
|
|
|
|
convertDegradeRule(itemJson), convertSystemRule(itemJson),
|
|
|
|
convertAuthorityRule(itemJson));
|
|
|
|
convertAuthorityRule(itemJson), convertParamFlowRule(itemJson));
|
|
|
|
|
|
|
|
|
|
|
|
List<AbstractRule> convertRuleList = rules.stream()
|
|
|
|
List<AbstractRule> convertRuleList = rules.stream()
|
|
|
|
.filter(rule -> !ObjectUtils.isEmpty(rule))
|
|
|
|
.filter(rule -> !ObjectUtils.isEmpty(rule))
|
|
|
@ -101,8 +103,6 @@ public class JsonConverter implements Converter<String, List<AbstractRule>> {
|
|
|
|
throw new RuntimeException(
|
|
|
|
throw new RuntimeException(
|
|
|
|
"Sentinel JsonConverter convert error: " + e.getMessage(), e);
|
|
|
|
"Sentinel JsonConverter convert error: " + e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.info("Sentinel JsonConverter convert {} rules: {}", ruleList.size(),
|
|
|
|
|
|
|
|
ruleList);
|
|
|
|
|
|
|
|
return ruleList;
|
|
|
|
return ruleList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -154,4 +154,15 @@ public class JsonConverter implements Converter<String, List<AbstractRule>> {
|
|
|
|
return rule;
|
|
|
|
return rule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ParamFlowRule convertParamFlowRule(String json) {
|
|
|
|
|
|
|
|
ParamFlowRule rule = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
rule = objectMapper.readValue(json, ParamFlowRule.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
|
|
|
// ignore
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return rule;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|