Skip to content

Commit

Permalink
NMS-16966: Added indices for metadata tables
Browse files Browse the repository at this point in the history
  • Loading branch information
christianpape committed Jan 23, 2025
1 parent 3abf80d commit e6628ba
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
26 changes: 26 additions & 0 deletions core/schema/src/main/liquibase/33.0.3/changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

<changeSet author="cpape" id="33.0.3-node_metadata-index">
<createIndex tableName="node_metadata" indexName="node_metadata_refid_idx" associatedWith="foreignKey" unique="false">
<column name="id" />
</createIndex>
</changeSet>

<changeSet author="cpape" id="33.0.3-ipinterface_metadata-index">
<createIndex tableName="ipinterface_metadata" indexName="ipinterface_metadata_refid_idx" associatedWith="foreignKey" unique="false">
<column name="id" />
</createIndex>
</changeSet>

<changeSet author="cpape" id="33.0.3-ifservices_metadata-index">
<createIndex tableName="ifservices_metadata" indexName="ifservices_metadata_refid_idx" associatedWith="foreignKey" unique="false">
<column name="id" />
</createIndex>
</changeSet>

</databaseChangeLog>
1 change: 1 addition & 0 deletions core/schema/src/main/liquibase/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<include file="31.0.2/changelog.xml"/>
<include file="foundation-2023/changelog.xml"/>
<include file="32.0.0/changelog.xml"/>
<include file="33.0.3/changelog.xml"/>

<include file="stored-procedures/getManagePercentAvailIntfWindow.xml" />
<include file="stored-procedures/getManagePercentAvailNodeWindow.xml" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@
* @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",
"classpath:/META-INF/opennms/applicationContext-mockDao.xml",
"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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Integer, AlarmAndFact> alarmsById = new HashMap<>();
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e6628ba

Please sign in to comment.