From e6628ba0004d01f952ff098d3ed85fb96a3810a8 Mon Sep 17 00:00:00 2001 From: Christian Pape Date: Tue, 21 Jan 2025 08:08:56 +0100 Subject: [PATCH] NMS-16966: Added indices for metadata tables --- .../src/main/liquibase/33.0.3/changelog.xml | 26 +++++++++++++++++++ core/schema/src/main/liquibase/changelog.xml | 1 + .../kafka/producer/KafkaForwarderIT.java | 5 +++- .../alarmd/drools/DroolsAlarmContext.java | 10 +++++++ .../alarmd/drools/DroolsAlarmContextIT.java | 7 +++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 core/schema/src/main/liquibase/33.0.3/changelog.xml diff --git a/core/schema/src/main/liquibase/33.0.3/changelog.xml b/core/schema/src/main/liquibase/33.0.3/changelog.xml new file mode 100644 index 000000000000..b516074c4ef7 --- /dev/null +++ b/core/schema/src/main/liquibase/33.0.3/changelog.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/schema/src/main/liquibase/changelog.xml b/core/schema/src/main/liquibase/changelog.xml index 0859b7195f9f..8169e99c8c9c 100644 --- a/core/schema/src/main/liquibase/changelog.xml +++ b/core/schema/src/main/liquibase/changelog.xml @@ -100,6 +100,7 @@ + diff --git a/features/kafka/producer/src/test/java/org/opennms/features/kafka/producer/KafkaForwarderIT.java b/features/kafka/producer/src/test/java/org/opennms/features/kafka/producer/KafkaForwarderIT.java index 0f3773c35042..ec8a643e485a 100644 --- a/features/kafka/producer/src/test/java/org/opennms/features/kafka/producer/KafkaForwarderIT.java +++ b/features/kafka/producer/src/test/java/org/opennms/features/kafka/producer/KafkaForwarderIT.java @@ -116,7 +116,9 @@ * @author jwhite */ @RunWith(OpenNMSJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:/META-INF/opennms/applicationContext-soa.xml", +@ContextConfiguration(locations = { + "classpath:/META-INF/opennms/applicationContext-dao.xml", + "classpath:/META-INF/opennms/applicationContext-soa.xml", "classpath:/META-INF/opennms/applicationContext-commonConfigs.xml", "classpath:/META-INF/opennms/applicationContext-eventUtil.xml", "classpath:/META-INF/opennms/applicationContext-minimal-conf.xml", @@ -124,6 +126,7 @@ "classpath:/META-INF/opennms/applicationContext-daemon.xml", "classpath:/META-INF/opennms/mockEventIpcManager.xml", "classpath:/META-INF/opennms/applicationContext-alarmd.xml", + "classpath*:/META-INF/opennms/component-dao.xml", "classpath:/applicationContext-test-kafka-producer.xml" }) @JUnitConfigurationEnvironment @JUnitTemporaryDatabase(dirtiesContext = false, tempDbClass = MockDatabase.class, reuseDatabase = false) diff --git a/opennms-alarms/daemon/src/main/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContext.java b/opennms-alarms/daemon/src/main/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContext.java index 2249b89229c2..b9fea920744a 100644 --- a/opennms-alarms/daemon/src/main/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContext.java +++ b/opennms-alarms/daemon/src/main/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContext.java @@ -42,6 +42,7 @@ import org.hibernate.Hibernate; import org.hibernate.ObjectNotFoundException; +import org.hibernate.SessionFactory; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; import org.opennms.core.sysprops.SystemProperties; @@ -107,6 +108,9 @@ public class DroolsAlarmContext extends ManagedDroolsContext implements AlarmLif @Autowired private AlarmDao alarmDao; + @Autowired + private SessionFactory sessionFactory; + private final AlarmCallbackStateTracker stateTracker = new AlarmCallbackStateTracker(); private final Map alarmsById = new HashMap<>(); @@ -456,6 +460,8 @@ private void eagerlyInitializeAlarm(OnmsAlarm alarm) { Hibernate.initialize(alarm.getNode().getCategories()); // Allow rules to use metadata of the associated node Hibernate.initialize(alarm.getNode().getMetaData()); + // see NMS-16966 + sessionFactory.getCurrentSession().setReadOnly(alarm.getNode(), true); } } @@ -589,4 +595,8 @@ public void setTransactionTemplate(TransactionTemplate template) { public void setAlarmDao(AlarmDao alarmDao) { this.alarmDao = alarmDao; } + + public void setSessionFactory(final SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } } diff --git a/opennms-alarms/daemon/src/test/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContextIT.java b/opennms-alarms/daemon/src/test/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContextIT.java index 77fc7945e16e..596ccb8352c7 100644 --- a/opennms-alarms/daemon/src/test/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContextIT.java +++ b/opennms-alarms/daemon/src/test/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContextIT.java @@ -50,6 +50,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import org.hibernate.classic.Session; +import org.hibernate.SessionFactory; import org.junit.After; import org.junit.Before; import org.junit.Ignore; @@ -127,6 +129,11 @@ public void setUp() throws InterruptedException, IOException { dac.setAlarmService(alarmService); dac.setAcknowledgmentDao(acknowledgmentDao); + Session session = mock(Session.class); + SessionFactory sessionFactory = mock(SessionFactory.class); + when(sessionFactory.getCurrentSession()).thenReturn(session); + dac.setSessionFactory(sessionFactory); + dac.start(); // Wait