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.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ProblemNotification;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * Important: Websocket notification must be the last action.
46 */ //OnfMicrowaveModelNotification //
47 public class MicrowaveEventListener12 implements OnfMicrowaveModelNotification, NotificationDelayedListener<ProblemNotificationXml> {
49 private static final Logger LOG = LoggerFactory.getLogger(MicrowaveEventListener12.class);
51 private final String nodeName;
52 private final WebSocketServiceClient webSocketService;
53 //private final WebsocketmanagerService websocketmanagerService;
54 //private final XmlMapper xmlMapper;
55 private final HtDatabaseEventsService databaseService;
56 private final ProviderClient dcaeProvider;
57 private final @Nullable ProviderClient aotsmClient;
59 private final MaintenanceService maintenanceService;
61 private final NotificationDelayFilter<ProblemNotificationXml> delayFilter;
62 private final ONFCoreNetworkElementCallback ne;
64 public MicrowaveEventListener12(String nodeName, WebSocketServiceClient webSocketService,
65 HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,@Nullable ProviderClient aotsmClient,
66 MaintenanceService maintenanceService2,NotificationDelayService<ProblemNotificationXml> notificationDelayService,
67 ONFCoreNetworkElementCallback ne) {
69 this.nodeName = nodeName;
70 //this.websocketmanagerService = websocketmanagerService;
71 //this.xmlMapper = xmlMapper;
72 this.webSocketService = webSocketService;
73 this.databaseService = databaseService;
74 this.dcaeProvider = dcaeProvider;
75 this.aotsmClient = aotsmClient;
76 this.maintenanceService=maintenanceService2;
77 this.delayFilter=notificationDelayService.getInstance(nodeName, this);//12(nodeName,this);
83 public void onAttributeValueChangedNotification(AttributeValueChangedNotificationXml notificationXml) {
85 ne.notificationFromNeListener(notificationXml);
87 databaseService.writeEventLog(notificationXml);
89 webSocketService.sendViaWebsockets(nodeName, notificationXml);
94 public void onObjectCreationNotification(ObjectCreationNotificationXml notificationXml) {
96 databaseService.writeEventLog(notificationXml);
98 webSocketService.sendViaWebsockets(nodeName, notificationXml);
103 public void onObjectDeletionNotification(ObjectDeletionNotificationXml notificationXml) {
105 databaseService.writeEventLog(notificationXml);
107 webSocketService.sendViaWebsockets(nodeName, notificationXml);
111 public void onProblemNotification(ProblemNotificationXml notificationXml) {
113 databaseService.writeFaultLog(notificationXml);
114 databaseService.updateFaultCurrent(notificationXml);
116 //ToggleAlarmFilter functionality
117 if(NotificationDelayFilter.isEnabled())
119 if(notificationXml.getSeverity() == InternalSeverity.NonAlarmed) {
120 delayFilter.clearAlarmNotification(notificationXml.getProblem(), notificationXml);
122 delayFilter.pushAlarmNotification(notificationXml.getProblem(), notificationXml);
127 this.pushAlarmIfNotInMaintenance(notificationXml);
129 //end of ToggleAlarmFilter
131 this.webSocketService.sendViaWebsockets(nodeName, notificationXml);
136 public void onNotificationDelay(ProblemNotificationXml notificationXml) {
138 LOG.debug("Got delayed event of type :: {}", ProblemNotification.class.getSimpleName());
139 this.pushAlarmIfNotInMaintenance(notificationXml);
142 private void pushAlarmIfNotInMaintenance(ProblemNotificationXml notificationXml)
144 if(!this.maintenanceService.isONFObjectInMaintenance(nodeName, notificationXml.getObjectId(), notificationXml.getProblem()))
146 this.dcaeProvider.sendProblemNotification(nodeName, notificationXml);
147 if(this.aotsmClient!=null) {
148 this.aotsmClient.sendProblemNotification(nodeName, notificationXml);
153 LOG.debug("Notification will not be sent to external services. Device "+this.nodeName+" is in maintenance mode");
156 private void initCurrentProblem(ProblemNotificationXml notificationXml) {
157 databaseService.updateFaultCurrent(notificationXml);
158 //to prevent push alarms on reconnect
159 //=> only pushed alarms are forwared to dcae
160 //dcaeProvider.sendProblemNotification(nodeName, notificationXml);
161 if(aotsmClient!=null) {
162 aotsmClient.sendProblemNotification(this.nodeName, notificationXml);
167 * Called to initialize with the current status and notify the clients
168 * @param notificationXmlList List with problems
170 public void initCurrentProblemStatus(List<ProblemNotificationXml> notificationXmlList) {
172 for (ProblemNotificationXml notificationXml : notificationXmlList) {
173 initCurrentProblem(notificationXml);
179 * Called on exit to remove everything from the current list.
180 * @return Number of deleted objects
182 public int removeAllCurrentProblemsOfNode() {
183 int deleted = databaseService.clearFaultsCurrentOfNode(nodeName);
188 * Called on exit to remove for one Object-Pac from the current list.
189 * @param objectId uuid of the interface-pac or equipment-pac
190 * @return Number of deleted objects
192 public int removeObjectsCurrentProblemsOfNode(String objectId) {
193 int deleted = databaseService.clearFaultsCurrentOfNodeWithObjectId(nodeName, objectId);
198 * Write equipment data to database
199 * @param equipment to write
201 public void writeEquipment(ONFCoreNetworkElement12Equipment equipment) {
202 databaseService.writeInventory(equipment);