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 / ORanDOMSupervisionNotifToVESMapper.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2023 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 com.fasterxml.jackson.annotation.JsonProperty;
25 import java.time.Instant;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDMDOMUtility;
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.VESStndDefinedFieldsPOJO;
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
33 /*
34  * {
35     "event": {
36         "stndDefinedFields": {
37             "schemaReference": "https://gerrit.o-ran-sc.org/r/gitweb?p=scp/oam/modeling.git;a=blob_plain;f=data-model/yang/published/o-ran/ru-fh/o-ran-supervision.yang#components/schemas/ofhm-event-stream",
38             "stndDefinedFieldsVersion": "1.0",
39             "data": {
40                 "ietf:notification": {
41                     "eventTime": "2023-06-28T07:28:55.098Z",
42                     "o-ran-supervision:supervision-notification": {
43                         "session-id": 999999
44                     }
45                 }
46             }
47         },
48         "commonEventHeader": {
49             "domain": "stndDefined",
50             "eventType": "o-ran-supervision:supervision-notification",
51             "eventId": "pnf2_o-ran-supervision:supervision-notification_fed2ab31f6e1da56",
52             "eventName": "stndDefined_o-ran-supervision:supervision-notification",
53             "sequence": 1687937335098,
54             "priority": "Low",
55             "reportingEntityId": "c2b7d6e9-ee35-459a-ab8e-717a6fc1fde6",
56             "reportingEntityName": "flows",
57             "sourceId": "378e9904-6d39-40ea-9994-0596fe2235a3",
58             "sourceName": "O-RAN-SC-OAM-Test-Component-01",
59             "startEpochMicrosec": 1687937335098000,
60             "lastEpochMicrosec": 1687937335098000,
61             "nfNamingCode": "pnf2",
62             "nfVendorName": "O-RAN-SC-OAM-Project",
63             "timeZoneOffset": "+00:00",
64             "stndDefinedNamespace": "o-ran-supervision:supervision-notification",
65             "version": "4.1",
66             "vesEventListenerVersion": "7.2.1"
67         }
68     }
69 }
70  */
71 public class ORanDOMSupervisionNotifToVESMapper {
72
73     private static final String VES_EVENT_DOMAIN = "stndDefined";
74     private static final String VES_EVENTTYPE = "o-ran-supervision:supervision-notification";
75     private static final String VES_EVENT_PRIORITY = "Low";
76     private static final String O_RU_SUPERVISION_SCHEMA_REFERENCE =
77             "https://gerrit.o-ran-sc.org/r/gitweb?p=scp/oam/modeling.git;a=blob_plain;f=data-model/yang/published/o-ran/ru-fh/o-ran-supervision.yang#components/schemas/ofhm-event-stream";
78     private final VESCollectorService vesProvider;
79     private final String notifName;
80     private final String nodeIdString;
81     //Initialized during registration
82     private String mfgName;
83     private String uuid;
84     private String modelName;
85
86     public ORanDOMSupervisionNotifToVESMapper(NodeId nodeId, VESCollectorService vesCollectorService,
87             String notifName) {
88         this.nodeIdString = nodeId.getValue();
89         this.vesProvider = vesCollectorService;
90         this.notifName = notifName;
91     }
92
93     public void setMfgName(String mfgName) {
94         this.mfgName = mfgName;
95     }
96
97     public void setUuid(String uuid) {
98         this.uuid = uuid;
99     }
100
101     public void setModelName(String modelName) {
102         this.modelName = modelName;
103     }
104
105     public VESCommonEventHeaderPOJO mapCommonEventHeader(DOMNotification notification, Instant eventTime,
106             int sequenceNo) {
107         VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
108         vesCEH.setDomain(VES_EVENT_DOMAIN);
109         vesCEH.setEventName(VES_EVENT_DOMAIN + "_" + VES_EVENTTYPE);
110         vesCEH.setEventType(VES_EVENTTYPE);
111         vesCEH.setPriority(VES_EVENT_PRIORITY);
112
113         String eventId = notifName + "-" + Long.toUnsignedString(sequenceNo);
114
115         vesCEH.setEventId(eventId);
116         vesCEH.setStartEpochMicrosec(eventTime.toEpochMilli() * 1000);
117         vesCEH.setLastEpochMicrosec(eventTime.toEpochMilli() * 1000);
118         vesCEH.setNfVendorName(mfgName);
119         vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
120         vesCEH.setSequence(sequenceNo);
121         vesCEH.setSourceId(uuid);
122         vesCEH.setSourceName(nodeIdString);
123
124         return vesCEH;
125     }
126
127     public VESStndDefinedFieldsPOJO mapStndDefinedFields(Instant eventTimeInstant) {
128         VESStndDefinedFieldsPOJO vesStndDefFields = new VESStndDefinedFieldsPOJO();
129         vesStndDefFields.setSchemaReference(O_RU_SUPERVISION_SCHEMA_REFERENCE);
130         vesStndDefFields.setData(getSupervisionData(eventTimeInstant));
131
132         return vesStndDefFields;
133     }
134
135     private DataObject getSupervisionData(Instant eventTimeInstant) {
136         ORanSupervisionNotification oruSuperNotif = new ORanSupervisionNotification();
137         oruSuperNotif.setSessionId(999999); // Hardcoded due to limitation in NTS Simulator. Ideally should be NETCONF Session ID
138
139         IetfNotification ietfNotif = new IetfNotification();
140         ietfNotif.setOranSupervisionNotif(oruSuperNotif);
141         ietfNotif.setEventTime(ORanDMDOMUtility.getDateAndTimeOfInstant(eventTimeInstant).getValue());
142
143         DataObject data = new DataObject();
144         data.setIetfNotification(ietfNotif);
145         return data;
146     }
147
148 }
149
150 /* Classes for serialization of stndDefinedFields "data" object */
151 class DataObject {
152     @JsonProperty("ietf:notification")
153     IetfNotification ietfNotification;
154
155     public DataObject() {}
156
157     public IetfNotification getIetfNotification() {
158         return ietfNotification;
159     }
160
161     public void setIetfNotification(IetfNotification ietfNotification) {
162         this.ietfNotification = ietfNotification;
163     }
164 }
165
166
167 class IetfNotification {
168     String eventTime;
169     @JsonProperty("o-ran-supervision:supervision-notification")
170     ORanSupervisionNotification oranSupervisionNotif;
171
172     public IetfNotification() {}
173
174     public String getEventTime() {
175         return eventTime;
176     }
177
178     public void setEventTime(String eventTime) {
179         this.eventTime = eventTime;
180     }
181
182     public ORanSupervisionNotification getOranSupervisionNotif() {
183         return oranSupervisionNotif;
184     }
185
186     public void setOranSupervisionNotif(ORanSupervisionNotification oranSupervisionNotif) {
187         this.oranSupervisionNotif = oranSupervisionNotif;
188     }
189
190 }
191
192
193 class ORanSupervisionNotification {
194     @JsonProperty("session-id")
195     int sessionId;
196
197     public ORanSupervisionNotification() {}
198
199     public int getSessionId() {
200         return sessionId;
201     }
202
203     public void setSessionId(int sessionId) {
204         this.sessionId = sessionId;
205     }
206 }