baa86b4c76edcf23ce3344e1282c7db2d8c5b733
[ccsdk/features.git] /
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.oran.impl;
19
20 import java.time.Instant;
21 import java.util.HashMap;
22 import java.util.List;
23 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 /**
40  * Listener for change notifications
41  */
42 public class ORanChangeNotificationListener implements IetfNetconfNotificationsListener {
43
44     private static final Logger log = LoggerFactory.getLogger(ORanChangeNotificationListener.class);
45
46     private final NetconfBindingAccessor netconfAccessor;
47     private final DataProvider databaseService;
48     private final VESCollectorService vesCollectorService;
49
50     private static int sequenceNo = 0;
51
52     public ORanChangeNotificationListener(NetconfBindingAccessor netconfAccessor, DataProvider databaseService, VESCollectorService vesCollectorService) {
53         this.netconfAccessor = netconfAccessor;
54         this.databaseService = databaseService;
55         this.vesCollectorService = vesCollectorService;
56     }
57
58     @Override
59     public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) {
60         log.info("onNetconfConfirmedCommit {}", notification);
61     }
62
63     @Override
64     public void onNetconfSessionStart(NetconfSessionStart notification) {
65         log.info("onNetconfSessionStart {}", notification);
66     }
67
68     @Override
69     public void onNetconfSessionEnd(NetconfSessionEnd notification) {
70         log.info("onNetconfSessionEnd {}", notification);
71     }
72
73     @Override
74     public void onNetconfCapabilityChange(NetconfCapabilityChange notification) {
75         log.info("onNetconfCapabilityChange {}", notification);
76     }
77
78     @Override
79     public void onNetconfConfigChange(NetconfConfigChange notification) {
80         log.info("onNetconfConfigChange (1) {}", notification);
81         sequenceNo++;
82         StringBuffer sb = new StringBuffer();
83         List<Edit> editList = notification.nonnullEdit();
84         for (Edit edit : editList) {
85             if (sb.length() > 0) {
86                 sb.append(", ");
87             }
88             sb.append(edit);
89
90             EventlogBuilder eventlogBuilder = new EventlogBuilder();
91
92             InstanceIdentifier<?> target = edit.getTarget();
93             if (target != null) {
94                 eventlogBuilder.setObjectId(target.toString());
95                 log.info("TARGET: {} {} {}", target.getClass(), target.getTargetType());
96                 for (PathArgument pa : target.getPathArguments()) {
97                     log.info("PathArgument {}", pa);
98                 }
99             }
100             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
101             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
102             databaseService.writeEventLog(eventlogBuilder.build());
103         }
104         log.info("onNetconfConfigChange (2) {}", sb);
105         ORanNotificationMapper mapper = new ORanNotificationMapper();
106         HashMap<String, String> xPathFieldsMap = mapper.performMapping(notification);
107         log.info("MappingInfo after mapping notification - {}", xPathFieldsMap);
108         Instant instant = mapper.getTime(notification);
109
110         ORanNotifToVESEventAssembly oranVESEventAssembly = new ORanNotifToVESEventAssembly(netconfAccessor, vesCollectorService);
111         String data = oranVESEventAssembly.performAssembly(xPathFieldsMap, instant, NetconfConfigChange.class.getSimpleName(),
112                 sequenceNo);
113         vesCollectorService.publishVESMessage(data);
114
115
116     }
117
118 }