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;
}
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;
}
Aggregations