747de40debd3c5844b8bb5ab421cd2bb27bb7809
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
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.openroadm71.impl;
23
24 import java.util.List;
25 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
28 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42
43 /**
44  * @author Shabnam Sultana
45  *
46  *         Listener for change notifications
47  *
48  **/
49 public class OpenroadmChangeNotificationListener implements IetfNetconfNotificationsListener {
50
51     // variables
52     private static final Logger LOG = LoggerFactory.getLogger(OpenroadmChangeNotificationListener.class);
53     private final NetconfAccessor netconfAccessor;
54     private final DataProvider databaseService;
55     private final WebsocketManagerService notificationServiceService;
56     // end of variables
57
58     // constructors
59     public OpenroadmChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService,
60             WebsocketManagerService notificationService) {
61         this.netconfAccessor = netconfAccessor;
62         this.databaseService = databaseService;
63         this.notificationServiceService = notificationService;
64     }
65     // end of constructors
66
67     // public methods
68     @Override
69     public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) {
70         LOG.debug("onNetconfConfirmedCommit {} ", notification);
71         this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(),
72                 NetconfConfirmedCommit.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp());
73     }
74
75     @Override
76     public void onNetconfSessionStart(NetconfSessionStart notification) {
77         LOG.debug("onNetconfSessionStart {} ", notification);
78         this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(),
79                 NetconfSessionStart.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp());
80
81     }
82
83     @Override
84     public void onNetconfSessionEnd(NetconfSessionEnd notification) {
85         LOG.debug("onNetconfSessionEnd {}", notification);
86         this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(),
87                 NetconfSessionEnd.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp());
88     }
89
90     @Override
91     public void onNetconfCapabilityChange(NetconfCapabilityChange notification) {
92         LOG.debug("onNetconfCapabilityChange {}", notification);
93         this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(),
94                 NetconfCapabilityChange.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp());
95     }
96
97     @Override
98     public void onNetconfConfigChange(NetconfConfigChange notification) {
99         LOG.info("onNetconfConfigChange (1) {}", notification);
100         StringBuffer sb = new StringBuffer();
101         List<Edit> editList = notification.nonnullEdit();
102         for (Edit edit : editList) {
103             if(edit==null) { //should never happen
104                 LOG.warn("null object in config change");
105                 continue;
106             }
107             if (sb.length() > 0) {
108                 sb.append(", ");
109             }
110             try {
111                 sb.append(edit);
112             } catch (Exception e) { //catch odl error
113                 LOG.warn("unable to serialize edit obj", e);
114             }
115
116             EventlogBuilder eventlogBuilder = new EventlogBuilder();
117
118             InstanceIdentifier<?> target = edit.getTarget();
119             if (target != null) {
120                 eventlogBuilder.setObjectId(target.toString());
121                 LOG.debug("TARGET: {} {}", target.getClass(), target.getTargetType());
122                 for (PathArgument pa : target.getPathArguments()) {
123                     LOG.debug("PathArgument {}", pa);
124                 }
125             }
126             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
127             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
128             databaseService.writeEventLog(eventlogBuilder.build());
129         }
130         LOG.debug("onNetconfConfigChange (2) {}", sb);
131         this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(),
132                 NetconfConfigChange.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp());
133
134     }
135
136     // end of public methods
137
138 }