Merge "Bump parent version to 2.5.4-SNAPSHOT"
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / onf14 / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf14 / dom / impl / Onf14DomAirInterfaceNotificationListener.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk feature sdnr wt
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl;
23
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.dataprovider.InternalDataModelSeverity;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DMDOMUtility;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DevicemanagerQNames;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
30 import org.opendaylight.mdsal.dom.api.DOMNotification;
31 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
37 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
38 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 public class Onf14DomAirInterfaceNotificationListener implements DOMNotificationListener {
43
44     private static final Logger log = LoggerFactory.getLogger(Onf14DomAirInterfaceNotificationListener.class);
45
46     private final NetconfDomAccessor netconfDomAccessor;
47     private final DeviceManagerServiceProvider serviceProvider;
48
49     public Onf14DomAirInterfaceNotificationListener(NetconfDomAccessor netconfDomAccessor,
50             DeviceManagerServiceProvider serviceProvider) {
51         this.netconfDomAccessor = netconfDomAccessor;
52         this.serviceProvider = serviceProvider;
53     }
54
55     @Override
56     public void onNotification(@NonNull DOMNotification domNotification) {
57         log.debug("Got event of type :: {}", domNotification.getType());
58         if (domNotification.getType()
59                 .equals(Absolute.of(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION))) {
60             onObjectCreateNotification(domNotification);
61         } else if (domNotification.getType()
62                 .equals(Absolute.of(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION))) {
63             onObjectAVCNotification(domNotification);
64         } else if (domNotification.getType()
65                 .equals(Absolute.of(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION))) {
66             onObjectProblemNotification(domNotification);
67         } else if (domNotification.getType()
68                 .equals(Absolute.of(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION))) {
69             onObjectDeletionNotification(domNotification);
70         }
71     }
72
73     private void onObjectCreateNotification(@NonNull DOMNotification domNotification) {
74
75         ContainerNode cn = domNotification.getBody();
76
77         EventlogBuilder eventlogBuilder = new EventlogBuilder();
78         eventlogBuilder.setNodeId(netconfDomAccessor.getNodeId().getValue())
79                 .setAttributeName(Onf14DMDOMUtility.getLeafValue(cn,
80                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION_OBJECT_TYPE))
81                 .setCounter(Integer.parseInt(Onf14DMDOMUtility.getLeafValue(cn,
82                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION_COUNTER)))
83                 .setNewValue("created")
84                 .setObjectId(Onf14DMDOMUtility.getLeafValue(cn,
85                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION_OBJECT_ID_REF))
86                 .setSourceType(SourceType.Netconf).setTimestamp(new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
87                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION_TIMESTAMP)));
88
89         serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
90         serviceProvider.getWebsocketService().sendNotification(domNotification, netconfDomAccessor.getNodeId(),
91                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION,
92                 new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
93                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION_TIMESTAMP)));
94         log.debug("onObjectCreationNotification log entry written");
95     }
96
97     private void onObjectAVCNotification(@NonNull DOMNotification domNotification) {
98
99         ContainerNode cn = domNotification.getBody();
100         EventlogBuilder eventlogBuilder = new EventlogBuilder();
101         eventlogBuilder.setNodeId(netconfDomAccessor.getNodeId().getValue())
102                 .setAttributeName(Onf14DMDOMUtility.getLeafValue(cn,
103                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_ATTRIBUTE_NAME))
104                 .setCounter(Integer.parseInt(Onf14DMDOMUtility.getLeafValue(cn,
105                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_COUNTER)))
106                 .setNewValue(Onf14DMDOMUtility.getLeafValue(cn,
107                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_NEW_VALUE))
108                 .setObjectId(Onf14DMDOMUtility.getLeafValue(cn,
109                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_OBJECT_ID_REF))
110                 .setSourceType(SourceType.Netconf).setTimestamp(new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
111                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_TIMESTAMP)));
112
113         serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
114         serviceProvider.getWebsocketService().sendNotification(domNotification, netconfDomAccessor.getNodeId(),
115                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION, new DateAndTime(Onf14DMDOMUtility
116                         .getLeafValue(cn, Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_TIMESTAMP)));
117         log.debug("onAttributeValueChangedNotification log entry written");
118     }
119
120     private void onObjectProblemNotification(@NonNull DOMNotification domNotification) {
121
122         ContainerNode cn = domNotification.getBody();
123         FaultlogEntity faultAlarm =
124                 new FaultlogBuilder()
125                         .setObjectId(Onf14DMDOMUtility.getLeafValue(cn,
126                                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_OBJECT_ID_REF))
127                         .setProblem(Onf14DMDOMUtility.getLeafValue(cn,
128                                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_PROBLEM))
129                         .setSourceType(SourceType.Netconf)
130                         .setTimestamp(new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
131                                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_TIMESTAMP)))
132                         .setNodeId(this.netconfDomAccessor.getNodeId().getValue())
133                         .setSeverity(InternalDataModelSeverity.mapSeverity(Onf14DMDOMUtility.getLeafValue(cn,
134                                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_SEVERITY)))
135                         .setCounter(Integer.parseInt(Onf14DMDOMUtility.getLeafValue(cn,
136                                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_COUNTER)))
137                         .build();
138
139         serviceProvider.getFaultService().faultNotification(faultAlarm);
140         serviceProvider.getWebsocketService().sendNotification(domNotification, netconfDomAccessor.getNodeId(),
141                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION,
142                 new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
143                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_TIMESTAMP)));
144         log.debug("onObjectProblemNotification log entry written");
145     }
146
147     private void onObjectDeletionNotification(@NonNull DOMNotification domNotification) {
148
149         ContainerNode cn = domNotification.getBody();
150         EventlogBuilder eventlogBuilder = new EventlogBuilder();
151         eventlogBuilder.setNodeId(netconfDomAccessor.getNodeId().getValue()).setAttributeName("")
152                 .setCounter(Integer.parseInt(Onf14DMDOMUtility.getLeafValue(cn,
153                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION_COUNTER)))
154                 .setNewValue("deleted")
155                 .setObjectId(Onf14DMDOMUtility.getLeafValue(cn,
156                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION_OBJECT_ID_REF))
157
158                 .setSourceType(SourceType.Netconf).setTimestamp(new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
159                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION_TIMESTAMP)));
160
161         serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
162         serviceProvider.getWebsocketService().sendNotification(domNotification, netconfDomAccessor.getNodeId(),
163                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION,
164                 new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
165                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION_TIMESTAMP)));
166
167         log.debug("onObjectDeletionNotification log entry written");
168     }
169
170 }