Search in sources :

Example 1 with RuleStrategyEnum

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;
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) Invoker(org.apache.dubbo.rpc.Invoker) GrayConfiguration(com.huawei.route.common.gray.label.entity.GrayConfiguration) RuleStrategyEnum(com.huawei.gray.dubbo.strategy.RuleStrategyEnum) Rule(com.huawei.route.common.gray.label.entity.Rule) URL(org.apache.dubbo.common.URL) Route(com.huawei.route.common.gray.label.entity.Route)

Aggregations

RuleStrategyEnum (com.huawei.gray.dubbo.strategy.RuleStrategyEnum)1 GrayConfiguration (com.huawei.route.common.gray.label.entity.GrayConfiguration)1 Route (com.huawei.route.common.gray.label.entity.Route)1 Rule (com.huawei.route.common.gray.label.entity.Rule)1 URL (org.apache.dubbo.common.URL)1 Invocation (org.apache.dubbo.rpc.Invocation)1 Invoker (org.apache.dubbo.rpc.Invoker)1