use of com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig in project Sentinel by alibaba.
the class ClusterParamFlowRuleManager method applyClusterParamRules.
private static void applyClusterParamRules(List<ParamFlowRule> list, /*@Valid*/
String namespace) {
if (list == null || list.isEmpty()) {
clearAndResetRulesFor(namespace);
return;
}
final ConcurrentHashMap<Long, ParamFlowRule> ruleMap = new ConcurrentHashMap<>();
Set<Long> flowIdSet = new HashSet<>();
for (ParamFlowRule rule : list) {
if (!rule.isClusterMode()) {
continue;
}
if (!ParamFlowRuleUtil.isValidRule(rule)) {
RecordLog.warn("[ClusterParamFlowRuleManager] Ignoring invalid param flow rule when loading new flow rules: " + rule);
continue;
}
if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT);
}
ParamFlowRuleUtil.fillExceptionFlowItems(rule);
ParamFlowClusterConfig clusterConfig = rule.getClusterConfig();
// Flow id should not be null after filtered.
Long flowId = clusterConfig.getFlowId();
if (flowId == null) {
continue;
}
ruleMap.put(flowId, rule);
FLOW_NAMESPACE_MAP.put(flowId, namespace);
flowIdSet.add(flowId);
// Prepare cluster parameter metric from valid rule ID.
ClusterParamMetricStatistics.putMetricIfAbsent(flowId, new ClusterParamMetric(clusterConfig.getSampleCount(), clusterConfig.getWindowIntervalMs()));
}
// Cleanup unused cluster parameter metrics.
clearAndResetRulesConditional(namespace, new Predicate<Long>() {
@Override
public boolean test(Long flowId) {
return !ruleMap.containsKey(flowId);
}
});
PARAM_RULES.putAll(ruleMap);
NAMESPACE_FLOW_ID_MAP.put(namespace, flowIdSet);
}
use of com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig in project pig by pig-mesh.
the class InMemParamFlowRuleStore method preProcess.
@Override
protected ParamFlowRuleEntity preProcess(ParamFlowRuleEntity entity) {
if (entity != null && entity.isClusterMode()) {
ParamFlowClusterConfig config = entity.getClusterConfig();
if (config == null) {
config = new ParamFlowClusterConfig();
}
// Set cluster rule id.
config.setFlowId(entity.getId());
}
return entity;
}
use of com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig in project Sentinel by alibaba.
the class JsonSerializeTest method paramFlowRuleSerializeTest.
@Test
public void paramFlowRuleSerializeTest() {
ParamFlowRuleEntity emptyRule = new ParamFlowRuleEntity();
Assert.assertTrue("{}".equals(JSON.toJSONString(emptyRule)));
ParamFlowRuleEntity paramFlowRule = new ParamFlowRuleEntity();
ParamFlowRule rule = new ParamFlowRule();
rule.setClusterConfig(new ParamFlowClusterConfig());
rule.setResource("rs").setLimitApp("default");
paramFlowRule.setRule(rule);
Assert.assertTrue("{\"rule\":{\"burstCount\":0,\"clusterConfig\":{\"fallbackToLocalWhenFail\":false,\"sampleCount\":10,\"thresholdType\":0,\"windowIntervalMs\":1000},\"clusterMode\":false,\"controlBehavior\":0,\"count\":0.0,\"durationInSec\":1,\"grade\":1,\"limitApp\":\"default\",\"maxQueueingTimeMs\":0,\"paramFlowItemList\":[],\"resource\":\"rs\"}}".equals(JSON.toJSONString(paramFlowRule)));
}
use of com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig in project Sentinel by alibaba.
the class InMemParamFlowRuleStore method preProcess.
@Override
protected ParamFlowRuleEntity preProcess(ParamFlowRuleEntity entity) {
if (entity != null && entity.isClusterMode()) {
ParamFlowClusterConfig config = entity.getClusterConfig();
if (config == null) {
config = new ParamFlowClusterConfig();
}
// Set cluster rule id.
config.setFlowId(entity.getId());
}
return entity;
}
use of com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig in project spring-boot-student by wyh-spring-ecosystem-student.
the class JsonSerializeTest method paramFlowRuleSerializeTest.
@Test
public void paramFlowRuleSerializeTest() {
ParamFlowRuleEntity emptyRule = new ParamFlowRuleEntity();
Assert.assertTrue("{}".equals(JSON.toJSONString(emptyRule)));
ParamFlowRuleEntity paramFlowRule = new ParamFlowRuleEntity();
ParamFlowRule rule = new ParamFlowRule();
rule.setClusterConfig(new ParamFlowClusterConfig());
rule.setResource("rs").setLimitApp("default");
paramFlowRule.setRule(rule);
Assert.assertTrue("{\"rule\":{\"burstCount\":0,\"clusterConfig\":{\"fallbackToLocalWhenFail\":false,\"sampleCount\":10,\"thresholdType\":0,\"windowIntervalMs\":1000},\"clusterMode\":false,\"controlBehavior\":0,\"count\":0.0,\"durationInSec\":1,\"grade\":1,\"limitApp\":\"default\",\"maxQueueingTimeMs\":0,\"paramFlowItemList\":[],\"resource\":\"rs\"}}".equals(JSON.toJSONString(paramFlowRule)));
}
Aggregations