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 java.time.format.DateTimeParseException;
27 import java.util.Collection;
28 import java.util.Objects;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.json.JSONException;
31 import org.json.JSONObject;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.dataprovider.ORanDOMToInternalDataModel;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDMDOMUtility;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.vesmapper.ORanDOMFaultToVESFaultMapper;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.ORANFM;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage;
43 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
44 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
45 import org.opendaylight.mdsal.dom.api.DOMNotification;
46 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
49 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
53 public class ORanDOMFaultNotificationListener implements DOMNotificationListener {
55 private static final Logger LOG = LoggerFactory.getLogger(ORanDOMFaultNotificationListener.class);
57 private final @NonNull NetconfDomAccessor netconfDomAccessor;
58 private final @NonNull VESCollectorService vesCollectorService;
59 private final @NonNull ORanDOMFaultToVESFaultMapper mapper;
60 private final @NonNull FaultService faultService;
61 private final @NonNull WebsocketManagerService websocketManagerService;
62 private final @NonNull DataProvider databaseService;
63 private final @NonNull ORANFM oranfm;
65 private Integer counter; //Local counter is assigned to Events in EventLog
67 public ORanDOMFaultNotificationListener(@NonNull NetconfDomAccessor netconfDomAccessor, ORANFM oranfm,
68 @NonNull VESCollectorService vesCollectorService, @NonNull FaultService faultService,
69 @NonNull WebsocketManagerService websocketManagerService, @NonNull DataProvider databaseService) {
70 this.netconfDomAccessor = Objects.requireNonNull(netconfDomAccessor);
71 this.vesCollectorService = Objects.requireNonNull(vesCollectorService);
72 this.faultService = Objects.requireNonNull(faultService);
73 this.websocketManagerService = Objects.requireNonNull(websocketManagerService);
74 this.databaseService = Objects.requireNonNull(databaseService);
76 this.mapper = new ORanDOMFaultToVESFaultMapper(netconfDomAccessor.getNodeId(), this.vesCollectorService,
77 this.oranfm, "AlarmNotif");
82 public void onNotification(@NonNull DOMNotification notification) {
83 onAlarmNotif(notification);
87 * Gets the mfg name, mode-name and Uuid of the root component (Ex: Chassis.) In cases where there are multiple root
88 * components i.e., components with no parent, the Uuid of the last occurred component from the componentList will
89 * be considered. Till now we haven't seen Uuid set for root components, so not an issue for now.
91 * @param componentList
93 public void setComponentList(Collection<MapEntryNode> componentList) {
94 for (MapEntryNode component : ORanDOMToInternalDataModel.getRootComponents(componentList)) {
96 ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME));
97 mapper.setUuid(ORanDMDOMUtility.getLeafValue(component,
98 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID) != null
99 ? ORanDMDOMUtility.getLeafValue(component,
100 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID)
101 : netconfDomAccessor.getNodeId().getValue());
102 mapper.setModelName(ORanDMDOMUtility.getLeafValue(component,
103 ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MODEL_NAME));
107 public void onAlarmNotif(DOMNotification notification) {
109 LOG.debug("onAlarmNotif {}", notification.getClass().getSimpleName());
111 // Send devicemanager specific notification for database and ODLUX
112 Instant eventTimeInstant = ORanDMDOMUtility.getNotificationInstant(notification);
113 faultService.faultNotification(
114 ORanDOMToInternalDataModel.getFaultLog(notification, oranfm, netconfDomAccessor.getNodeId()));
115 // Send model specific notification to WebSocketManager
116 websocketManagerService.sendNotification(notification, netconfDomAccessor.getNodeId(),
117 oranfm.getAlarmNotifQName());
120 if (vesCollectorService.getConfig().isVESCollectorEnabled()) {
121 VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(notification, eventTimeInstant);
122 VESFaultFieldsPOJO body = mapper.mapFaultFields(notification);
123 VESMessage vesMsg = vesCollectorService.generateVESEvent(header, body);
124 vesCollectorService.publishVESMessage(vesMsg);
125 LOG.debug("VES Message is {}", vesMsg.getMessage());
126 writeToEventLog(vesMsg.getMessage(), eventTimeInstant, oranfm.getAlarmNotifQName().getLocalName(),
129 } catch (JsonProcessingException | DateTimeParseException e) {
130 LOG.debug("Can not convert event into VES message {}", notification, e);
134 private void writeToEventLog(String data, Instant eventTimeInstant, String notificationName, int sequenceNo) {
135 EventlogBuilder eventlogBuilder = new EventlogBuilder();
137 eventlogBuilder.setObjectId("Device");
138 eventlogBuilder.setCounter(sequenceNo);
139 eventlogBuilder.setAttributeName(notificationName);
140 eventlogBuilder.setNodeId(netconfDomAccessor.getNodeId().getValue());
141 String eventLogMsgLvl = vesCollectorService.getConfig().getEventLogMsgDetail();
142 if (eventLogMsgLvl.equalsIgnoreCase("SHORT")) {
143 data = getShortEventLogMessage(data);
144 } else if (eventLogMsgLvl.equalsIgnoreCase("MEDIUM")) {
145 data = getMediumEventLogMessage(data);
146 } else if (eventLogMsgLvl.equalsIgnoreCase("LONG")) {
147 // do nothing, data already contains long message
148 } else { // Unknown value, default to "SHORT"
149 data = getShortEventLogMessage(data);
151 eventlogBuilder.setNewValue(data);
152 eventlogBuilder.setSourceType(SourceType.Netconf);
153 eventlogBuilder.setTimestamp(ORanDMDOMUtility.getDateAndTimeOfInstant(eventTimeInstant));
155 databaseService.writeEventLog(eventlogBuilder.build());
158 private String getShortEventLogMessage(String data) {
160 JSONObject jsonObj = new JSONObject(data);
161 String domain = jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").getString("domain");
162 String eventId = jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").getString("eventId");
163 return "domain:" + domain + " eventId:" + eventId;
164 } catch (JSONException e) {
166 return "Invalid message received";
170 private String getMediumEventLogMessage(String data) {
172 JSONObject jsonObj = new JSONObject(data);
173 return jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").toString();
174 } catch (JSONException e) {
176 return "Invalid message received";