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 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener;
20 import java.util.List;
22 import javax.annotation.Nullable;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.ONFCoreNetworkElement12Equipment;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.ONFCoreNetworkElementCallback;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.OnfMicrowaveModelNotification;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayFilter;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayedListener;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.ProviderClient;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service.HtDatabaseEventsService;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectCreationNotificationXml;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectDeletionNotificationXml;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClient;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceService;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * Important: Websocket notification must be the last action.
43 * At the beginning intended to handle notifications of type <code>OnfMicrowaveModelNotification</code>.
44 * Today an abstract class for processing notifications independent of model.
48 public class NetconfEventListener12 implements OnfMicrowaveModelNotification, NotificationDelayedListener<ProblemNotificationXml> {
50 private static final Logger LOG = LoggerFactory.getLogger(NetconfEventListener12.class);
52 private final String nodeName;
53 private final WebSocketServiceClient webSocketService;
54 //private final WebsocketmanagerService websocketmanagerService;
55 //private final XmlMapper xmlMapper;
56 private final HtDatabaseEventsService databaseService;
57 private final ProviderClient dcaeProvider;
58 private final @Nullable ProviderClient aotsmClient;
60 private final MaintenanceService maintenanceService;
62 private final NotificationDelayFilter<ProblemNotificationXml> delayFilter;
63 private final ONFCoreNetworkElementCallback ne;
65 public NetconfEventListener12(String nodeName, WebSocketServiceClient webSocketService,
66 HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,@Nullable ProviderClient aotsmClient,
67 MaintenanceService maintenanceService2,NotificationDelayService<ProblemNotificationXml> notificationDelayService,
68 ONFCoreNetworkElementCallback ne) {
70 this.nodeName = nodeName;
71 //this.websocketmanagerService = websocketmanagerService;
72 //this.xmlMapper = xmlMapper;
73 this.webSocketService = webSocketService;
74 this.databaseService = databaseService;
75 this.dcaeProvider = dcaeProvider;
76 this.aotsmClient = aotsmClient;
77 this.maintenanceService=maintenanceService2;
78 this.delayFilter=notificationDelayService.getInstance(nodeName, this);//12(nodeName,this);
84 public void onAttributeValueChangedNotification(AttributeValueChangedNotificationXml notificationXml) {
86 ne.notificationFromNeListener(notificationXml);
88 databaseService.writeEventLog(notificationXml);
90 webSocketService.sendViaWebsockets(nodeName, notificationXml);
95 public void onObjectCreationNotification(ObjectCreationNotificationXml notificationXml) {
97 databaseService.writeEventLog(notificationXml);
99 webSocketService.sendViaWebsockets(nodeName, notificationXml);
104 public void onObjectDeletionNotification(ObjectDeletionNotificationXml notificationXml) {
106 databaseService.writeEventLog(notificationXml);
108 webSocketService.sendViaWebsockets(nodeName, notificationXml);
112 public void onProblemNotification(ProblemNotificationXml notificationXml) {
114 databaseService.writeFaultLog(notificationXml);
115 databaseService.updateFaultCurrent(notificationXml);
117 //ToggleAlarmFilter functionality
118 if(NotificationDelayFilter.isEnabled())
120 if(notificationXml.getSeverity() == InternalSeverity.NonAlarmed) {
121 delayFilter.clearAlarmNotification(notificationXml.getProblem(), notificationXml);
123 delayFilter.pushAlarmNotification(notificationXml.getProblem(), notificationXml);
128 this.pushAlarmIfNotInMaintenance(notificationXml);
130 //end of ToggleAlarmFilter
132 this.webSocketService.sendViaWebsockets(nodeName, notificationXml);
137 public void onNotificationDelay(ProblemNotificationXml notificationXml) {
139 LOG.debug("Got delayed event of type :: {}", ProblemNotificationXml.class.getSimpleName());
140 this.pushAlarmIfNotInMaintenance(notificationXml);
143 private void pushAlarmIfNotInMaintenance(ProblemNotificationXml notificationXml)
145 if(!this.maintenanceService.isONFObjectInMaintenance(nodeName, notificationXml.getObjectId(), notificationXml.getProblem()))
147 this.dcaeProvider.sendProblemNotification(nodeName, notificationXml);
148 if(this.aotsmClient!=null) {
149 this.aotsmClient.sendProblemNotification(nodeName, notificationXml);
154 LOG.debug("Notification will not be sent to external services. Device "+this.nodeName+" is in maintenance mode");
157 private void initCurrentProblem(ProblemNotificationXml notificationXml) {
158 databaseService.updateFaultCurrent(notificationXml);
159 //to prevent push alarms on reconnect
160 //=> only pushed alarms are forwared to dcae
161 //dcaeProvider.sendProblemNotification(nodeName, notificationXml);
162 if(aotsmClient!=null) {
163 aotsmClient.sendProblemNotification(this.nodeName, notificationXml);
168 * Called to initialize with the current status and notify the clients
169 * @param notificationXmlList List with problems
171 public void initCurrentProblemStatus(List<ProblemNotificationXml> notificationXmlList) {
173 for (ProblemNotificationXml notificationXml : notificationXmlList) {
174 initCurrentProblem(notificationXml);
180 * Called on exit to remove everything from the current list.
181 * @return Number of deleted objects
183 public int removeAllCurrentProblemsOfNode() {
184 int deleted = databaseService.clearFaultsCurrentOfNode(nodeName);
189 * Called on exit to remove for one Object-Pac from the current list.
190 * @param objectId uuid of the interface-pac or equipment-pac
191 * @return Number of deleted objects
193 public int removeObjectsCurrentProblemsOfNode(String objectId) {
194 int deleted = databaseService.clearFaultsCurrentOfNodeWithObjectId(nodeName, objectId);
199 * Write equipment data to database
200 * @param equipment to write
202 public void writeEquipment(ONFCoreNetworkElement12Equipment equipment) {
203 databaseService.writeInventory(equipment);