SDN-R Server provide GUI cut through for ODLUX
[ccsdk/features.git] / sdnr / wt / devicemanager-onf14 / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf14 / impl / Onf14WireInterfaceNotificationListener.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.impl;
23
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
26 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.AttributeValueChangedNotification;
27 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.ObjectCreationNotification;
28 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.ObjectDeletionNotification;
29 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.ProblemNotification;
30 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.WireInterface20Listener;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class Onf14WireInterfaceNotificationListener implements WireInterface20Listener {
37
38     private static final Logger log = LoggerFactory.getLogger(Onf14WireInterfaceNotificationListener.class);
39
40     private final NetconfAccessor netconfAccessor;
41     private final DeviceManagerServiceProvider serviceProvider;
42
43     public Onf14WireInterfaceNotificationListener(NetconfAccessor netconfAccessor,
44             DeviceManagerServiceProvider serviceProvider) {
45         this.netconfAccessor = netconfAccessor;
46         this.serviceProvider = serviceProvider;
47     }
48
49     @Override
50     public void onObjectDeletionNotification(ObjectDeletionNotification notification) {
51         log.debug("Got event of type :: {}", ObjectDeletionNotification.class.getSimpleName());
52
53         EventlogBuilder eventlogBuilder = new EventlogBuilder();
54         eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue())
55         .setAttributeName("")
56         .setCounter(notification.getCounter())
57         .setNewValue("deleted")
58         .setObjectId(notification.getObjectIdRef().getValue())
59         .setSourceType(SourceType.Netconf)
60         .setTimestamp(notification.getTimestamp());
61         serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
62         serviceProvider.getNotificationService().deletionNotification(netconfAccessor.getNodeId(),
63                 notification.getCounter(), notification.getTimestamp(), notification.getObjectIdRef().getValue());
64
65         log.debug("onObjectDeletionNotification log entry written");
66     }
67
68     @Override
69     public void onProblemNotification(ProblemNotification notification) {
70         log.debug("Got event of type :: {}", ProblemNotification.class.getSimpleName());
71
72         serviceProvider.getFaultService().faultNotification(netconfAccessor.getNodeId(), notification.getCounter(),
73                 notification.getTimestamp(), notification.getObjectIdRef().getValue(), notification.getProblem(),
74                 Onf14WireInterface.mapSeverity(notification.getSeverity()));
75
76     }
77
78     @Override
79     public void onAttributeValueChangedNotification(AttributeValueChangedNotification notification) {
80         log.debug("Got event of type :: {}", AttributeValueChangedNotification.class.getSimpleName());
81
82         EventlogBuilder eventlogBuilder = new EventlogBuilder();
83         eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue())
84         .setAttributeName(notification.getAttributeName())
85         .setCounter(notification.getCounter())
86         .setNewValue(notification.getNewValue())
87         .setObjectId(notification.getObjectIdRef().getValue())
88         .setSourceType(SourceType.Netconf)
89         .setTimestamp(notification.getTimestamp());
90         serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
91         serviceProvider.getNotificationService().eventNotification(eventlogBuilder.build());
92
93         log.debug("onAttributeValueChangedNotification log entry written");
94     }
95
96     @Override
97     public void onObjectCreationNotification(ObjectCreationNotification notification) {
98         log.debug("Got event of type :: {}", ObjectCreationNotification.class.getSimpleName());
99
100         EventlogBuilder eventlogBuilder = new EventlogBuilder();
101         eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue())
102         .setAttributeName(notification.getObjectType())
103         .setCounter(notification.getCounter())
104         .setNewValue("created")
105         .setObjectId(notification.getObjectIdRef().getValue())
106         .setSourceType(SourceType.Netconf)
107         .setTimestamp(notification.getTimestamp());
108         serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
109         serviceProvider.getNotificationService().creationNotification(netconfAccessor.getNodeId(),
110                 notification.getCounter(), notification.getTimestamp(), notification.getObjectIdRef().getValue());
111
112         log.debug("onObjectCreationNotification log entry written");
113     }
114
115 }