use of com.huawei.gray.dubbo.strategy.RuleStrategyEnum in project Sermant by huaweicloud.
the class RegistryDirectoryServiceImpl method selectInvokers.
@Override
public Object selectInvokers(Object[] arguments, Object result) {
if (arguments != null && arguments.length > 0 && arguments[0] instanceof Invocation) {
GrayConfiguration grayConfiguration = LabelCache.getLabel(DubboCache.getLabelName());
if (GrayConfiguration.isInValid(grayConfiguration)) {
return result;
}
Invocation invocation = (Invocation) arguments[0];
URL requestUrl = invocation.getInvoker().getUrl();
if (!RouterUtil.isConsumer(requestUrl)) {
return result;
}
String targetService = RouterUtil.getTargetService(requestUrl);
String interfaceName = requestUrl.getServiceInterface() + "." + invocation.getMethodName();
List<Rule> rules = RouterUtil.getValidRules(grayConfiguration, targetService, interfaceName);
List<Route> routes = RouterUtil.getRoutes(rules, invocation.getArguments());
RuleStrategyEnum ruleStrategyEnum = CollectionUtils.isEmpty(routes) ? RuleStrategyEnum.UPSTREAM : RuleStrategyEnum.WEIGHT;
return ruleStrategyEnum.getTargetInvoker(routes, invocation, (List<Invoker<?>>) result, grayConfiguration.getVersionFrom());
}
return result;
}
Aggregations