Andrea Campanella
Committed by Gerrit Code Review

[ONOS-4260]Alarm and fault managment application refactoring according to ONOS architecture

Change-Id: I47e9db37eb5fc27ac19db2e4cb87774736b44685
Showing 30 changed files with 588 additions and 220 deletions
...@@ -76,7 +76,6 @@ CORE = [ ...@@ -76,7 +76,6 @@ CORE = [
76 '//providers/pcep/topology:onos-pcep-provider-topology', 76 '//providers/pcep/topology:onos-pcep-provider-topology',
77 '//providers/pcep/tunnel:onos-pcep-provider-tunnel', 77 '//providers/pcep/tunnel:onos-pcep-provider-tunnel',
78 '//providers/rest/device:onos-restsb-provider-device', 78 '//providers/rest/device:onos-restsb-provider-device',
79 - '//providers/snmp/alarm:onos-snmp-provider-alarm',
80 '//providers/snmp/device:onos-snmp-provider-device', 79 '//providers/snmp/device:onos-snmp-provider-device',
81 80
82 '//web/api:onos-rest', 81 '//web/api:onos-rest',
......
...@@ -35,9 +35,9 @@ public class GetAllAlarmsCounts extends AbstractShellCommand { ...@@ -35,9 +35,9 @@ public class GetAllAlarmsCounts extends AbstractShellCommand {
35 printCounts(alarmCounts); 35 printCounts(alarmCounts);
36 } 36 }
37 37
38 - static void printCounts(Map<Alarm.SeverityLevel, Long> alarmCounts) { 38 + void printCounts(Map<Alarm.SeverityLevel, Long> alarmCounts) {
39 alarmCounts.entrySet().stream().forEach((countEntry) -> { 39 alarmCounts.entrySet().stream().forEach((countEntry) -> {
40 - System.out.println(String.format("%s, %d", 40 + print(String.format("%s, %d",
41 countEntry.getKey(), countEntry.getValue())); 41 countEntry.getKey(), countEntry.getValue()));
42 42
43 }); 43 });
......
...@@ -38,7 +38,14 @@ public class GetDeviceAlarmsCounts extends AbstractShellCommand { ...@@ -38,7 +38,14 @@ public class GetDeviceAlarmsCounts extends AbstractShellCommand {
38 Map<Alarm.SeverityLevel, Long> alarmCounts = AbstractShellCommand.get(AlarmService.class). 38 Map<Alarm.SeverityLevel, Long> alarmCounts = AbstractShellCommand.get(AlarmService.class).
39 getAlarmCounts(DeviceId.deviceId(deviceId)); 39 getAlarmCounts(DeviceId.deviceId(deviceId));
40 // Deliberately using same formatting for both ... 40 // Deliberately using same formatting for both ...
41 - GetAllAlarmsCounts.printCounts(alarmCounts); 41 + printCounts(alarmCounts);
42 } 42 }
43 43
44 + void printCounts(Map<Alarm.SeverityLevel, Long> alarmCounts) {
45 + alarmCounts.entrySet().stream().forEach((countEntry) -> {
46 + print(String.format("%s, %d",
47 + countEntry.getKey(), countEntry.getValue()));
48 +
49 + });
50 + }
44 } 51 }
......
...@@ -42,7 +42,7 @@ import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; ...@@ -42,7 +42,7 @@ import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
42 import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService; 42 import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService;
43 43
44 /** 44 /**
45 - * Skeletal ONOS UI Topology-Overlay message handler. 45 + * FaultManagement UI Topology-Overlay message handler.
46 */ 46 */
47 public class AlarmTopovMessageHandler extends UiMessageHandler { 47 public class AlarmTopovMessageHandler extends UiMessageHandler {
48 48
......
...@@ -45,11 +45,6 @@ ...@@ -45,11 +45,6 @@
45 <version>${project.version}</version> 45 <version>${project.version}</version>
46 </dependency> 46 </dependency>
47 <dependency> 47 <dependency>
48 - <groupId>org.onosproject</groupId>
49 - <artifactId>onos-snmp-provider-alarm</artifactId>
50 - <version>${project.version}</version>
51 - </dependency>
52 - <dependency>
53 <groupId>org.osgi</groupId> 48 <groupId>org.osgi</groupId>
54 <artifactId>org.osgi.compendium</artifactId> 49 <artifactId>org.osgi.compendium</artifactId>
55 <version>5.0.0</version> 50 <version>5.0.0</version>
......
...@@ -15,109 +15,136 @@ ...@@ -15,109 +15,136 @@
15 */ 15 */
16 package org.onosproject.faultmanagement.impl; 16 package org.onosproject.faultmanagement.impl;
17 17
18 -import com.google.common.collect.Sets; 18 +import com.google.common.collect.ImmutableSet;
19 -import java.util.Collections; 19 +import org.junit.Before;
20 -import java.util.HashMap; 20 +import org.junit.Rule;
21 -import java.util.HashSet;
22 -import java.util.Map;
23 import org.junit.Test; 21 import org.junit.Test;
24 -import static org.junit.Assert.*; 22 +import org.junit.rules.ExpectedException;
25 import org.onlab.util.ItemNotFoundException; 23 import org.onlab.util.ItemNotFoundException;
26 -import org.onosproject.net.DeviceId;
27 -import static org.hamcrest.Matchers.containsString;
28 import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; 24 import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
29 -import static org.onosproject.incubator.net.faultmanagement.alarm.Alarm.SeverityLevel.*;
30 import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId; 25 import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId;
31 import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; 26 import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId;
32 import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; 27 import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
28 +import org.onosproject.net.DeviceId;
33 29
30 +import java.util.Collections;
31 +import java.util.HashMap;
32 +import java.util.Map;
33 +
34 +import static org.junit.Assert.assertEquals;
35 +import static org.junit.Assert.assertTrue;
36 +import static org.onosproject.incubator.net.faultmanagement.alarm.Alarm.SeverityLevel.CLEARED;
37 +import static org.onosproject.incubator.net.faultmanagement.alarm.Alarm.SeverityLevel.CRITICAL;
38 +
39 +/**
40 + * Alarm manager test suite.
41 + */
34 public class AlarmsManagerTest { 42 public class AlarmsManagerTest {
35 43
36 - @Test 44 + private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo:bar");
37 - public void testGettersWhenNoAlarms() { 45 + private static final DefaultAlarm ALARM_A = new DefaultAlarm.Builder(
38 - AlarmsManager am = new AlarmsManager(); 46 + DEVICE_ID, "aaa", Alarm.SeverityLevel.CRITICAL, 0).build();
39 - assertTrue("No alarms", am.getAlarms().isEmpty()); 47 +
40 - assertTrue("No active alarms", am.getActiveAlarms().isEmpty()); 48 + private static final DefaultAlarm ALARM_A_WITHSRC = new DefaultAlarm.Builder(
41 - assertTrue("No alarms gives empty map per unknown device", am.getAlarmCounts(DeviceId.NONE).keySet().isEmpty()); 49 + ALARM_A).forSource(AlarmEntityId.alarmEntityId("port:foo")).build();
42 - assertTrue("No alarms gives empty map", am.getAlarmCounts().keySet().isEmpty()); 50 +
43 - 51 + private static final DefaultAlarm ALARM_B = new DefaultAlarm.Builder(
44 - assertEquals("Zero alarms for that device", 0, am.getAlarms(DeviceId.NONE).size()); 52 + DEVICE_ID, "bbb", Alarm.SeverityLevel.CRITICAL, 0).build();
45 - assertEquals("Zero major alarms", 0, am.getAlarms(Alarm.SeverityLevel.MAJOR).size()); 53 +
46 - 54 + private AlarmsManager am;
47 - try { 55 +
48 - assertEquals("no alarms", 0, am.getAlarm(null)); 56 + @Rule
49 - } catch (NullPointerException ex) { 57 + public final ExpectedException exception = ExpectedException.none();
50 - assertThat(ex.getMessage(), 58 +
51 - containsString("cannot be null")); 59 + @Before
60 + public void setUp() throws Exception {
61 + am = new AlarmsManager();
52 } 62 }
53 63
54 - try { 64 + @Test
55 - assertEquals("no alarms", 0, am.getAlarm(AlarmId.alarmId(1))); 65 + public void deactivate() throws Exception {
56 - } catch (ItemNotFoundException ex) { 66 + am.updateAlarms(DEVICE_ID, ImmutableSet.of(ALARM_B, ALARM_A));
57 - assertThat(ex.getMessage(), 67 + verifyGettingSetsOfAlarms(am, 2, 2);
58 - containsString("not found")); 68 + am.deactivate(null);
69 + assertEquals("Alarms should be purged", 0, am.alarms.size());
59 } 70 }
71 +
72 + @Test
73 + public void testGettersWhenNoAlarms() {
74 +
75 + assertTrue("No alarms should be present", am.getAlarms().isEmpty());
76 + assertTrue("No active alarms should be present", am.getActiveAlarms().isEmpty());
77 + assertTrue("The map should be empty per unknown device",
78 + am.getAlarmCounts(DeviceId.NONE).keySet().isEmpty());
79 + assertTrue("The counts should be empty", am.getAlarmCounts().keySet().isEmpty());
80 +
81 + assertEquals("Incorrect number of alarms for unknown device",
82 + 0, am.getAlarms(DeviceId.NONE).size());
83 + assertEquals("Incorrect number of major alarms for unknown device",
84 + 0, am.getAlarms(Alarm.SeverityLevel.MAJOR).size());
85 +
86 + exception.expect(NullPointerException.class);
87 + am.getAlarm(null);
88 +
89 + exception.expect(ItemNotFoundException.class);
90 + am.getAlarm(AlarmId.alarmId(1));
60 } 91 }
61 92
62 @Test 93 @Test
63 public void testAlarmUpdates() { 94 public void testAlarmUpdates() {
64 - AlarmsManager am = new AlarmsManager();
65 - assertTrue("no alarms", am.getAlarms().isEmpty());
66 95
67 - am.updateAlarms(new HashSet<>(), DEVICE_ID); 96 + assertTrue("No alarms should be present", am.getAlarms().isEmpty());
68 - assertTrue("still no alarms", am.getAlarms().isEmpty()); 97 + am.updateAlarms(DEVICE_ID, ImmutableSet.of());
98 + assertTrue("No alarms should be present", am.getAlarms().isEmpty());
69 Map<Alarm.SeverityLevel, Long> zeroAlarms = new CountsMapBuilder().create(); 99 Map<Alarm.SeverityLevel, Long> zeroAlarms = new CountsMapBuilder().create();
70 - assertEquals(zeroAlarms, am.getAlarmCounts()); 100 + assertEquals("No alarms count should be present", zeroAlarms, am.getAlarmCounts());
71 - assertEquals(zeroAlarms, am.getAlarmCounts(DEVICE_ID)); 101 + assertEquals("No alarms count should be present", zeroAlarms, am.getAlarmCounts(DEVICE_ID));
72 102
73 - am.updateAlarms(Sets.newHashSet(ALARM_B, ALARM_A), DEVICE_ID); 103 + am.updateAlarms(DEVICE_ID, ImmutableSet.of(ALARM_B, ALARM_A));
74 verifyGettingSetsOfAlarms(am, 2, 2); 104 verifyGettingSetsOfAlarms(am, 2, 2);
75 Map<Alarm.SeverityLevel, Long> critical2 = new CountsMapBuilder().with(CRITICAL, 2L).create(); 105 Map<Alarm.SeverityLevel, Long> critical2 = new CountsMapBuilder().with(CRITICAL, 2L).create();
76 - assertEquals(critical2, am.getAlarmCounts()); 106 + assertEquals("A critical should be present", critical2, am.getAlarmCounts());
77 - assertEquals(critical2, am.getAlarmCounts(DEVICE_ID)); 107 + assertEquals("A critical should be present", critical2, am.getAlarmCounts(DEVICE_ID));
78 108
79 - am.updateAlarms(Sets.newHashSet(ALARM_A), DEVICE_ID); 109 + am.updateAlarms(DEVICE_ID, ImmutableSet.of(ALARM_A));
80 verifyGettingSetsOfAlarms(am, 2, 1); 110 verifyGettingSetsOfAlarms(am, 2, 1);
81 Map<Alarm.SeverityLevel, Long> critical1cleared1 = 111 Map<Alarm.SeverityLevel, Long> critical1cleared1 =
82 new CountsMapBuilder().with(CRITICAL, 1L).with(CLEARED, 1L).create(); 112 new CountsMapBuilder().with(CRITICAL, 1L).with(CLEARED, 1L).create();
83 - assertEquals(critical1cleared1, am.getAlarmCounts()); 113 + assertEquals("A critical should be present and cleared", critical1cleared1,
84 - assertEquals(critical1cleared1, am.getAlarmCounts(DEVICE_ID)); 114 + am.getAlarmCounts());
115 + assertEquals("A critical should be present and cleared", critical1cleared1,
116 + am.getAlarmCounts(DEVICE_ID));
85 117
86 // No change map when same alarms sent 118 // No change map when same alarms sent
87 - am.updateAlarms(Sets.newHashSet(ALARM_A), DEVICE_ID); 119 + am.updateAlarms(DEVICE_ID, ImmutableSet.of(ALARM_A));
88 verifyGettingSetsOfAlarms(am, 2, 1); 120 verifyGettingSetsOfAlarms(am, 2, 1);
89 - assertEquals(critical1cleared1, am.getAlarmCounts()); 121 + assertEquals("Map should not be changed for same alarm", critical1cleared1,
90 - assertEquals(critical1cleared1, am.getAlarmCounts(DEVICE_ID)); 122 + am.getAlarmCounts());
123 + assertEquals("Map should not be changed for same alarm", critical1cleared1,
124 + am.getAlarmCounts(DEVICE_ID));
91 125
92 - am.updateAlarms(Sets.newHashSet(ALARM_A, ALARM_A_WITHSRC), DEVICE_ID); 126 + am.updateAlarms(DEVICE_ID, ImmutableSet.of(ALARM_A, ALARM_A_WITHSRC));
93 verifyGettingSetsOfAlarms(am, 3, 2); 127 verifyGettingSetsOfAlarms(am, 3, 2);
94 Map<Alarm.SeverityLevel, Long> critical2cleared1 = 128 Map<Alarm.SeverityLevel, Long> critical2cleared1 =
95 new CountsMapBuilder().with(CRITICAL, 2L).with(CLEARED, 1L).create(); 129 new CountsMapBuilder().with(CRITICAL, 2L).with(CLEARED, 1L).create();
96 - assertEquals(critical2cleared1, am.getAlarmCounts()); 130 + assertEquals("A critical should be present", critical2cleared1, am.getAlarmCounts());
97 - assertEquals(critical2cleared1, am.getAlarmCounts(DEVICE_ID)); 131 + assertEquals("A critical should be present", critical2cleared1, am.getAlarmCounts(DEVICE_ID));
98 132
99 - am.updateAlarms(Sets.newHashSet(), DEVICE_ID); 133 + am.updateAlarms(DEVICE_ID, ImmutableSet.of());
100 verifyGettingSetsOfAlarms(am, 3, 0); 134 verifyGettingSetsOfAlarms(am, 3, 0);
101 assertEquals(new CountsMapBuilder().with(CLEARED, 3L).create(), am.getAlarmCounts(DEVICE_ID)); 135 assertEquals(new CountsMapBuilder().with(CLEARED, 3L).create(), am.getAlarmCounts(DEVICE_ID));
102 136
103 - assertEquals("No alarms for unknown devices", zeroAlarms, am.getAlarmCounts(DeviceId.NONE)); 137 + assertEquals("The counts should be empty for unknown devices", zeroAlarms,
104 - assertEquals("No alarms for unknown devices", zeroAlarms, am.getAlarmCounts(DeviceId.deviceId("junk:junk"))); 138 + am.getAlarmCounts(DeviceId.NONE));
139 + assertEquals("The counts should be empty for unknown devices", zeroAlarms,
140 + am.getAlarmCounts(DeviceId.deviceId("junk:junk")));
105 141
106 } 142 }
107 143
108 private void verifyGettingSetsOfAlarms(AlarmsManager am, int expectedTotal, int expectedActive) { 144 private void verifyGettingSetsOfAlarms(AlarmsManager am, int expectedTotal, int expectedActive) {
109 - assertEquals("Wrong total", expectedTotal, am.getAlarms().size()); 145 + assertEquals("Incorrect total alarms", expectedTotal, am.getAlarms().size());
110 - assertEquals("Wrong active count", expectedActive, am.getActiveAlarms().size()); 146 + assertEquals("Incorrect active alarms count", expectedActive, am.getActiveAlarms().size());
111 } 147 }
112 - private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo:bar");
113 - private static final DefaultAlarm ALARM_A = new DefaultAlarm.Builder(
114 - DEVICE_ID, "aaa", Alarm.SeverityLevel.CRITICAL, 0).build();
115 -
116 - private static final DefaultAlarm ALARM_A_WITHSRC = new DefaultAlarm.Builder(
117 - ALARM_A).forSource(AlarmEntityId.alarmEntityId("port:foo")).build();
118 -
119 - private static final DefaultAlarm ALARM_B = new DefaultAlarm.Builder(
120 - DEVICE_ID, "bbb", Alarm.SeverityLevel.CRITICAL, 0).build();
121 148
122 private static class CountsMapBuilder { 149 private static class CountsMapBuilder {
123 150
......
...@@ -46,7 +46,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -46,7 +46,7 @@ import static org.slf4j.LoggerFactory.getLogger;
46 @Path("alarms") 46 @Path("alarms")
47 public class AlarmsWebResource extends AbstractWebResource { 47 public class AlarmsWebResource extends AbstractWebResource {
48 48
49 - public static final String ALARM_NOT_FOUND = "Alarm is not found"; 49 + private static final String ALARM_NOT_FOUND = "Alarm is not found";
50 50
51 private final Logger log = getLogger(getClass()); 51 private final Logger log = getLogger(getClass());
52 52
...@@ -63,7 +63,7 @@ public class AlarmsWebResource extends AbstractWebResource { ...@@ -63,7 +63,7 @@ public class AlarmsWebResource extends AbstractWebResource {
63 @DefaultValue("") @QueryParam("devId") String devId 63 @DefaultValue("") @QueryParam("devId") String devId
64 ) { 64 ) {
65 65
66 - log.info("Requesting all alarms, includeCleared={}", includeCleared); 66 + log.debug("Requesting all alarms, includeCleared={}", includeCleared);
67 AlarmService service = get(AlarmService.class); 67 AlarmService service = get(AlarmService.class);
68 68
69 Iterable<Alarm> alarms; 69 Iterable<Alarm> alarms;
...@@ -90,7 +90,7 @@ public class AlarmsWebResource extends AbstractWebResource { ...@@ -90,7 +90,7 @@ public class AlarmsWebResource extends AbstractWebResource {
90 @Path("{id}") 90 @Path("{id}")
91 @Produces(MediaType.APPLICATION_JSON) 91 @Produces(MediaType.APPLICATION_JSON)
92 public Response getAlarm(@PathParam("id") String id) { 92 public Response getAlarm(@PathParam("id") String id) {
93 - log.info("HTTP GET alarm for id={}", id); 93 + log.debug("HTTP GET alarm for id={}", id);
94 94
95 AlarmId alarmId = toAlarmId(id); 95 AlarmId alarmId = toAlarmId(id);
96 Alarm alarm = get(AlarmService.class).getAlarm(alarmId); 96 Alarm alarm = get(AlarmService.class).getAlarm(alarmId);
...@@ -113,11 +113,11 @@ public class AlarmsWebResource extends AbstractWebResource { ...@@ -113,11 +113,11 @@ public class AlarmsWebResource extends AbstractWebResource {
113 @Consumes(MediaType.APPLICATION_JSON) 113 @Consumes(MediaType.APPLICATION_JSON)
114 @Produces(MediaType.APPLICATION_JSON) 114 @Produces(MediaType.APPLICATION_JSON)
115 public Response update(@PathParam("alarm_id") String alarmIdPath, InputStream stream) { 115 public Response update(@PathParam("alarm_id") String alarmIdPath, InputStream stream) {
116 - log.info("PUT NEW ALARM at /{}", alarmIdPath); 116 + log.debug("PUT NEW ALARM at /{}", alarmIdPath);
117 117
118 try { 118 try {
119 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); 119 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
120 - log.info("jsonTree={}", jsonTree); 120 + log.debug("jsonTree={}", jsonTree);
121 121
122 Alarm alarm = new AlarmCodec().decode(jsonTree, this); 122 Alarm alarm = new AlarmCodec().decode(jsonTree, this);
123 123
...@@ -139,7 +139,7 @@ public class AlarmsWebResource extends AbstractWebResource { ...@@ -139,7 +139,7 @@ public class AlarmsWebResource extends AbstractWebResource {
139 } 139 }
140 } 140 }
141 141
142 - private static AlarmId toAlarmId(String id) { 142 + private AlarmId toAlarmId(String id) {
143 try { 143 try {
144 return AlarmId.alarmId(Long.parseLong(id)); 144 return AlarmId.alarmId(Long.parseLong(id));
145 } catch (NumberFormatException ex) { 145 } catch (NumberFormatException ex) {
......
...@@ -6,6 +6,7 @@ CURRENT_TARGET = ':' + CURRENT_NAME ...@@ -6,6 +6,7 @@ CURRENT_TARGET = ':' + CURRENT_NAME
6 COMPILE_DEPS = [ 6 COMPILE_DEPS = [
7 '//lib:CORE_DEPS', 7 '//lib:CORE_DEPS',
8 '//protocols/snmp/api:onos-snmp-api', 8 '//protocols/snmp/api:onos-snmp-api',
9 + '//incubator/api:onos-incubator-api',
9 '//lib:org.apache.servicemix.bundles.snmp4j', 10 '//lib:org.apache.servicemix.bundles.snmp4j',
10 '//lib:snmp-core', 11 '//lib:snmp-core',
11 '//lib:bti7000', 12 '//lib:bti7000',
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.provider.snmp.alarm.impl; 16 +
17 +package org.onosproject.drivers.bti;
17 18
18 import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.I_Device; 19 import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.I_Device;
19 import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0._OidRegistry; 20 import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0._OidRegistry;
...@@ -23,31 +24,34 @@ import com.btisystems.pronx.ems.core.model.ClassRegistry; ...@@ -23,31 +24,34 @@ import com.btisystems.pronx.ems.core.model.ClassRegistry;
23 import com.btisystems.pronx.ems.core.model.IClassRegistry; 24 import com.btisystems.pronx.ems.core.model.IClassRegistry;
24 import com.btisystems.pronx.ems.core.model.NetworkDevice; 25 import com.btisystems.pronx.ems.core.model.NetworkDevice;
25 import com.btisystems.pronx.ems.core.snmp.ISnmpSession; 26 import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
26 -import java.io.IOException; 27 +import com.google.common.collect.ImmutableList;
27 -import java.util.Arrays;
28 -import java.util.Calendar;
29 -import java.util.Collection;
30 -import java.util.Date;
31 -import java.util.GregorianCalendar;
32 -import java.util.HashSet;
33 -import java.util.Set;
34 -import java.util.TimeZone;
35 import org.apache.commons.lang.StringUtils; 28 import org.apache.commons.lang.StringUtils;
36 import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; 29 import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
30 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmConsumer;
37 import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId; 31 import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId;
38 import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; 32 import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
39 import org.onosproject.net.DeviceId; 33 import org.onosproject.net.DeviceId;
34 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
35 +import org.onosproject.snmp.SnmpController;
40 import org.slf4j.Logger; 36 import org.slf4j.Logger;
41 -import static org.slf4j.LoggerFactory.getLogger;
42 -import org.snmp4j.smi.OID;
43 import org.snmp4j.smi.OctetString; 37 import org.snmp4j.smi.OctetString;
44 38
39 +import java.io.IOException;
40 +import java.util.ArrayList;
41 +import java.util.Calendar;
42 +import java.util.Collections;
43 +import java.util.Date;
44 +import java.util.GregorianCalendar;
45 +import java.util.List;
46 +import java.util.TimeZone;
47 +
48 +import static com.google.common.base.Preconditions.checkNotNull;
49 +import static org.slf4j.LoggerFactory.getLogger;
50 +
45 /** 51 /**
46 * BTI 7000 specific implementation to provide a list of current alarms. 52 * BTI 7000 specific implementation to provide a list of current alarms.
47 - * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
48 */ 53 */
49 -@Deprecated 54 +public class Bti7000SnmpAlarmConsumer extends AbstractHandlerBehaviour implements AlarmConsumer {
50 -public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider {
51 private final Logger log = getLogger(getClass()); 55 private final Logger log = getLogger(getClass());
52 protected static final IClassRegistry CLASS_REGISTRY = new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class); 56 protected static final IClassRegistry CLASS_REGISTRY = new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class);
53 57
...@@ -55,40 +59,6 @@ public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider { ...@@ -55,40 +59,6 @@ public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider {
55 static final int ALARM_SEVERITY_MAJOR = 3; 59 static final int ALARM_SEVERITY_MAJOR = 3;
56 static final int ALARM_SEVERITY_CRITICAL = 4; 60 static final int ALARM_SEVERITY_CRITICAL = 4;
57 61
58 - @Override
59 - public Collection<Alarm> getAlarms(ISnmpSession session, DeviceId deviceID) {
60 - log.info("Getting alarms for BTI 7000 device at {}", deviceID);
61 - Set<Alarm> alarms = new HashSet<>();
62 - NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY,
63 - session.getAddress().getHostAddress());
64 -
65 - try {
66 - session.walkDevice(networkDevice, Arrays.asList(
67 - new OID[]{CLASS_REGISTRY.getClassToOidMap().get(ActAlarmTable.class)}));
68 -
69 - IActAlarmTable deviceAlarms = (IActAlarmTable) networkDevice.getRootObject()
70 - .getEntity(CLASS_REGISTRY.getClassToOidMap().get(ActAlarmTable.class));
71 - if ((deviceAlarms != null) && (deviceAlarms.getActAlarmEntry() != null)
72 - && (!deviceAlarms.getActAlarmEntry().isEmpty())) {
73 -
74 - deviceAlarms.getActAlarmEntry().values().stream().forEach((alarm) -> {
75 - DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(
76 - deviceID, alarm.getActAlarmDescription(),
77 - mapAlarmSeverity(alarm.getActAlarmSeverity()),
78 - getLocalDateAndTime(alarm.getActAlarmDateAndTime(), null, null).getTime())
79 - .forSource(AlarmEntityId.alarmEntityId("other:" + alarm.getActAlarmInstanceIdx()));
80 - alarms.add(alarmBuilder.build());
81 - });
82 -
83 - }
84 - log.info("Conditions retrieved: {}", deviceAlarms);
85 -
86 - } catch (IOException ex) {
87 - log.error("Error reading alarms for device {}.", deviceID, ex);
88 - }
89 -
90 - return alarms;
91 - }
92 62
93 private Alarm.SeverityLevel mapAlarmSeverity(int intAlarmSeverity) { 63 private Alarm.SeverityLevel mapAlarmSeverity(int intAlarmSeverity) {
94 Alarm.SeverityLevel mappedSeverity; 64 Alarm.SeverityLevel mappedSeverity;
...@@ -108,6 +78,7 @@ public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider { ...@@ -108,6 +78,7 @@ public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider {
108 } 78 }
109 return mappedSeverity; 79 return mappedSeverity;
110 } 80 }
81 +
111 /** 82 /**
112 * Converts an SNMP string representation into a {@link Date} object, 83 * Converts an SNMP string representation into a {@link Date} object,
113 * and applies time zone conversion to provide the time on the local machine, ie PSM server. 84 * and applies time zone conversion to provide the time on the local machine, ie PSM server.
...@@ -141,14 +112,13 @@ public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider { ...@@ -141,14 +112,13 @@ public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider {
141 /** 112 /**
142 * This method is similar to SNMP4J approach with some fixes for the 11-bytes version (ie the one with timezone 113 * This method is similar to SNMP4J approach with some fixes for the 11-bytes version (ie the one with timezone
143 * offset). 114 * offset).
144 - * 115 + * <p>
145 * For original makeCalendar refer @see http://www.snmp4j.org/agent/doc/org/snmp4j/agent/mo/snmp/DateAndTime.html 116 * For original makeCalendar refer @see http://www.snmp4j.org/agent/doc/org/snmp4j/agent/mo/snmp/DateAndTime.html
146 - * 117 + * <p>
147 * Creates a <code>GregorianCalendar</code> from a properly formatted SNMP4J DateAndTime <code>OctetString</code>. 118 * Creates a <code>GregorianCalendar</code> from a properly formatted SNMP4J DateAndTime <code>OctetString</code>.
148 * 119 *
149 * @param dateAndTimeValue an OctetString conforming to the DateAndTime TC. 120 * @param dateAndTimeValue an OctetString conforming to the DateAndTime TC.
150 * @return the corresponding <code>GregorianCalendar</code> instance. 121 * @return the corresponding <code>GregorianCalendar</code> instance.
151 - *
152 */ 122 */
153 public static GregorianCalendar btiMakeCalendar(OctetString dateAndTimeValue) { 123 public static GregorianCalendar btiMakeCalendar(OctetString dateAndTimeValue) {
154 int year = (dateAndTimeValue.get(0) & 0xFF) * 256 124 int year = (dateAndTimeValue.get(0) & 0xFF) * 256
...@@ -179,4 +149,44 @@ public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider { ...@@ -179,4 +149,44 @@ public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider {
179 private static TimeZone getTimeZone() { 149 private static TimeZone getTimeZone() {
180 return Calendar.getInstance().getTimeZone(); 150 return Calendar.getInstance().getTimeZone();
181 } 151 }
152 +
153 + @Override
154 + public List<Alarm> consumeAlarms() {
155 + SnmpController controller = checkNotNull(handler().get(SnmpController.class));
156 + ISnmpSession session;
157 + List<Alarm> alarms = new ArrayList<>();
158 + DeviceId deviceId = handler().data().deviceId();
159 + try {
160 + session = controller.getSession(deviceId);
161 + log.debug("Getting alarms for BTI 7000 device at {}", deviceId);
162 + NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY,
163 + session.getAddress().getHostAddress());
164 + session.walkDevice(networkDevice, Collections.singletonList(
165 + CLASS_REGISTRY.getClassToOidMap().get(ActAlarmTable.class)));
166 +
167 + IActAlarmTable deviceAlarms = (IActAlarmTable) networkDevice.getRootObject()
168 + .getEntity(CLASS_REGISTRY.getClassToOidMap().get(ActAlarmTable.class));
169 + if ((deviceAlarms != null) && (deviceAlarms.getActAlarmEntry() != null)
170 + && (!deviceAlarms.getActAlarmEntry().isEmpty())) {
171 +
172 + deviceAlarms.getActAlarmEntry().values().stream().forEach((alarm) -> {
173 + DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(
174 + deviceId, alarm.getActAlarmDescription(),
175 + mapAlarmSeverity(alarm.getActAlarmSeverity()),
176 + getLocalDateAndTime(alarm.getActAlarmDateAndTime(), null, null).getTime())
177 + .forSource(AlarmEntityId.alarmEntityId("other:" + alarm.getActAlarmInstanceIdx()));
178 + alarms.add(alarmBuilder.build());
179 + });
180 +
181 + }
182 + log.debug("Conditions retrieved: {}", deviceAlarms);
183 +
184 + } catch (IOException ex) {
185 + log.error("Error reading alarms for device {}.", deviceId, ex);
186 + alarms.add(controller.buildWalkFailedAlarm(deviceId));
187 +
188 + }
189 +
190 + return ImmutableList.copyOf(alarms);
191 + }
182 } 192 }
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.drivers.bti;
18 +
19 +import com.btisystems.mibbler.mibs.netsnmp.netsnmp.I_Device;
20 +import com.btisystems.mibbler.mibs.netsnmp.netsnmp._OidRegistry;
21 +import com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.interfaces.IfTable;
22 +import com.btisystems.pronx.ems.core.model.ClassRegistry;
23 +import com.btisystems.pronx.ems.core.model.IClassRegistry;
24 +import com.btisystems.pronx.ems.core.model.NetworkDevice;
25 +import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
26 +import com.google.common.collect.ImmutableList;
27 +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
28 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmConsumer;
29 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId;
30 +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
31 +import org.onosproject.net.DeviceId;
32 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
33 +import org.onosproject.snmp.SnmpController;
34 +import org.slf4j.Logger;
35 +
36 +import java.io.IOException;
37 +import java.util.ArrayList;
38 +import java.util.Collections;
39 +import java.util.List;
40 +
41 +import static com.google.common.base.Preconditions.checkNotNull;
42 +import static org.slf4j.LoggerFactory.getLogger;
43 +
44 +/**
45 + * Net SNMP specific implementation to provide a list of current alarms.
46 + */
47 +public class NetSnmpAlarmConsumer extends AbstractHandlerBehaviour implements AlarmConsumer {
48 + private final Logger log = getLogger(getClass());
49 + protected static final IClassRegistry CLASS_REGISTRY =
50 + new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class);
51 +
52 + @Override
53 + public List<Alarm> consumeAlarms() {
54 + SnmpController controller = checkNotNull(handler().get(SnmpController.class));
55 + List<Alarm> alarms = new ArrayList<>();
56 + ISnmpSession session;
57 + DeviceId deviceId = handler().data().deviceId();
58 + try {
59 + session = controller.getSession(deviceId);
60 +
61 + NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY,
62 + session.getAddress()
63 + .getHostAddress());
64 + session.walkDevice(networkDevice, Collections.singletonList(
65 + CLASS_REGISTRY.getClassToOidMap().get(IfTable.class)));
66 +
67 + IfTable interfaceTable = (IfTable) networkDevice.getRootObject()
68 + .getEntity(CLASS_REGISTRY.getClassToOidMap().get(IfTable.class));
69 + if (interfaceTable != null) {
70 + interfaceTable.getEntries().values().stream().forEach((ifEntry) -> {
71 + if (ifEntry.getIfAdminStatus() == 1 && ifEntry.getIfOperStatus() == 2) {
72 + alarms.add(new DefaultAlarm.Builder(deviceId, "Link Down.",
73 + Alarm.SeverityLevel.CRITICAL,
74 + System.currentTimeMillis())
75 + .forSource(AlarmEntityId
76 + .alarmEntityId("port:" + ifEntry.
77 + getIfDescr())).build());
78 + }
79 + log.debug("Interface: " + ifEntry);
80 + });
81 + }
82 + } catch (IOException ex) {
83 + log.error("Error reading alarms for device {}.", deviceId, ex);
84 + alarms.add(controller.buildWalkFailedAlarm(deviceId));
85 + }
86 + return ImmutableList.copyOf(alarms);
87 + }
88 +}
...@@ -19,10 +19,14 @@ ...@@ -19,10 +19,14 @@
19 <driver name="bti7000" manufacturer="bti" hwVersion="1.0.0" swVersion="1.0.0"> 19 <driver name="bti7000" manufacturer="bti" hwVersion="1.0.0" swVersion="1.0.0">
20 <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery" 20 <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
21 impl="org.onosproject.drivers.bti.Bti7000DeviceDescriptor"/> 21 impl="org.onosproject.drivers.bti.Bti7000DeviceDescriptor"/>
22 + <behaviour api="org.onosproject.incubator.net.faultmanagement.alarm.AlarmConsumer"
23 + impl="org.onosproject.drivers.bti.Bti7000SnmpAlarmConsumer"/>
22 </driver> 24 </driver>
23 <driver name="NetSnmp" manufacturer="bti" hwVersion="1.0.0" swVersion="1.0.0"> 25 <driver name="NetSnmp" manufacturer="bti" hwVersion="1.0.0" swVersion="1.0.0">
24 <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery" 26 <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
25 impl="org.onosproject.drivers.bti.NetSnmpDeviceDescriptor"/> 27 impl="org.onosproject.drivers.bti.NetSnmpDeviceDescriptor"/>
28 + <behaviour api="org.onosproject.incubator.net.faultmanagement.alarm.AlarmConsumer"
29 + impl="org.onosproject.drivers.bti.NetSnmpAlarmConsumer"/>
26 </driver> 30 </driver>
27 </drivers> 31 </drivers>
28 32
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.net.faultmanagement.alarm;
18 +
19 +import org.onosproject.net.driver.HandlerBehaviour;
20 +
21 +import java.util.List;
22 +
23 +/**
24 + * Abstraction of a device behaviour capable of retrieving/consuming list of
25 + * pending alarms from the device.
26 + */
27 +public interface AlarmConsumer extends HandlerBehaviour {
28 +
29 + /**
30 + * Returns the list of active alarms consumed from the device.
31 + * This means that subsequent retrieval of alarms will not contain
32 + * any duplicates.
33 + *
34 + * @return list of alarms consumed from the device
35 + */
36 + List<Alarm> consumeAlarms();
37 +
38 +}
...@@ -19,30 +19,18 @@ import org.onosproject.net.DeviceId; ...@@ -19,30 +19,18 @@ import org.onosproject.net.DeviceId;
19 import org.onosproject.net.provider.Provider; 19 import org.onosproject.net.provider.Provider;
20 20
21 /** 21 /**
22 - * Abstraction of a Alarm provider. 22 + * Abstraction of an entity capable of supplying alarms collected from
23 + * network devices.
23 */ 24 */
24 public interface AlarmProvider extends Provider { 25 public interface AlarmProvider extends Provider {
25 26
26 /** 27 /**
27 - * Triggers an asynchronous discovery of the alarms on the specified device, intended to refresh internal alarm 28 + * Triggers an asynchronous discovery of the alarms on the specified device,
28 - * model for the device. An indirect result of this should be a event sent later with discovery result ie a set of 29 + * intended to refresh internal alarm model for the device. An indirect
29 - * alarms. 30 + * result of this should be a event sent later with discovery result
31 + * ie a set of alarms.
30 * 32 *
31 * @param deviceId ID of device to be probed 33 * @param deviceId ID of device to be probed
32 */ 34 */
33 void triggerProbe(DeviceId deviceId); 35 void triggerProbe(DeviceId deviceId);
34 -
35 - /**
36 - * Register a listener for alarms.
37 - *
38 - * @param listener the listener to notify
39 - */
40 - void addAlarmListener(AlarmListener listener);
41 -
42 - /**
43 - * Unregister a listener.
44 - *
45 - * @param listener the listener to unregister
46 - */
47 - void removeAlarmListener(AlarmListener listener);
48 } 36 }
......
1 /* 1 /*
2 -<<<<<<< HEAD
3 * Copyright 2015-present Open Networking Laboratory 2 * Copyright 2015-present Open Networking Laboratory
4 -=======
5 - * Copyright 2015-present Open Networking Laboratory
6 ->>>>>>> master
7 * 3 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -18,7 +14,29 @@ ...@@ -18,7 +14,29 @@
18 * limitations under the License. 14 * limitations under the License.
19 */ 15 */
20 16
17 +package org.onosproject.incubator.net.faultmanagement.alarm;
18 +
19 +import org.onosproject.net.provider.ProviderId;
20 +
21 +import java.util.Set;
22 +
21 /** 23 /**
22 - * Provider that will support SNMP alarm discoveries. 24 + * Adapter for Alarm Provider Registry.
23 */ 25 */
24 -package org.onosproject.provider.snmp.alarm.impl; 26 +public class AlarmProviderRegistryAdapter implements AlarmProviderRegistry {
27 +
28 + @Override
29 + public AlarmProviderService register(AlarmProvider provider) {
30 + return null;
31 + }
32 +
33 + @Override
34 + public void unregister(AlarmProvider provider) {
35 +
36 + }
37 +
38 + @Override
39 + public Set<ProviderId> getProviders() {
40 + return null;
41 + }
42 +}
......
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
55 <dependency> 55 <dependency>
56 <groupId>org.apache.felix</groupId> 56 <groupId>org.apache.felix</groupId>
57 <artifactId>org.apache.felix.scr</artifactId> 57 <artifactId>org.apache.felix.scr</artifactId>
58 - <version>1.8.2</version>
59 </dependency> 58 </dependency>
60 <dependency> 59 <dependency>
61 <groupId>org.osgi</groupId> 60 <groupId>org.osgi</groupId>
...@@ -71,5 +70,4 @@ ...@@ -71,5 +70,4 @@
71 </plugin> 70 </plugin>
72 </plugins> 71 </plugins>
73 </build> 72 </build>
74 -
75 </project> 73 </project>
......
...@@ -14,6 +14,9 @@ TEST_DEPS = [ ...@@ -14,6 +14,9 @@ TEST_DEPS = [
14 '//core/common:onos-core-common-tests', 14 '//core/common:onos-core-common-tests',
15 '//incubator/store:onos-incubator-store', 15 '//incubator/store:onos-incubator-store',
16 '//core/store/serializers:onos-core-serializers', 16 '//core/store/serializers:onos-core-serializers',
17 + '//utils/osgi:onlab-osgi',
18 + '//utils/osgi:onlab-osgi-tests',
19 + '//incubator/api:onos-incubator-api-tests',
17 ] 20 ]
18 21
19 osgi_jar( 22 osgi_jar(
......
...@@ -41,6 +41,15 @@ ...@@ -41,6 +41,15 @@
41 41
42 <dependency> 42 <dependency>
43 <groupId>org.onosproject</groupId> 43 <groupId>org.onosproject</groupId>
44 + <artifactId>onos-incubator-api</artifactId>
45 + <version>${project.version}</version>
46 + <classifier>tests</classifier>
47 + <scope>test</scope>
48 + </dependency>
49 +
50 +
51 + <dependency>
52 + <groupId>org.onosproject</groupId>
44 <artifactId>onos-core-common</artifactId> 53 <artifactId>onos-core-common</artifactId>
45 <version>${project.version}</version> 54 <version>${project.version}</version>
46 <classifier>tests</classifier> 55 <classifier>tests</classifier>
...@@ -67,11 +76,6 @@ ...@@ -67,11 +76,6 @@
67 </dependency> 76 </dependency>
68 77
69 <dependency> 78 <dependency>
70 - <groupId>org.apache.felix</groupId>
71 - <artifactId>org.apache.felix.scr.annotations</artifactId>
72 - </dependency>
73 -
74 - <dependency>
75 <groupId>org.apache.karaf.features</groupId> 79 <groupId>org.apache.karaf.features</groupId>
76 <artifactId>org.apache.karaf.features.core</artifactId> 80 <artifactId>org.apache.karaf.features.core</artifactId>
77 </dependency> 81 </dependency>
...@@ -87,6 +91,19 @@ ...@@ -87,6 +91,19 @@
87 <version>${project.version}</version> 91 <version>${project.version}</version>
88 <scope>test</scope> 92 <scope>test</scope>
89 </dependency> 93 </dependency>
94 +
95 + <dependency>
96 + <groupId>org.apache.felix</groupId>
97 + <artifactId>org.apache.felix.scr.annotations</artifactId>
98 + </dependency>
99 +
100 + <dependency>
101 + <groupId>org.onosproject</groupId>
102 + <artifactId>onlab-osgi</artifactId>
103 + <version>${project.version}</version>
104 + <classifier>tests</classifier>
105 + <scope>test</scope>
106 + </dependency>
90 </dependencies> 107 </dependencies>
91 108
92 <build> 109 <build>
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm.impl;
17 +
18 +import org.apache.felix.scr.annotations.Activate;
19 +import org.apache.felix.scr.annotations.Component;
20 +import org.apache.felix.scr.annotations.Deactivate;
21 +import org.apache.felix.scr.annotations.Modified;
22 +import org.apache.felix.scr.annotations.Property;
23 +import org.apache.felix.scr.annotations.Reference;
24 +import org.apache.felix.scr.annotations.ReferenceCardinality;
25 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmConsumer;
26 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProvider;
27 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderRegistry;
28 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderService;
29 +import org.onosproject.mastership.MastershipEvent;
30 +import org.onosproject.mastership.MastershipListener;
31 +import org.onosproject.mastership.MastershipService;
32 +import org.onosproject.net.Device;
33 +import org.onosproject.net.DeviceId;
34 +import org.onosproject.net.device.DeviceEvent;
35 +import org.onosproject.net.device.DeviceListener;
36 +import org.onosproject.net.device.DeviceService;
37 +import org.onosproject.net.provider.AbstractProvider;
38 +import org.onosproject.net.provider.ProviderId;
39 +import org.osgi.service.component.ComponentContext;
40 +import org.slf4j.Logger;
41 +
42 +import java.util.Dictionary;
43 +import java.util.concurrent.ExecutorService;
44 +import java.util.concurrent.Executors;
45 +import java.util.concurrent.ScheduledExecutorService;
46 +import java.util.concurrent.ScheduledFuture;
47 +import java.util.concurrent.TimeUnit;
48 +
49 +import static com.google.common.base.Strings.isNullOrEmpty;
50 +import static org.onlab.util.Tools.get;
51 +import static org.onlab.util.Tools.groupedThreads;
52 +import static org.slf4j.LoggerFactory.getLogger;
53 +
54 +/**
55 + * Alarm provider capable of polling the environment using the device driver
56 + * {@link AlarmConsumer} behaviour.
57 + */
58 +@Component(immediate = true)
59 +public class PollingAlarmProvider extends AbstractProvider implements AlarmProvider {
60 +
61 + private final Logger log = getLogger(getClass());
62 +
63 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 + protected DeviceService deviceService;
65 +
66 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
67 + protected MastershipService mastershipService;
68 +
69 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
70 + protected AlarmProviderRegistry providerRegistry;
71 +
72 + protected AlarmProviderService providerService;
73 +
74 + protected ScheduledExecutorService alarmsExecutor;
75 +
76 + private ScheduledFuture<?> scheduledTask;
77 +
78 + private ExecutorService eventHandlingExecutor;
79 +
80 + protected final MastershipListener mastershipListener = new InternalMastershipListener();
81 +
82 + protected final DeviceListener deviceListener = new InternalDeviceListener();
83 +
84 + private static final int CORE_POOL_SIZE = 10;
85 +
86 + private static final int DEFAULT_POLL_FREQUENCY_SECONDS = 60;
87 + @Property(name = "alarmPollFrequencySeconds", intValue = DEFAULT_POLL_FREQUENCY_SECONDS,
88 + label = "Frequency (in seconds) for polling alarm from devices")
89 + protected int alarmPollFrequencySeconds = DEFAULT_POLL_FREQUENCY_SECONDS;
90 +
91 + // TODO implement purging of old alarms.
92 + private static final int DEFAULT_CLEAR_FREQUENCY_SECONDS = 500;
93 + @Property(name = "clearedAlarmPurgeSeconds", intValue = DEFAULT_CLEAR_FREQUENCY_SECONDS,
94 + label = "Frequency (in seconds) for deleting cleared alarms")
95 + private int clearedAlarmPurgeFrequencySeconds = DEFAULT_CLEAR_FREQUENCY_SECONDS;
96 +
97 + public PollingAlarmProvider() {
98 + super(new ProviderId("default", "org.onosproject.core"));
99 + }
100 +
101 + @Activate
102 + public void activate(ComponentContext context) {
103 + alarmsExecutor = Executors.newScheduledThreadPool(CORE_POOL_SIZE);
104 + eventHandlingExecutor =
105 + Executors.newFixedThreadPool(CORE_POOL_SIZE,
106 + groupedThreads("onos/pollingalarmprovider",
107 + "device-installer-%d", log));
108 +
109 + providerService = providerRegistry.register(this);
110 +
111 + deviceService.addListener(deviceListener);
112 + mastershipService.addListener(mastershipListener);
113 +
114 + if (context == null) {
115 + alarmPollFrequencySeconds = DEFAULT_POLL_FREQUENCY_SECONDS;
116 + log.info("No component configuration");
117 + } else {
118 + Dictionary<?, ?> properties = context.getProperties();
119 + alarmPollFrequencySeconds = getNewPollFrequency(properties, alarmPollFrequencySeconds);
120 + }
121 + scheduledTask = schedulePolling();
122 + log.info("Started");
123 + }
124 +
125 + @Deactivate
126 + public void deactivate() {
127 + providerRegistry.unregister(this);
128 + mastershipService.removeListener(mastershipListener);
129 + deviceService.removeListener(deviceListener);
130 + alarmsExecutor.shutdown();
131 + providerService = null;
132 + log.info("Stopped");
133 + }
134 +
135 + @Modified
136 + public void modified(ComponentContext context) {
137 + if (context == null) {
138 + log.info("No component configuration");
139 + return;
140 + }
141 +
142 + Dictionary<?, ?> properties = context.getProperties();
143 + int newPollFrequency = getNewPollFrequency(properties, alarmPollFrequencySeconds);
144 + if (newPollFrequency != alarmPollFrequencySeconds) {
145 + alarmPollFrequencySeconds = newPollFrequency;
146 + //stops the old scheduled task
147 + scheduledTask.cancel(true);
148 + //schedules new task at the new polling rate
149 + scheduledTask = schedulePolling();
150 + }
151 + }
152 +
153 + private ScheduledFuture schedulePolling() {
154 + return alarmsExecutor.scheduleAtFixedRate(this::consumeAlarms,
155 + alarmPollFrequencySeconds / 4, alarmPollFrequencySeconds,
156 + TimeUnit.SECONDS);
157 + }
158 +
159 + private int getNewPollFrequency(Dictionary<?, ?> properties, int pollFrequency) {
160 + int newPollFrequency;
161 + try {
162 + String s = get(properties, "pollFrequency");
163 + newPollFrequency = isNullOrEmpty(s) ? pollFrequency : Integer.parseInt(s.trim());
164 + } catch (NumberFormatException | ClassCastException e) {
165 + newPollFrequency = DEFAULT_POLL_FREQUENCY_SECONDS;
166 + }
167 + return newPollFrequency;
168 + }
169 +
170 + @Override
171 + public void triggerProbe(DeviceId deviceId) {
172 + if (mastershipService.isLocalMaster(deviceId)) {
173 + triggerProbe(deviceService.getDevice(deviceId));
174 + }
175 + }
176 +
177 + private void triggerProbe(Device device) {
178 + alarmsExecutor.submit(() -> consumeAlarms(device));
179 + }
180 +
181 + private void consumeAlarms() {
182 + deviceService.getAvailableDevices().forEach(device -> {
183 + if (mastershipService.isLocalMaster(device.id())) {
184 + consumeAlarms(device);
185 + }
186 + });
187 + }
188 +
189 + private void consumeAlarms(Device device) {
190 + if (device.is(AlarmConsumer.class)) {
191 + providerService.updateAlarmList(device.id(),
192 + device.as(AlarmConsumer.class).consumeAlarms());
193 + } else {
194 + log.info("Device {} does not support alarm consumer behaviour", device.id());
195 + }
196 + }
197 +
198 + private class InternalMastershipListener implements MastershipListener {
199 +
200 + @Override
201 + public boolean isRelevant(MastershipEvent event) {
202 + return mastershipService.isLocalMaster(event.subject());
203 + }
204 +
205 + @Override
206 + public void event(MastershipEvent event) {
207 + triggerProbe(event.subject());
208 + }
209 + }
210 +
211 + /**
212 + * Internal listener for device service events.
213 + */
214 + private class InternalDeviceListener implements DeviceListener {
215 +
216 + @Override
217 + public boolean isRelevant(DeviceEvent event) {
218 + return event.type().equals(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED)
219 + && deviceService.isAvailable(event.subject().id());
220 + }
221 +
222 + @Override
223 + public void event(DeviceEvent event) {
224 + log.debug("InternalDeviceListener has got event from device-service{} with ", event);
225 + eventHandlingExecutor.execute(() -> triggerProbe(event.subject().id()));
226 + }
227 +
228 + }
229 +}
...@@ -13,13 +13,8 @@ ...@@ -13,13 +13,8 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.incubator.net.faultmanagement.alarm;
17 -
18 -import org.onosproject.event.EventListener;
19 -
20 -
21 /** 16 /**
22 - * Entity capable of receiving Alarm related events. 17 + * Abstractions for interacting with alarms. An alarm is a persistent indication
18 + * of a fault that clears only when the triggering condition has been resolved.
23 */ 19 */
24 -public interface AlarmListener extends EventListener<AlarmEvent> { 20 +package org.onosproject.incubator.net.faultmanagement.alarm.impl;
25 -}
......
...@@ -77,7 +77,6 @@ ...@@ -77,7 +77,6 @@
77 <groupId>org.apache.felix</groupId> 77 <groupId>org.apache.felix</groupId>
78 <artifactId>maven-bundle-plugin</artifactId> 78 <artifactId>maven-bundle-plugin</artifactId>
79 </plugin> 79 </plugin>
80 -
81 <plugin> 80 <plugin>
82 <groupId>org.onosproject</groupId> 81 <groupId>org.onosproject</groupId>
83 <artifactId>onos-maven-plugin</artifactId> 82 <artifactId>onos-maven-plugin</artifactId>
......
...@@ -83,7 +83,6 @@ ...@@ -83,7 +83,6 @@
83 </dependency> 83 </dependency>
84 </dependencies> 84 </dependencies>
85 85
86 -
87 <build> 86 <build>
88 <plugins> 87 <plugins>
89 <plugin> 88 <plugin>
...@@ -92,5 +91,4 @@ ...@@ -92,5 +91,4 @@
92 </plugin> 91 </plugin>
93 </plugins> 92 </plugins>
94 </build> 93 </build>
95 -
96 </project> 94 </project>
......
1 -SRC = 'src/main/java/org/onosproject/**/'
2 -TEST = 'src/test/java/org/onosproject/**/'
3 -
4 -CURRENT_NAME = 'onos-snmp-provider-alarm'
5 -CURRENT_TARGET = ':' + CURRENT_NAME
6 -
7 -COMPILE_DEPS = [
8 - '//lib:CORE_DEPS',
9 - '//lib:org.apache.servicemix.bundles.snmp4j',
10 - '//lib:snmp-core',
11 - '//lib:bti7000',
12 - '//lib:mibs-net-snmp',
13 - '//lib:mibs-rfc',
14 - '//incubator/api:onos-incubator-api',
15 - '//protocols/snmp/api:onos-snmp-api',
16 -]
17 -
18 -TEST_DEPS = [
19 - '//lib:TEST',
20 -]
21 -
22 -osgi_jar(
23 - name = CURRENT_NAME,
24 - srcs = glob([SRC + '/*.java']),
25 - deps = COMPILE_DEPS,
26 - visibility = ['PUBLIC'],
27 -)
28 -
29 -java_test(
30 - name = 'tests',
31 - srcs = glob([TEST + '/*.java']),
32 - deps = COMPILE_DEPS +
33 - TEST_DEPS +
34 - [CURRENT_TARGET],
35 - source_under_test = [CURRENT_TARGET],
36 -)
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
20 features="${project.artifactId}"> 20 features="${project.artifactId}">
21 <description>${project.description}</description> 21 <description>${project.description}</description>
22 <artifact>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</artifact> 22 <artifact>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</artifact>
23 - <artifact>mvn:${project.groupId}/onos-snmp-provider-alarm/${project.version}</artifact>
24 23
25 <artifact>mvn:${project.groupId}/onos-snmp-api/${project.version}</artifact> 24 <artifact>mvn:${project.groupId}/onos-snmp-api/${project.version}</artifact>
26 <artifact>mvn:${project.groupId}/onos-snmp-ctl/${project.version}</artifact> 25 <artifact>mvn:${project.groupId}/onos-snmp-ctl/${project.version}</artifact>
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
22 <bundle>mvn:${project.groupId}/onos-snmp-api/${project.version}</bundle> 22 <bundle>mvn:${project.groupId}/onos-snmp-api/${project.version}</bundle>
23 <bundle>mvn:${project.groupId}/onos-snmp-ctl/${project.version}</bundle> 23 <bundle>mvn:${project.groupId}/onos-snmp-ctl/${project.version}</bundle>
24 <bundle>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</bundle> 24 <bundle>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</bundle>
25 - <bundle>mvn:${project.groupId}/onos-snmp-provider-alarm/${project.version}</bundle>
26 25
27 <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j/2.3.4_1</bundle> 26 <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j/2.3.4_1</bundle>
28 <bundle>mvn:com.btisystems/snmp-core/1.3-SNAPSHOT</bundle> 27 <bundle>mvn:com.btisystems/snmp-core/1.3-SNAPSHOT</bundle>
......
...@@ -37,11 +37,6 @@ ...@@ -37,11 +37,6 @@
37 <artifactId>onos-snmp-provider-device</artifactId> 37 <artifactId>onos-snmp-provider-device</artifactId>
38 <version>${project.version}</version> 38 <version>${project.version}</version>
39 </dependency> 39 </dependency>
40 - <dependency>
41 - <groupId>org.onosproject</groupId>
42 - <artifactId>onos-snmp-provider-alarm</artifactId>
43 - <version>${project.version}</version>
44 - </dependency>
45 </dependencies> 40 </dependencies>
46 41
47 </project> 42 </project>
......
...@@ -77,12 +77,12 @@ ...@@ -77,12 +77,12 @@
77 <dependency> 77 <dependency>
78 <groupId>org.onosproject</groupId> 78 <groupId>org.onosproject</groupId>
79 <artifactId>onos-core-net</artifactId> 79 <artifactId>onos-core-net</artifactId>
80 - <version>1.6.0-SNAPSHOT</version> 80 + <version>${project.version}</version>
81 </dependency> 81 </dependency>
82 <dependency> 82 <dependency>
83 <groupId>org.onosproject</groupId> 83 <groupId>org.onosproject</groupId>
84 <artifactId>onos-api</artifactId> 84 <artifactId>onos-api</artifactId>
85 - <version>1.6.0-SNAPSHOT</version> 85 + <version>${project.version}</version>
86 <classifier>tests</classifier> 86 <classifier>tests</classifier>
87 <scope>test</scope> 87 <scope>test</scope>
88 </dependency> 88 </dependency>
...@@ -96,4 +96,3 @@ ...@@ -96,4 +96,3 @@
96 </plugins> 96 </plugins>
97 </build> 97 </build>
98 </project> 98 </project>
99 -
......
...@@ -48,7 +48,6 @@ import org.onosproject.net.device.DeviceService; ...@@ -48,7 +48,6 @@ import org.onosproject.net.device.DeviceService;
48 import org.onosproject.net.device.DeviceServiceAdapter; 48 import org.onosproject.net.device.DeviceServiceAdapter;
49 import org.onosproject.net.device.DeviceStore; 49 import org.onosproject.net.device.DeviceStore;
50 import org.onosproject.net.device.DeviceStoreAdapter; 50 import org.onosproject.net.device.DeviceStoreAdapter;
51 -import org.onosproject.net.driver.DriverService;
52 import org.onosproject.net.driver.DriverServiceAdapter; 51 import org.onosproject.net.driver.DriverServiceAdapter;
53 import org.onosproject.net.provider.ProviderId; 52 import org.onosproject.net.provider.ProviderId;
54 import org.onosproject.snmp.SnmpController; 53 import org.onosproject.snmp.SnmpController;
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
34 <modules> 34 <modules>
35 <module>device</module> 35 <module>device</module>
36 <module>app</module> 36 <module>app</module>
37 - <module>alarm</module>
38 </modules> 37 </modules>
39 38
40 <repositories> 39 <repositories>
......