Search in sources :

Example 1 with CbRule

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);
}
Also used : DefaultServiceEventKeysProvider(com.tencent.polaris.api.pojo.DefaultServiceEventKeysProvider) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) Service(com.tencent.polaris.api.pojo.Service) ResourcesResponse(com.tencent.polaris.client.flow.ResourcesResponse) CircuitBreakerProto(com.tencent.polaris.client.pb.CircuitBreakerProto) ServiceEventKey(com.tencent.polaris.api.pojo.ServiceEventKey) CbRule(com.tencent.polaris.client.pb.CircuitBreakerProto.CbRule) HashSet(java.util.HashSet)

Aggregations

DefaultServiceEventKeysProvider (com.tencent.polaris.api.pojo.DefaultServiceEventKeysProvider)1 Service (com.tencent.polaris.api.pojo.Service)1 ServiceEventKey (com.tencent.polaris.api.pojo.ServiceEventKey)1 ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)1 ResourcesResponse (com.tencent.polaris.client.flow.ResourcesResponse)1 CircuitBreakerProto (com.tencent.polaris.client.pb.CircuitBreakerProto)1 CbRule (com.tencent.polaris.client.pb.CircuitBreakerProto.CbRule)1 HashSet (java.util.HashSet)1