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
1025 additions
and
403 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,95 +15,79 @@ | ... | @@ -15,95 +15,79 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.faultmanagement.impl; | 16 | package org.onosproject.faultmanagement.impl; |
17 | 17 | ||
18 | -import static com.google.common.base.Preconditions.checkNotNull; | 18 | +import com.google.common.collect.ImmutableSet; |
19 | -import java.util.Dictionary; | ||
20 | -import java.util.HashSet; | ||
21 | -import java.util.Map; | ||
22 | -import java.util.Set; | ||
23 | -import java.util.concurrent.ConcurrentHashMap; | ||
24 | -import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
25 | -import java.util.concurrent.ScheduledExecutorService; | ||
26 | -import java.util.stream.Collectors; | ||
27 | import org.apache.commons.collections.CollectionUtils; | 19 | import org.apache.commons.collections.CollectionUtils; |
28 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
29 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
30 | import org.apache.felix.scr.annotations.Deactivate; | 22 | import org.apache.felix.scr.annotations.Deactivate; |
31 | import org.apache.felix.scr.annotations.Modified; | 23 | import org.apache.felix.scr.annotations.Modified; |
32 | -import org.apache.felix.scr.annotations.Property; | 24 | +import org.apache.felix.scr.annotations.Service; |
33 | -import static org.onlab.util.Tools.nullIsNotFound; | 25 | +import org.onlab.util.ItemNotFoundException; |
34 | - | ||
35 | import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; | 26 | import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; |
36 | import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId; | 27 | import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId; |
37 | -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEvent; | ||
38 | import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; | 28 | import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; |
39 | -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmListener; | 29 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProvider; |
30 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderRegistry; | ||
31 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderService; | ||
40 | import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService; | 32 | import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService; |
33 | +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; | ||
41 | import org.onosproject.net.ConnectPoint; | 34 | import org.onosproject.net.ConnectPoint; |
42 | import org.onosproject.net.DeviceId; | 35 | import org.onosproject.net.DeviceId; |
43 | -import org.slf4j.Logger; | 36 | +import org.onosproject.net.provider.AbstractProviderRegistry; |
44 | -import static org.slf4j.LoggerFactory.getLogger; | 37 | +import org.onosproject.net.provider.AbstractProviderService; |
45 | -import org.apache.felix.scr.annotations.Service; | ||
46 | -import static org.onlab.util.Tools.get; | ||
47 | -import org.onosproject.core.ApplicationId; | ||
48 | -import org.onosproject.core.IdGenerator; | ||
49 | -import org.onosproject.core.CoreService; | ||
50 | -import org.apache.felix.scr.annotations.Reference; | ||
51 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
52 | -import org.onlab.util.ItemNotFoundException; | ||
53 | -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProvider; | ||
54 | -import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; | ||
55 | -import org.onosproject.net.device.DeviceService; | ||
56 | import org.osgi.service.component.ComponentContext; | 38 | import org.osgi.service.component.ComponentContext; |
57 | -import static java.util.concurrent.TimeUnit.SECONDS; | 39 | +import org.slf4j.Logger; |
58 | 40 | ||
41 | +import java.util.Collection; | ||
42 | +import java.util.Map; | ||
43 | +import java.util.Set; | ||
44 | +import java.util.concurrent.ConcurrentHashMap; | ||
59 | import java.util.concurrent.atomic.AtomicLong; | 45 | import java.util.concurrent.atomic.AtomicLong; |
60 | -import static org.onlab.util.Tools.groupedThreads; | 46 | +import java.util.stream.Collectors; |
61 | -import org.onosproject.net.Device; | 47 | + |
48 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
49 | +import static org.onlab.util.Tools.nullIsNotFound; | ||
50 | +import static org.slf4j.LoggerFactory.getLogger; | ||
62 | 51 | ||
63 | /** | 52 | /** |
64 | * Implementation of the Alarm service. | 53 | * Implementation of the Alarm service. |
65 | */ | 54 | */ |
66 | @Component(immediate = true) | 55 | @Component(immediate = true) |
67 | @Service | 56 | @Service |
68 | -public class AlarmsManager implements AlarmService { | 57 | +public class AlarmsManager |
58 | + extends AbstractProviderRegistry<AlarmProvider, AlarmProviderService> | ||
59 | + implements AlarmService, AlarmProviderRegistry { | ||
69 | 60 | ||
70 | - // For subscribing to device-related events | 61 | + private final Logger log = getLogger(getClass()); |
71 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
72 | - protected CoreService coreService; | ||
73 | 62 | ||
74 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 63 | + private final AtomicLong alarmIdGenerator = new AtomicLong(0); |
75 | - protected DeviceService deviceService; | ||
76 | 64 | ||
77 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 65 | + // TODO Later should must be persisted to disk or database |
78 | - protected AlarmProvider alarmProvider; | 66 | + protected final Map<AlarmId, Alarm> alarms = new ConcurrentHashMap<>(); |
79 | 67 | ||
80 | - private final Logger log = getLogger(getClass()); | 68 | + private static final String NOT_SUPPORTED_YET = "Not supported yet."; |
81 | - private ApplicationId appId; | ||
82 | - private IdGenerator idGenerator; | ||
83 | 69 | ||
84 | - private ScheduledExecutorService alarmPollExecutor; | 70 | + @Activate |
71 | + public void activate(ComponentContext context) { | ||
72 | + log.info("Started"); | ||
73 | + } | ||
85 | 74 | ||
86 | - // dummy data | 75 | + @Deactivate |
87 | - private final AtomicLong alarmIdGenerator = new AtomicLong(0); | 76 | + public void deactivate(ComponentContext context) { |
77 | + alarms.clear(); | ||
78 | + log.info("Stopped"); | ||
79 | + } | ||
80 | + | ||
81 | + @Modified | ||
82 | + public boolean modified(ComponentContext context) { | ||
83 | + log.info("Modified"); | ||
84 | + return true; | ||
85 | + } | ||
88 | 86 | ||
89 | private AlarmId generateAlarmId() { | 87 | private AlarmId generateAlarmId() { |
90 | return AlarmId.alarmId(alarmIdGenerator.incrementAndGet()); | 88 | return AlarmId.alarmId(alarmIdGenerator.incrementAndGet()); |
91 | } | 89 | } |
92 | 90 | ||
93 | - private static final int DEFAULT_POLL_FREQUENCY_SECONDS = 120; | ||
94 | - @Property(name = "alarmPollFrequencySeconds", intValue = DEFAULT_POLL_FREQUENCY_SECONDS, | ||
95 | - label = "Frequency (in seconds) for polling alarm from devices") | ||
96 | - private int alarmPollFrequencySeconds = DEFAULT_POLL_FREQUENCY_SECONDS; | ||
97 | - | ||
98 | - // TODO implement purging of old alarms. | ||
99 | - private static final int DEFAULT_CLEAR_FREQUENCY_SECONDS = 500; | ||
100 | - @Property(name = "clearedAlarmPurgeSeconds", intValue = DEFAULT_CLEAR_FREQUENCY_SECONDS, | ||
101 | - label = "Frequency (in seconds) for deleting cleared alarms") | ||
102 | - private int clearedAlarmPurgeFrequencySeconds = DEFAULT_CLEAR_FREQUENCY_SECONDS; | ||
103 | - | ||
104 | - // TODO Later should must be persisted to disk or database | ||
105 | - private final Map<AlarmId, Alarm> alarms = new ConcurrentHashMap<>(); | ||
106 | - | ||
107 | @Override | 91 | @Override |
108 | public Alarm updateBookkeepingFields(AlarmId id, boolean isAcknowledged, String assignedUser) { | 92 | public Alarm updateBookkeepingFields(AlarmId id, boolean isAcknowledged, String assignedUser) { |
109 | 93 | ||
... | @@ -120,7 +104,6 @@ public class AlarmsManager implements AlarmService { | ... | @@ -120,7 +104,6 @@ public class AlarmsManager implements AlarmService { |
120 | } | 104 | } |
121 | 105 | ||
122 | public Alarm clear(AlarmId id) { | 106 | public Alarm clear(AlarmId id) { |
123 | - | ||
124 | Alarm found = alarms.get(id); | 107 | Alarm found = alarms.get(id); |
125 | if (found == null) { | 108 | if (found == null) { |
126 | log.warn("id {} cant be cleared as it is already gone.", id); | 109 | log.warn("id {} cant be cleared as it is already gone.", id); |
... | @@ -133,33 +116,25 @@ public class AlarmsManager implements AlarmService { | ... | @@ -133,33 +116,25 @@ public class AlarmsManager implements AlarmService { |
133 | 116 | ||
134 | @Override | 117 | @Override |
135 | public Map<Alarm.SeverityLevel, Long> getAlarmCounts(DeviceId deviceId) { | 118 | public Map<Alarm.SeverityLevel, Long> getAlarmCounts(DeviceId deviceId) { |
136 | - | ||
137 | return getAlarms(deviceId).stream().collect( | 119 | return getAlarms(deviceId).stream().collect( |
138 | Collectors.groupingBy(Alarm::severity, Collectors.counting())); | 120 | Collectors.groupingBy(Alarm::severity, Collectors.counting())); |
139 | - | ||
140 | } | 121 | } |
141 | 122 | ||
142 | @Override | 123 | @Override |
143 | public Map<Alarm.SeverityLevel, Long> getAlarmCounts() { | 124 | public Map<Alarm.SeverityLevel, Long> getAlarmCounts() { |
144 | - | ||
145 | return getAlarms().stream().collect( | 125 | return getAlarms().stream().collect( |
146 | Collectors.groupingBy(Alarm::severity, Collectors.counting())); | 126 | Collectors.groupingBy(Alarm::severity, Collectors.counting())); |
147 | } | 127 | } |
148 | 128 | ||
149 | - | ||
150 | - private static final String NOT_SUPPORTED_YET = "Not supported yet."; | ||
151 | - | ||
152 | @Override | 129 | @Override |
153 | public Alarm getAlarm(AlarmId alarmId) { | 130 | public Alarm getAlarm(AlarmId alarmId) { |
154 | - return nullIsNotFound( | 131 | + return nullIsNotFound(alarms.get(checkNotNull(alarmId, "Alarm Id cannot be null")), |
155 | - alarms.get( | 132 | + "Alarm is not found"); |
156 | - checkNotNull(alarmId, "Alarm Id cannot be null")), | ||
157 | - "Alarm is not found"); | ||
158 | } | 133 | } |
159 | 134 | ||
160 | @Override | 135 | @Override |
161 | public Set<Alarm> getAlarms() { | 136 | public Set<Alarm> getAlarms() { |
162 | - return new HashSet<>(alarms.values()); | 137 | + return ImmutableSet.copyOf(alarms.values()); |
163 | } | 138 | } |
164 | 139 | ||
165 | @Override | 140 | @Override |
... | @@ -198,122 +173,21 @@ public class AlarmsManager implements AlarmService { | ... | @@ -198,122 +173,21 @@ public class AlarmsManager implements AlarmService { |
198 | 173 | ||
199 | @Override | 174 | @Override |
200 | public Set<Alarm> getAlarmsForLink(ConnectPoint src, ConnectPoint dst) { | 175 | public Set<Alarm> getAlarmsForLink(ConnectPoint src, ConnectPoint dst) { |
201 | - //TODO | ||
202 | throw new UnsupportedOperationException(NOT_SUPPORTED_YET); | 176 | throw new UnsupportedOperationException(NOT_SUPPORTED_YET); |
203 | } | 177 | } |
204 | 178 | ||
205 | @Override | 179 | @Override |
206 | public Set<Alarm> getAlarmsForFlow(DeviceId deviceId, long flowId) { | 180 | public Set<Alarm> getAlarmsForFlow(DeviceId deviceId, long flowId) { |
207 | - //TODO | ||
208 | throw new UnsupportedOperationException(NOT_SUPPORTED_YET); | 181 | throw new UnsupportedOperationException(NOT_SUPPORTED_YET); |
209 | } | 182 | } |
210 | 183 | ||
211 | - private final AlarmListener alarmListener = new InternalAlarmListener(); | 184 | + @Override |
212 | - | 185 | + protected AlarmProviderService createProviderService(AlarmProvider provider) { |
213 | - private class InternalAlarmListener implements AlarmListener { | 186 | + return new InternalAlarmProviderService(provider); |
214 | - | ||
215 | - @Override | ||
216 | - public void event(AlarmEvent event) { | ||
217 | - log.debug("AlarmsManager. InternalAlarmListener received {}", event); | ||
218 | - try { | ||
219 | - | ||
220 | - switch (event.type()) { | ||
221 | - case DEVICE_DISCOVERY: | ||
222 | - DeviceId deviceId = checkNotNull(event.getDeviceRefreshed(), "Listener cannot be null"); | ||
223 | - log.info("New alarm set for {} received!", deviceId); | ||
224 | - updateAlarms(event.subject(), deviceId); | ||
225 | - break; | ||
226 | - | ||
227 | - case NOTIFICATION: | ||
228 | - throw new IllegalArgumentException( | ||
229 | - "Alarm Notifications (Traps) not expected or implemented yet. Received =" + event); | ||
230 | - default: | ||
231 | - break; | ||
232 | - } | ||
233 | - } catch (Exception e) { | ||
234 | - log.warn("Failed to process {}", event, e); | ||
235 | - } | ||
236 | - } | ||
237 | - } | ||
238 | - | ||
239 | - @Activate | ||
240 | - public void activate(ComponentContext context) { | ||
241 | - appId = coreService.registerApplication("org.onosproject.faultmanagement.alarms"); | ||
242 | - idGenerator = coreService.getIdGenerator("alarm-ids"); | ||
243 | - log.info("Started with appId={}", appId); | ||
244 | - | ||
245 | - alarmProvider.addAlarmListener(alarmListener); | ||
246 | - | ||
247 | - probeActiveDevices(); | ||
248 | - | ||
249 | - boolean result = modified(context); | ||
250 | - log.info("modified result = {}", result); | ||
251 | - | ||
252 | - alarmPollExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/fm", "alarms-poll-%d")); | ||
253 | - alarmPollExecutor.scheduleAtFixedRate(new PollAlarmsTask(), | ||
254 | - alarmPollFrequencySeconds, alarmPollFrequencySeconds, SECONDS); | ||
255 | - | ||
256 | - } | ||
257 | - | ||
258 | - /** | ||
259 | - * Auxiliary task to keep alarms up to date. IN future release alarm-notifications will be used as an optimization | ||
260 | - * so we dont have to wait until polling to detect changes. Furthermore with simple polling flapping alarms may be | ||
261 | - * missed. | ||
262 | - */ | ||
263 | - private final class PollAlarmsTask implements Runnable { | ||
264 | - | ||
265 | - @Override | ||
266 | - public void run() { | ||
267 | - if (Thread.currentThread().isInterrupted()) { | ||
268 | - log.info("Interrupted, quitting"); | ||
269 | - return; | ||
270 | - } | ||
271 | - try { | ||
272 | - probeActiveDevices(); | ||
273 | - } catch (RuntimeException e) { | ||
274 | - log.error("Exception thrown during alarm synchronization process", e); | ||
275 | - } | ||
276 | - } | ||
277 | - } | ||
278 | - | ||
279 | - private void probeActiveDevices() { | ||
280 | - Iterable<Device> devices = deviceService.getAvailableDevices(); | ||
281 | - log.info("Refresh alarms for all available devices={} ...", devices); | ||
282 | - for (Device d : devices) { | ||
283 | - log.info("Lets tell alarm provider to refresh alarms for {} ...", d.id()); | ||
284 | - alarmProvider.triggerProbe(d.id()); | ||
285 | - } | ||
286 | - } | ||
287 | - | ||
288 | - @Deactivate | ||
289 | - public void deactivate(ComponentContext context) { | ||
290 | - log.info("Deactivate ..."); | ||
291 | - alarmProvider.removeAlarmListener(alarmListener); | ||
292 | - | ||
293 | - if (alarmPollExecutor != null) { | ||
294 | - alarmPollExecutor.shutdownNow(); | ||
295 | - } | ||
296 | - alarms.clear(); | ||
297 | - log.info("Stopped"); | ||
298 | - } | ||
299 | - | ||
300 | - @Modified | ||
301 | - public boolean modified(ComponentContext context) { | ||
302 | - log.info("context={}", context); | ||
303 | - if (context == null) { | ||
304 | - log.info("No configuration file"); | ||
305 | - return false; | ||
306 | - } | ||
307 | - Dictionary<?, ?> properties = context.getProperties(); | ||
308 | - String clearedAlarmPurgeSeconds = get(properties, "clearedAlarmPurgeSeconds"); | ||
309 | - | ||
310 | - log.info("Settings: clearedAlarmPurgeSeconds={}", clearedAlarmPurgeSeconds); | ||
311 | - | ||
312 | - return true; | ||
313 | } | 187 | } |
314 | 188 | ||
315 | // Synchronised to prevent duplicate NE alarms being raised | 189 | // Synchronised to prevent duplicate NE alarms being raised |
316 | - synchronized void updateAlarms(Set<Alarm> discoveredSet, DeviceId deviceId) { | 190 | + protected synchronized void updateAlarms(DeviceId deviceId, Set<Alarm> discoveredSet) { |
317 | Set<Alarm> storedSet = getActiveAlarms(deviceId); | 191 | Set<Alarm> storedSet = getActiveAlarms(deviceId); |
318 | log.trace("currentNeAlarms={}. discoveredAlarms={}", storedSet, discoveredSet); | 192 | log.trace("currentNeAlarms={}. discoveredAlarms={}", storedSet, discoveredSet); |
319 | 193 | ||
... | @@ -324,16 +198,31 @@ public class AlarmsManager implements AlarmService { | ... | @@ -324,16 +198,31 @@ public class AlarmsManager implements AlarmService { |
324 | 198 | ||
325 | storedSet.stream().filter( | 199 | storedSet.stream().filter( |
326 | (stored) -> (!discoveredSet.contains(stored))).forEach((stored) -> { | 200 | (stored) -> (!discoveredSet.contains(stored))).forEach((stored) -> { |
327 | - log.info("Alarm will be cleared as it is not on the element. Cleared alarm: {}.", stored); | 201 | + log.debug("Alarm will be cleared as it is not on the element. Cleared alarm: {}.", stored); |
328 | - clear(stored.id()); | 202 | + clear(stored.id()); |
329 | - }); | 203 | + }); |
330 | 204 | ||
331 | discoveredSet.stream().filter( | 205 | discoveredSet.stream().filter( |
332 | (discovered) -> (!storedSet.contains(discovered))).forEach((discovered) -> { | 206 | (discovered) -> (!storedSet.contains(discovered))).forEach((discovered) -> { |
333 | - log.info("Alarm will be raised as it is missing. New alarm: {}.", discovered); | 207 | + log.info("New alarm raised as it is missing. New alarm: {}.", discovered); |
334 | AlarmId id = generateAlarmId(); | 208 | AlarmId id = generateAlarmId(); |
335 | alarms.put(id, new DefaultAlarm.Builder(discovered).withId(id).build()); | 209 | alarms.put(id, new DefaultAlarm.Builder(discovered).withId(id).build()); |
336 | }); | 210 | }); |
337 | } | 211 | } |
338 | 212 | ||
213 | + private class InternalAlarmProviderService | ||
214 | + extends AbstractProviderService<AlarmProvider> | ||
215 | + implements AlarmProviderService { | ||
216 | + | ||
217 | + InternalAlarmProviderService(AlarmProvider provider) { | ||
218 | + super(provider); | ||
219 | + | ||
220 | + | ||
221 | + } | ||
222 | + | ||
223 | + @Override | ||
224 | + public void updateAlarmList(DeviceId deviceId, Collection<Alarm> alarms) { | ||
225 | + updateAlarms(deviceId, ImmutableSet.copyOf(alarms)); | ||
226 | + } | ||
227 | + } | ||
339 | } | 228 | } | ... | ... |
apps/faultmanagement/fmmgr/src/test/java/org/onosproject/faultmanagement/impl/AlarmsManagerTest.java
... | @@ -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 | ||
44 | + private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo:bar"); | ||
45 | + private static final DefaultAlarm ALARM_A = new DefaultAlarm.Builder( | ||
46 | + DEVICE_ID, "aaa", Alarm.SeverityLevel.CRITICAL, 0).build(); | ||
47 | + | ||
48 | + private static final DefaultAlarm ALARM_A_WITHSRC = new DefaultAlarm.Builder( | ||
49 | + ALARM_A).forSource(AlarmEntityId.alarmEntityId("port:foo")).build(); | ||
50 | + | ||
51 | + private static final DefaultAlarm ALARM_B = new DefaultAlarm.Builder( | ||
52 | + DEVICE_ID, "bbb", Alarm.SeverityLevel.CRITICAL, 0).build(); | ||
53 | + | ||
54 | + private AlarmsManager am; | ||
55 | + | ||
56 | + @Rule | ||
57 | + public final ExpectedException exception = ExpectedException.none(); | ||
58 | + | ||
59 | + @Before | ||
60 | + public void setUp() throws Exception { | ||
61 | + am = new AlarmsManager(); | ||
62 | + } | ||
63 | + | ||
64 | + @Test | ||
65 | + public void deactivate() throws Exception { | ||
66 | + am.updateAlarms(DEVICE_ID, ImmutableSet.of(ALARM_B, ALARM_A)); | ||
67 | + verifyGettingSetsOfAlarms(am, 2, 2); | ||
68 | + am.deactivate(null); | ||
69 | + assertEquals("Alarms should be purged", 0, am.alarms.size()); | ||
70 | + } | ||
71 | + | ||
36 | @Test | 72 | @Test |
37 | public void testGettersWhenNoAlarms() { | 73 | public void testGettersWhenNoAlarms() { |
38 | - AlarmsManager am = new AlarmsManager(); | ||
39 | - assertTrue("No alarms", am.getAlarms().isEmpty()); | ||
40 | - assertTrue("No active alarms", am.getActiveAlarms().isEmpty()); | ||
41 | - assertTrue("No alarms gives empty map per unknown device", am.getAlarmCounts(DeviceId.NONE).keySet().isEmpty()); | ||
42 | - assertTrue("No alarms gives empty map", am.getAlarmCounts().keySet().isEmpty()); | ||
43 | - | ||
44 | - assertEquals("Zero alarms for that device", 0, am.getAlarms(DeviceId.NONE).size()); | ||
45 | - assertEquals("Zero major alarms", 0, am.getAlarms(Alarm.SeverityLevel.MAJOR).size()); | ||
46 | - | ||
47 | - try { | ||
48 | - assertEquals("no alarms", 0, am.getAlarm(null)); | ||
49 | - } catch (NullPointerException ex) { | ||
50 | - assertThat(ex.getMessage(), | ||
51 | - containsString("cannot be null")); | ||
52 | - } | ||
53 | 74 | ||
54 | - try { | 75 | + assertTrue("No alarms should be present", am.getAlarms().isEmpty()); |
55 | - assertEquals("no alarms", 0, am.getAlarm(AlarmId.alarmId(1))); | 76 | + assertTrue("No active alarms should be present", am.getActiveAlarms().isEmpty()); |
56 | - } catch (ItemNotFoundException ex) { | 77 | + assertTrue("The map should be empty per unknown device", |
57 | - assertThat(ex.getMessage(), | 78 | + am.getAlarmCounts(DeviceId.NONE).keySet().isEmpty()); |
58 | - containsString("not found")); | 79 | + assertTrue("The counts should be empty", am.getAlarmCounts().keySet().isEmpty()); |
59 | - } | 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,18 +78,19 @@ public class Bti7000SnmpAlarmProvider implements SnmpDeviceAlarmProvider { | ... | @@ -108,18 +78,19 @@ 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. |
114 | * | 85 | * |
115 | * @param actAlarmDateAndTime MIB-II DateAndTime formatted. May optionally contain | 86 | * @param actAlarmDateAndTime MIB-II DateAndTime formatted. May optionally contain |
116 | - * a timezone offset in 3 extra bytes | 87 | + * a timezone offset in 3 extra bytes |
117 | - * @param sysInfoTimeZone Must be supplied if actAlarmDateAndTime is just local time (with no timezone) | 88 | + * @param sysInfoTimeZone Must be supplied if actAlarmDateAndTime is just local time (with no timezone) |
118 | - * @param swVersion Must be supplied if actAlarmDateAndTime is just local time (with no timezone) | 89 | + * @param swVersion Must be supplied if actAlarmDateAndTime is just local time (with no timezone) |
119 | * @return adjusted {@link Date} or a simple conversion if other fields are null. | 90 | * @return adjusted {@link Date} or a simple conversion if other fields are null. |
120 | */ | 91 | */ |
121 | public static Date getLocalDateAndTime(String actAlarmDateAndTime, String sysInfoTimeZone, | 92 | public static Date getLocalDateAndTime(String actAlarmDateAndTime, String sysInfoTimeZone, |
122 | - String swVersion) { | 93 | + String swVersion) { |
123 | if (StringUtils.isBlank(actAlarmDateAndTime)) { | 94 | if (StringUtils.isBlank(actAlarmDateAndTime)) { |
124 | return null; | 95 | return null; |
125 | } | 96 | } |
... | @@ -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 | ... | ... |
incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/AlarmConsumer.java
0 → 100644
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 | -} | ... | ... |
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.impl; | ||
18 | + | ||
19 | +import com.google.common.collect.ImmutableList; | ||
20 | +import com.google.common.collect.ImmutableSet; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.osgi.ComponentContextAdapter; | ||
24 | +import org.onlab.packet.ChassisId; | ||
25 | +import org.onosproject.cluster.NodeId; | ||
26 | +import org.onosproject.cluster.RoleInfo; | ||
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.AlarmProvider; | ||
30 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderRegistry; | ||
31 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderRegistryAdapter; | ||
32 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderService; | ||
33 | +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; | ||
34 | +import org.onosproject.mastership.MastershipEvent; | ||
35 | +import org.onosproject.mastership.MastershipListener; | ||
36 | +import org.onosproject.mastership.MastershipService; | ||
37 | +import org.onosproject.mastership.MastershipServiceAdapter; | ||
38 | +import org.onosproject.net.AbstractProjectableModel; | ||
39 | +import org.onosproject.net.Annotations; | ||
40 | +import org.onosproject.net.DefaultAnnotations; | ||
41 | +import org.onosproject.net.DefaultDevice; | ||
42 | +import org.onosproject.net.Device; | ||
43 | +import org.onosproject.net.DeviceId; | ||
44 | +import org.onosproject.net.device.DeviceEvent; | ||
45 | +import org.onosproject.net.device.DeviceListener; | ||
46 | +import org.onosproject.net.device.DeviceService; | ||
47 | +import org.onosproject.net.device.DeviceServiceAdapter; | ||
48 | +import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
49 | +import org.onosproject.net.driver.Behaviour; | ||
50 | +import org.onosproject.net.driver.Driver; | ||
51 | +import org.onosproject.net.driver.DriverAdapter; | ||
52 | +import org.onosproject.net.driver.DriverHandler; | ||
53 | +import org.onosproject.net.driver.DriverServiceAdapter; | ||
54 | +import org.onosproject.net.provider.ProviderId; | ||
55 | +import org.osgi.service.component.ComponentContext; | ||
56 | + | ||
57 | +import java.io.IOException; | ||
58 | +import java.util.Collection; | ||
59 | +import java.util.Dictionary; | ||
60 | +import java.util.Enumeration; | ||
61 | +import java.util.HashMap; | ||
62 | +import java.util.HashSet; | ||
63 | +import java.util.List; | ||
64 | +import java.util.Set; | ||
65 | + | ||
66 | +import static org.junit.Assert.*; | ||
67 | +import static org.onlab.junit.TestTools.assertAfter; | ||
68 | + | ||
69 | +/** | ||
70 | + * Test for the polling alarm provider based on the driver subsystem. | ||
71 | + */ | ||
72 | +public class PollingAlarmProviderTest { | ||
73 | + | ||
74 | + private final DeviceService deviceService = new MockDeviceService(); | ||
75 | + | ||
76 | + private final MastershipService mastershipService = new MockMastershipService(); | ||
77 | + | ||
78 | + private final AlarmProviderRegistry providerRegistry = new MockDeviceProviderRegistry(); | ||
79 | + | ||
80 | + private final AlarmProviderService alarmProviderService = new MockAlarmProviderService(); | ||
81 | + | ||
82 | + private final ComponentContext context = new MockComponentContext(); | ||
83 | + | ||
84 | + private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo:1.1.1.1:1"); | ||
85 | + | ||
86 | + private Device device = new MockDevice(ProviderId.NONE, DEVICE_ID, Device.Type.OTHER, | ||
87 | + "foo.inc", "0", "0", "0", null, | ||
88 | + DefaultAnnotations.builder().build()); | ||
89 | + | ||
90 | + private final NodeId nodeId = NodeId.nodeId("fooNode"); | ||
91 | + | ||
92 | + private final MastershipEvent mastershipEvent = | ||
93 | + new MastershipEvent(MastershipEvent.Type.MASTER_CHANGED, DEVICE_ID, | ||
94 | + new RoleInfo(nodeId, ImmutableList.of())); | ||
95 | + | ||
96 | + private final DeviceEvent deviceEvent = | ||
97 | + new DeviceEvent(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED, device); | ||
98 | + | ||
99 | + | ||
100 | + private static final DefaultAlarm ALARM = new DefaultAlarm.Builder( | ||
101 | + DEVICE_ID, "aaa", Alarm.SeverityLevel.CRITICAL, 0).build(); | ||
102 | + | ||
103 | + private final Driver driver = new MockDriver(); | ||
104 | + | ||
105 | + private PollingAlarmProvider provider = new PollingAlarmProvider(); | ||
106 | + private Set<DeviceListener> deviceListeners = new HashSet<>(); | ||
107 | + private Set<MastershipListener> mastershipListeners = new HashSet<>(); | ||
108 | + private HashMap<DeviceId, Collection<Alarm>> alarmStore = new HashMap<>(); | ||
109 | + | ||
110 | + @Before | ||
111 | + public void setUp() { | ||
112 | + provider.providerRegistry = providerRegistry; | ||
113 | + provider.deviceService = deviceService; | ||
114 | + provider.mastershipService = mastershipService; | ||
115 | + AbstractProjectableModel.setDriverService(null, new DriverServiceAdapter()); | ||
116 | + provider.activate(context); | ||
117 | + } | ||
118 | + | ||
119 | + @Test | ||
120 | + public void activate() throws Exception { | ||
121 | + assertFalse("Provider should be registered", providerRegistry.getProviders().contains(provider)); | ||
122 | + assertEquals("Device listener should be added", 1, deviceListeners.size()); | ||
123 | + assertEquals("Incorrect alarm provider service", alarmProviderService, provider.providerService); | ||
124 | + assertEquals("Mastership listener should be added", 1, mastershipListeners.size()); | ||
125 | + assertEquals("Incorrect polling frequency", 1, provider.alarmPollFrequencySeconds); | ||
126 | + assertFalse("Executor should be running", provider.alarmsExecutor.isShutdown()); | ||
127 | + provider.activate(null); | ||
128 | + assertEquals("Incorrect polling frequency, should be default", 60, provider.alarmPollFrequencySeconds); | ||
129 | + } | ||
130 | + | ||
131 | + @Test | ||
132 | + public void deactivate() throws Exception { | ||
133 | + provider.deactivate(); | ||
134 | + assertEquals("Device listener should be removed", 0, deviceListeners.size()); | ||
135 | + assertEquals("Mastership listener should be removed", 0, mastershipListeners.size()); | ||
136 | + assertFalse("Provider should not be registered", providerRegistry.getProviders().contains(provider)); | ||
137 | + assertTrue(provider.alarmsExecutor.isShutdown()); | ||
138 | + assertNull(provider.providerService); | ||
139 | + } | ||
140 | + | ||
141 | + @Test | ||
142 | + public void modified() throws Exception { | ||
143 | + provider.modified(null); | ||
144 | + assertEquals("Incorrect polling frequency", 1, provider.alarmPollFrequencySeconds); | ||
145 | + provider.activate(null); | ||
146 | + provider.modified(context); | ||
147 | + assertEquals("Incorrect polling frequency", 1, provider.alarmPollFrequencySeconds); | ||
148 | + } | ||
149 | + | ||
150 | + @Test | ||
151 | + public void alarmsPresent() throws IOException { | ||
152 | + assertAfter(1100, () -> { | ||
153 | + assertTrue("Alarms should be added", alarmStore.containsKey(DEVICE_ID)); | ||
154 | + assertTrue("Alarms should be added", alarmStore.get(DEVICE_ID).contains(ALARM)); | ||
155 | + }); | ||
156 | + } | ||
157 | + | ||
158 | + @Test | ||
159 | + public void mastershipListenerEvent() throws Exception { | ||
160 | + assertTrue("Incorrect relevant event", provider.mastershipListener | ||
161 | + .isRelevant(mastershipEvent)); | ||
162 | + provider.mastershipListener.event(mastershipEvent); | ||
163 | + assertAfter(1100, () -> { | ||
164 | + assertTrue("Alarms should be added", alarmStore.containsKey(DEVICE_ID)); | ||
165 | + }); | ||
166 | + } | ||
167 | + | ||
168 | + @Test | ||
169 | + public void deviceListenerEvent() throws Exception { | ||
170 | + assertTrue("Incorrect relevant event", provider.deviceListener | ||
171 | + .isRelevant(deviceEvent)); | ||
172 | + provider.deviceListener.event(deviceEvent); | ||
173 | + assertAfter(1100, () -> { | ||
174 | + assertTrue("Alarms should be added", alarmStore.containsKey(DEVICE_ID)); | ||
175 | + }); | ||
176 | + } | ||
177 | + | ||
178 | + //TODO add test for modified context and event handling form device listener. | ||
179 | + | ||
180 | + private class MockDeviceService extends DeviceServiceAdapter { | ||
181 | + | ||
182 | + @Override | ||
183 | + public Device getDevice(DeviceId did) { | ||
184 | + if (did.equals(DEVICE_ID)) { | ||
185 | + return device; | ||
186 | + } | ||
187 | + return null; | ||
188 | + } | ||
189 | + | ||
190 | + @Override | ||
191 | + public Iterable<Device> getAvailableDevices() { | ||
192 | + return ImmutableSet.of(device); | ||
193 | + } | ||
194 | + | ||
195 | + @Override | ||
196 | + public boolean isAvailable(DeviceId did) { | ||
197 | + return did.equals(DEVICE_ID); | ||
198 | + } | ||
199 | + | ||
200 | + @Override | ||
201 | + public void addListener(DeviceListener listener) { | ||
202 | + deviceListeners.add(listener); | ||
203 | + } | ||
204 | + | ||
205 | + @Override | ||
206 | + public void removeListener(DeviceListener listener) { | ||
207 | + deviceListeners.remove(listener); | ||
208 | + } | ||
209 | + } | ||
210 | + | ||
211 | + private class MockMastershipService extends MastershipServiceAdapter { | ||
212 | + | ||
213 | + @Override | ||
214 | + public boolean isLocalMaster(DeviceId deviceId) { | ||
215 | + return true; | ||
216 | + } | ||
217 | + | ||
218 | + @Override | ||
219 | + public void addListener(MastershipListener listener) { | ||
220 | + mastershipListeners.add(listener); | ||
221 | + } | ||
222 | + | ||
223 | + @Override | ||
224 | + public void removeListener(MastershipListener listener) { | ||
225 | + mastershipListeners.remove(listener); | ||
226 | + } | ||
227 | + } | ||
228 | + | ||
229 | + private class MockDeviceProviderRegistry extends AlarmProviderRegistryAdapter { | ||
230 | + | ||
231 | + Set<ProviderId> providers = new HashSet<>(); | ||
232 | + | ||
233 | + @Override | ||
234 | + public AlarmProviderService register(AlarmProvider provider) { | ||
235 | + return alarmProviderService; | ||
236 | + } | ||
237 | + | ||
238 | + @Override | ||
239 | + public void unregister(AlarmProvider provider) { | ||
240 | + providers.remove(provider.id()); | ||
241 | + } | ||
242 | + | ||
243 | + @Override | ||
244 | + public Set<ProviderId> getProviders() { | ||
245 | + return providers; | ||
246 | + } | ||
247 | + | ||
248 | + } | ||
249 | + | ||
250 | + private class MockAlarmProviderService implements AlarmProviderService { | ||
251 | + | ||
252 | + @Override | ||
253 | + public void updateAlarmList(DeviceId deviceId, Collection<Alarm> alarms) { | ||
254 | + if (alarmStore.containsKey(deviceId)) { | ||
255 | + Collection<Alarm> deviceAlarms = alarmStore.get(deviceId); | ||
256 | + deviceAlarms.addAll(alarms); | ||
257 | + alarmStore.put(deviceId, deviceAlarms); | ||
258 | + } else { | ||
259 | + alarmStore.put(deviceId, alarms); | ||
260 | + } | ||
261 | + | ||
262 | + } | ||
263 | + | ||
264 | + @Override | ||
265 | + public AlarmProvider provider() { | ||
266 | + return null; | ||
267 | + } | ||
268 | + } | ||
269 | + | ||
270 | + private class MockComponentContext extends ComponentContextAdapter { | ||
271 | + @Override | ||
272 | + public Dictionary getProperties() { | ||
273 | + return new MockDictionary(); | ||
274 | + } | ||
275 | + } | ||
276 | + | ||
277 | + private class MockDictionary extends Dictionary { | ||
278 | + | ||
279 | + @Override | ||
280 | + public int size() { | ||
281 | + return 0; | ||
282 | + } | ||
283 | + | ||
284 | + @Override | ||
285 | + public boolean isEmpty() { | ||
286 | + return false; | ||
287 | + } | ||
288 | + | ||
289 | + @Override | ||
290 | + public Enumeration keys() { | ||
291 | + return null; | ||
292 | + } | ||
293 | + | ||
294 | + @Override | ||
295 | + public Enumeration elements() { | ||
296 | + return null; | ||
297 | + } | ||
298 | + | ||
299 | + @Override | ||
300 | + public Object get(Object key) { | ||
301 | + if (key.equals("pollFrequency")) { | ||
302 | + return "1"; | ||
303 | + } | ||
304 | + return null; | ||
305 | + } | ||
306 | + | ||
307 | + @Override | ||
308 | + public Object put(Object key, Object value) { | ||
309 | + return null; | ||
310 | + } | ||
311 | + | ||
312 | + @Override | ||
313 | + public Object remove(Object key) { | ||
314 | + return null; | ||
315 | + } | ||
316 | + } | ||
317 | + | ||
318 | + private class MockDevice extends DefaultDevice { | ||
319 | + /** | ||
320 | + * Creates a network element attributed to the specified provider. | ||
321 | + * | ||
322 | + * @param providerId identity of the provider | ||
323 | + * @param id device identifier | ||
324 | + * @param type device type | ||
325 | + * @param manufacturer device manufacturer | ||
326 | + * @param hwVersion device HW version | ||
327 | + * @param swVersion device SW version | ||
328 | + * @param serialNumber device serial number | ||
329 | + * @param chassisId chassis id | ||
330 | + * @param annotations optional key/value annotations | ||
331 | + */ | ||
332 | + public MockDevice(ProviderId providerId, DeviceId id, Type type, | ||
333 | + String manufacturer, String hwVersion, String swVersion, | ||
334 | + String serialNumber, ChassisId chassisId, Annotations... annotations) { | ||
335 | + super(providerId, id, type, manufacturer, hwVersion, swVersion, serialNumber, | ||
336 | + chassisId, annotations); | ||
337 | + } | ||
338 | + | ||
339 | + @Override | ||
340 | + protected Driver locateDriver() { | ||
341 | + return driver; | ||
342 | + } | ||
343 | + | ||
344 | + @Override | ||
345 | + public Driver driver() { | ||
346 | + return driver; | ||
347 | + } | ||
348 | + } | ||
349 | + | ||
350 | + private class MockDriver extends DriverAdapter { | ||
351 | + @Override | ||
352 | + public <T extends Behaviour> T createBehaviour(DriverHandler handler, Class<T> behaviourClass) { | ||
353 | + return (T) new TestAlarmConsumer(); | ||
354 | + } | ||
355 | + } | ||
356 | + | ||
357 | + private class TestAlarmConsumer extends AbstractHandlerBehaviour implements AlarmConsumer { | ||
358 | + | ||
359 | + @Override | ||
360 | + public List<Alarm> consumeAlarms() { | ||
361 | + return ImmutableList.of(ALARM); | ||
362 | + } | ||
363 | + } | ||
364 | + | ||
365 | +} |
... | @@ -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> | ... | ... |
providers/snmp/alarm/BUCK
deleted
100644 → 0
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; | ... | ... |
-
Please register or login to post a comment