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.config.HtDevicemanagerConfiguration;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.IConfigChangedListener;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.DmConfig;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener.ODLEventListener;
33 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * Implementation of concept "Active monitoring" of a device.<br>
40 * For each existing mountpoint a task runs with 120s cycle time. Every 120 seconds the check actions are performed.
41 * The request is handled by the NETCONF layer with a (default)configured time-out of 60 seconds.<br>
42 * Generated alarms, by the object/node "SDN-Controller" are (enum DeviceMonitorProblems):<br>
43 * - notConnected(InternalSeverity.Warning)<br>
44 * - noConnectionMediator(InternalSeverity.Minor)<br>
45 * - noConnectionNe(InternalSeverity.Critical)<br>
47 * 1. Mountpoint does not exist<br>
48 * If the mountpoint does not exists there are no related current alarms in the database.<br>
50 * 2. Created mountpoint with state "Connecting" or "UnableToConnect"<br>
51 * If the Mountpoint is created and connection status is "Connecting" or "UnableToConnect".<br>
52 * - After about 2..4 Minutes ... raise alarm "notConnected" with severity warning<br>
54 * 3. Created mountpoint with state "Connection"<br>
55 * There are two monitor activities.<br>
56 * 3a. Check of Mediator connection by requesting (typical) cached data.<br>
57 * - After about 60 seconds raise alarm: connection-loss-mediator with severity minor<br>
58 * - Request from Mediator: network-element<br>
60 * 3b. Check connection to NEby requesting (typical) non-cached data.<br>
61 * - Only if AirInterface available. The first one is used.<br>
62 * - Requested are the currentAlarms<br>
63 * - After about 60 seconds raise alarm: connection-loss-network-element with severity critical<br>
68 @SuppressWarnings("deprecation")
69 public class DeviceMonitorImpl implements DeviceMonitor, IConfigChangedListener {
71 private static final Logger LOG = LoggerFactory.getLogger(DeviceMonitorImpl.class);
73 private final ConcurrentHashMap<String, DeviceMonitorTask> queue;
74 private final ScheduledExecutorService scheduler;
75 private final ODLEventListener odlEventListener;
76 @SuppressWarnings("unused")
77 private final DataBroker dataBroker; //Future usage
79 /*-------------------------------------------------------------
80 * Construction/ destruction of service
84 * Basic implementation of devicemonitoring
85 * @param odlEventListener as destination for problems
87 public DeviceMonitorImpl(DataBroker dataBroker, ODLEventListener odlEventListener, HtDevicemanagerConfiguration htconfig) {
88 LOG.info("Construct {}", this.getClass().getSimpleName());
90 this.odlEventListener = odlEventListener;
91 this.dataBroker = dataBroker;
93 htconfig.registerConfigChangedListener(this);
94 DmConfig dmConfig = htconfig.getDmConfig();
95 setDmConfig(dmConfig);
97 this.queue = new ConcurrentHashMap<>();
98 this.scheduler = Executors.newScheduledThreadPool(10);
102 * Stop the service. Stop all running monitoring tasks.
105 synchronized public void close() {
106 LOG.info("Close {}", this.getClass().getSimpleName());
108 Enumeration<String> e = queue.keys();
109 while (e.hasMoreElements()) {
110 deviceDisconnectIndication(e.nextElement());
113 scheduler.shutdown();
117 public void onConfigChanged() {
118 DmConfig cfg = DmConfig.reload();
122 private void setDmConfig(DmConfig dmConfig) {
123 for (DeviceMonitorProblems problem : DeviceMonitorProblems.values()) {
124 problem.setSeverity(dmConfig.getSeverity(problem));
128 /*-------------------------------------------------------------
129 * Start/ stop/ update service for Mountpoint
133 * Notify of device state changes to "connected" for slave nodes
134 * @param mountPointNodeName name of mount point
136 synchronized public void deviceConnectSlaveIndication(String mountPointNodeName) {
137 deviceConnectMasterIndication(mountPointNodeName, null);
141 * Notify of device state changes to "connected"
142 * @param mountPointNodeName name of mount point
143 * @param ne to monitor
145 synchronized public void deviceConnectMasterIndication(String mountPointNodeName, DeviceMonitoredNe ne) {
147 LOG.debug("ne changes to connected state {}",mountPointNodeName);
148 createMonitoringTask(mountPointNodeName);
149 if (queue.containsKey(mountPointNodeName)) {
150 DeviceMonitorTask task = queue.get(mountPointNodeName);
151 task.deviceConnectIndication(ne);
153 LOG.warn("Monitoring task not in queue: {} {} {}", mountPointNodeName, mountPointNodeName.hashCode(), queue.size());
158 * Notify of device state change to "disconnected"
159 * Mount point supervision
160 * @param mountPointNodeName to deregister
162 synchronized public void deviceDisconnectIndication(String mountPointNodeName) {
164 LOG.debug("State changes to not connected state {}",mountPointNodeName);
165 createMonitoringTask(mountPointNodeName);
166 if (queue.containsKey(mountPointNodeName)) {
167 DeviceMonitorTask task = queue.get(mountPointNodeName);
168 task.deviceDisconnectIndication();
170 LOG.warn("Monitoring task not in queue: {} {} {}", mountPointNodeName, mountPointNodeName.hashCode(), queue.size());
175 * removeMountpointIndication deregisters a mountpoint for registration services
176 * @param mountPointNodeName to deregister
178 synchronized public void removeMountpointIndication(String mountPointNodeName) {
180 if (queue.containsKey(mountPointNodeName)) {
181 DeviceMonitorTask task = queue.get(mountPointNodeName);
183 queue.remove(mountPointNodeName);
185 task.removeMountpointIndication();
186 LOG.debug("Task stopped: {}", mountPointNodeName);
188 LOG.warn("Task not in queue: {}", mountPointNodeName);
193 * Referesh database by raising all alarms again.
195 public void refreshAlarmsInDb() {
196 synchronized(queue) {
197 for (DeviceMonitorTask task : queue.values()) {
198 task.refreshAlarms();
203 /*-------------------------------------------------------------
208 * createMountpoint registers a new mountpoint monitoring service
209 * @param mountPointNodeName name of mountpoint
211 synchronized private DeviceMonitorTask createMonitoringTask(String mountPointNodeName) {
213 DeviceMonitorTask task;
214 LOG.debug("Register for monitoring {} {}",mountPointNodeName, mountPointNodeName.hashCode());
216 if (queue.containsKey(mountPointNodeName)) {
217 LOG.info("Monitoring task exists");
218 task = queue.get(mountPointNodeName);
220 LOG.info("Do start of DeviceMonitor task");
221 //Runnable task = new PerformanceManagerTask(queue, databaseService);
222 task = new DeviceMonitorTask(mountPointNodeName, this.odlEventListener);
223 queue.put(mountPointNodeName, task);
224 task.start(scheduler);