[ONOS-3203] End-to-end demo of Fault Management via SNMP.
This adds SNMP device-discovery, and a Fault Management app which makes alarms available to users via REST/GUI/CLI interfaces.
There is still code cleanup that could be done, but aim of this commit is an end-to-end proof of concept.
To demonstrate :
1) /opt/onos/bin/onos-service
onos> app activate org.onosproject.snmp
onos> app activate org.onosproject.faultmanagement
2) SNMP devices are seeded via config file. The default seed file contains connection details for devices (SNMP agents) available via internet e.g. demo.snmplabs.com
cp /opt/onos/apache-karaf-3.0.3/etc/samples/org.onosproject.provider.snmp.device.impl.SnmpDeviceProvider.cfg /opt/onos/apache-karaf-3.0.3/etc/
3) ONOS will poll these SNMP devices and store their alarms.
4) You can now manipulate the alarms via REST e.g. http://<onos>:8181/onos/v1/fm/alarms , via CLI via various "alarm-*” commands or in UI with an Alarms Overlay.
More info at https://wiki.onosproject.org/display/ONOS/Fault+Management
15/Dec/15: Updated regarding review comments from Thomas Vachuska.
17/Dec/15: Updated coreService.registerApplication(name) as per https://gerrit.onosproject.org/#/c/6878/
Change-Id: I886f8511f178dc4600ab96e5ff10cc90329cabec
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/DefaultAlarm.java b/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/DefaultAlarm.java
index afa366a..013eec1 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/DefaultAlarm.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/DefaultAlarm.java
@@ -145,14 +145,16 @@
@Override
public int hashCode() {
- return Objects.hash(id, deviceId, description,
- source, timeRaised, timeUpdated, timeCleared, severity,
+ // id or timeRaised or timeUpdated may differ
+ return Objects.hash(deviceId, description,
+ source, timeCleared, severity,
isServiceAffecting, isAcknowledged,
isManuallyClearable, assignedUser);
}
@Override
public boolean equals(final Object obj) {
+ // Make sure equals() is tune with hashCode() so works ok in a hashSet !
if (obj == null) {
return false;
}
@@ -160,9 +162,8 @@
return false;
}
final DefaultAlarm other = (DefaultAlarm) obj;
- if (!Objects.equals(this.id, other.id)) {
- return false;
- }
+
+ // id or timeRaised or timeUpdated may differ
if (!Objects.equals(this.deviceId, other.deviceId)) {
return false;
}
@@ -172,12 +173,7 @@
if (!Objects.equals(this.source, other.source)) {
return false;
}
- if (this.timeRaised != other.timeRaised) {
- return false;
- }
- if (this.timeUpdated != other.timeUpdated) {
- return false;
- }
+
if (!Objects.equals(this.timeCleared, other.timeCleared)) {
return false;
}
@@ -219,11 +215,11 @@
public static class Builder {
- // Manadatory fields ..
- private final AlarmId id;
+ // Manadatory fields when constructing alarm ...
+ private AlarmId id;
private final DeviceId deviceId;
private final String description;
- private final SeverityLevel severity;
+ private SeverityLevel severity;
private final long timeRaised;
// Optional fields ..
@@ -236,8 +232,8 @@
private String assignedUser = null;
public Builder(final Alarm alarm) {
- this(alarm.id(), alarm.deviceId(), alarm.description(), alarm.severity(), alarm.timeRaised());
- this.source = AlarmEntityId.NONE;
+ this(alarm.deviceId(), alarm.description(), alarm.severity(), alarm.timeRaised());
+ this.source = alarm.source();
this.timeUpdated = alarm.timeUpdated();
this.timeCleared = alarm.timeCleared();
this.isServiceAffecting = alarm.serviceAffecting();
@@ -247,10 +243,10 @@
}
- public Builder(final AlarmId id, final DeviceId deviceId,
+ public Builder(final DeviceId deviceId,
final String description, final SeverityLevel severity, final long timeRaised) {
super();
- this.id = id;
+ this.id = AlarmId.NONE;
this.deviceId = deviceId;
this.description = description;
this.severity = severity;
@@ -274,6 +270,17 @@
return this;
}
+ public Builder withId(final AlarmId id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder clear() {
+ this.severity = SeverityLevel.CLEARED;
+ final long now = System.currentTimeMillis();
+ return withTimeCleared(now).withTimeUpdated(now);
+ }
+
public Builder withServiceAffecting(final boolean isServiceAffecting) {
this.isServiceAffecting = isServiceAffecting;
return this;