Search in sources :

Example 6 with ClusterTestSwitchOffEvent

use of com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent 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 7 with ClusterTestSwitchOffEvent

use of com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent in project LinkAgent by shulieTech.

the class ClusterTestConfigHttpResolver method pradarSwitchClosed.

/**
 * 压测开关开启,执行开关前,判断开关执行状态
 */
private void pradarSwitchClosed() {
    try {
        // 执行前清空异常信息
        ErrorReporter.getInstance().clear();
        ClusterTestSwitchOffEvent event = new ClusterTestSwitchOffEvent(this);
        boolean isSuccess = EventRouter.router().publish(event);
        if (!isSuccess) {
            PradarSwitcher.turnClusterTestSwitchOn();
        }
    } catch (Throwable e) {
        LOGGER.warn("SIMULATOR: [FetchConfig] switch do closed has error", e);
        /**
         * 关闭失败则重置压测开关
         */
        PradarSwitcher.turnClusterTestSwitchOn();
    } finally {
        pradarSwitchProcessing.set(false);
    }
}
Also used : ClusterTestSwitchOffEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)

Example 8 with ClusterTestSwitchOffEvent

use of com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent in project LinkAgent by shulieTech.

the class ConsumerRegistry method addListener.

private static void addListener(final DefaultMQPushConsumer businessConsumer) {
    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("alibaba-rocketmq-plugin-open", "Alibaba-RocketMQ PT Consumer start failed: " + e.getMessage());
                }
                return EventResult.success("alibaba-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 = businessConsumer.getDefaultMQPushConsumerImpl().getRebalanceImpl().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 : PradarEventListener(com.pamirs.pradar.pressurement.agent.listener.PradarEventListener) IEvent(com.pamirs.pradar.pressurement.agent.event.IEvent) ClusterTestSwitchOnEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOnEvent) SilenceSwitchOnEvent(com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent) DefaultMQPushConsumer(com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException) ShadowConsumerDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent) ClusterTestSwitchOffEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent) ShadowConsumerDisableInfo(com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo)

Aggregations

ClusterTestSwitchOffEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)8 IEvent (com.pamirs.pradar.pressurement.agent.event.IEvent)4 ClusterTestSwitchOnEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOnEvent)4 ShadowConsumerDisableEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowConsumerDisableEvent)4 SilenceSwitchOnEvent (com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent)4 PradarEventListener (com.pamirs.pradar.pressurement.agent.listener.PradarEventListener)4 ShadowConsumerDisableInfo (com.pamirs.pradar.pressurement.agent.listener.model.ShadowConsumerDisableInfo)4 EventResult (com.pamirs.pradar.pressurement.agent.listener.EventResult)2 DefaultMQPushConsumer (com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer)1 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)1 AtomikosDataSourceBeanMediaDataSource (com.pamirs.attach.plugin.atomikos.utils.AtomikosDataSourceBeanMediaDataSource)1 AtomikosNonXADataSourceBeanMediaDataSource (com.pamirs.attach.plugin.atomikos.utils.AtomikosNonXADataSourceBeanMediaDataSource)1 XxlJobAdapter (com.pamirs.attach.plugin.shadowjob.adapter.XxlJobAdapter)1 ShadowDatabaseConfig (com.pamirs.pradar.internal.config.ShadowDatabaseConfig)1 ShadowDataSourceConfigModifyEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowDataSourceConfigModifyEvent)1 ShadowImplListener (com.pamirs.pradar.pressurement.agent.listener.impl.ShadowImplListener)1 DataSourceMeta (com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)1 EnhanceCallback (com.shulie.instrument.simulator.api.instrument.EnhanceCallback)1 InstrumentClass (com.shulie.instrument.simulator.api.instrument.InstrumentClass)1 InstrumentMethod (com.shulie.instrument.simulator.api.instrument.InstrumentMethod)1