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.handler;
20 import java.util.List;
21 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.ONFCoreNetworkElement12Equipment;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.ONFCoreNetworkElementCallback;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.wrapperc.OnfMicrowaveModelNotification;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderInternal;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectCreationNotificationXml;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectDeletionNotificationXml;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.NotificationDelayFilter;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.NotificationDelayService;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.NotificationDelayedListener;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * Important: Websocket notification must be the last action.
41 * At the beginning intended to handle notifications of type <code>OnfMicrowaveModelNotification</code>.
42 * Today an abstract class for processing notifications independent of model.
46 public class NetconfEventListenerHandler12 implements OnfMicrowaveModelNotification, NotificationDelayedListener<ProblemNotificationXml> {
48 private static final Logger LOG = LoggerFactory.getLogger(NetconfEventListenerHandler12.class);
50 private final String nodeName;
51 private final WebSocketServiceClientInternal webSocketService;
52 //private final WebsocketmanagerService websocketmanagerService;
53 //private final XmlMapper xmlMapper;
54 private final DataProvider databaseService;
55 private final DcaeForwarderInternal dcaeForwarder;
57 private final NotificationDelayFilter<ProblemNotificationXml> delayFilter;
58 private final ONFCoreNetworkElementCallback ne;
60 public NetconfEventListenerHandler12(String nodeName, WebSocketServiceClientInternal webSocketService,
61 DataProvider databaseService, DcaeForwarderInternal aotsDcaeForwarder,
62 NotificationDelayService<ProblemNotificationXml> notificationDelayService,
63 ONFCoreNetworkElementCallback ne) {
65 this.nodeName = nodeName;
66 //this.websocketmanagerService = websocketmanagerService;
67 //this.xmlMapper = xmlMapper;
68 this.webSocketService = webSocketService;
69 this.databaseService = databaseService;
70 this.dcaeForwarder = aotsDcaeForwarder;
71 this.delayFilter=notificationDelayService.getInstance(nodeName, this);//12(nodeName,this);
77 public void onAttributeValueChangedNotification(AttributeValueChangedNotificationXml notificationXml) {
79 ne.notificationFromNeListener(notificationXml);
81 databaseService.writeEventLog(notificationXml.getEventlogEntity());
82 webSocketService.sendViaWebsockets(nodeName, notificationXml);
87 public void onObjectCreationNotification(ObjectCreationNotificationXml notificationXml) {
89 databaseService.writeEventLog(notificationXml.getEventlogEntity());
90 webSocketService.sendViaWebsockets(nodeName, notificationXml);
95 public void onObjectDeletionNotification(ObjectDeletionNotificationXml notificationXml) {
97 databaseService.writeEventLog(notificationXml.getEventlogEntity());
98 webSocketService.sendViaWebsockets(nodeName, notificationXml);
102 public void onProblemNotification(ProblemNotificationXml notificationXml) {
104 databaseService.writeFaultLog(notificationXml.getFaultlog(SourceType.Netconf));
105 databaseService.updateFaultCurrent(notificationXml.getFaultcurrent());
107 // ToggleAlarmFilter functionality
108 if (delayFilter.processNotification(notificationXml.getSeverity() == InternalSeverity.NonAlarmed, notificationXml.getProblem(), notificationXml))
110 dcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(this.nodeName, notificationXml);
111 // end of ToggleAlarmFilter
114 this.webSocketService.sendViaWebsockets(nodeName, notificationXml);
119 public void onNotificationDelay(ProblemNotificationXml notificationXml) {
121 LOG.debug("Got delayed event of type :: {}", ProblemNotificationXml.class.getSimpleName());
122 dcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(this.nodeName, notificationXml);
125 private void initCurrentProblem(ProblemNotificationXml notificationXml) {
126 databaseService.updateFaultCurrent(notificationXml.getFaultcurrent());
127 dcaeForwarder.sendProblemNotification(this.nodeName, notificationXml);
131 * Called to initialize with the current status and notify the clients
132 * @param notificationXmlList List with problems
134 public void initCurrentProblemStatus(List<ProblemNotificationXml> notificationXmlList) {
136 for (ProblemNotificationXml notificationXml : notificationXmlList) {
137 initCurrentProblem(notificationXml);
143 * Called on exit to remove everything from the current list.
144 * @return Number of deleted objects
146 public int removeAllCurrentProblemsOfNode() {
147 int deleted = databaseService.clearFaultsCurrentOfNode(nodeName);
152 * Called on exit to remove for one Object-Pac from the current list.
153 * @param objectId uuid of the interface-pac or equipment-pac
154 * @return Number of deleted objects
156 public int removeObjectsCurrentProblemsOfNode(String objectId) {
157 int deleted = databaseService.clearFaultsCurrentOfNodeWithObjectId(nodeName, objectId);
162 * Write equipment data to database
163 * @param equipment to write
165 public void writeEquipment(ONFCoreNetworkElement12Equipment equipment) {
166 // List<ExtendedEquipment> equipmentList = equipment.getEquipmentList();
167 // for (ExtendedEquipment card : equipmentList) {
168 // databaseService.writeInventory(card.getCreateInventoryInput());
170 equipment.getEquipmentList().forEach(card -> databaseService.writeInventory(card.getCreateInventoryInput()) );