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.ConfigurationProperties;
36 import org.springframework.boot.context.properties.EnableConfigurationProperties;
37 import reactor.core.publisher.Flux;
39 @EnableConfigurationProperties
40 @ConfigurationProperties()
41 public class ApplicationConfig {
44 @Value("${app.filepath}")
45 private String localConfigurationFilePath;
47 @Value("${server.ssl.key-store-type}")
48 private String sslKeyStoreType = "";
50 @Value("${server.ssl.key-store-password}")
51 private String sslKeyStorePassword = "";
53 @Value("${server.ssl.key-store}")
54 private String sslKeyStore = "";
56 @Value("${server.ssl.key-password}")
57 private String sslKeyPassword = "";
59 @Value("${app.webclient.trust-store-used}")
60 private boolean sslTrustStoreUsed = false;
62 @Value("${app.webclient.trust-store-password}")
63 private String sslTrustStorePassword = "";
65 @Value("${app.webclient.trust-store}")
66 private String sslTrustStore = "";
68 @Value("${app.webclient.http.proxy-host}")
69 private String httpProxyHost = "";
71 @Value("${app.webclient.http.proxy-port}")
72 private int httpProxyPort = 0;
74 private Map<String, RicConfig> ricConfigs = new HashMap<>();
77 private String dmaapConsumerTopicUrl;
80 private String dmaapProducerTopicUrl;
82 private Map<String, ControllerConfig> controllerConfigs = new HashMap<>();
84 public synchronized Collection<RicConfig> getRicConfigs() {
85 return this.ricConfigs.values();
88 public WebClientConfig getWebClientConfig() {
89 HttpProxyConfig httpProxyConfig = ImmutableHttpProxyConfig.builder() //
90 .httpProxyHost(this.httpProxyHost) //
91 .httpProxyPort(this.httpProxyPort) //
94 return ImmutableWebClientConfig.builder() //
95 .keyStoreType(this.sslKeyStoreType) //
96 .keyStorePassword(this.sslKeyStorePassword) //
97 .keyStore(this.sslKeyStore) //
98 .keyPassword(this.sslKeyPassword) //
99 .isTrustStoreUsed(this.sslTrustStoreUsed) //
100 .trustStore(this.sslTrustStore) //
101 .trustStorePassword(this.sslTrustStorePassword) //
102 .httpProxyConfig(httpProxyConfig) //
106 public synchronized ControllerConfig getControllerConfig(String name) throws ServiceException {
107 ControllerConfig controllerConfig = this.controllerConfigs.get(name);
108 if (controllerConfig == null) {
109 throw new ServiceException("Could not find controller config: " + name);
111 return controllerConfig;
114 public synchronized RicConfig getRic(String ricId) throws ServiceException {
115 RicConfig ricConfig = this.ricConfigs.get(ricId);
116 if (ricConfig == null) {
117 throw new ServiceException("Could not find ric configuration: " + ricId);
122 public static class RicConfigUpdate {
124 ADDED, CHANGED, REMOVED
128 private final RicConfig ricConfig;
130 private final Type type;
132 RicConfigUpdate(RicConfig ric, Type event) {
133 this.ricConfig = ric;
138 public synchronized Flux<RicConfigUpdate> setConfiguration(
139 ApplicationConfigParser.ConfigParserResult parserResult) {
141 Collection<RicConfigUpdate> modifications = new ArrayList<>();
142 this.controllerConfigs = parserResult.controllerConfigs();
144 this.dmaapConsumerTopicUrl = parserResult.dmaapConsumerTopicUrl();
145 this.dmaapProducerTopicUrl = parserResult.dmaapProducerTopicUrl();
147 Map<String, RicConfig> newRicConfigs = new HashMap<>();
148 for (RicConfig newConfig : parserResult.ricConfigs()) {
149 RicConfig oldConfig = this.ricConfigs.get(newConfig.ricId());
150 this.ricConfigs.remove(newConfig.ricId());
151 if (oldConfig == null) {
152 newRicConfigs.put(newConfig.ricId(), newConfig);
153 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED));
154 } else if (!newConfig.equals(oldConfig)) {
155 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED));
156 newRicConfigs.put(newConfig.ricId(), newConfig);
158 newRicConfigs.put(oldConfig.ricId(), oldConfig);
161 for (RicConfig deletedConfig : this.ricConfigs.values()) {
162 modifications.add(new RicConfigUpdate(deletedConfig, RicConfigUpdate.Type.REMOVED));
164 this.ricConfigs = newRicConfigs;
166 return Flux.fromIterable(modifications);