Search in sources :

Example 11 with GrayConfiguration

use of com.huawei.route.common.gray.label.entity.GrayConfiguration in project Sermant by huaweicloud.

the class LabelCache method getLabel.

/**
 * 获取指定标签
 *
 * @param labelName 缓存的标签名
 * @return 标签
 */
public static GrayConfiguration getLabel(String labelName) {
    GrayConfiguration grayConfiguration = CACHE.get(labelName);
    if (grayConfiguration == null) {
        synchronized (LabelCache.class) {
            grayConfiguration = CACHE.get(labelName);
            if (grayConfiguration == null) {
                CACHE.put(labelName, new GrayConfiguration());
                grayConfiguration = CACHE.get(labelName);
            }
        }
    }
    return grayConfiguration;
}
Also used : GrayConfiguration(com.huawei.route.common.gray.label.entity.GrayConfiguration)

Example 12 with GrayConfiguration

use of com.huawei.route.common.gray.label.entity.GrayConfiguration 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

GrayConfiguration (com.huawei.route.common.gray.label.entity.GrayConfiguration)12 CurrentTag (com.huawei.route.common.gray.label.entity.CurrentTag)7 Rule (com.huawei.route.common.gray.label.entity.Rule)4 Route (com.huawei.route.common.gray.label.entity.Route)3 GrayConfig (com.huawei.route.common.gray.config.GrayConfig)2 HashMap (java.util.HashMap)2 List (java.util.List)2 RuleStrategyEnum (com.huawei.gray.dubbo.strategy.RuleStrategyEnum)1 FieldPrivilegedAction (com.huawei.gray.dubbo.utils.FieldPrivilegedAction)1 FeignResolvedUrl (com.huawei.gray.feign.context.FeignResolvedUrl)1 RuleType (com.huawei.gray.feign.rule.RuleType)1 Instances (com.huawei.route.common.gray.addr.entity.Instances)1 Request (feign.Request)1 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 URL (org.apache.dubbo.common.URL)1 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)1 Invocation (org.apache.dubbo.rpc.Invocation)1