2 * (c) 2017 highstreet technologies GmbH
5 package org.opendaylight.mwtn.deviceMonitor.impl;
7 import java.util.Enumeration;
8 import java.util.concurrent.ConcurrentHashMap;
9 import java.util.concurrent.Executors;
10 import java.util.concurrent.ScheduledExecutorService;
12 import org.opendaylight.mwtn.base.netconf.ONFCoreNetworkElementRepresentation;
13 import org.opendaylight.mwtn.devicemanager.impl.listener.ODLEventListener;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * Implementation of concept "Active monitoring" of a device.<br>
20 * For each existing mountpoint a task runs with 120s cycle time. Every 120 seconds the check actions are performed.
21 * The request is handled by the NETCONF layer with a (default)configured time-out of 60 seconds.<br>
22 * Generated alarms, by the object/node "SDN-Controller" are (enum DeviceMonitorProblems):<br>
23 * - notConnected(InternalSeverity.Warning)<br>
24 * - noConnectionMediator(InternalSeverity.Minor)<br>
25 * - noConnectionNe(InternalSeverity.Critical)<br>
27 * 1. Mountpoint does not exist<br>
28 * If the mountpoint does not exists there are no related current alarms in the database.<br>
30 * 2. Created mountpoint with state "Connecting" or "UnableToConnect"<br>
31 * If the Mountpoint is created and connection status is "Connecting" or "UnableToConnect".<br>
32 * - After about 2..4 Minutes ... raise alarm "notConnected" with severity warning<br>
34 * 3. Created mountpoint with state "Connection"<br>
35 * There are two monitor activities.<br>
36 * 3a. Check of Mediator connection by requesting (typical) cached data.<br>
37 * - After about 60 seconds raise alarm: connection-loss-mediator with severity minor<br>
38 * - Request from Mediator: network-element<br>
40 * 3b. Check connection to NEby requesting (typical) non-cached data.<br>
41 * - Only if AirInterface available. The first one is used.<br>
42 * - Requested are the currentAlarms<br>
43 * - After about 60 seconds raise alarm: connection-loss-network-element with severity critical<br>
48 public class DeviceMonitorImpl implements DeviceMonitor, AutoCloseable {
50 private static final Logger LOG = LoggerFactory.getLogger(DeviceMonitorImpl.class);
52 private final ConcurrentHashMap<String, DeviceMonitorTask> queue;
53 private final ScheduledExecutorService scheduler;
54 private final ODLEventListener odlEventListener;
56 /*-------------------------------------------------------------
57 * Construction/ destruction of service
61 * Basic implementation of devicemonitoring
62 * @param odlEventListener as destination for problems
64 public DeviceMonitorImpl(ODLEventListener odlEventListener) {
65 LOG.info("Construct {}", this.getClass().getSimpleName());
67 this.odlEventListener = odlEventListener;
68 this.queue = new ConcurrentHashMap<>();
69 this.scheduler = Executors.newScheduledThreadPool(1);
73 * Stop the service. Stop all running monitoring tasks.
76 synchronized public void close() {
77 LOG.info("Close {}", this.getClass().getSimpleName());
79 Enumeration<String> e = queue.keys();
80 while (e.hasMoreElements()) {
81 deviceDisconnectIndication(e.nextElement());
87 /*-------------------------------------------------------------
88 * Register/ Deregister Mountpoint
92 synchronized public void createMountpointIndication(String mountPointNodeName) {
94 LOG.debug("Register for monitoring {} {}",mountPointNodeName, mountPointNodeName.hashCode());
96 LOG.info("Do start of DeviceMonitor task");
97 //Runnable task = new PerformanceManagerTask(queue, databaseService);
98 DeviceMonitorTask task = new DeviceMonitorTask(mountPointNodeName, this.odlEventListener);
99 queue.put(mountPointNodeName, task);
100 task.start(scheduler);
104 synchronized public void removeMountpointIndication(String mountPointNodeName) {
106 if (queue.containsKey(mountPointNodeName)) {
107 DeviceMonitorTask task = queue.get(mountPointNodeName);
109 queue.remove(mountPointNodeName);
112 task.removeMountpointIndication();
113 LOG.debug("Task stopped: {}", mountPointNodeName);
115 LOG.warn("Task not in queue anymore: {}", mountPointNodeName);
119 /*-------------------------------------------------------------
120 * Register/ Deregister device
124 synchronized public void deviceConnectIndication(String mountPointNodeName, ONFCoreNetworkElementRepresentation ne) {
126 LOG.debug("ne changes to connected state {}",mountPointNodeName);
127 if (queue.containsKey(mountPointNodeName)) {
128 DeviceMonitorTask task = queue.get(mountPointNodeName);
129 task.deviceConnectIndication(ne);
131 LOG.warn("Monitoring task not in queue anymore: {} {} {}", mountPointNodeName, mountPointNodeName.hashCode(), queue.size());
136 synchronized public void deviceDisconnectIndication(String mountPointNodeName) {
138 LOG.debug("ne changes to disconnected state {}",mountPointNodeName);
139 if (queue.containsKey(mountPointNodeName)) {
140 DeviceMonitorTask task = queue.get(mountPointNodeName);
141 task.deviceDisconnectIndication();
143 LOG.warn("Monitoring task not in queue anymore: {} {} {}", mountPointNodeName, mountPointNodeName.hashCode(), queue.size());
147 /*-------------------------------------------------------------