SDN-R Server provide GUI cut through for ODLUX
[ccsdk/features.git] / sdnr / wt / devicemanager-openroadm / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / openroadm / impl / OpenroadmChangeNotificationListener.java
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.openroadm.impl;
23
24 import java.util.List;
25 import org.eclipse.jdt.annotation.NonNull;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification;
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     // end of variables
56
57     // constructors
58     public OpenroadmChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) {
59         this.netconfAccessor = netconfAccessor;
60         this.databaseService = databaseService;
61     }
62     // end of constructors
63
64     // public methods
65     @Override
66     public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) {
67         log.info("onNetconfConfirmedCommit ", notification);
68     }
69
70     @Override
71     public void onNetconfSessionStart(NetconfSessionStart notification) {
72         log.info("onNetconfSessionStart ", notification);
73     }
74
75     @Override
76     public void onNetconfSessionEnd(NetconfSessionEnd notification) {
77         log.info("onNetconfSessionEnd ", notification);
78     }
79
80     @Override
81     public void onNetconfCapabilityChange(NetconfCapabilityChange notification) {
82         log.info("onNetconfCapabilityChange ", notification);
83     }
84
85     @Override
86     public void onNetconfConfigChange(NetconfConfigChange notification) {
87         log.info("onNetconfConfigChange (1) {}", notification);
88         StringBuffer sb = new StringBuffer();
89         List<Edit> editList = notification.nonnullEdit();
90         for (Edit edit : editList) {
91             if (sb.length() > 0) {
92                 sb.append(", ");
93             }
94             sb.append(edit);
95
96             EventlogBuilder eventlogBuilder = new EventlogBuilder();
97
98             InstanceIdentifier<?> target = edit.getTarget();
99             if (target != null) {
100                 eventlogBuilder.setObjectId(target.toString());
101                 log.info("TARGET: {} {}", target.getClass(), target.getTargetType());
102                 for (PathArgument pa : target.getPathArguments()) {
103                     log.info("PathArgument {}", pa);
104                 }
105             }
106             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
107             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
108             databaseService.writeEventLog(eventlogBuilder.build());
109         }
110         log.info("onNetconfConfigChange (2) {}", sb);
111     }
112
113     public void onDeviceConfigChange(ChangeNotification notification) {
114         log.info("onDeviceConfigChange(1){}", notification);
115         StringBuffer sb = new StringBuffer();
116         @NonNull
117         List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit> editList =
118                 notification.nonnullEdit();
119         for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit edit : editList) {
120             if (sb.length() > 0) {
121                 sb.append(", ");
122             }
123             sb.append(edit);
124
125             EventlogBuilder eventlogBuilder = new EventlogBuilder();
126
127             InstanceIdentifier<?> target = edit.getTarget();
128             if (target != null) {
129                 eventlogBuilder.setObjectId(target.toString());
130                 log.info("TARGET: {} {}", target.getClass(), target.getTargetType());
131                 for (PathArgument pa : target.getPathArguments()) {
132                     log.info("PathArgument {}", pa);
133                 }
134             }
135             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
136             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
137             databaseService.writeEventLog(eventlogBuilder.build());
138
139         }
140         log.info("onDeviceConfigChange (2) {}", sb);
141     }
142     // end of public methods
143
144 }