juniper-contrail: publish events only for the module (#11373)

* juniper-contrail: publish events only for the module

This plugin has an ActionEventInterceptor of its own and currently it
intercepts all action events which is incorrect as all action events are
already handled by com.cloud.event.ActionEventInterceptor.
This PR limits publishing events on event bus by plugin's interceptor
only in case the event is from the same module.

Existing behaviour was causing warnings in Webhook service as event
account was missing.

2025-07-31 19:18:59,391 WARN  [o.a.c.m.w.WebhookServiceImpl] ... to any webhook as account ID is missing

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2025-08-04 16:37:32 +05:30 committed by GitHub
parent 626f3de69a
commit cda3640be1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,6 +48,10 @@ public class EventUtils {
private static EventDistributor eventDistributor; private static EventDistributor eventDistributor;
private static final String MODULE_TOP_LEVEL_PACKAGE =
EventUtils.class.getPackage().getName().substring(0,
EventUtils.class.getPackage().getName().lastIndexOf('.'));
public EventUtils() { public EventUtils() {
} }
@ -143,6 +147,13 @@ public class EventUtils {
@Override @Override
public void interceptComplete(Method method, Object target, Object event) { public void interceptComplete(Method method, Object target, Object event) {
ActionEvent actionEvent = method.getAnnotation(ActionEvent.class); ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
boolean sameModule = false;
if (target != null && target.getClass().getPackage() != null) {
sameModule = target.getClass().getPackage().getName().startsWith(MODULE_TOP_LEVEL_PACKAGE);
}
if (!sameModule) {
return;
}
if (actionEvent != null) { if (actionEvent != null) {
CallContext ctx = CallContext.current(); CallContext ctx = CallContext.current();
if (!actionEvent.create()) { if (!actionEvent.create()) {