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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
20 import com.fasterxml.jackson.core.JsonProcessingException;
21 import java.util.List;
22 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
23 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * Listener for change notifications
49 public class ORanChangeNotificationListener implements IetfNetconfNotificationsListener {
51 private static final Logger log = LoggerFactory.getLogger(ORanChangeNotificationListener.class);
53 private final NetconfBindingAccessor netconfAccessor;
54 private final DataProvider databaseService;
55 private final NotificationService notificationService;
56 private final VESCollectorService vesCollectorService;
57 private final NotificationProxyParser notificationProxyParser;
58 private ORanNotifToVESEventAssembly mapper = null;
60 private static int sequenceNo = 0;
62 public ORanChangeNotificationListener(NetconfBindingAccessor netconfAccessor,
63 DeviceManagerServiceProvider serviceProvider) {
64 this.netconfAccessor = netconfAccessor;
65 this.databaseService = serviceProvider.getDataProvider();
66 this.notificationService = serviceProvider.getNotificationService();
67 this.vesCollectorService = serviceProvider.getVESCollectorService();
68 this.notificationProxyParser = vesCollectorService.getNotificationProxyParser();
72 public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) {
73 log.info("onNetconfConfirmedCommit {}", notification);
77 public void onNetconfSessionStart(NetconfSessionStart notification) {
78 log.info("onNetconfSessionStart {}", notification);
82 public void onNetconfSessionEnd(NetconfSessionEnd notification) {
83 log.info("onNetconfSessionEnd {}", notification);
87 public void onNetconfCapabilityChange(NetconfCapabilityChange notification) {
88 log.info("onNetconfCapabilityChange {}", notification);
92 public void onNetconfConfigChange(NetconfConfigChange notification) {
93 log.info("onNetconfConfigChange (1) {}", notification.toString());
95 StringBuffer sb = new StringBuffer();
96 List<Edit> editList = notification.nonnullEdit();
97 for (Edit edit : editList) {
98 if (sb.length() > 0) {
103 InstanceIdentifier<?> target = edit.getTarget();
104 if (target != null) {
105 log.info("TARGET: {} {}", target.getClass(), target.getTargetType());
106 for (PathArgument pa : target.getPathArguments()) {
107 log.info("PathArgument {} Type {}", pa, pa.getType().getFields());
110 EventlogEntity eventLogEntity1 = new EventlogBuilder().setNodeId(netconfAccessor.getNodeId().getValue())
111 .setCounter(sequenceNo++).setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp())
112 .setObjectId(target.getTargetType().getCanonicalName()).setAttributeName("N.A")
113 .setSourceType(SourceType.Netconf).setNewValue(String.valueOf(edit.getOperation())).build();
114 databaseService.writeEventLog(eventLogEntity1);
117 log.info("onNetconfConfigChange (2) {}", sb);
119 if (vesCollectorService.getConfig().isVESCollectorEnabled()) {
120 if (mapper == null) {
121 this.mapper = new ORanNotifToVESEventAssembly(netconfAccessor, vesCollectorService);
123 VESCommonEventHeaderPOJO header =
124 mapper.createVESCommonEventHeader(notificationProxyParser.getTime(notification),
125 NetconfConfigChange.class.getSimpleName(), sequenceNo);
126 VESNotificationFieldsPOJO body =
127 mapper.createVESNotificationFields(notificationProxyParser.parseNotificationProxy(notification),
128 NetconfConfigChange.class.getSimpleName());
130 vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body));
131 } catch (JsonProcessingException e) {
132 log.warn("Exception while generating JSON object ", e);