2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
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
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.onap.ccsdk.oran.a1policymanagementservice.configuration;
23 import com.google.common.base.Strings;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashMap;
30 import javax.validation.constraints.NotEmpty;
34 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.WebClientConfig.HttpProxyConfig;
35 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
36 import org.springframework.beans.factory.annotation.Value;
37 import org.springframework.boot.context.properties.EnableConfigurationProperties;
39 import reactor.core.publisher.Flux;
40 import reactor.netty.transport.ProxyProvider;
42 @EnableConfigurationProperties
43 public class ApplicationConfig {
46 @Value("${app.filepath}")
47 private String localConfigurationFilePath;
50 @Value("${app.config-file-schema-path:}")
51 private String configurationFileSchemaPath;
54 @Value("${app.vardata-directory:null}")
55 private String vardataDirectory;
57 @Value("${server.ssl.key-store-type}")
58 private String sslKeyStoreType = "";
60 @Value("${server.ssl.key-store-password}")
61 private String sslKeyStorePassword = "";
63 @Value("${server.ssl.key-store}")
64 private String sslKeyStore = "";
66 @Value("${server.ssl.key-password}")
67 private String sslKeyPassword = "";
69 @Value("${app.webclient.trust-store-used}")
70 private boolean sslTrustStoreUsed = false;
72 @Value("${app.webclient.trust-store-password}")
73 private String sslTrustStorePassword = "";
75 @Value("${app.webclient.trust-store}")
76 private String sslTrustStore = "";
78 @Value("${app.webclient.http.proxy-host:}")
79 private String httpProxyHost = "";
81 @Value("${app.webclient.http.proxy-port:0}")
82 private int httpProxyPort = 0;
84 @Value("${app.webclient.http.proxy-type:HTTP}")
85 private String httpProxyType = "HTTP";
88 @Value("${app.s3.endpointOverride:}")
89 private String s3EndpointOverride;
92 @Value("${app.s3.accessKeyId:}")
93 private String s3AccessKeyId;
96 @Value("${app.s3.secretAccessKey:}")
97 private String s3SecretAccessKey;
100 @Value("${app.s3.bucket:}")
101 private String s3Bucket;
103 private Map<String, RicConfig> ricConfigs = new HashMap<>();
106 private String dmaapConsumerTopicUrl;
109 private String dmaapProducerTopicUrl;
111 private Map<String, ControllerConfig> controllerConfigs = new HashMap<>();
113 private WebClientConfig webClientConfig = null;
115 public synchronized Collection<RicConfig> getRicConfigs() {
116 return this.ricConfigs.values();
119 public WebClientConfig getWebClientConfig() {
120 if (this.webClientConfig == null) {
121 HttpProxyConfig httpProxyConfig = HttpProxyConfig.builder() //
122 .httpProxyHost(this.httpProxyHost) //
123 .httpProxyPort(this.httpProxyPort) //
124 .httpProxyType(ProxyProvider.Proxy.valueOf(this.httpProxyType)) //
127 this.webClientConfig = WebClientConfig.builder() //
128 .keyStoreType(this.sslKeyStoreType) //
129 .keyStorePassword(this.sslKeyStorePassword) //
130 .keyStore(this.sslKeyStore) //
131 .keyPassword(this.sslKeyPassword) //
132 .isTrustStoreUsed(this.sslTrustStoreUsed) //
133 .trustStore(this.sslTrustStore) //
134 .trustStorePassword(this.sslTrustStorePassword) //
135 .httpProxyConfig(httpProxyConfig) //
138 return this.webClientConfig;
141 public synchronized ControllerConfig getControllerConfig(String name) throws ServiceException {
142 ControllerConfig controllerConfig = this.controllerConfigs.get(name);
143 if (controllerConfig == null) {
144 throw new ServiceException("Could not find controller config: " + name);
146 return controllerConfig;
149 public synchronized RicConfig getRic(String ricId) throws ServiceException {
150 RicConfig ricConfig = this.ricConfigs.get(ricId);
151 if (ricConfig == null) {
152 throw new ServiceException("Could not find ric configuration: " + ricId);
157 public static class RicConfigUpdate {
159 ADDED, CHANGED, REMOVED
163 private final RicConfig ricConfig;
165 private final Type type;
167 public RicConfigUpdate(RicConfig config, Type event) {
168 this.ricConfig = config;
173 public synchronized Flux<RicConfigUpdate> setConfiguration(
174 ApplicationConfigParser.ConfigParserResult parserResult) {
176 Collection<RicConfigUpdate> modifications = new ArrayList<>();
177 this.controllerConfigs = parserResult.getControllerConfigs();
179 this.dmaapConsumerTopicUrl = parserResult.getDmaapConsumerTopicUrl();
180 this.dmaapProducerTopicUrl = parserResult.getDmaapProducerTopicUrl();
182 Map<String, RicConfig> newRicConfigs = new HashMap<>();
183 for (RicConfig newConfig : parserResult.getRicConfigs()) {
184 RicConfig oldConfig = this.ricConfigs.get(newConfig.getRicId());
185 this.ricConfigs.remove(newConfig.getRicId());
186 if (oldConfig == null) {
187 newRicConfigs.put(newConfig.getRicId(), newConfig);
188 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED));
189 } else if (!newConfig.equals(oldConfig)) {
190 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED));
191 newRicConfigs.put(newConfig.getRicId(), newConfig);
193 newRicConfigs.put(oldConfig.getRicId(), oldConfig);
196 for (RicConfig deletedConfig : this.ricConfigs.values()) {
197 modifications.add(new RicConfigUpdate(deletedConfig, RicConfigUpdate.Type.REMOVED));
199 this.ricConfigs = newRicConfigs;
201 return Flux.fromIterable(modifications);
204 public boolean isS3Enabled() {
205 return !(Strings.isNullOrEmpty(s3EndpointOverride) || Strings.isNullOrEmpty(s3Bucket));