Search in sources :

Example 1 with SourceMatcher

use of com.tencent.polaris.client.pb.CircuitBreakerProto.SourceMatcher in project polaris-java by polarismesh.

the class CircuitBreakUtils method matchSource.

private static MatchSourceResult matchSource(CbRule rule, RuleIdentifier ruleIdentifier) {
    if (rule.getSourcesCount() == 0) {
        return new MatchSourceResult(true, true);
    }
    Service callerService = ruleIdentifier.getCallerService();
    for (SourceMatcher sourceMatcher : rule.getSourcesList()) {
        boolean matchAllNamespace = sourceMatcher.getNamespace().getValue().equals(matchAll);
        boolean matchAllService = sourceMatcher.getService().getValue().equals(matchAll);
        if (matchAllNamespace && matchAllService) {
            return new MatchSourceResult(true, true);
        }
        if (null == callerService) {
            continue;
        }
        boolean namespaceMatch = matchAllNamespace;
        boolean serviceMatch = matchAllService;
        if (!namespaceMatch) {
            namespaceMatch = sourceMatcher.getNamespace().getValue().equals(callerService.getNamespace());
        }
        if (!serviceMatch) {
            serviceMatch = sourceMatcher.getService().getValue().equals(callerService.getService());
        }
        if (namespaceMatch && serviceMatch) {
            return new MatchSourceResult(true, false);
        }
    }
    return new MatchSourceResult(false, false);
}
Also used : SourceMatcher(com.tencent.polaris.client.pb.CircuitBreakerProto.SourceMatcher) Service(com.tencent.polaris.api.pojo.Service)

Aggregations

Service (com.tencent.polaris.api.pojo.Service)1 SourceMatcher (com.tencent.polaris.client.pb.CircuitBreakerProto.SourceMatcher)1