bf80d66f55d9f738673b2eb501d3238be28ebcc9
[nonrtric.git] / pmlog / src / main / java / org / oran / pmlog / PmReport.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2023 Nordix Foundation
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 package org.oran.pmlog;
22
23 import com.google.gson.annotations.Expose;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27
28 import lombok.Builder;
29 import lombok.Getter;
30 import lombok.Setter;
31
32
33 @Builder(toBuilder = true)
34 public class PmReport {
35
36     private static com.google.gson.Gson gson = new com.google.gson.GsonBuilder() //
37             .disableHtmlEscaping() //
38             .create();
39
40     public static PmReport parse(DataFromKafkaTopic data) {
41         return gson.fromJson(data.valueAsString(), PmReport.class);
42     }
43
44     public long lastTimeEpochMili() {
45         return event.commonEventHeader.lastEpochMicrosec / 1000;
46     }
47
48     @Expose
49     public Event event;
50
51     public static class CommonEventHeader {
52         @Expose
53         private String domain;
54
55         @Expose
56         private String eventId;
57
58         @Expose
59         private String eventName;
60
61         @Expose
62         @Getter
63         private String sourceName;
64
65         @Expose
66         private String reportingEntityName;
67
68         @Expose
69         private long startEpochMicrosec;
70
71         @Expose
72         @Setter
73         private long lastEpochMicrosec;
74
75         @Expose
76         private String timeZoneOffset;
77
78         /* Not reported elements */
79         int sequence;
80         String priority;
81         String version;
82         String vesEventListenerVersion;
83     }
84
85     public static class MeasInfoId {
86         @Expose
87         private String sMeasInfoId = "";
88     }
89
90     public static class MeasTypes {
91         public String getMeasType(int pValue) {
92             if (pValue > sMeasTypesList.size()) {
93                 return "MeasTypeIndexOutOfBounds:" + pValue;
94             }
95             return sMeasTypesList.get(pValue - 1);
96         }
97
98         @Expose
99         protected ArrayList<String> sMeasTypesList = new ArrayList<>();
100     }
101
102     @Getter
103     @Builder(toBuilder = true)
104     public static class MeasResult {
105         @Expose
106         @Setter
107         private int p;
108
109         @Expose
110         @Setter
111         private String sValue;
112     }
113
114     @Builder(toBuilder = true)
115     public static class MeasValuesList {
116         @Expose
117         @Getter
118         private String measObjInstId;
119
120         @Expose
121         @Getter
122         private String suspectFlag;
123
124         @Expose
125         @Getter
126         private Collection<MeasResult> measResults;
127
128         public boolean isEmpty() {
129             return this.measResults.isEmpty();
130         }
131
132         static MeasValuesList emptyList = MeasValuesList.builder().measResults(new ArrayList<>()).build();
133
134         public static MeasValuesList empty() {
135             return emptyList;
136         }
137     }
138
139     @Getter
140     @Builder(toBuilder = true)
141     public static class MeasInfoList {
142         @Expose
143         private MeasInfoId measInfoId;
144
145         @Expose
146         private MeasTypes measTypes;
147
148         @Expose
149         private Collection<MeasValuesList> measValuesList;
150
151     }
152
153     @Builder(toBuilder = true)
154     @Getter
155     public static class MeasDataCollection {
156         @Expose
157         private int granularityPeriod;
158
159         @Expose
160         private String measuredEntityUserName;
161
162         @Expose
163         private String measuredEntityDn;
164
165         @Expose
166         private String measuredEntitySoftwareVersion;
167
168         @Expose
169         private Collection<MeasInfoList> measInfoList;
170     }
171
172     @Builder(toBuilder = true)
173     @Getter
174     public static class Perf3gppFields {
175         @Expose
176         private String perf3gppFieldsVersion;
177
178         @Expose
179         private MeasDataCollection measDataCollection;
180     }
181
182     @Getter
183     @Builder(toBuilder = true)
184     public static class Event {
185         @Expose
186         private CommonEventHeader commonEventHeader;
187
188         @Expose
189         private Perf3gppFields perf3gppFields;
190     }
191
192 }