use of com.huawei.route.common.gray.label.entity.CurrentTag in project Sermant by huaweicloud.
the class RouterUtil method getLdc.
/**
* 获取当前服务的ldc
*
* @return LDC
*/
public static String getLdc() {
GrayConfiguration grayConfiguration = LabelCache.getLabel(DubboCache.getLabelName());
if (GrayConfiguration.isInValid(grayConfiguration)) {
return GrayConstant.GRAY_DEFAULT_LDC;
}
CurrentTag currentTag = grayConfiguration.getCurrentTag();
if (currentTag == null || StringUtils.isBlank(currentTag.getLdc())) {
return GrayConstant.GRAY_DEFAULT_LDC;
}
return currentTag.getLdc();
}
use of com.huawei.route.common.gray.label.entity.CurrentTag in project Sermant by huaweicloud.
the class InterfaceConfigServiceImpl method getName.
@Override
public void getName(Object result) {
if (result instanceof ApplicationConfig) {
ApplicationConfig config = (ApplicationConfig) result;
GrayConfig grayConfig = PluginConfigManager.getPluginConfig(GrayConfig.class);
String version = grayConfig.getGrayVersion(GrayConstant.GRAY_DEFAULT_VERSION);
Map<String, String> versionMap = new HashMap<String, String>();
versionMap.put(GrayConstant.GRAY_VERSION_KEY, version);
Map<String, String> parameters = config.getParameters();
if (parameters == null) {
config.setParameters(versionMap);
parameters = config.getParameters();
} else if (parameters.get(GrayConstant.GRAY_VERSION_KEY) == null) {
config.getParameters().putAll(versionMap);
}
String ldc = grayConfig.getLdc(GrayConstant.GRAY_DEFAULT_LDC);
parameters.put(GrayConstant.GRAY_LDC_KEY, ldc);
DubboCache.setAppName(config.getName());
GrayConfiguration grayConfiguration = LabelCache.getLabel(DubboCache.getLabelName());
CurrentTag currentTag = grayConfiguration.getCurrentTag();
if (currentTag == null) {
currentTag = new CurrentTag();
}
currentTag.setVersion(parameters.get(GrayConstant.GRAY_VERSION_KEY));
currentTag.setLdc(ldc);
grayConfiguration.setCurrentTag(currentTag);
}
}
use of com.huawei.route.common.gray.label.entity.CurrentTag in project Sermant by huaweicloud.
the class RegistrationServiceImpl method getVersion.
/**
* 拦截点前执行
*
* @param obj 增强的类
* @param arguments 增强方法的所有参数
*/
@Override
public void getVersion(Object obj, Object[] arguments) throws NoSuchFieldException, IllegalAccessException {
if (arguments.length <= 2 || !(arguments[2] instanceof List<?>)) {
return;
}
Field field = obj.getClass().getDeclaredField("microservice");
AccessController.doPrivileged(new FieldPrivilegedAction(field));
Microservice microservice = (Microservice) field.get(obj);
GrayConfiguration grayConfiguration = LabelCache.getLabel(DubboCache.getLabelName());
CurrentTag currentTag = grayConfiguration.getCurrentTag();
currentTag.setRegisterVersion(microservice.getVersion());
List<MicroserviceInstance> instances = (List<MicroserviceInstance>) arguments[2];
for (MicroserviceInstance instance : instances) {
for (String endpoint : instance.getEndpoints()) {
AddrCache.setRegisterVersionCache(endpoint.substring(GrayConstant.DUBBO_PREFIX.length()), instance.getVersion());
}
}
}
use of com.huawei.route.common.gray.label.entity.CurrentTag in project Sermant by huaweicloud.
the class ApplicationConfigServiceImpl method getName.
/**
* 获取dubbo服务名,并设置灰度参数
*
* @param obj 增强的类
* @see com.alibaba.dubbo.config.ApplicationConfig
* @see org.apache.dubbo.config.ApplicationConfig
*/
@Override
public void getName(Object obj) {
String name = ReflectUtils.getName(obj);
if (StringUtils.isBlank(name)) {
return;
}
DubboCache.INSTANCE.setAppName(name);
String version = grayConfig.getGrayVersion(GrayConstant.GRAY_DEFAULT_VERSION);
Map<String, String> versionMap = new HashMap<>();
versionMap.put(GrayConstant.GRAY_VERSION_KEY, version);
String ldc = grayConfig.getLdc(GrayConstant.GRAY_DEFAULT_LDC);
versionMap.put(GrayConstant.GRAY_LDC_KEY, ldc);
Map<String, String> parameters = ReflectUtils.getParameters(obj);
if (parameters == null) {
ReflectUtils.setParameters(obj, versionMap);
} else {
parameters.putAll(versionMap);
}
GrayConfiguration grayConfiguration = LabelCache.getLabel(GrayConstant.GRAY_LABEL_CACHE_NAME);
CurrentTag currentTag = grayConfiguration.getCurrentTag();
if (currentTag == null) {
currentTag = new CurrentTag();
}
currentTag.setVersion(version);
currentTag.setLdc(ldc);
grayConfiguration.setCurrentTag(currentTag);
}
use of com.huawei.route.common.gray.label.entity.CurrentTag in project Sermant by huaweicloud.
the class RegistrationServiceImpl method setRegisterVersion.
/**
* 设置自身版本缓存
*
* @param version 版本
*/
@Override
public void setRegisterVersion(String version) {
GrayConfiguration grayConfiguration = LabelCache.getLabel(GrayConstant.GRAY_LABEL_CACHE_NAME);
CurrentTag currentTag = grayConfiguration.getCurrentTag();
currentTag.setRegisterVersion(version);
}
Aggregations