use of com.tencent.polaris.client.pb.CircuitBreakerProto.CbRule in project polaris-java by polarismesh.
the class CircuitBreakUtils method getRuleDestinationSet.
/**
* 通过配置获取远程规则
*
* @param ruleIdentifier 规则标识
* @param extensions 插件集合
* @param controlParam 控制参数
* @return 过滤信息
*/
public static RuleDestinationResult getRuleDestinationSet(RuleIdentifier ruleIdentifier, Extensions extensions, FlowControlParam controlParam) {
Set<ServiceEventKey> svcEventKeys = new HashSet<>();
ServiceEventKey dstSvcEventKey = new ServiceEventKey(new ServiceKey(ruleIdentifier.getNamespace(), ruleIdentifier.getService()), EventType.CIRCUIT_BREAKING);
svcEventKeys.add(dstSvcEventKey);
ServiceEventKey srcSvcEventKey = null;
Service callerService = ruleIdentifier.getCallerService();
if (null != callerService && StringUtils.isNotBlank(callerService.getNamespace()) && StringUtils.isNotBlank(callerService.getService())) {
srcSvcEventKey = new ServiceEventKey(new ServiceKey(callerService.getNamespace(), callerService.getService()), EventType.CIRCUIT_BREAKING);
svcEventKeys.add(srcSvcEventKey);
}
DefaultServiceEventKeysProvider serviceEventKeysProvider = new DefaultServiceEventKeysProvider();
serviceEventKeysProvider.setSvcEventKeys(svcEventKeys);
serviceEventKeysProvider.setUseCache(true);
ResourcesResponse resourcesResponse = BaseFlow.syncGetResources(extensions, false, serviceEventKeysProvider, controlParam);
CircuitBreakerProto.CircuitBreaker dstRule = getCircuitBreakerRule(resourcesResponse.getServiceRule(dstSvcEventKey));
CircuitBreakerProto.CircuitBreaker srcRule = null;
if (null != srcSvcEventKey) {
srcRule = getCircuitBreakerRule(resourcesResponse.getServiceRule(srcSvcEventKey));
}
List<CbRule> rules = getRules(dstRule, srcRule);
if (CollectionUtils.isEmpty(rules)) {
return new RuleDestinationResult(null, false, false);
}
for (CbRule rule : rules) {
MatchSourceResult matchSourceResult = matchSource(rule, ruleIdentifier);
if (!matchSourceResult.matched) {
continue;
}
MatchDestResult matchDestResult = matchDestination(rule, ruleIdentifier, extensions.getFlowCache());
if (null == matchDestResult.destinationSet) {
continue;
}
return new RuleDestinationResult(matchDestResult.destinationSet, matchSourceResult.allSourcesMatched, matchDestResult.allMethod);
}
return new RuleDestinationResult(null, false, false);
}
Aggregations