Merge "YANG Model update for A1 Adapter"
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / impl / handler / NetconfEventListenerHandler12.java
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.handler;
19
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;
38
39 /**
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.
43  *
44  * @author herbert
45  */
46 public class NetconfEventListenerHandler12 implements OnfMicrowaveModelNotification, NotificationDelayedListener<ProblemNotificationXml> {
47
48     private static final Logger LOG = LoggerFactory.getLogger(NetconfEventListenerHandler12.class);
49
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;
56
57     private final NotificationDelayFilter<ProblemNotificationXml> delayFilter;
58     private final ONFCoreNetworkElementCallback ne;
59
60     public NetconfEventListenerHandler12(String nodeName, WebSocketServiceClientInternal webSocketService,
61             DataProvider databaseService, DcaeForwarderInternal aotsDcaeForwarder,
62             NotificationDelayService<ProblemNotificationXml> notificationDelayService,
63             ONFCoreNetworkElementCallback ne) {
64         super();
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);
72         this.ne = ne;
73     }
74
75
76     @Override
77     public void onAttributeValueChangedNotification(AttributeValueChangedNotificationXml notificationXml) {
78
79         ne.notificationFromNeListener(notificationXml);
80
81         databaseService.writeEventLog(notificationXml.getEventlogEntity());
82         webSocketService.sendViaWebsockets(nodeName, notificationXml);
83     }
84
85
86     @Override
87     public void onObjectCreationNotification(ObjectCreationNotificationXml notificationXml) {
88
89         databaseService.writeEventLog(notificationXml.getEventlogEntity());
90         webSocketService.sendViaWebsockets(nodeName, notificationXml);
91
92     }
93
94     @Override
95     public void onObjectDeletionNotification(ObjectDeletionNotificationXml notificationXml) {
96
97         databaseService.writeEventLog(notificationXml.getEventlogEntity());
98         webSocketService.sendViaWebsockets(nodeName, notificationXml);
99     }
100
101     @Override
102     public void onProblemNotification(ProblemNotificationXml notificationXml) {
103
104         databaseService.writeFaultLog(notificationXml.getFaultlog(SourceType.Netconf));
105         databaseService.updateFaultCurrent(notificationXml.getFaultcurrent());
106
107         // ToggleAlarmFilter functionality
108         if (delayFilter.processNotification(notificationXml.getSeverity() == InternalSeverity.NonAlarmed, notificationXml.getProblem(), notificationXml))
109          {
110             dcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(this.nodeName, notificationXml);
111         // end of ToggleAlarmFilter
112         }
113
114         this.webSocketService.sendViaWebsockets(nodeName, notificationXml);
115
116     }
117
118     @Override
119     public void onNotificationDelay(ProblemNotificationXml notificationXml) {
120
121         LOG.debug("Got delayed event of type :: {}", ProblemNotificationXml.class.getSimpleName());
122         dcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(this.nodeName, notificationXml);
123
124     }
125     private void initCurrentProblem(ProblemNotificationXml notificationXml) {
126         databaseService.updateFaultCurrent(notificationXml.getFaultcurrent());
127         dcaeForwarder.sendProblemNotification(this.nodeName, notificationXml);
128     }
129
130     /**
131      * Called to initialize with the current status and notify the clients
132      * @param notificationXmlList List with problems
133      */
134     public void initCurrentProblemStatus(List<ProblemNotificationXml> notificationXmlList) {
135
136         for (ProblemNotificationXml notificationXml : notificationXmlList) {
137             initCurrentProblem(notificationXml);
138         }
139
140     }
141
142     /**
143      * Called on exit to remove everything from the current list.
144      * @return Number of deleted objects
145      */
146     public int removeAllCurrentProblemsOfNode() {
147         int deleted = databaseService.clearFaultsCurrentOfNode(nodeName);
148         return deleted;
149     }
150
151     /**
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
155      */
156     public int removeObjectsCurrentProblemsOfNode(String objectId) {
157         int deleted = databaseService.clearFaultsCurrentOfNodeWithObjectId(nodeName, objectId);
158         return deleted;
159     }
160
161     /**
162      * Write equipment data to database
163      * @param equipment to write
164      */
165     public void writeEquipment(ONFCoreNetworkElement12Equipment equipment) {
166 //        List<ExtendedEquipment> equipmentList = equipment.getEquipmentList();
167 //        for (ExtendedEquipment card : equipmentList) {
168 //            databaseService.writeInventory(card.getCreateInventoryInput());
169 //        }
170         equipment.getEquipmentList().forEach(card -> databaseService.writeInventory(card.getCreateInventoryInput()) );
171
172     }
173
174  }