1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
19 * (c) 2017 highstreet technologies GmbH
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl;
24 import java.util.Enumeration;
25 import java.util.concurrent.ConcurrentHashMap;
26 import java.util.concurrent.Executors;
27 import java.util.concurrent.ScheduledExecutorService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayFilter;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.HtDevicemanagerConfiguration;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.IConfigChangedListener;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.DmConfig;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.ToggleAlarmConfig;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener.ODLEventListener;
35 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * Implementation of concept "Active monitoring" of a device.<br>
42 * For each existing mountpoint a task runs with 120s cycle time. Every 120 seconds the check actions are performed.
43 * The request is handled by the NETCONF layer with a (default)configured time-out of 60 seconds.<br>
44 * Generated alarms, by the object/node "SDN-Controller" are (enum DeviceMonitorProblems):<br>
45 * - notConnected(InternalSeverity.Warning)<br>
46 * - noConnectionMediator(InternalSeverity.Minor)<br>
47 * - noConnectionNe(InternalSeverity.Critical)<br>
49 * 1. Mountpoint does not exist<br>
50 * If the mountpoint does not exists there are no related current alarms in the database.<br>
52 * 2. Created mountpoint with state "Connecting" or "UnableToConnect"<br>
53 * If the Mountpoint is created and connection status is "Connecting" or "UnableToConnect".<br>
54 * - After about 2..4 Minutes ... raise alarm "notConnected" with severity warning<br>
56 * 3. Created mountpoint with state "Connection"<br>
57 * There are two monitor activities.<br>
58 * 3a. Check of Mediator connection by requesting (typical) cached data.<br>
59 * - After about 60 seconds raise alarm: connection-loss-mediator with severity minor<br>
60 * - Request from Mediator: network-element<br>
62 * 3b. Check connection to NEby requesting (typical) non-cached data.<br>
63 * - Only if AirInterface available. The first one is used.<br>
64 * - Requested are the currentAlarms<br>
65 * - After about 60 seconds raise alarm: connection-loss-network-element with severity critical<br>
70 @SuppressWarnings("deprecation")
71 public class DeviceMonitorImpl implements DeviceMonitor, IConfigChangedListener {
73 private static final Logger LOG = LoggerFactory.getLogger(DeviceMonitorImpl.class);
75 private final ConcurrentHashMap<String, DeviceMonitorTask> queue;
76 private final ScheduledExecutorService scheduler;
77 private final ODLEventListener odlEventListener;
78 @SuppressWarnings("unused")
79 private final DataBroker dataBroker; //Future usage
81 /*-------------------------------------------------------------
82 * Construction/ destruction of service
86 * Basic implementation of devicemonitoring
87 * @param odlEventListener as destination for problems
89 public DeviceMonitorImpl(DataBroker dataBroker, ODLEventListener odlEventListener, HtDevicemanagerConfiguration htconfig) {
90 LOG.info("Construct {}", this.getClass().getSimpleName());
92 this.odlEventListener = odlEventListener;
93 this.dataBroker = dataBroker;
95 htconfig.registerConfigChangedListener(this);
96 DmConfig dmConfig = htconfig.getDmConfig();
97 setDmConfig(dmConfig);
99 this.queue = new ConcurrentHashMap<>();
100 this.scheduler = Executors.newScheduledThreadPool(10);
104 * Stop the service. Stop all running monitoring tasks.
107 synchronized public void close() {
108 LOG.info("Close {}", this.getClass().getSimpleName());
110 Enumeration<String> e = queue.keys();
111 while (e.hasMoreElements()) {
112 deviceDisconnectIndication(e.nextElement());
115 scheduler.shutdown();
119 public void onConfigChanged() {
120 DmConfig cfg = DmConfig.reload();
124 private void setDmConfig(DmConfig dmConfig) {
125 for (DeviceMonitorProblems problem : DeviceMonitorProblems.values()) {
126 problem.setSeverity(dmConfig.getSeverity(problem));
130 /*-------------------------------------------------------------
131 * Start/ stop/ update service for Mountpoint
135 * Notify of device state changes to "connected" for slave nodes
136 * @param mountPointNodeName name of mount point
138 synchronized public void deviceConnectSlaveIndication(String mountPointNodeName) {
139 deviceConnectMasterIndication(mountPointNodeName, null);
143 * Notify of device state changes to "connected"
144 * @param mountPointNodeName name of mount point
145 * @param ne to monitor
147 synchronized public void deviceConnectMasterIndication(String mountPointNodeName, DeviceMonitoredNe ne) {
149 LOG.debug("ne changes to connected state {}",mountPointNodeName);
150 createMonitoringTask(mountPointNodeName);
151 if (queue.containsKey(mountPointNodeName)) {
152 DeviceMonitorTask task = queue.get(mountPointNodeName);
153 task.deviceConnectIndication(ne);
155 LOG.warn("Monitoring task not in queue: {} {} {}", mountPointNodeName, mountPointNodeName.hashCode(), queue.size());
160 * Notify of device state change to "disconnected"
161 * Mount point supervision
162 * @param mountPointNodeName to deregister
164 synchronized public void deviceDisconnectIndication(String mountPointNodeName) {
166 LOG.debug("State changes to not connected state {}",mountPointNodeName);
167 createMonitoringTask(mountPointNodeName);
168 if (queue.containsKey(mountPointNodeName)) {
169 DeviceMonitorTask task = queue.get(mountPointNodeName);
170 task.deviceDisconnectIndication();
172 LOG.warn("Monitoring task not in queue: {} {} {}", mountPointNodeName, mountPointNodeName.hashCode(), queue.size());
177 * removeMountpointIndication deregisters a mountpoint for registration services
178 * @param mountPointNodeName to deregister
180 synchronized public void removeMountpointIndication(String mountPointNodeName) {
182 if (queue.containsKey(mountPointNodeName)) {
183 DeviceMonitorTask task = queue.get(mountPointNodeName);
185 queue.remove(mountPointNodeName);
187 task.removeMountpointIndication();
188 LOG.debug("Task stopped: {}", mountPointNodeName);
190 LOG.warn("Task not in queue: {}", mountPointNodeName);
195 * Referesh database by raising all alarms again.
197 public void refreshAlarmsInDb() {
198 synchronized(queue) {
199 for (DeviceMonitorTask task : queue.values()) {
200 task.refreshAlarms();
205 /*-------------------------------------------------------------
210 * createMountpoint registers a new mountpoint monitoring service
211 * @param mountPointNodeName name of mountpoint
213 synchronized private DeviceMonitorTask createMonitoringTask(String mountPointNodeName) {
215 DeviceMonitorTask task;
216 LOG.debug("Register for monitoring {} {}",mountPointNodeName, mountPointNodeName.hashCode());
218 if (queue.containsKey(mountPointNodeName)) {
219 LOG.info("Monitoring task exists");
220 task = queue.get(mountPointNodeName);
222 LOG.info("Do start of DeviceMonitor task");
223 //Runnable task = new PerformanceManagerTask(queue, databaseService);
224 task = new DeviceMonitorTask(mountPointNodeName, this.odlEventListener);
225 queue.put(mountPointNodeName, task);
226 task.start(scheduler);