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;
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.devicemanager.service.NotificationProxyParser;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * Listener for change notifications
44 public class ORanChangeNotificationListener implements IetfNetconfNotificationsListener {
46 private static final Logger log = LoggerFactory.getLogger(ORanChangeNotificationListener.class);
48 private final NetconfBindingAccessor netconfAccessor;
49 private final DataProvider databaseService;
50 private final VESCollectorService vesCollectorService;
51 private final NotificationProxyParser notificationProxyParser;
52 private ORanNotifToVESEventAssembly mapper = null;
54 private static int sequenceNo = 0;
56 public ORanChangeNotificationListener(NetconfBindingAccessor netconfAccessor, DataProvider databaseService,
57 VESCollectorService vesCollectorService, NotificationProxyParser notificationProxyParser) {
58 this.netconfAccessor = netconfAccessor;
59 this.databaseService = databaseService;
60 this.vesCollectorService = vesCollectorService;
61 this.notificationProxyParser = notificationProxyParser;
65 public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) {
66 log.info("onNetconfConfirmedCommit {}", notification);
70 public void onNetconfSessionStart(NetconfSessionStart notification) {
71 log.info("onNetconfSessionStart {}", notification);
75 public void onNetconfSessionEnd(NetconfSessionEnd notification) {
76 log.info("onNetconfSessionEnd {}", notification);
80 public void onNetconfCapabilityChange(NetconfCapabilityChange notification) {
81 log.info("onNetconfCapabilityChange {}", notification);
85 public void onNetconfConfigChange(NetconfConfigChange notification) {
86 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) {
96 EventlogBuilder eventlogBuilder = new EventlogBuilder();
98 InstanceIdentifier<?> target = edit.getTarget();
100 eventlogBuilder.setObjectId(target.toString());
101 log.info("TARGET: {} {} {}", target.getClass(), target.getTargetType());
102 for (PathArgument pa : target.getPathArguments()) {
103 log.info("PathArgument {}", pa);
106 eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
107 eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
108 databaseService.writeEventLog(eventlogBuilder.build());
110 log.info("onNetconfConfigChange (2) {}", sb);
112 if (vesCollectorService.getConfig().isVESCollectorEnabled()) {
113 if (mapper == null) {
114 this.mapper = new ORanNotifToVESEventAssembly(netconfAccessor, vesCollectorService);
116 VESCommonEventHeaderPOJO header = mapper.createVESCommonEventHeader(notificationProxyParser.getTime(notification),
117 NetconfConfigChange.class.getSimpleName(), sequenceNo);
118 VESNotificationFieldsPOJO body =
119 mapper.createVESNotificationFields(notificationProxyParser.parseNotificationProxy(notification),
120 NetconfConfigChange.class.getSimpleName());
122 vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body));
123 } catch (JsonProcessingException e) {
124 log.warn("Exception while generating JSON object ", e);