2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.notification;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import java.time.Instant;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
34 import org.opendaylight.mdsal.dom.api.DOMEvent;
35 import org.opendaylight.mdsal.dom.api.DOMNotification;
36 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
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.data.api.YangInstanceIdentifier.NodeIdentifier;
42 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
43 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
44 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
48 public class ORanDOMChangeNotificationListener implements DOMNotificationListener {
50 private static final Logger log = LoggerFactory.getLogger(ORanDOMChangeNotificationListener.class);
52 private final NetconfDomAccessor netconfDomAccessor;
53 private final DataProvider databaseService;
54 private @NonNull VESCollectorService vesCollectorService;
55 private final ORanDOMNotificationToXPath domNotificationXPath;
56 private ORanDOMNotifToVESEventAssembly mapper = null;
57 private static int sequenceNo = 0;
59 public ORanDOMChangeNotificationListener(NetconfDomAccessor netconfDomAccessor,
60 @NonNull VESCollectorService vesCollectorService, DataProvider databaseService) {
61 this.netconfDomAccessor = netconfDomAccessor;
62 this.databaseService = databaseService;
63 this.vesCollectorService = vesCollectorService;
64 domNotificationXPath = new ORanDOMNotificationToXPath();
68 public void onNotification(@NonNull DOMNotification domNotification) {
69 if (domNotification.getType()
70 .equals(Absolute.of(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE))) {
71 handleNetconfConfigChange(domNotification);
75 private void handleNetconfConfigChange(@NonNull DOMNotification domNotification) {
76 DateAndTime eventTime;
77 Instant notificationEventTime = null;
78 if (domNotification instanceof DOMEvent) {
79 notificationEventTime = ((DOMEvent) domNotification).getEventInstant();
80 eventTime = NetconfTimeStampImpl.getConverter().getTimeStamp(notificationEventTime.toString());
82 eventTime = NetconfTimeStampImpl.getConverter().getTimeStamp();
85 ContainerNode cn = domNotification.getBody();
87 // Process the changed-by child
88 // ContainerNode changedByContainerNode = (ContainerNode) cn
89 // .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_CHANGEDBY));
90 // ChoiceNode serverOrUserIDVal = (ChoiceNode) changedByContainerNode
91 // .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SERVERORUSER));
92 // @SuppressWarnings("unused")
93 // String userIDValue = serverOrUserIDVal
94 // .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_USERNAME)).body()
96 // @SuppressWarnings("unused")
97 // Integer sessionIDVal = Integer.valueOf(serverOrUserIDVal
98 // .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SESSIONID)).body()
101 // // Process the datastore child
102 // @SuppressWarnings("unused")
103 // String datastoreValue = cn
104 // .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_DATASTORE)).body()
107 // Process the edit child
108 UnkeyedListNode editList = (UnkeyedListNode) cn
109 .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_EDITNODE));
110 if (editList != null) {
111 for (int listCnt = 0; listCnt < editList.size(); listCnt++) {
112 String operationValue = editList.childAt(listCnt)
113 .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_OPERATION))
115 String targetValue = editList.childAt(listCnt)
116 .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_TARGET))
119 EventlogEntity eventLogEntity1 = new EventlogBuilder()
120 .setNodeId(netconfDomAccessor.getNodeId().getValue()).setCounter(sequenceNo++)
121 .setTimestamp(eventTime).setObjectId(targetValue).setAttributeName("N.A")
122 .setSourceType(SourceType.Netconf).setNewValue(String.valueOf(operationValue)).build();
123 databaseService.writeEventLog(eventLogEntity1);
127 if (vesCollectorService.getConfig().isVESCollectorEnabled()) {
128 if (mapper == null) {
129 this.mapper = new ORanDOMNotifToVESEventAssembly(netconfDomAccessor, vesCollectorService);
131 VESCommonEventHeaderPOJO header =
132 mapper.createVESCommonEventHeader(domNotificationXPath.getTime(domNotification),
133 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE.getLocalName(),
135 VESNotificationFieldsPOJO body =
136 mapper.createVESNotificationFields(domNotificationXPath.convertDomNotifToXPath(domNotification),
137 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE.getLocalName());
138 log.debug("domNotification in XPath format = {}",
139 domNotificationXPath.convertDomNotifToXPath(domNotification));
141 vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body));
142 } catch (JsonProcessingException e) {
143 log.warn("Exception while generating JSON object ", e);