Align initial alarms and notifications parsing
[ccsdk/features.git] / sdnr / wt / devicemanager-o-ran-sc / o-ran / ru-fh / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / oran / vesmapper / ORanDOMFaultToVESFaultMapper.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.vesmapper;
23
24 import java.time.Instant;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDMDOMUtility;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.ORANFM;
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.VESFaultFieldsPOJO;
30 import org.opendaylight.mdsal.dom.api.DOMNotification;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
32 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 //@formatter:off
37 /*
38 * Maps ORAN Fault fields to VES fault domain fields and VES commonEventHeader fields
39 *
40 *
41 *      VES Fields                  Mapping
42 *      ----------                  -------
43 *      domain                      "fault"
44 *      eventId                     "nt:network-topology/nt:topology/nt:node/nt:node-id"
45 *      eventName                   "nt:network-topology/nt:topology/nt:node/nt:node-id"
46 *      eventType                   "O-RAN-RU-Fault"
47 *      lastEpochMicrosec           TimeStamp represented by <eventTime> field in NetConf notification header in unix time format - as microseconds elapsed since 1 Jan 1970 not including leap seconds.
48 *      nfcNamingCode               always ""
49 *      nfNamingCode                always ""
50 *      nfVendorName                /ietf-hardware:hardware/component[not(parent)][1]/mfg-name
51 *      priority                    "Normal"
52 *      reportingEntityId           The OAM-Controller identifier with in the SMO - e.g. the fully qualified domain name or IP-Address.
53 *      reportingEntityName         as configured by helm charts for the OpenDaylight cluster name ??????
54 *      sequence                    As per NetConf notification increasing sequence number as unsigned integer 32 bits. The value is reused in the eventId field.
55 *      sourceId                    Value of ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/uuid or 'nt:network-topology/nt:topology/nt:node/nt:node-id' if ietf component not found.
56 *      sourceName                  "nt:network-topology/nt:topology/nt:node/nt:node-id"
57 *      startEpochMicrosec          Current OAM-Controller Node timestamp in unix time format - as microseconds elapsed since 1 Jan 1970 not including leap seconds.
58 *      timeZoneOffset              Static text: "+00:00"
59 *      version                     "4.1"
60 *      vesEventListenerVersion     "7.2.1"
61 *
62 *
63 *      alarmAdditionalInformation
64 *      alarmCondition              Value of "o-ran-fm:alarm-notif/fault-id"
65 *      alarmInterfaceA             Value of "o-ran-fm:alarm-notif/fault-source"
66 *      eventCategory               Static text "O-RU failure"
67 *      eventSeverity               Value of "o-ran-fm:alarm-notif/fault-severity". But if "o-ran-fm:alarm-notif/is-cleared" then "NORMAL"
68 *      eventSourceType             The value of ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/model-name or "O-RU" if not found.
69 *      faultFieldsVersion          "4.0"
70 *      specificProblem             A mapping of the fault-id to its description according to O-RAN OpenFronthaul specification.
71 *      vfStatus                    "Active"
72 *
73 */
74 //@formatter:on
75
76 public class ORanDOMFaultToVESFaultMapper {
77     @SuppressWarnings("unused")
78     private static final Logger LOG = LoggerFactory.getLogger(ORanDOMFaultToVESFaultMapper.class);
79     private static final String VES_EVENT_DOMAIN = "fault";
80     private static final String VES_EVENTTYPE = "ORAN_Fault";
81     private static final String VES_EVENT_PRIORITY = "Normal";
82     private static final String VES_EVENT_CATEGORY = "O-RU Failure";
83     private static final String VES_FAULT_FIELDS_VERSION = "4.0";
84     private static final String VES_FAULT_FIELDS_VFSTATUS = "Active"; //virtual function status
85
86     private final VESCollectorService vesProvider;
87     private final String notifName; // Name
88     private final ORANFM oranfm;
89     private final String nodeIdString; // Sourcename
90     //Initialized during registration
91     private String mfgName;
92     private String uuid;
93     private String modelName;
94
95     public ORanDOMFaultToVESFaultMapper(NodeId nodeId, VESCollectorService vesCollectorService, ORANFM oranfm,
96             String notifName) {
97         this.nodeIdString = nodeId.getValue();
98         this.vesProvider = vesCollectorService;
99         this.oranfm = oranfm;
100         this.notifName = notifName;
101     }
102
103     public void setMfgName(String mfgName) {
104         this.mfgName = mfgName;
105     }
106
107     public void setUuid(String uuid) {
108         this.uuid = uuid;
109     }
110
111     public void setModelName(String modelName) {
112         this.modelName = modelName;
113     }
114
115     public VESCommonEventHeaderPOJO mapCommonEventHeader(DOMNotification notification, Instant eventTime) {
116         VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
117         ContainerNode cn = notification.getBody();
118         vesCEH.setDomain(VES_EVENT_DOMAIN);
119         vesCEH.setEventName(notifName);
120         vesCEH.setEventType(VES_EVENTTYPE);
121         vesCEH.setPriority(VES_EVENT_PRIORITY);
122
123         String eventId =
124                 notifName + "-" + Integer.parseInt(ORanDMDOMUtility.getLeafValue(cn, oranfm.getFaultIdQName()));
125
126         vesCEH.setEventId(eventId);
127         vesCEH.setStartEpochMicrosec(eventTime.toEpochMilli() * 1000);
128         vesCEH.setLastEpochMicrosec(eventTime.toEpochMilli() * 1000);
129         vesCEH.setNfVendorName(mfgName);
130         vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
131         vesCEH.setSequence(Integer.parseInt(ORanDMDOMUtility.getLeafValue(cn, oranfm.getFaultIdQName())));
132         vesCEH.setSourceId(uuid);
133         vesCEH.setSourceName(nodeIdString);
134
135         return vesCEH;
136     }
137
138     public VESFaultFieldsPOJO mapFaultFields(DOMNotification alarmNotif) {
139         VESFaultFieldsPOJO vesFaultFields = new VESFaultFieldsPOJO();
140         ContainerNode cn = alarmNotif.getBody();
141         vesFaultFields.setAlarmCondition(ORanDMDOMUtility.getLeafValue(cn, oranfm.getFaultIdQName()));
142         vesFaultFields.setAlarmInterfaceA(ORanDMDOMUtility.getLeafValue(cn, oranfm.getFaultSourceQName()));
143         vesFaultFields.setEventCategory(VES_EVENT_CATEGORY);
144         if (ORanDMDOMUtility.getLeafValue(cn, oranfm.getFaultIsClearedQName()).equals("true")) {
145             vesFaultFields.setEventSeverity("NORMAL");
146         } else {
147             vesFaultFields.setEventSeverity(ORanDMDOMUtility.getLeafValue(cn, oranfm.getFaultSeverityQName()));
148         }
149         vesFaultFields.setEventSourceType(modelName);
150         vesFaultFields.setFaultFieldsVersion(VES_FAULT_FIELDS_VERSION);
151         vesFaultFields.setSpecificProblem(ORanDMDOMUtility.getLeafValue(cn, oranfm.getFaultTextQName()));
152         vesFaultFields.setVfStatus(VES_FAULT_FIELDS_VFSTATUS);
153
154         return vesFaultFields;
155     }
156
157 }