use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project Sentinel by alibaba.
the class ConcurrentClusterFlowCheckerTest method setUp.
@Before
public void setUp() {
FlowRule rule = new FlowRule();
ClusterFlowConfig config = new ClusterFlowConfig();
config.setResourceTimeout(500);
config.setClientOfflineTime(1000);
config.setFlowId(111L);
config.setThresholdType(ClusterRuleConstant.FLOW_THRESHOLD_GLOBAL);
rule.setClusterConfig(config);
rule.setClusterMode(true);
rule.setCount(10);
rule.setResource("test");
rule.setGrade(RuleConstant.FLOW_GRADE_THREAD);
ArrayList<FlowRule> rules = new ArrayList<>();
rules.add(rule);
ClusterFlowRuleManager.registerPropertyIfAbsent("1-name");
ClusterFlowRuleManager.loadRules("1-name", rules);
}
use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project Sentinel by alibaba.
the class TokenCacheNodeManagerTest method setUp.
@Before
public void setUp() {
FlowRule rule = new FlowRule();
ClusterFlowConfig config = new ClusterFlowConfig();
config.setResourceTimeout(500);
config.setClientOfflineTime(1000);
config.setFlowId(111L);
config.setThresholdType(ClusterRuleConstant.FLOW_THRESHOLD_GLOBAL);
rule.setClusterConfig(config);
rule.setClusterMode(true);
rule.setCount(10);
rule.setResource("test");
rule.setGrade(RuleConstant.FLOW_GRADE_THREAD);
ArrayList<FlowRule> rules = new ArrayList<>();
rules.add(rule);
ClusterFlowRuleManager.registerPropertyIfAbsent("1-name");
ClusterFlowRuleManager.loadRules("1-name", rules);
}
use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project Sentinel by alibaba.
the class ClusterFlowRuleManager method applyClusterFlowRule.
private static void applyClusterFlowRule(List<FlowRule> list, /*@Valid*/
String namespace) {
if (list == null || list.isEmpty()) {
clearAndResetRulesFor(namespace);
return;
}
final ConcurrentHashMap<Long, FlowRule> ruleMap = new ConcurrentHashMap<>();
Set<Long> flowIdSet = new HashSet<>();
for (FlowRule rule : list) {
if (!rule.isClusterMode()) {
continue;
}
if (!FlowRuleUtil.isValidRule(rule)) {
RecordLog.warn("[ClusterFlowRuleManager] Ignoring invalid flow rule when loading new flow rules: " + rule);
continue;
}
if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT);
}
// Flow id should not be null after filtered.
ClusterFlowConfig clusterConfig = rule.getClusterConfig();
Long flowId = clusterConfig.getFlowId();
if (flowId == null) {
continue;
}
ruleMap.put(flowId, rule);
FLOW_NAMESPACE_MAP.put(flowId, namespace);
flowIdSet.add(flowId);
if (!CurrentConcurrencyManager.containsFlowId(flowId)) {
CurrentConcurrencyManager.put(flowId, 0);
}
// Prepare cluster metric from valid flow ID.
ClusterMetricStatistics.putMetricIfAbsent(flowId, new ClusterMetric(clusterConfig.getSampleCount(), clusterConfig.getWindowIntervalMs()));
}
// Cleanup unused cluster metrics.
clearAndResetRulesConditional(namespace, new Predicate<Long>() {
@Override
public boolean test(Long flowId) {
return !ruleMap.containsKey(flowId);
}
});
FLOW_RULES.putAll(ruleMap);
NAMESPACE_FLOW_ID_MAP.put(namespace, flowIdSet);
}
use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project pig by pig-mesh.
the class InMemFlowRuleStore method preProcess.
@Override
protected FlowRuleEntity preProcess(FlowRuleEntity entity) {
if (entity != null && entity.isClusterMode()) {
ClusterFlowConfig config = entity.getClusterConfig();
if (config == null) {
config = new ClusterFlowConfig();
entity.setClusterConfig(config);
}
// Set cluster rule id.
config.setFlowId(entity.getId());
}
return entity;
}
use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project RuoYi-Cloud-Plus by JavaLionLi.
the class InMemFlowRuleStore method preProcess.
@Override
protected FlowRuleEntity preProcess(FlowRuleEntity entity) {
if (entity != null && entity.isClusterMode()) {
ClusterFlowConfig config = entity.getClusterConfig();
if (config == null) {
config = new ClusterFlowConfig();
entity.setClusterConfig(config);
}
// Set cluster rule id.
config.setFlowId(entity.getId());
}
return entity;
}
Aggregations