2 * ========================LICENSE_START=================================
5 * Copyright (C) 2023 Nordix Foundation
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package org.oran.pmproducer.repository;
23 import com.fasterxml.jackson.annotation.JsonProperty;
25 import io.swagger.v3.oas.annotations.media.Schema;
27 import java.lang.invoke.MethodHandles;
29 import lombok.Builder;
30 import lombok.EqualsAndHashCode;
32 import lombok.ToString;
34 import org.oran.pmproducer.configuration.ApplicationConfig;
35 import org.oran.pmproducer.filter.FilterFactory;
36 import org.oran.pmproducer.filter.FilteredData;
37 import org.oran.pmproducer.filter.PmReportFilter;
38 import org.oran.pmproducer.tasks.TopicListener.DataFromTopic;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
44 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
48 @Schema(name = "job_statistics", description = "Statistics information for one job")
49 public static class Statistics {
51 @JsonProperty(value = "jobId", required = true)
54 @JsonProperty(value = "typeId", required = true)
57 @JsonProperty(value = "inputTopic", required = false)
60 @JsonProperty(value = "outputTopic", required = false)
63 @JsonProperty(value = "groupId", required = false)
66 @JsonProperty(value = "clientId", required = false)
69 @JsonProperty(value = "noOfReceivedObjects", required = true)
71 long noOfReceivedObjects = 0;
73 @JsonProperty(value = "noOfReceivedBytes", required = true)
75 long noOfReceivedBytes = 0;
77 @JsonProperty(value = "noOfSentObjects", required = true)
79 long noOfSentObjects = 0;
81 @JsonProperty(value = "noOfSentBytes", required = true)
83 long noOfSentBytes = 0;
85 public void received(byte[] bytes) {
86 noOfReceivedBytes += bytes.length;
87 noOfReceivedObjects += 1;
91 public void filtered(byte[] bytes) {
92 noOfSentBytes += bytes.length;
99 public static class Parameters {
102 private PmReportFilter.FilterData filter;
106 public static class KafkaDeliveryInfo {
108 private String topic;
111 private String bootStrapServers;
115 private KafkaDeliveryInfo deliveryInfo;
119 private final String id;
122 private final InfoType type;
125 private final String owner;
128 private final Parameters parameters;
131 private final String lastUpdated;
134 private final PmReportFilter filter;
137 private final Statistics statistics;
139 public Job(String id, InfoType type, String owner, String lastUpdated, Parameters parameters,
140 ApplicationConfig appConfig) {
144 this.lastUpdated = lastUpdated;
145 this.parameters = parameters;
146 filter = parameters.filter == null ? null : FilterFactory.create(parameters.getFilter());
148 statistics = Statistics.builder() //
149 .groupId(type.getKafkaGroupId()) //
150 .inputTopic(type.getKafkaInputTopic()) //
152 .outputTopic(parameters.getDeliveryInfo() == null ? "" : parameters.getDeliveryInfo().topic) //
153 .typeId(type.getId()) //
154 .clientId(type.getKafkaClientId(appConfig)) //
158 public FilteredData filter(DataFromTopic data) {
159 return filter.filter(data);