Add x-ran devicemanager
[oam.git] / features / devicemanager / x-ran / ru-fh / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / xran / impl / XRanChangeNotificationListener.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.xran.impl;
19
20 import java.util.List;
21 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
22 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37  * Listener for change notifications
38  */
39 public class XRanChangeNotificationListener  implements IetfNetconfNotificationsListener {
40
41     private static final Logger log = LoggerFactory.getLogger(XRanChangeNotificationListener.class);
42
43     private final NetconfAccessor netconfAccessor;
44     private final DataProvider databaseService;
45
46     public XRanChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) {
47         this.netconfAccessor = netconfAccessor;
48         this.databaseService = databaseService;
49     }
50
51     @Override
52     public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) {
53         log.info("onNetconfConfirmedCommit ", notification);
54     }
55
56     @Override
57     public void onNetconfSessionStart(NetconfSessionStart notification) {
58         log.info("onNetconfSessionStart ", notification);
59     }
60
61     @Override
62     public void onNetconfSessionEnd(NetconfSessionEnd notification) {
63         log.info("onNetconfSessionEnd ", notification);
64     }
65
66     @Override
67     public void onNetconfCapabilityChange(NetconfCapabilityChange notification) {
68         log.info("onNetconfCapabilityChange ", notification);
69     }
70
71     @Override
72     public void onNetconfConfigChange(NetconfConfigChange notification) {
73         log.info("onNetconfConfigChange (1) {}", notification);
74         StringBuffer sb = new StringBuffer();
75         List<Edit> editList = notification.nonnullEdit();
76         for (Edit edit : editList) {
77             if (sb.length() > 0) {
78                 sb.append(", ");
79             }
80             sb.append(edit);
81
82             EventlogBuilder eventlogBuilder = new EventlogBuilder();
83
84             InstanceIdentifier<?> target = edit.getTarget();
85             if (target != null) {
86                 eventlogBuilder.setObjectId(target.toString());
87                 log.info("TARGET: {} {} {}", target.getClass(), target.getTargetType());
88                 for (PathArgument pa : target.getPathArguments()) {
89                     log.info("PathArgument {}", pa);
90                 }
91             }
92             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
93             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
94             databaseService.writeEventLog(eventlogBuilder.build());
95         }
96         log.info("onNetconfConfigChange (2) {}", sb);
97     }
98
99 }