Search in sources :

Example 1 with CurrentTag

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();
}
Also used : GrayConfiguration(com.huawei.route.common.gray.label.entity.GrayConfiguration) CurrentTag(com.huawei.route.common.gray.label.entity.CurrentTag)

Example 2 with CurrentTag

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);
    }
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) GrayConfig(com.huawei.route.common.gray.config.GrayConfig) HashMap(java.util.HashMap) GrayConfiguration(com.huawei.route.common.gray.label.entity.GrayConfiguration) CurrentTag(com.huawei.route.common.gray.label.entity.CurrentTag)

Example 3 with 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());
        }
    }
}
Also used : Field(java.lang.reflect.Field) Microservice(org.apache.servicecomb.service.center.client.model.Microservice) GrayConfiguration(com.huawei.route.common.gray.label.entity.GrayConfiguration) CurrentTag(com.huawei.route.common.gray.label.entity.CurrentTag) MicroserviceInstance(org.apache.servicecomb.service.center.client.model.MicroserviceInstance) List(java.util.List) FieldPrivilegedAction(com.huawei.gray.dubbo.utils.FieldPrivilegedAction)

Example 4 with CurrentTag

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);
}
Also used : HashMap(java.util.HashMap) GrayConfiguration(com.huawei.route.common.gray.label.entity.GrayConfiguration) CurrentTag(com.huawei.route.common.gray.label.entity.CurrentTag)

Example 5 with 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);
}
Also used : GrayConfiguration(com.huawei.route.common.gray.label.entity.GrayConfiguration) CurrentTag(com.huawei.route.common.gray.label.entity.CurrentTag)

Aggregations

CurrentTag (com.huawei.route.common.gray.label.entity.CurrentTag)11 GrayConfiguration (com.huawei.route.common.gray.label.entity.GrayConfiguration)7 HashMap (java.util.HashMap)3 Instances (com.huawei.route.common.gray.addr.entity.Instances)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FieldPrivilegedAction (com.huawei.gray.dubbo.utils.FieldPrivilegedAction)1 GrayConfig (com.huawei.route.common.gray.config.GrayConfig)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)1 Microservice (org.apache.servicecomb.service.center.client.model.Microservice)1 MicroserviceInstance (org.apache.servicecomb.service.center.client.model.MicroserviceInstance)1 ServiceInstance (org.springframework.cloud.client.ServiceInstance)1 CachingServiceInstanceListSupplier (org.springframework.cloud.loadbalancer.core.CachingServiceInstanceListSupplier)1 DiscoveryClientServiceInstanceListSupplier (org.springframework.cloud.loadbalancer.core.DiscoveryClientServiceInstanceListSupplier)1 Flux (reactor.core.publisher.Flux)1