use of com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent in project LinkAgent by shulieTech.
the class SilenceSwitch method compareIsChangeAndSet.
@Override
public Boolean compareIsChangeAndSet(ClusterTestConfig config, Boolean newValue) {
boolean silenceSwitchOn = PradarSwitcher.silenceSwitchOn();
if (ObjectUtils.equals(newValue, silenceSwitchOn)) {
return Boolean.FALSE;
}
// 变更后配置更新到内存
if (newValue) {
SilenceSwitchOnEvent event = new SilenceSwitchOnEvent(this);
EventRouter.router().publish(event);
PradarSwitcher.turnSilenceSwitchOn();
config.setSilenceSwitchOn(true);
} else {
SilenceSwitchOffEvent event = new SilenceSwitchOffEvent(this);
EventRouter.router().publish(event);
PradarSwitcher.turnSilenceSwitchOff();
config.setSilenceSwitchOn(false);
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("publish silence switch config successful. config={}", newValue);
}
return Boolean.TRUE;
}
use of com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent 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());
}
use of com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent 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);
}
}
use of com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent 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());
}
use of com.pamirs.pradar.pressurement.agent.event.impl.SilenceSwitchOnEvent 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);
}
}
Aggregations