use of com.huawei.route.common.gray.label.entity.CurrentTag in project Sermant by huaweicloud.
the class AddrCache method getAddr.
/**
* 获取路由服务返回的实例
*
* @param targetService 服务名
* @param application 应用服务名
* @param ldc ldc
* @param version 版本号
* @return 实例
*/
public static Instances getAddr(String targetService, String ldc, String version, String application) {
if (ldc == null || version == null) {
return new Instances();
}
List<Instances> instanceList = getAddrFromCache(targetService);
if (CollectionUtils.isEmpty(instanceList)) {
return new Instances();
}
Instances[] arr = new Instances[INSTANCE_LENGTH];
for (Instances instance : instanceList) {
CurrentTag currentTag = instance.getCurrentTag();
if (currentTag == null) {
continue;
}
String instanceLdc = instance.getLdc();
String instanceVersion = application == null ? currentTag.getVersion() : currentTag.getValidVersion(application);
if (ldc.equals(instanceLdc) && version.equals(instanceVersion)) {
// 优先返回这个实例
return instance;
}
if (!ldc.equals(instanceLdc) && version.equals(instanceVersion)) {
// 第二优先级
arr[0] = instance;
continue;
}
if (ldc.equals(instanceLdc)) {
// 第三优先级
arr[1] = instance;
}
// 这里的优先级可考虑优化成分数的形式,然后取分数最高的
}
if (arr[0] != null) {
return arr[0];
}
if (arr[1] != null) {
return arr[1];
}
return new Instances();
}
Aggregations