use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project JHodgepodge by werwolfGu.
the class RtDegradeDemo method initDegradeRule.
private static void initDegradeRule() {
List<DegradeRule> rules = new ArrayList<DegradeRule>();
DegradeRule rule = new DegradeRule();
rule.setResource(KEY);
// set threshold rt, 10 ms
rule.setCount(10);
rule.setGrade(RuleConstant.DEGRADE_GRADE_RT);
rule.setTimeWindow(10);
rules.add(rule);
DegradeRuleManager.loadRules(rules);
}
use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project hummer-framework by hummer-team.
the class ListenerConfig method addSentinelConfigForUpdate.
private void addSentinelConfigForUpdate(Set<DegradeRule> degradeRules, Set<GatewayFlowRule> gatewayFlowRules, Set<ApiDefinition> apiDefinitions, DoorGoodConfig doorGoodConfig) {
if (!PropertiesContainer.valueOf("csp.sentinel.enable", Boolean.class, false)) {
return;
}
if (doorGoodConfig.getSentinelConfig() == null) {
cleanSentinelConfig(degradeRules, gatewayFlowRules, apiDefinitions);
return;
}
if (CollectionUtils.isNotEmpty(doorGoodConfig.getSentinelConfig().getDegradeRule2())) {
Map<String, DegradeRule> degradeRuleMap = new ConcurrentHashMap<>(16);
for (DegradeRule rule : degradeRules) {
degradeRuleMap.put(rule.getResource(), rule);
}
for (DegradeRule rule : doorGoodConfig.getSentinelConfig().getDegradeRule2()) {
degradeRuleMap.put(rule.getResource(), rule);
}
degradeRules.clear();
degradeRules.addAll(degradeRuleMap.values());
}
if (CollectionUtils.isNotEmpty(doorGoodConfig.getSentinelConfig().getGatewayFlowRules())) {
Map<String, GatewayFlowRule> gatewayFlowRuleMap = new ConcurrentHashMap<>(16);
for (GatewayFlowRule rule : gatewayFlowRules) {
gatewayFlowRuleMap.put(rule.getResource(), rule);
}
for (GatewayFlowRule rule : doorGoodConfig.getSentinelConfig().getGatewayFlowRules()) {
gatewayFlowRuleMap.put(rule.getResource(), rule);
}
gatewayFlowRules.clear();
gatewayFlowRules.addAll(gatewayFlowRuleMap.values());
}
if (CollectionUtils.isNotEmpty(doorGoodConfig.getSentinelConfig().getApiDefinitions())) {
Map<String, ApiDefinition> apiDefinitionMap = new ConcurrentHashMap<>(16);
for (ApiDefinition api : apiDefinitions) {
apiDefinitionMap.put(api.getApiName(), api);
}
for (ApiDefinition api : doorGoodConfig.getSentinelConfig().getApiDefinitions()) {
apiDefinitionMap.put(api.getApiName(), api);
}
apiDefinitions.clear();
apiDefinitions.addAll(apiDefinitionMap.values());
}
}
use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project hummer-framework by hummer-team.
the class ListenerConfig method addListener.
private void addListener(List<String> gatewayGroup, String groupId, long timeoutMillis, ConfigService configService, boolean isFirstLoading) throws NacosException {
Set<DegradeRule> degradeRules = Sets.newConcurrentHashSet();
Set<GatewayFlowRule> gatewayFlowRules = Sets.newConcurrentHashSet();
Set<ApiDefinition> apiDefinitions = Sets.newConcurrentHashSet();
for (String dataId : gatewayGroup) {
Listener listener = getListener();
String configVal = configService.getConfigAndSignListener(dataId, groupId, timeoutMillis, listener);
if (!Strings.isNullOrEmpty(configVal)) {
// refresh gateway config
log.debug("refresh config done,config value is \n{}", configVal);
DoorGoodConfig doorGoodConfig = JSON.parseObject(configVal, new TypeReference<DoorGoodConfig>() {
});
refreshGatewayRule(doorGoodConfig);
listenerMap.put(dataId, ListenerEvent.builder().dataId(dataId).groupId(groupId).listener(listener).sentinelConfig(doorGoodConfig.getSentinelConfig()).build());
if (isFirstLoading) {
addSentinelConfigForInitLoad(degradeRules, gatewayFlowRules, apiDefinitions, doorGoodConfig);
} else {
// refresh sentinel config
refreshSentinelConfig(doorGoodConfig);
}
}
}
firstLoadingSentinel(isFirstLoading, degradeRules, gatewayFlowRules, apiDefinitions);
}
use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project pig by pig-mesh.
the class DegradeRuleEntity method toRule.
@Override
public DegradeRule toRule() {
DegradeRule rule = new DegradeRule();
rule.setResource(resource);
rule.setLimitApp(limitApp);
rule.setCount(count);
rule.setTimeWindow(timeWindow);
rule.setGrade(grade);
if (minRequestAmount != null) {
rule.setMinRequestAmount(minRequestAmount);
}
if (slowRatioThreshold != null) {
rule.setSlowRatioThreshold(slowRatioThreshold);
}
if (statIntervalMs != null) {
rule.setStatIntervalMs(statIntervalMs);
}
return rule;
}
use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project spring-boot-student by wyh-spring-ecosystem-student.
the class DegradeRuleEntity method toRule.
@Override
public DegradeRule toRule() {
DegradeRule rule = new DegradeRule();
rule.setResource(resource);
rule.setLimitApp(limitApp);
rule.setCount(count);
rule.setTimeWindow(timeWindow);
rule.setGrade(grade);
return rule;
}
Aggregations