a138dfbd81afa253afbdbdbf5b183f44ab411a4e
[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.openroadm.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.netconfnodestateservice.NetconfAccessor;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40
41 /**
42  * @author Shabnam Sultana
43  *
44  *         Listener for change notifications
45  *
46  **/
47 public class OpenroadmChangeNotificationListener implements IetfNetconfNotificationsListener {
48
49     // variables
50     private static final Logger log = LoggerFactory.getLogger(OpenroadmChangeNotificationListener.class);
51     private final NetconfAccessor netconfAccessor;
52     private final DataProvider databaseService;
53     // end of variables
54
55     // constructors
56     public OpenroadmChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) {
57         this.netconfAccessor = netconfAccessor;
58         this.databaseService = databaseService;
59     }
60     // end of constructors
61
62     // public methods
63     @Override
64     public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) {
65         log.info("onNetconfConfirmedCommit {} ", notification);
66     }
67
68     @Override
69     public void onNetconfSessionStart(NetconfSessionStart notification) {
70         log.info("onNetconfSessionStart {} ", notification);
71     }
72
73     @Override
74     public void onNetconfSessionEnd(NetconfSessionEnd notification) {
75         log.info("onNetconfSessionEnd {}", notification);
76     }
77
78     @Override
79     public void onNetconfCapabilityChange(NetconfCapabilityChange notification) {
80         log.info("onNetconfCapabilityChange {}", notification);
81     }
82
83     @Override
84     public void onNetconfConfigChange(NetconfConfigChange notification) {
85         log.info("onNetconfConfigChange (1) {}", notification);
86         StringBuffer sb = new StringBuffer();
87         List<Edit> editList = notification.nonnullEdit();
88         for (Edit edit : editList) {
89             if (sb.length() > 0) {
90                 sb.append(", ");
91             }
92             sb.append(edit);
93
94             EventlogBuilder eventlogBuilder = new EventlogBuilder();
95
96             InstanceIdentifier<?> target = edit.getTarget();
97             if (target != null) {
98                 eventlogBuilder.setObjectId(target.toString());
99                 log.info("TARGET: {} {}", target.getClass(), target.getTargetType());
100                 for (PathArgument pa : target.getPathArguments()) {
101                     log.info("PathArgument {}", pa);
102                 }
103             }
104             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
105             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
106             databaseService.writeEventLog(eventlogBuilder.build());
107         }
108         log.info("onNetconfConfigChange (2) {}", sb);
109     }
110
111     // end of public methods
112
113 }