use of com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule 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.adapter.gateway.common.rule.GatewayFlowRule 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.adapter.gateway.common.rule.GatewayFlowRule in project pig by pig-mesh.
the class GatewayFlowRuleEntity method toGatewayFlowRule.
public GatewayFlowRule toGatewayFlowRule() {
GatewayFlowRule rule = new GatewayFlowRule();
rule.setResource(resource);
rule.setResourceMode(resourceMode);
rule.setGrade(grade);
rule.setCount(count);
rule.setIntervalSec(calIntervalSec(interval, intervalUnit));
rule.setControlBehavior(controlBehavior);
if (burst != null) {
rule.setBurst(burst);
}
if (maxQueueingTimeoutMs != null) {
rule.setMaxQueueingTimeoutMs(maxQueueingTimeoutMs);
}
if (paramItem != null) {
GatewayParamFlowItem ruleItem = new GatewayParamFlowItem();
rule.setParamItem(ruleItem);
ruleItem.setParseStrategy(paramItem.getParseStrategy());
ruleItem.setFieldName(paramItem.getFieldName());
ruleItem.setPattern(paramItem.getPattern());
if (paramItem.getMatchStrategy() != null) {
ruleItem.setMatchStrategy(paramItem.getMatchStrategy());
}
}
return rule;
}
use of com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule in project spring-boot-student by wyh-spring-ecosystem-student.
the class GatewayFlowRuleEntity method toGatewayFlowRule.
public GatewayFlowRule toGatewayFlowRule() {
GatewayFlowRule rule = new GatewayFlowRule();
rule.setResource(resource);
rule.setResourceMode(resourceMode);
rule.setGrade(grade);
rule.setCount(count);
rule.setIntervalSec(calIntervalSec(interval, intervalUnit));
rule.setControlBehavior(controlBehavior);
if (burst != null) {
rule.setBurst(burst);
}
if (maxQueueingTimeoutMs != null) {
rule.setMaxQueueingTimeoutMs(maxQueueingTimeoutMs);
}
if (paramItem != null) {
GatewayParamFlowItem ruleItem = new GatewayParamFlowItem();
rule.setParamItem(ruleItem);
ruleItem.setParseStrategy(paramItem.getParseStrategy());
ruleItem.setFieldName(paramItem.getFieldName());
ruleItem.setPattern(paramItem.getPattern());
if (paramItem.getMatchStrategy() != null) {
ruleItem.setMatchStrategy(paramItem.getMatchStrategy());
}
}
return rule;
}
use of com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule in project spring-cloud-alibaba by longlylong.
the class NacosSentinelConfig method initGatewayRules.
private void initGatewayRules() {
List<RouteDefinition> routes = gatewayProperties.getRoutes();
Set<GatewayFlowRule> rules = new HashSet<>();
for (RouteDefinition route : routes) {
rules.add(new GatewayFlowRule(route.getId()).setCount(200).setIntervalSec(1).setBurst(100).setResourceMode(SentinelGatewayConstants.RESOURCE_MODE_ROUTE_ID));
}
GatewayRuleManager.loadRules(rules);
}
Aggregations