use of com.tencent.polaris.api.pojo.ServiceRule in project spring-cloud-tencent by Tencent.
the class ServiceRuleManager method getServiceRouterRule.
public List<RoutingProto.Route> getServiceRouterRule(String namespace, String sourceService, String dstService) {
Set<ServiceEventKey> routerKeys = new HashSet<>();
ServiceEventKey dstSvcEventKey = new ServiceEventKey(new ServiceKey(namespace, dstService), ServiceEventKey.EventType.ROUTING);
routerKeys.add(dstSvcEventKey);
ServiceEventKey srcSvcEventKey = new ServiceEventKey(new ServiceKey(namespace, sourceService), ServiceEventKey.EventType.ROUTING);
routerKeys.add(srcSvcEventKey);
DefaultServiceEventKeysProvider svcKeysProvider = new DefaultServiceEventKeysProvider();
svcKeysProvider.setSvcEventKeys(routerKeys);
ResourcesResponse resourcesResponse = BaseFlow.syncGetResources(sdkContext.getExtensions(), true, svcKeysProvider, controlParam);
List<RoutingProto.Route> rules = new ArrayList<>();
// get source service outbound rules.
ServiceRule sourceServiceRule = resourcesResponse.getServiceRule(srcSvcEventKey);
if (sourceServiceRule != null) {
Object rule = sourceServiceRule.getRule();
if (rule instanceof RoutingProto.Routing) {
rules.addAll(((RoutingProto.Routing) rule).getOutboundsList());
}
}
// get peer service inbound rules.
ServiceRule dstServiceRule = resourcesResponse.getServiceRule(dstSvcEventKey);
if (dstServiceRule != null) {
Object rule = dstServiceRule.getRule();
if (rule instanceof RoutingProto.Routing) {
rules.addAll(((RoutingProto.Routing) rule).getInboundsList());
}
}
return rules;
}
use of com.tencent.polaris.api.pojo.ServiceRule in project spring-cloud-tencent by Tencent.
the class ServiceRuleManager method getServiceRateLimitRule.
public RateLimitProto.RateLimit getServiceRateLimitRule(String namespace, String service) {
ServiceEventKey serviceEventKey = new ServiceEventKey(new ServiceKey(namespace, service), ServiceEventKey.EventType.RATE_LIMITING);
DefaultServiceEventKeysProvider svcKeysProvider = new DefaultServiceEventKeysProvider();
svcKeysProvider.setSvcEventKey(serviceEventKey);
ResourcesResponse resourcesResponse = BaseFlow.syncGetResources(sdkContext.getExtensions(), true, svcKeysProvider, controlParam);
ServiceRule serviceRule = resourcesResponse.getServiceRule(serviceEventKey);
if (serviceRule != null) {
Object rule = serviceRule.getRule();
if (rule instanceof RateLimitProto.RateLimit) {
return (RateLimitProto.RateLimit) rule;
}
}
return null;
}
use of com.tencent.polaris.api.pojo.ServiceRule in project polaris-java by polarismesh.
the class QuotaFlow method lookupRateLimitWindow.
private RateLimitWindow lookupRateLimitWindow(CommonQuotaRequest request) throws PolarisException {
// 1.获取限流规则
ResourcesResponse resourcesResponse = BaseFlow.syncGetResources(rateLimitExtension.getExtensions(), false, request, request.getFlowControlParam());
ServiceRule serviceRule = resourcesResponse.getServiceRule(request.getSvcEventKey());
// 2.进行规则匹配
Rule rule = lookupRule(serviceRule, request.getLabels());
if (null == rule) {
return null;
}
request.setTargetRule(rule);
// 3.获取已有的限流窗口
ServiceKey serviceKey = request.getSvcEventKey().getServiceKey();
String labelsStr = formatLabelsToStr(request);
RateLimitWindowSet rateLimitWindowSet = getRateLimitWindowSet(serviceKey);
RateLimitWindow rateLimitWindow = rateLimitWindowSet.getRateLimitWindow(rule, labelsStr);
if (null != rateLimitWindow) {
return rateLimitWindow;
}
// 3.创建限流窗口
return rateLimitWindowSet.addRateLimitWindow(request, labelsStr);
}
Aggregations