Search in sources :

Example 6 with ShadowRedisConfig

use of com.pamirs.pradar.internal.config.ShadowRedisConfig in project LinkAgent by shulieTech.

the class LettuceMasterSlaveFactory method create.

private RedisClientMediator<?> create(Advice advice) {
    ShadowRedisConfig shadowRedisConfig = serverMatch.getConfig(advice);
    if (null == shadowRedisConfig) {
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.RedisServer).setErrorCode("redisServer-0001").setMessage("没有配置影子Redis Server").setDetail("没有配置影子Redis Server").report();
        // 抛出相关异常信息
        throw new PressureMeasureError("not found redis shadow server config error.");
    }
    validationConfig(shadowRedisConfig);
    RedisClientMediator mediator = createMediator(advice, shadowRedisConfig);
    putMediator(advice.getReturnObj(), mediator);
    return mediator;
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) ShadowRedisConfig(com.pamirs.pradar.internal.config.ShadowRedisConfig) RedisClientMediator(com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator)

Example 7 with ShadowRedisConfig

use of com.pamirs.pradar.internal.config.ShadowRedisConfig in project LinkAgent by shulieTech.

the class RedisShadowServerConfig method compareIsChangeAndSet.

@Override
public Boolean compareIsChangeAndSet(ApplicationConfig applicationConfig, Map<String, ShadowRedisConfig> newConfig) {
    Map<String, ShadowRedisConfig> old = GlobalConfig.getInstance().getShadowRedisConfigs();
    if (old.size() == 0 && newConfig.size() == 0) {
        return Boolean.FALSE;
    } else if (old.size() == 0 && newConfig.size() != 0) {
        GlobalConfig.getInstance().setShadowRedisConfigs(newConfig);
        applicationConfig.setShadowRedisConfigs(newConfig);
        return Boolean.TRUE;
    } else if (old.size() != 0 && newConfig.size() == 0) {
        GlobalConfig.getInstance().setShadowRedisConfigs(newConfig);
        applicationConfig.setShadowRedisConfigs(newConfig);
        for (Map.Entry<String, ShadowRedisConfig> entry : old.entrySet()) {
            ShadowRedisConfig oldValue = entry.getValue();
            ShadowRedisServerDisableEvent event = new ShadowRedisServerDisableEvent(Collections.singletonList(oldValue));
            EventRouter.router().publish(event);
        }
        return Boolean.TRUE;
    } else if (old.size() != 0 && newConfig.size() != 0) {
        Boolean change = false;
        if (old.size() != newConfig.size()) {
            change = true;
        }
        List<ShadowRedisConfig> removeKeys = new ArrayList<ShadowRedisConfig>();
        for (Map.Entry entry : old.entrySet()) {
            String oldKey = String.valueOf(entry.getKey());
            ShadowRedisConfig oldValue = (ShadowRedisConfig) entry.getValue();
            if (!newConfig.containsKey(oldKey)) {
                change = true;
                removeKeys.add(oldValue);
            } else if (newConfig.containsKey(oldKey)) {
                if (!oldValue.equals(newConfig.get(oldKey))) {
                    removeKeys.add(oldValue);
                    change = true;
                }
            }
        }
        if (removeKeys.size() > 0) {
            EventRouter.router().publish(new ShadowRedisServerDisableEvent(removeKeys));
        }
        if (change) {
            GlobalConfig.getInstance().setShadowRedisConfigs(newConfig);
            applicationConfig.setShadowRedisConfigs(newConfig);
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
    return Boolean.FALSE;
}
Also used : ShadowRedisServerDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowRedisServerDisableEvent) List(java.util.List) ArrayList(java.util.ArrayList) ShadowRedisConfig(com.pamirs.pradar.internal.config.ShadowRedisConfig) Map(java.util.Map)

Aggregations

ShadowRedisConfig (com.pamirs.pradar.internal.config.ShadowRedisConfig)7 RedisClientMediator (com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator)2 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)2 ClusterServersConfig (org.redisson.config.ClusterServersConfig)2 Config (org.redisson.config.Config)2 MasterSlaveServersConfig (org.redisson.config.MasterSlaveServersConfig)2 ReplicatedServersConfig (org.redisson.config.ReplicatedServersConfig)2 SentinelServersConfig (org.redisson.config.SentinelServersConfig)2 SingleServerConfig (org.redisson.config.SingleServerConfig)2 RedisServerMatchStrategy (com.pamirs.attach.plugin.common.datasource.redisserver.RedisServerMatchStrategy)1 ShadowRedisServerDisableEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowRedisServerDisableEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 RedissonReactiveClient (org.redisson.api.RedissonReactiveClient)1 RedisClusterConfiguration (org.springframework.data.redis.connection.RedisClusterConfiguration)1 RedisNode (org.springframework.data.redis.connection.RedisNode)1 RedisSentinelConfiguration (org.springframework.data.redis.connection.RedisSentinelConfiguration)1 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)1 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)1