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 java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.HashMap;
28 import javax.validation.constraints.NotEmpty;
32 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.WebClientConfig.HttpProxyConfig;
33 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.boot.context.properties.EnableConfigurationProperties;
36 import reactor.core.publisher.Flux;
38 @EnableConfigurationProperties
39 public class ApplicationConfig {
42 @Value("${app.filepath}")
43 private String localConfigurationFilePath;
46 @Value("${app.vardata-directory:null}")
47 private String vardataDirectory;
49 @Value("${server.ssl.key-store-type}")
50 private String sslKeyStoreType = "";
52 @Value("${server.ssl.key-store-password}")
53 private String sslKeyStorePassword = "";
55 @Value("${server.ssl.key-store}")
56 private String sslKeyStore = "";
58 @Value("${server.ssl.key-password}")
59 private String sslKeyPassword = "";
61 @Value("${app.webclient.trust-store-used}")
62 private boolean sslTrustStoreUsed = false;
64 @Value("${app.webclient.trust-store-password}")
65 private String sslTrustStorePassword = "";
67 @Value("${app.webclient.trust-store}")
68 private String sslTrustStore = "";
70 @Value("${app.webclient.http.proxy-host:\"\"}")
71 private String httpProxyHost = "";
73 @Value("${app.webclient.http.proxy-port:0}")
74 private int httpProxyPort = 0;
76 private Map<String, RicConfig> ricConfigs = new HashMap<>();
79 private String dmaapConsumerTopicUrl;
82 private String dmaapProducerTopicUrl;
84 private Map<String, ControllerConfig> controllerConfigs = new HashMap<>();
86 private WebClientConfig webClientConfig = null;
88 public synchronized Collection<RicConfig> getRicConfigs() {
89 return this.ricConfigs.values();
92 public WebClientConfig getWebClientConfig() {
93 if (this.webClientConfig == null) {
94 HttpProxyConfig httpProxyConfig = ImmutableHttpProxyConfig.builder() //
95 .httpProxyHost(this.httpProxyHost) //
96 .httpProxyPort(this.httpProxyPort) //
99 this.webClientConfig = ImmutableWebClientConfig.builder() //
100 .keyStoreType(this.sslKeyStoreType) //
101 .keyStorePassword(this.sslKeyStorePassword) //
102 .keyStore(this.sslKeyStore) //
103 .keyPassword(this.sslKeyPassword) //
104 .isTrustStoreUsed(this.sslTrustStoreUsed) //
105 .trustStore(this.sslTrustStore) //
106 .trustStorePassword(this.sslTrustStorePassword) //
107 .httpProxyConfig(httpProxyConfig) //
110 return this.webClientConfig;
113 public synchronized ControllerConfig getControllerConfig(String name) throws ServiceException {
114 ControllerConfig controllerConfig = this.controllerConfigs.get(name);
115 if (controllerConfig == null) {
116 throw new ServiceException("Could not find controller config: " + name);
118 return controllerConfig;
121 public synchronized RicConfig getRic(String ricId) throws ServiceException {
122 RicConfig ricConfig = this.ricConfigs.get(ricId);
123 if (ricConfig == null) {
124 throw new ServiceException("Could not find ric configuration: " + ricId);
129 public static class RicConfigUpdate {
131 ADDED, CHANGED, REMOVED
135 private final RicConfig ricConfig;
137 private final Type type;
139 public RicConfigUpdate(RicConfig config, Type event) {
140 this.ricConfig = config;
145 public synchronized Flux<RicConfigUpdate> setConfiguration(
146 ApplicationConfigParser.ConfigParserResult parserResult) {
148 Collection<RicConfigUpdate> modifications = new ArrayList<>();
149 this.controllerConfigs = parserResult.controllerConfigs();
151 this.dmaapConsumerTopicUrl = parserResult.dmaapConsumerTopicUrl();
152 this.dmaapProducerTopicUrl = parserResult.dmaapProducerTopicUrl();
154 Map<String, RicConfig> newRicConfigs = new HashMap<>();
155 for (RicConfig newConfig : parserResult.ricConfigs()) {
156 RicConfig oldConfig = this.ricConfigs.get(newConfig.ricId());
157 this.ricConfigs.remove(newConfig.ricId());
158 if (oldConfig == null) {
159 newRicConfigs.put(newConfig.ricId(), newConfig);
160 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED));
161 } else if (!newConfig.equals(oldConfig)) {
162 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED));
163 newRicConfigs.put(newConfig.ricId(), newConfig);
165 newRicConfigs.put(oldConfig.ricId(), oldConfig);
168 for (RicConfig deletedConfig : this.ricConfigs.values()) {
169 modifications.add(new RicConfigUpdate(deletedConfig, RicConfigUpdate.Type.REMOVED));
171 this.ricConfigs = newRicConfigs;
173 return Flux.fromIterable(modifications);