1 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.notification;
3 import com.fasterxml.jackson.core.JsonProcessingException;
4 import java.time.Instant;
5 import java.time.format.DateTimeParseException;
6 import java.util.ArrayList;
7 import java.util.Collection;
8 import java.util.Iterator;
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
12 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.config.ORanDMConfig;
13 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.dataprovider.ORanDOMToInternalDataModel;
14 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDMDOMUtility;
15 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
16 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.vesmapper.ORanDOMSupervisionNotifToVESMapper;
17 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
18 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
19 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage;
20 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESStndDefinedFieldsPOJO;
21 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
22 import org.opendaylight.mdsal.dom.api.DOMNotification;
23 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
24 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class ORanDOMSupervisionNotificationListener implements DOMNotificationListener, ORanNotificationReceivedService {
29 private static final Logger LOG = LoggerFactory.getLogger(ORanDOMSupervisionNotificationListener.class);
31 private @NonNull NetconfDomAccessor netconfDomAccessor;
32 private @NonNull DataProvider databaseService;
33 private @NonNull VESCollectorService vesCollectorService;
34 private List<ORanNotificationObserver> notificationObserverList;
35 private Integer counter; //Local counter is assigned to Notifications
37 private @NonNull ORanDOMSupervisionNotifToVESMapper mapper;
39 public ORanDOMSupervisionNotificationListener(@NonNull NetconfDomAccessor netconfDomAccessor,
40 @NonNull VESCollectorService vesCollectorService, @NonNull DataProvider databaseService,
41 ORanDMConfig oranSupervisionConfig) {
42 this.netconfDomAccessor = netconfDomAccessor;
43 this.databaseService = databaseService;
44 this.vesCollectorService = vesCollectorService;
45 this.mapper = new ORanDOMSupervisionNotifToVESMapper(netconfDomAccessor.getNodeId(), vesCollectorService, "o-ran-supervision");
46 notificationObserverList = new ArrayList<>();
50 public void setComponentList(Collection<MapEntryNode> componentList) {
51 for (MapEntryNode component : ORanDOMToInternalDataModel.getRootComponents(componentList)) {
53 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
54 mapper.setUuid(ORanDMDOMUtility.getLeafValue(component,
55 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID) != null
56 ? ORanDMDOMUtility.getLeafValue(component,
57 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID)
58 : netconfDomAccessor.getNodeId().getValue());
59 mapper.setModelName(ORanDMDOMUtility.getLeafValue(component,
60 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MODEL_NAME));
65 public void onNotification(@NonNull DOMNotification notification) {
66 LOG.trace("Notification Type = {}", notification.getType().toString());
68 Instant eventTimeInstant = ORanDMDOMUtility.getNotificationInstant(notification);
70 if (vesCollectorService.getConfig().isVESCollectorEnabled()) {
71 VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(notification, eventTimeInstant, counter);
72 VESStndDefinedFieldsPOJO body = mapper.mapStndDefinedFields(eventTimeInstant);
73 VESMessage vesMsg = vesCollectorService.generateVESEvent(header, body);
74 vesCollectorService.publishVESMessage(vesMsg);
75 LOG.debug("VES Message is {}", vesMsg.getMessage());
77 } catch (JsonProcessingException | DateTimeParseException e) {
78 LOG.debug("Cannot convert event into VES message {}", notification, e);
82 private void notifyObservers() {
83 Iterator<ORanNotificationObserver> it = notificationObserverList.iterator();
84 while (it.hasNext()) {
85 ORanNotificationObserver o = it.next();
96 public void registerForNotificationReceivedEvent(ORanNotificationObserver o) {
97 notificationObserverList.add(o);
101 public void deregisterNotificationReceivedEvent(ORanNotificationObserver o) {
102 notificationObserverList.remove(o);