Search in sources :

Example 1 with ShadowConsumerDisableInfo

use of com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo in project LinkAgent by shulieTech.

the class ShadowConsumerDisableListenerImpl method onEvent.

@Override
public EventResult onEvent(IEvent event) {
    // any event flush LAST_MQ_WHITELIST
    LastMqWhiteListHolder.LAST_MQ_WHITELIST.set(Collections.<String>emptySet());
    try {
        if (event instanceof ShadowConsumerDisableEvent) {
            ShadowConsumerDisableEvent shadowConsumerDisableEvent = (ShadowConsumerDisableEvent) event;
            List<ShadowConsumerDisableInfo> list = shadowConsumerDisableEvent.getTarget();
            disableBatch(list);
        } else if (event instanceof ClusterTestSwitchOffEvent) {
            disableAll();
        } else if (event instanceof SilenceSwitchOnEvent) {
            disableAll();
        }
    } catch (Throwable e) {
        EventResult.error(event.getTarget(), e.getMessage());
    }
    return EventResult.success(event.getTarget());
}
Also used : SilenceSwitchOnEvent(com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent) ShadowConsumerDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent) ShadowConsumerDisableInfo(com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo) ClusterTestSwitchOffEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)

Example 2 with ShadowConsumerDisableInfo

use of com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo in project LinkAgent by shulieTech.

the class ConsumerRegistry method addListener.

private static void addListener(final DefaultMQPushConsumer businessConsumer) {
    final RebalanceImpl rebalance = businessConsumer.getDefaultMQPushConsumerImpl().getRebalanceImpl();
    final PradarEventListener listener = new PradarEventListener() {

        @Override
        public EventResult onEvent(IEvent event) {
            if (event instanceof ClusterTestSwitchOnEvent) {
                try {
                    // 取出配置创建影子消费者
                    DefaultMQPushConsumer defaultMQPushConsumer = buildMQPushConsumer(businessConsumer);
                    if (defaultMQPushConsumer != null) {
                        defaultMQPushConsumer.start();
                    }
                } catch (MQClientException e) {
                    logger.error(e.getMessage());
                    return EventResult.error("apache-rocketmq-plugin-open", "Apache-RocketMQ PT Consumer start failed: " + e.getMessage());
                }
                return EventResult.success("apache-rocketmq-plugin-open");
            } else if (event instanceof ClusterTestSwitchOffEvent || event instanceof SilenceSwitchOnEvent) {
                return shutdownShadowConsumer(businessConsumer);
            } else if (event instanceof ShadowConsumerDisableEvent) {
                String group = businessConsumer.getConsumerGroup();
                Set<String> topics = rebalance.getSubscriptionInner().keySet();
                for (String topic : topics) {
                    List<ShadowConsumerDisableInfo> disableInfos = ((ShadowConsumerDisableEvent) event).getTarget();
                    for (ShadowConsumerDisableInfo disableInfo : disableInfos) {
                        if (topic.equals(disableInfo.getTopic()) && group.equals(disableInfo.getConsumerGroup())) {
                            return shutdownShadowConsumer(businessConsumer);
                        }
                    }
                }
            }
            return EventResult.IGNORE;
        }

        @Override
        public int order() {
            return 4;
        }
    };
    PradarEventListener old = listeners.putIfAbsent(businessConsumer, listener);
    if (old == null) {
        EventRouter.router().addListener(listener);
    }
}
Also used : IEvent(com.pamirs.pradar.pressurement.agent.event.IEvent) RebalanceImpl(org.apache.rocketmq.client.impl.consumer.RebalanceImpl) SilenceSwitchOnEvent(com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent) DefaultMQPushConsumer(org.apache.rocketmq.client.consumer.DefaultMQPushConsumer) ShadowConsumerDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent) ShadowConsumerDisableInfo(com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo) PradarEventListener(com.pamirs.pradar.pressurement.agent.listener.PradarEventListener) ClusterTestSwitchOnEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOnEvent) MQClientException(org.apache.rocketmq.client.exception.MQClientException) ClusterTestSwitchOffEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)

Example 3 with ShadowConsumerDisableInfo

use of com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo in project LinkAgent by shulieTech.

the class MQWhiteList method compareIsChangeAndSet.

@Override
public Boolean compareIsChangeAndSet(ApplicationConfig currentValue, Set<String> newValue) {
    final MqWhiteListConfigEvent mqWhiteListConfigEvent = new MqWhiteListConfigEvent(newValue);
    EventRouter.router().publish(mqWhiteListConfigEvent);
    Set<String> mqWhiteList = GlobalConfig.getInstance().getMqWhiteList();
    if (ObjectUtils.equals(mqWhiteList.size(), newValue.size()) && mqWhiteList.containsAll(newValue)) {
        return Boolean.FALSE;
    }
    // 仅对影子消费者禁用事件处理
    for (String s : mqWhiteList) {
        List<ShadowConsumerDisableInfo> disableInfos = new ArrayList<ShadowConsumerDisableInfo>();
        if (!newValue.contains(s)) {
            ShadowConsumerDisableInfo disableInfo = new ShadowConsumerDisableInfo();
            if (s.contains("@")) {
                // rabbitmq routing使用方式,配置为direct-exchange#queue1@queue1
                disableInfo.setTopic(s.split("@")[1]);
            } else if (s.contains("#")) {
                String[] topicGroup = s.split("#", 2);
                if (StringUtils.isBlank(topicGroup[0])) {
                    disableInfo.setTopic(topicGroup[1]);
                } else {
                    disableInfo.setTopic(topicGroup[0]);
                    disableInfo.setConsumerGroup(topicGroup[1]);
                }
            }
            disableInfos.add(disableInfo);
        }
        if (!disableInfos.isEmpty()) {
            EventRouter.router().publish(new ShadowConsumerDisableEvent(disableInfos));
        }
    }
    currentValue.setMqList(newValue);
    PradarSwitcher.turnConfigSwitcherOn(ConfigNames.MQ_WHITE_LIST);
    GlobalConfig.getInstance().setMqWhiteList(newValue);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("publish mq whitelist config successful. config={}", newValue);
    }
    return Boolean.TRUE;
}
Also used : MqWhiteListConfigEvent(com.pamirs.pradar.pressurement.agent.event.impl.MqWhiteListConfigEvent) ArrayList(java.util.ArrayList) ShadowConsumerDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent) ShadowConsumerDisableInfo(com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo)

Example 4 with ShadowConsumerDisableInfo

use of com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo in project LinkAgent by shulieTech.

the class ShadowConsumerDisableListenerImpl method onEvent.

@Override
public EventResult onEvent(IEvent event) {
    try {
        if (event instanceof ShadowConsumerDisableEvent) {
            ShadowConsumerDisableEvent shadowConsumerDisableEvent = (ShadowConsumerDisableEvent) event;
            List<ShadowConsumerDisableInfo> list = shadowConsumerDisableEvent.getTarget();
            disableBatch(list);
        } else if (event instanceof ClusterTestSwitchOffEvent) {
            disableAll();
        } else if (event instanceof SilenceSwitchOnEvent) {
            disableAll();
        }
    } catch (Throwable e) {
        EventResult.error(event.getTarget(), e.getMessage());
    }
    return EventResult.success(event.getTarget());
}
Also used : SilenceSwitchOnEvent(com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent) ShadowConsumerDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent) ShadowConsumerDisableInfo(com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo) ClusterTestSwitchOffEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)

Example 5 with ShadowConsumerDisableInfo

use of com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo in project LinkAgent by shulieTech.

the class ShadowConsumerDisableListenerImpl method disableBatch.

@Override
public boolean disableBatch(List<ShadowConsumerDisableInfo> list) {
    boolean result = true;
    for (ShadowConsumerDisableInfo shadowConsumerDisableInfo : list) {
        String springKey = Pradar.addClusterTestPrefix(shadowConsumerDisableInfo.getTopic()) + "#" + shadowConsumerDisableInfo.getConsumerGroup();
        String originKey = shadowConsumerDisableInfo.getTopic() + "#" + shadowConsumerDisableInfo.getConsumerGroup();
        if (ShadowConsumerHolder.topicGroupBeanNameMap.containsKey(springKey)) {
            disableBatchSpringKafka(springKey);
            break;
        } else if (ConsumerHolder.getShadowProxyMapping().containsKey(originKey)) {
            disableBatchOriginKafka(originKey, shadowConsumerDisableInfo.getTopic(), shadowConsumerDisableInfo.getConsumerGroup());
            break;
        }
    }
    return result;
}
Also used : ShadowConsumerDisableInfo(com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo)

Aggregations

ShadowConsumerDisableInfo (com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo)6 ShadowConsumerDisableEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent)5 ClusterTestSwitchOffEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)4 SilenceSwitchOnEvent (com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent)4 IEvent (com.pamirs.pradar.pressurement.agent.event.IEvent)2 ClusterTestSwitchOnEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOnEvent)2 PradarEventListener (com.pamirs.pradar.pressurement.agent.listener.PradarEventListener)2 DefaultMQPushConsumer (com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer)1 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)1 MqWhiteListConfigEvent (com.pamirs.pradar.pressurement.agent.event.impl.MqWhiteListConfigEvent)1 ArrayList (java.util.ArrayList)1 DefaultMQPushConsumer (org.apache.rocketmq.client.consumer.DefaultMQPushConsumer)1 MQClientException (org.apache.rocketmq.client.exception.MQClientException)1 RebalanceImpl (org.apache.rocketmq.client.impl.consumer.RebalanceImpl)1