From c524f4b7faa5f9a94d947d51af20528b9ee3e067 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 25 May 2023 14:45:09 -0400 Subject: [PATCH 1/2] bump to 1.5.0-SNAPSHOT since we are adding a feature --- api/pom.xml | 2 +- archetypes/example-kar-plugin/pom.xml | 2 +- archetypes/pom.xml | 2 +- common/pom.xml | 2 +- config/pom.xml | 2 +- karaf-features/pom.xml | 2 +- pom.xml | 2 +- sample/pom.xml | 2 +- test-api/pom.xml | 2 +- test-suites/pom.xml | 2 +- test-suites/tss-tests/pom.xml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 0829fe5..b6d4960 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -2,7 +2,7 @@ org.opennms.integration.api api-project - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT 4.0.0 api diff --git a/archetypes/example-kar-plugin/pom.xml b/archetypes/example-kar-plugin/pom.xml index 5429aa4..527548b 100644 --- a/archetypes/example-kar-plugin/pom.xml +++ b/archetypes/example-kar-plugin/pom.xml @@ -5,7 +5,7 @@ org.opennms.integration.api archetypes - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT example-kar-plugin maven-archetype diff --git a/archetypes/pom.xml b/archetypes/pom.xml index 0529434..e62ca9f 100644 --- a/archetypes/pom.xml +++ b/archetypes/pom.xml @@ -2,7 +2,7 @@ org.opennms.integration.api api-project - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT 4.0.0 archetypes diff --git a/common/pom.xml b/common/pom.xml index fbe920e..f752a69 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -2,7 +2,7 @@ org.opennms.integration.api api-project - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT 4.0.0 common diff --git a/config/pom.xml b/config/pom.xml index 99a7805..bfa4071 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -2,7 +2,7 @@ org.opennms.integration.api api-project - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT 4.0.0 config diff --git a/karaf-features/pom.xml b/karaf-features/pom.xml index 4ba64e6..a531ac5 100644 --- a/karaf-features/pom.xml +++ b/karaf-features/pom.xml @@ -2,7 +2,7 @@ org.opennms.integration.api api-project - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT 4.0.0 karaf-features diff --git a/pom.xml b/pom.xml index 7264fd3..541a6ee 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.opennms.integration.api api-project pom - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT OpenNMS Integration API :: Parent https://github.com/OpenNMS/opennms-integration-api Integration and extension API for OpenNMS diff --git a/sample/pom.xml b/sample/pom.xml index fae2308..4af8844 100644 --- a/sample/pom.xml +++ b/sample/pom.xml @@ -2,7 +2,7 @@ org.opennms.integration.api api-project - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT 4.0.0 org.opennms.integration.api.sample diff --git a/test-api/pom.xml b/test-api/pom.xml index fe792c1..6b11f04 100644 --- a/test-api/pom.xml +++ b/test-api/pom.xml @@ -2,7 +2,7 @@ org.opennms.integration.api api-project - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT 4.0.0 test-api diff --git a/test-suites/pom.xml b/test-suites/pom.xml index 470fc4b..e90745e 100644 --- a/test-suites/pom.xml +++ b/test-suites/pom.xml @@ -2,7 +2,7 @@ org.opennms.integration.api api-project - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT 4.0.0 test-suites diff --git a/test-suites/tss-tests/pom.xml b/test-suites/tss-tests/pom.xml index d9b9e04..4e7bb0c 100644 --- a/test-suites/tss-tests/pom.xml +++ b/test-suites/tss-tests/pom.xml @@ -3,7 +3,7 @@ org.opennms.integration.api test-suites - v1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT 4.0.0 tss-tests From bca7eec8341107a7b197b171069ed52aff3107a0 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 25 May 2023 15:46:11 -0400 Subject: [PATCH 2/2] NMS-15439: add alarmdao ticket handling --- .../integration/api/v1/dao/AlarmDao.java | 86 ++++++++++++++++++- .../integration/api/v1/model/Alarm.java | 17 +++- .../v1/model/immutables/ImmutableAlarm.java | 42 ++++++++- 3 files changed, 136 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/org/opennms/integration/api/v1/dao/AlarmDao.java b/api/src/main/java/org/opennms/integration/api/v1/dao/AlarmDao.java index 726dad8..e37f3dd 100644 --- a/api/src/main/java/org/opennms/integration/api/v1/dao/AlarmDao.java +++ b/api/src/main/java/org/opennms/integration/api/v1/dao/AlarmDao.java @@ -1,8 +1,8 @@ /******************************************************************************* * This file is part of OpenNMS(R). * - * Copyright (C) 2018 The OpenNMS Group, Inc. - * OpenNMS(R) is Copyright (C) 1999-2018 The OpenNMS Group, Inc. + * Copyright (C) 2018-2023 The OpenNMS Group, Inc. + * OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc. * * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc. * @@ -34,6 +34,8 @@ import org.opennms.integration.api.v1.annotations.Consumable; import org.opennms.integration.api.v1.graph.NodeRef; import org.opennms.integration.api.v1.model.Alarm; +import org.opennms.integration.api.v1.model.Severity; +import org.opennms.integration.api.v1.ticketing.Ticket.State; /** * Lookup alarms. @@ -42,10 +44,88 @@ */ @Consumable public interface AlarmDao { - + /** + * Get the number of alarms. + * + * @return the number of alarms + */ Long getAlarmCount(); + /** + * Get all alarms. + * + * @return the list of alarms + */ List getAlarms(); + /** + * Retrieve the highest-severity alarm associated with a node. + * + * @param nodeRef a node reference of foreignSource:foreignId + * @return the alarm, if any + */ Optional getAlarmWithHighestSeverity(NodeRef nodeRef); + + /** + * Get the alarm associated with the given trouble ticket ID. + * + * @since 1.5.0 + * @param ticketId the ticket ID to search for + * @return the associated alarm + */ + Optional getAlarmForTicket(final String ticketId); + + /** + * Updates the ticket state for the given alarm(s). + * + * @since 1.5.0 + * @param state the ticket state to set + * @param alarmIds the alarm(s) to set the state on + */ + void setTicketState(final State state, final int... alarmIds); + + /** + * Acknowledge the specified alarm(s). + * + * @since 1.5.0 + * @param user the user acknowledging the alarm(s) + * @param alarmIds the alarm(s) to acknowledge + */ + void acknowledge(final String user, final int... alarmIds); + + /** + * Unacknowledge the specified alarm(s). + * + * @since 1.5.0 + * @param alarmIds the alarm(s) to unacknowledge + */ + void unacknowledge(final int... alarmIds); + + /** + * Escalate the specified alarm(s). + * + * @since 1.5.0 + * @param user the user escalating the alarm(s) + * @param alarmIds the alarm(s) to escalate + */ + void escalate(final String user, final int... alarmIds); + + /** + * Clear the specified alarm(s). + * + * @since 1.5.0 + * @param alarmIds the alarm(s) to clear + */ + void clear(final int... alarmIds); + + /** + * Set the severity of the specified alarm(s). + * + * @since 1.5.0 + * @param severity the severity to set + * @param alarmIds the alarm(s) to update + */ + void setSeverity(final Severity severity, final int... alarmIds); + + } diff --git a/api/src/main/java/org/opennms/integration/api/v1/model/Alarm.java b/api/src/main/java/org/opennms/integration/api/v1/model/Alarm.java index 3e1ee81..8edc1c9 100644 --- a/api/src/main/java/org/opennms/integration/api/v1/model/Alarm.java +++ b/api/src/main/java/org/opennms/integration/api/v1/model/Alarm.java @@ -1,8 +1,8 @@ /******************************************************************************* * This file is part of OpenNMS(R). * - * Copyright (C) 2018 The OpenNMS Group, Inc. - * OpenNMS(R) is Copyright (C) 1999-2018 The OpenNMS Group, Inc. + * Copyright (C) 2018-2023 The OpenNMS Group, Inc. + * OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc. * * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc. * @@ -34,6 +34,7 @@ import org.opennms.integration.api.v1.annotations.Model; import org.opennms.integration.api.v1.config.events.AlarmType; +import org.opennms.integration.api.v1.ticketing.Ticket.State; /** * An alarm. @@ -77,4 +78,16 @@ public interface Alarm { boolean isAcknowledged(); + /** + * @since 1.5.0 + * @return the ticket ID associated with this alarm + */ + String getTicketId(); + + /** + * @since 1.5.0 + * @return the state of the ticket associated with this alarm + */ + State getTicketState(); + } diff --git a/common/src/main/java/org/opennms/integration/api/v1/model/immutables/ImmutableAlarm.java b/common/src/main/java/org/opennms/integration/api/v1/model/immutables/ImmutableAlarm.java index debb633..0b373b8 100644 --- a/common/src/main/java/org/opennms/integration/api/v1/model/immutables/ImmutableAlarm.java +++ b/common/src/main/java/org/opennms/integration/api/v1/model/immutables/ImmutableAlarm.java @@ -1,8 +1,8 @@ /******************************************************************************* * This file is part of OpenNMS(R). * - * Copyright (C) 2019 The OpenNMS Group, Inc. - * OpenNMS(R) is Copyright (C) 1999-2019 The OpenNMS Group, Inc. + * Copyright (C) 2019-2023 The OpenNMS Group, Inc. + * OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc. * * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc. * @@ -40,6 +40,7 @@ import org.opennms.integration.api.v1.model.DatabaseEvent; import org.opennms.integration.api.v1.model.Node; import org.opennms.integration.api.v1.model.Severity; +import org.opennms.integration.api.v1.ticketing.Ticket.State; import org.opennms.integration.api.v1.util.ImmutableCollections; import org.opennms.integration.api.v1.util.MutableCollections; @@ -62,6 +63,8 @@ public final class ImmutableAlarm implements Alarm { private final Date firstEventTime; private final DatabaseEvent lastEvent; private final boolean acknowledged; + private final String ticketId; + private final State ticketState; private ImmutableAlarm(Builder builder) { reductionKey = builder.reductionKey; @@ -79,6 +82,8 @@ private ImmutableAlarm(Builder builder) { firstEventTime = builder.firstEventTime; lastEvent = builder.lastEvent; acknowledged = builder.acknowledged; + ticketId = builder.ticketId; + ticketState = builder.ticketState; } public static Builder newBuilder() { @@ -112,6 +117,8 @@ public static final class Builder { private Date firstEventTime; private DatabaseEvent lastEvent; private boolean acknowledged; + private String ticketId; + private State ticketState; private Builder() { } @@ -132,6 +139,8 @@ private Builder(Alarm alarm) { firstEventTime = alarm.getFirstEventTime(); lastEvent = alarm.getLastEvent(); acknowledged = alarm.isAcknowledged(); + ticketId = alarm.getTicketId(); + ticketState = alarm.getTicketState(); } public Builder setReductionKey(String reductionKey) { @@ -225,6 +234,16 @@ public Builder setAcknowledged(boolean acknowledged) { return this; } + public Builder setTicketId(final String id) { + this.ticketId = id; + return this; + } + + public Builder setTicketState(final State state) { + this.ticketState = state; + return this; + } + public ImmutableAlarm build() { return new ImmutableAlarm(this); } @@ -310,6 +329,16 @@ public boolean isAcknowledged() { return acknowledged; } + @Override + public String getTicketId() { + return ticketId; + } + + @Override + public State getTicketState() { + return ticketState; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -329,14 +358,16 @@ public boolean equals(Object o) { Objects.equals(lastEventTime, that.lastEventTime) && Objects.equals(firstEventTime, that.firstEventTime) && Objects.equals(lastEvent, that.lastEvent) && - Objects.equals(acknowledged, that.acknowledged); + Objects.equals(acknowledged, that.acknowledged) && + Objects.equals(ticketId, that.ticketId) && + Objects.equals(ticketState, that.ticketState); } @Override public int hashCode() { return Objects.hash(reductionKey, id, node, managedObjectInstance, managedObjectType, type, severity, attributes, relatedAlarms, logMessage, description, lastEventTime, firstEventTime, - lastEvent, acknowledged); + lastEvent, acknowledged, ticketId, ticketState); } @Override @@ -357,6 +388,9 @@ public String toString() { ", firstEventTime=" + firstEventTime + ", lastEvent=" + lastEvent + ", acknowledged=" + acknowledged + + ", ticketId=" + ticketId + + ", ticketState=" + ticketState + '}'; } + }