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.pmlog.configuration;
23 import java.lang.invoke.MethodHandles;
24 import java.nio.charset.Charset;
25 import java.nio.file.Files;
28 import lombok.ToString;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.boot.context.properties.EnableConfigurationProperties;
35 @EnableConfigurationProperties
37 public class ApplicationConfig {
39 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
40 private static com.google.gson.Gson gson = new com.google.gson.GsonBuilder().disableHtmlEscaping().create();
41 private static final String JOB_DEFINITION_PATH = "./config/jobDefinition.json";
43 @Value("${server.ssl.key-store-type}")
44 private String sslKeyStoreType = "";
46 @Value("${server.ssl.key-store-password}")
47 private String sslKeyStorePassword = "";
49 @Value("${server.ssl.key-store}")
50 private String sslKeyStore = "";
52 @Value("${server.ssl.key-password}")
53 private String sslKeyPassword = "";
55 @Value("${app.webclient.trust-store-used}")
56 private boolean sslTrustStoreUsed = false;
58 @Value("${app.webclient.trust-store-password}")
59 private String sslTrustStorePassword = "";
61 @Value("${app.webclient.trust-store}")
62 private String sslTrustStore = "";
64 @Value("${app.webclient.http.proxy-host:}")
65 private String httpProxyHost = "";
67 @Value("${app.webclient.http.proxy-port:0}")
68 private int httpProxyPort = 0;
71 @Value("${server.port}")
72 private int localServerHttpsPort;
75 @Value("${app.kafka.max-poll-records:300}")
76 private int kafkaMaxPollRecords;
79 @Value("${app.kafka.group-id}")
80 private String kafkaGroupId;
83 @Value("${app.kafka.client-id}")
84 private String kafkaClientId;
86 @Value("${app.kafka.bootstrap-servers}")
87 private String kafkaBootstrapServers;
89 @Value("${app.kafka.input-topic}")
90 private String kafkaInputTopic;
93 @Value("${app.influx.url}")
94 private String influxUrl;
97 @Value("${app.influx.access-token}")
98 private String influxAccessToken;
101 @Value("${app.ics-base-url}")
102 private String icsBaseUrl;
105 @Value("${app.consumer-job-id:shouldHaveBeenDefinedInYaml}")
106 private String consumerJobId;
109 @Value("${app.influx.user}")
110 private String influxUser;
113 @Value("${app.influx.password}")
114 private String influxPassword;
117 @Value("${app.influx.database}")
118 private String influxDatabase;
121 @Value("${app.influx.bucket}")
122 private String influxBucket;
125 @Value("${app.influx.org}")
126 private String influxOrg;
128 private WebClientConfig webClientConfig = null;
130 public WebClientConfig getWebClientConfig() {
131 if (this.webClientConfig == null) {
132 WebClientConfig.HttpProxyConfig httpProxyConfig = WebClientConfig.HttpProxyConfig.builder() //
133 .httpProxyHost(this.httpProxyHost) //
134 .httpProxyPort(this.httpProxyPort) //
137 this.webClientConfig = WebClientConfig.builder() //
138 .keyStoreType(this.sslKeyStoreType) //
139 .keyStorePassword(this.sslKeyStorePassword) //
140 .keyStore(this.sslKeyStore) //
141 .keyPassword(this.sslKeyPassword) //
142 .isTrustStoreUsed(this.sslTrustStoreUsed) //
143 .trustStore(this.sslTrustStore) //
144 .trustStorePassword(this.sslTrustStorePassword) //
145 .httpProxyConfig(httpProxyConfig) //
148 return this.webClientConfig;
151 public String getConsumerJobInfo() {
154 return Files.readString(java.nio.file.Path.of(JOB_DEFINITION_PATH), Charset.defaultCharset());
155 } catch (Exception e) {
156 logger.error("Could not load configuration file: {}, reason: {}", JOB_DEFINITION_PATH, e.getMessage());
161 private ConsumerJobInfo.KafkaDeliveryInfo getKafkaDeliveryInfoFromAplicationYaml() {
162 return ConsumerJobInfo.KafkaDeliveryInfo.builder() //
163 .bootStrapServers(this.kafkaBootstrapServers) //
164 .topic(kafkaInputTopic) //
168 private ConsumerJobInfo.KafkaDeliveryInfo getKafkaDeliveryInfo() {
170 ConsumerJobInfo infoFromFile = gson.fromJson(getConsumerJobInfo(), ConsumerJobInfo.class);
171 if (infoFromFile != null && infoFromFile.jobDefinition != null
172 && infoFromFile.jobDefinition.getDeliveryInfo() != null) {
173 return infoFromFile.jobDefinition.getDeliveryInfo();
176 } catch (Exception e) {
177 logger.warn("Could not parse file: {}, reason: {}, falling back to parameters in Application.yaml",
178 JOB_DEFINITION_PATH, e.getMessage());
180 return getKafkaDeliveryInfoFromAplicationYaml();
184 public String getKafkaInputTopic() {
185 return getKafkaDeliveryInfo().getTopic();
188 public String getKafkaBootStrapServers() {
189 return getKafkaDeliveryInfo().getBootStrapServers();