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;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener.ODLEventListener;
29 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * Implementation of concept "Active monitoring" of a device.<br>
36 * For each existing mountpoint a task runs with 120s cycle time. Every 120 seconds the check actions are performed.
37 * The request is handled by the NETCONF layer with a (default)configured time-out of 60 seconds.<br>
38 * Generated alarms, by the object/node "SDN-Controller" are (enum DeviceMonitorProblems):<br>
39 * - notConnected(InternalSeverity.Warning)<br>
40 * - noConnectionMediator(InternalSeverity.Minor)<br>
41 * - noConnectionNe(InternalSeverity.Critical)<br>
43 * 1. Mountpoint does not exist<br>
44 * If the mountpoint does not exists there are no related current alarms in the database.<br>
46 * 2. Created mountpoint with state "Connecting" or "UnableToConnect"<br>
47 * If the Mountpoint is created and connection status is "Connecting" or "UnableToConnect".<br>
48 * - After about 2..4 Minutes ... raise alarm "notConnected" with severity warning<br>
50 * 3. Created mountpoint with state "Connection"<br>
51 * There are two monitor activities.<br>
52 * 3a. Check of Mediator connection by requesting (typical) cached data.<br>
53 * - After about 60 seconds raise alarm: connection-loss-mediator with severity minor<br>
54 * - Request from Mediator: network-element<br>
56 * 3b. Check connection to NEby requesting (typical) non-cached data.<br>
57 * - Only if AirInterface available. The first one is used.<br>
58 * - Requested are the currentAlarms<br>
59 * - After about 60 seconds raise alarm: connection-loss-network-element with severity critical<br>
64 @SuppressWarnings("deprecation")
65 public class DeviceMonitorImpl implements AutoCloseable {
67 private static final Logger LOG = LoggerFactory.getLogger(DeviceMonitorImpl.class);
69 private final ConcurrentHashMap<String, DeviceMonitorTask> queue;
70 private final ScheduledExecutorService scheduler;
71 private final ODLEventListener odlEventListener;
72 @SuppressWarnings("unused")
73 private final DataBroker dataBroker; //Future usage
75 /*-------------------------------------------------------------
76 * Construction/ destruction of service
80 * Basic implementation of devicemonitoring
81 * @param odlEventListener as destination for problems
83 public DeviceMonitorImpl(DataBroker dataBroker, ODLEventListener odlEventListener) {
84 LOG.info("Construct {}", this.getClass().getSimpleName());
86 this.odlEventListener = odlEventListener;
87 this.dataBroker = dataBroker;
88 this.queue = new ConcurrentHashMap<>();
89 this.scheduler = Executors.newScheduledThreadPool(10);
93 * Stop the service. Stop all running monitoring tasks.
96 synchronized public void close() {
97 LOG.info("Close {}", this.getClass().getSimpleName());
99 Enumeration<String> e = queue.keys();
100 while (e.hasMoreElements()) {
101 deviceDisconnectIndication(e.nextElement());
104 scheduler.shutdown();
107 /*-------------------------------------------------------------
108 * Start/ stop/ update service for Mountpoint
112 * Notify of device state changes to "connected" for slave nodes
113 * @param mountPointNodeName name of mount point
115 synchronized public void deviceConnectSlaveIndication(String mountPointNodeName) {
116 deviceConnectMasterIndication(mountPointNodeName, null);
120 * Notify of device state changes to "connected"
121 * @param mountPointNodeName name of mount point
122 * @param ne to monitor
124 synchronized public void deviceConnectMasterIndication(String mountPointNodeName, DeviceMonitoredNe ne) {
126 LOG.debug("ne changes to connected state {}",mountPointNodeName);
127 createMonitoringTask(mountPointNodeName);
128 if (queue.containsKey(mountPointNodeName)) {
129 DeviceMonitorTask task = queue.get(mountPointNodeName);
130 task.deviceConnectIndication(ne);
132 LOG.warn("Monitoring task not in queue: {} {} {}", mountPointNodeName, mountPointNodeName.hashCode(), queue.size());
137 * Notify of device state change to "disconnected"
138 * Mount point supervision
139 * @param mountPointNodeName to deregister
141 synchronized public void deviceDisconnectIndication(String mountPointNodeName) {
143 LOG.debug("State changes to not connected state {}",mountPointNodeName);
144 createMonitoringTask(mountPointNodeName);
145 if (queue.containsKey(mountPointNodeName)) {
146 DeviceMonitorTask task = queue.get(mountPointNodeName);
147 task.deviceDisconnectIndication();
149 LOG.warn("Monitoring task not in queue: {} {} {}", mountPointNodeName, mountPointNodeName.hashCode(), queue.size());
154 * removeMountpointIndication deregisters a mountpoint for registration services
155 * @param mountPointNodeName to deregister
157 synchronized public void removeMountpointIndication(String mountPointNodeName) {
159 if (queue.containsKey(mountPointNodeName)) {
160 DeviceMonitorTask task = queue.get(mountPointNodeName);
162 queue.remove(mountPointNodeName);
165 task.removeMountpointIndication();
166 LOG.debug("Task stopped: {}", mountPointNodeName);
168 LOG.warn("Task not in queue: {}", mountPointNodeName);
173 * Referesh database by raising all alarms again.
175 public void refreshAlarmsInDb() {
176 synchronized(queue) {
177 for (DeviceMonitorTask task : queue.values()) {
178 task.refreshAlarms();
183 /*-------------------------------------------------------------
188 * createMountpoint registers a new mountpoint monitoring service
189 * @param mountPointNodeName name of mountpoint
191 synchronized private DeviceMonitorTask createMonitoringTask(String mountPointNodeName) {
193 DeviceMonitorTask task;
194 LOG.debug("Register for monitoring {} {}",mountPointNodeName, mountPointNodeName.hashCode());
196 if (queue.containsKey(mountPointNodeName)) {
197 LOG.info("Monitoring task exists");
198 task = queue.get(mountPointNodeName);
200 LOG.info("Do start of DeviceMonitor task");
201 //Runnable task = new PerformanceManagerTask(queue, databaseService);
202 task = new DeviceMonitorTask(mountPointNodeName, this.odlEventListener);
203 queue.put(mountPointNodeName, task);
204 task.start(scheduler);