Add bounds to sphinx requirement
[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 / impl / binding / ORanFaultToVESFaultMapper.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.impl.binding;
23
24 import java.time.Instant;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO;
28 import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.AlarmNotif;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 //@formatter:off
34 /*
35  * Maps ORAN Fault fields to VES fault domain fields and VES commonEventHeader fields
36  *
37  *
38  *      VES Fields                  Mapping
39  *      ----------                  -------
40  *      domain                      "fault"
41  *      eventId                     "nt:network-topology/nt:topology/nt:node/nt:node-id"
42  *      eventName                   "nt:network-topology/nt:topology/nt:node/nt:node-id"
43  *      eventType                   "O-RAN-RU-Fault"
44  *      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.
45  *      nfcNamingCode               always ""
46  *      nfNamingCode                always ""
47  *      nfVendorName                /ietf-hardware:hardware/component[not(parent)][1]/mfg-name
48  *      priority                    "Normal"
49  *      reportingEntityId           The OAM-Controller identifier with in the SMO - e.g. the fully qualified domain name or IP-Address.
50  *      reportingEntityName         as configured by helm charts for the OpenDaylight cluster name ??????
51  *      sequence                    As per NetConf notification increasing sequence number as unsigned integer 32 bits. The value is reused in the eventId field.
52  *      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.
53  *      sourceName                  "nt:network-topology/nt:topology/nt:node/nt:node-id"
54  *      startEpochMicrosec          Current OAM-Controller Node timestamp in unix time format - as microseconds elapsed since 1 Jan 1970 not including leap seconds.
55  *      timeZoneOffset              Static text: "+00:00"
56  *      version                     "4.1"
57  *      vesEventListenerVersion     "7.2.1"
58  *
59  *
60  *      alarmAdditionalInformation
61  *      alarmCondition              Value of "o-ran-fm:alarm-notif/fault-id"
62  *      alarmInterfaceA             Value of "o-ran-fm:alarm-notif/fault-source"
63  *      eventCategory               Static text "O-RU failure"
64  *      eventSeverity               Value of "o-ran-fm:alarm-notif/fault-severity". But if "o-ran-fm:alarm-notif/is-cleared" then "NORMAL"
65  *      eventSourceType             The value of ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/model-name or "O-RU" if not found.
66  *      faultFieldsVersion          "4.0"
67  *      specificProblem             A mapping of the fault-id to its description according to O-RAN OpenFronthaul specification.
68  *      vfStatus                    "Active"
69  *
70  */
71 //@formatter:on
72
73 public class ORanFaultToVESFaultMapper {
74
75     @SuppressWarnings("unused")
76     private static final Logger LOG = LoggerFactory.getLogger(ORanFaultToVESFaultMapper.class);
77     private static final String VES_EVENT_DOMAIN = "fault";
78     private static final String VES_EVENTTYPE = "ORAN_Fault";
79     private static final String VES_EVENT_PRIORITY = "Normal";
80     private static final String VES_EVENT_CATEGORY = "O-RU Failure";
81     private static final String VES_FAULT_FIELDS_VERSION = "4.0";
82     private static final String VES_FAULT_FIELDS_VFSTATUS = "Active"; //virtual function status
83
84     private final VESCollectorService vesProvider;
85     private final String notifName;    // Name
86     private final String nodeIdString; // Sourcename
87     private String mfgName;
88     private String uuid;
89     private String modelName;
90
91     public ORanFaultToVESFaultMapper(NodeId nodeId, VESCollectorService vesCollectorService,
92             String notifName) {
93         this.nodeIdString = nodeId.getValue();
94         this.vesProvider = vesCollectorService;
95         this.notifName = notifName;
96     }
97
98     public void setMfgName(String mfgName) {
99         this.mfgName= mfgName;
100     }
101
102     private String getMfgName() {
103         return mfgName;
104     }
105
106     public void setUuid(String uuid) {
107         this.uuid = uuid;
108     }
109
110     private String getUuid() {
111         return uuid;
112     }
113
114     public void setModelName(String modelName) {
115         this.modelName = modelName;
116     }
117
118     private String getModelName() {
119         return modelName;
120     }
121
122     public VESCommonEventHeaderPOJO mapCommonEventHeader(AlarmNotif notification, Instant eventTime, int sequenceNo) {
123         VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
124         vesCEH.setDomain(VES_EVENT_DOMAIN);
125         vesCEH.setEventName(notifName);
126         vesCEH.setEventType(VES_EVENTTYPE);
127         vesCEH.setPriority(VES_EVENT_PRIORITY);
128
129         String eventId;
130
131         eventId = notifName + "-" + Long.toUnsignedString(sequenceNo);
132
133         vesCEH.setEventId(eventId);
134         vesCEH.setStartEpochMicrosec(eventTime.toEpochMilli() * 1000);
135         vesCEH.setLastEpochMicrosec(eventTime.toEpochMilli() * 1000);
136         vesCEH.setNfVendorName(getMfgName());
137         vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
138         vesCEH.setSequence(sequenceNo);
139         vesCEH.setSourceId(getUuid());
140         vesCEH.setSourceName(nodeIdString);
141
142         return vesCEH;
143     }
144
145     public VESFaultFieldsPOJO mapFaultFields(AlarmNotif alarmNotif) {
146         VESFaultFieldsPOJO vesFaultFields = new VESFaultFieldsPOJO();
147
148         vesFaultFields.setAlarmCondition(alarmNotif.getFaultId().toString());
149         vesFaultFields.setAlarmInterfaceA(alarmNotif.getFaultSource());
150         vesFaultFields.setEventCategory(VES_EVENT_CATEGORY);
151         if (alarmNotif.getIsCleared()) {
152             vesFaultFields.setEventSeverity("NORMAL");
153         } else {
154             vesFaultFields.setEventSeverity(alarmNotif.getFaultSeverity().getName());
155         }
156         vesFaultFields.setEventSourceType(getModelName());
157         vesFaultFields.setFaultFieldsVersion(VES_FAULT_FIELDS_VERSION);
158         vesFaultFields.setSpecificProblem(alarmNotif.getFaultText());
159         vesFaultFields.setVfStatus(VES_FAULT_FIELDS_VFSTATUS);
160
161         return vesFaultFields;
162     }
163
164 }