Skip to content

Commit

Permalink
NMS-16978: Changed event's primary key to BIGINT
Browse files Browse the repository at this point in the history
christianpape authored Jan 28, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3c58d8b commit b485b88
Showing 88 changed files with 522 additions and 196 deletions.
2 changes: 1 addition & 1 deletion .circleci/main/executors.yml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ executors:
- image: cimg/base:stable-20.04
build-executor:
docker:
- image: opennms/build-env:circleci-ubuntu-jdk11
- image: opennms/build-env:circleci-ubuntu-jdk17
coverage-executor:
docker:
- image: opennms/build-env:circleci-ubuntu-jdk17
Original file line number Diff line number Diff line change
@@ -117,6 +117,16 @@ public static int[] safeParseInt(String[] dirty) throws NumberFormatException {
return clean;
}

public static long[] safeParseLong(String[] dirty) throws NumberFormatException {
final long[] clean = new long[dirty.length];
String cleanString;
for (int i = 0; i < dirty.length; i++) {
cleanString = ILLEGAL_IN_INTEGER.matcher(dirty[i]).replaceAll("");
clean[i] = Long.parseLong(cleanString);
}
return clean;
}

/**
* <p>safeParseInt</p>
*
175 changes: 175 additions & 0 deletions core/schema/src/main/liquibase/34.0.0/changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?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="34.0.0-drop-views-alter-eventid-to-bigint-and-recreate-views">
<dropView viewName="node_alarms"/>
<dropView viewName="node_outages"/>
<dropView viewName="node_outage_status"/>

<modifyDataType tableName="outages" columnName="svclosteventid" newDataType="bigint"/>
<modifyDataType tableName="outages" columnName="svcregainedeventid" newDataType="bigint"/>
<modifyDataType tableName="notifications" columnName="eventid" newDataType="bigint"/>
<modifyDataType tableName="event_parameters" columnName="eventid" newDataType="bigint"/>
<modifyDataType tableName="alarms" columnName="lasteventid" newDataType="bigint"/>
<modifyDataType tableName="events" columnName="eventid" newDataType="bigint"/>

<!--
<sql>
ALTER SEQUENCE eventsNxtId RESTART WITH 10000000000
</sql>
-->

<createView replaceIfExists="true" viewName="node_outage_status">
SELECT
node.nodeid,
(CASE WHEN severity IS NULL OR severity &lt; 3 THEN 3 ELSE severity END) AS max_outage_severity
FROM
(
SELECT events.nodeid, max(events.eventseverity) AS severity
FROM events
JOIN outages ON outages.svclosteventid = events.eventid
WHERE outages.ifregainedservice IS NULL AND outages.perspective IS NULL
GROUP BY events.nodeid
) AS tmp
RIGHT JOIN node ON tmp.nodeid = node.nodeid
</createView>

<createView replaceIfExists="true" viewName="node_outages">
SELECT
outages.outageid,
outages.svclosteventid,
outages.svcregainedeventid,
outages.iflostservice,
outages.ifregainedservice,
outages.ifserviceid,
e.eventuei AS svclosteventuei,
e.eventsource,
e.alarmid,
e.eventseverity,
(ifregainedservice NOTNULL) AS resolved,
s.servicename,
i.serviceid,
ipif.ipaddr,
COALESCE(outages.ifregainedservice - outages.iflostservice, now() - outages.iflostservice) AS duration,
nos.max_outage_severity,
nc.*
FROM
outages
JOIN
events e
ON
outages.svclosteventid = e.eventid
JOIN
ifservices i
ON
outages.ifserviceid = i.id
JOIN
service s
ON
i.serviceid = s.serviceid
JOIN
ipinterface ipif
ON
i.ipinterfaceid = ipif.id
JOIN
node_categories nc
ON
nc.nodeid = e.nodeid
JOIN
node_outage_status nos
ON
nc.nodeid = nos.nodeid
WHERE
outages.perspective IS NULL
</createView>

<createView replaceIfExists="true" viewName="node_alarms">
SELECT
n.nodeid,
n.nodecreatetime,
n.nodeparentid,
n.nodetype,
n.nodesysoid,
n.nodesysname,
n.nodesysdescription,
n.nodesyslocation,
n.nodesyscontact,
n.nodelabel,
n.nodelabelsource,
n.nodenetbiosname,
n.nodedomainname,
n.operatingsystem,
n.lastcapsdpoll,
n.foreignsource,
n.foreignid,
n.location,
a.alarmid,
a.eventuei,
a.ipaddr,
a.reductionkey,
a.alarmtype,
a.counter,
a.severity,
a.lasteventid,
a.firsteventtime,
a.lasteventtime,
a.firstautomationtime,
a.lastautomationtime,
a.description,
a.logmsg,
a.operinstruct,
a.tticketid,
a.tticketstate,
a.suppresseduntil,
a.suppresseduser,
a.suppressedtime,
a.alarmackuser,
a.alarmacktime,
a.managedobjectinstance,
a.managedobjecttype,
a.applicationdn,
a.ossprimarykey,
a.x733alarmtype,
a.qosalarmstate,
a.clearkey,
a.ifindex,
a.stickymemo,
a.systemid,
(a.alarmacktime NOTNULL) AS acknowledged,
COALESCE(s_cat.categoryname, 'no category') AS categoryname,
s_cat.categorydescription,
s.servicename,
nas.max_alarm_severity,
nas.max_alarm_severity_unack,
nas.alarm_count_unack,
nas.alarm_count
FROM
node n
JOIN
alarms a
ON
n.nodeid = a.nodeid
JOIN
node_alarm_status nas
ON
a.nodeid = nas.nodeid
LEFT JOIN
service s
ON
a.serviceid = s.serviceid
LEFT JOIN
category_node cat
ON
n.nodeid = cat.nodeid
LEFT JOIN
categories s_cat
ON
cat.categoryid = s_cat.categoryid
</createView>
</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
@@ -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="34.0.0/changelog.xml"/>

<include file="stored-procedures/getManagePercentAvailIntfWindow.xml" />
<include file="stored-procedures/getManagePercentAvailNodeWindow.xml" />
Original file line number Diff line number Diff line change
@@ -176,8 +176,8 @@ public String getNextEventIdStatement() {
return getNextSequenceValStatement("eventsNxtId");
}

public Integer getNextEventId() {
return getNextId(getNextEventIdStatement());
public Long getNextEventId() {
return getNextIdLong(getNextEventIdStatement());
}

public String getNextServiceIdStatement() {
@@ -229,11 +229,11 @@ public void createOutage(MockService svc, Event svcLostEvent) {
createOutage(svc, svcLostEvent.getDbid(), new Timestamp(svcLostEvent.getTime().getTime()));
}

public void createOutage(MockService svc, int eventId, Timestamp time) {
public void createOutage(MockService svc, long eventId, Timestamp time) {
Object[] values = {
getNextOutageId(), // outageID
svc.getId(), // service ID
Integer.valueOf(eventId), // svcLostEventId
Long.valueOf(eventId), // svcLostEventId
time, // ifLostService
};

@@ -245,10 +245,10 @@ public void resolveOutage(MockService svc, Event svcRegainEvent) {
resolveOutage(svc, svcRegainEvent.getDbid(), new Timestamp(svcRegainEvent.getTime().getTime()));
}

public void resolveOutage(MockService svc, int eventId, Timestamp timestamp) {
public void resolveOutage(MockService svc, long eventId, Timestamp timestamp) {

Object[] values = {
Integer.valueOf(eventId), // svcLostEventId
Long.valueOf(eventId), // svcLostEventId
timestamp, // ifLostService
Integer.valueOf(svc.getId()) // ifServiceId
};
@@ -262,7 +262,7 @@ public void resolveOutage(MockService svc, int eventId, Timestamp timestamp) {
*/
@Override
public void writeEvent(Event e) {
Integer eventId = getNextEventId();
Long eventId = getNextEventId();

if (e.getCreationTime() == null) {
e.setCreationTime(new Date());
@@ -456,7 +456,7 @@ public void processRow(ResultSet rs) throws SQLException {
notifyIds.add(rs.getInt(1));
}
};
loadExisting.execute(Integer.valueOf(event.getDbid()));
loadExisting.execute(Long.valueOf(event.getDbid()));
return notifyIds;
}

@@ -485,6 +485,10 @@ protected Integer getNextId(String nxtIdStmt) {
return getJdbcTemplate().queryForObject(nxtIdStmt, Integer.class);
}

protected Long getNextIdLong(String nxtIdStmt) {
return getJdbcTemplate().queryForObject(nxtIdStmt, Long.class);
}

public void setDistPoller(String distPoller) {
this.distPoller = distPoller;
}
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ public void setUp() throws IOException {

@Test
public void canGetAlarmAtTimestamp() {
OnmsAlarm a1 = createAlarm(1, 1L);
OnmsAlarm a1 = createAlarm(1, 1L, 1L);

// An alarm that doesn't exist should return null
assertThat(repo.getAlarmWithDbIdAt(a1.getId(), 0).orElse(null), nullValue());
@@ -124,7 +124,7 @@ public void canGetAlarmAtTimestamp() {
PseudoClock.getInstance().advanceTime(1, TimeUnit.MILLISECONDS);

// Update the alarm
updateAlarmWithEvent(a1, 2L);
updateAlarmWithEvent(a1, a1.getId(), 2L);
indexer.handleNewOrUpdatedAlarm(a1);

await().until(() -> repo.getAlarmWithDbIdAt(a1.getId(), 2).get().getCounter(), equalTo(2));
@@ -143,7 +143,7 @@ public void canGetAlarmAtTimestamp() {

@Test
public void canGetStatesForAlarmWithDbId() {
OnmsAlarm a1 = createAlarm(1, 1L);
OnmsAlarm a1 = createAlarm(1, 1L, 1L);

// An alarm that doesn't exist should return an empty list
assertThat(repo.getStatesForAlarmWithDbId(a1.getId()), empty());
@@ -163,7 +163,7 @@ public void canGetStatesForAlarmWithDbId() {
PseudoClock.getInstance().advanceTime(1, TimeUnit.MILLISECONDS);

// Update the alarm
updateAlarmWithEvent(a1, 2L);
updateAlarmWithEvent(a1, a1.getId(), 2L);
indexer.handleNewOrUpdatedAlarm(a1);

// Two state changes
@@ -193,7 +193,7 @@ public void canGetActiveAlarmsAtTimestamp() {
PseudoClock.getInstance().advanceTime(1, TimeUnit.MILLISECONDS);

// Index some alarm
OnmsAlarm a1 = createAlarm(1, 1L);
OnmsAlarm a1 = createAlarm(1, 1L, 1L);
indexer.handleNewOrUpdatedAlarm(a1);

// One alarm active
@@ -204,7 +204,7 @@ public void canGetActiveAlarmsAtTimestamp() {
PseudoClock.getInstance().advanceTime(1, TimeUnit.MILLISECONDS);

// Index another alarm
OnmsAlarm a2 = createAlarm(2, 2L);
OnmsAlarm a2 = createAlarm(2, 2L, 2L);
indexer.handleNewOrUpdatedAlarm(a2);

// Two alarms active
@@ -239,7 +239,7 @@ public void canGetLastStateOfAllAlarms() {

// Index a1

OnmsAlarm a1 = createAlarm(1, 1L);
OnmsAlarm a1 = createAlarm(1, 1L, 1L);
indexer.handleNewOrUpdatedAlarm(a1);

// t=2
@@ -250,7 +250,7 @@ public void canGetLastStateOfAllAlarms() {

// Index a2

OnmsAlarm a2 = createAlarm(2, 2L);
OnmsAlarm a2 = createAlarm(2, 2L, 2L);
indexer.handleNewOrUpdatedAlarm(a2);

// Wait until we have two results
@@ -267,23 +267,23 @@ public void canGetLastStateOfAllAlarms() {
assertThat(a2State.getDeletedTime(), nullValue());
}

private static OnmsAlarm createAlarm(int id, long firstEventTime) {
private static OnmsAlarm createAlarm(int id, long eventid, long firstEventTime) {
OnmsAlarm alarm = new OnmsAlarm();
alarm.setId(id);
alarm.setReductionKey("rkey-" + id);
alarm.setFirstEventTime(new Date(firstEventTime));
alarm.setCounter(1);

OnmsEvent lastEvent = new OnmsEvent();
lastEvent.setId(id);
lastEvent.setId(eventid);
lastEvent.setEventTime(new Date(firstEventTime));
alarm.setLastEvent(lastEvent);
return alarm;
}

private static void updateAlarmWithEvent(OnmsAlarm a, long lastEventTime) {
private static void updateAlarmWithEvent(OnmsAlarm a, long eventid, long lastEventTime) {
OnmsEvent lastEvent = new OnmsEvent();
lastEvent.setId(a.getId());
lastEvent.setId(eventid);
lastEvent.setEventTime(new Date(lastEventTime));
a.setLastEvent(lastEvent);
a.setCounter(a.getCounter() + 1);
Loading

0 comments on commit b485b88

Please sign in to comment.