X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fconfiguration%2FApplicationConfig.java;h=5e020983e46608d75d460dfec0e647451f8d2730;hb=1178fb45f6d79fb3988b2806073aeeee3d68324e;hp=3b4f8104b377b5dd31daa89b20e5ac37dc77b861;hpb=4f602854561a08e754eb0c4ba9327bf49b0e63d7;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java index 3b4f8104..5e020983 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java @@ -24,85 +24,86 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import java.util.Properties; import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; import lombok.Getter; import org.oransc.policyagent.exceptions.ServiceException; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import reactor.core.publisher.Flux; @EnableConfigurationProperties -@ConfigurationProperties("app") +@ConfigurationProperties() public class ApplicationConfig { @NotEmpty - private String filepath; + @Getter + @Value("${app.filepath}") + private String localConfigurationFilePath; - @NotEmpty - private String a1ControllerBaseUrl; + @Value("${server.ssl.key-store-type}") + private String sslKeyStoreType = ""; - @NotEmpty - private String a1ControllerUsername; + @Value("${server.ssl.key-store-password}") + private String sslKeyStorePassword = ""; - @NotEmpty - private String a1ControllerPassword; + @Value("${server.ssl.key-store}") + private String sslKeyStore = ""; - private Map ricConfigs = new HashMap<>(); - @Getter - private Properties dmaapPublisherConfig; - @Getter - private Properties dmaapConsumerConfig; + @Value("${server.ssl.key-password}") + private String sslKeyPassword = ""; - public String getLocalConfigurationFilePath() { - return this.filepath; - } + @Value("${app.webclient.trust-store-used}") + private boolean sslTrustStoreUsed = false; - public synchronized String getA1ControllerBaseUrl() { - return this.a1ControllerBaseUrl; - } + @Value("${app.webclient.trust-store-password}") + private String sslTrustStorePassword = ""; - public synchronized String getA1ControllerUsername() { - return this.a1ControllerUsername; - } + @Value("${app.webclient.trust-store}") + private String sslTrustStore = ""; - public synchronized String getA1ControllerPassword() { - return this.a1ControllerPassword; - } + private Map ricConfigs = new HashMap<>(); - /* - * Do not remove, used by framework! - */ - public synchronized void setFilepath(String filepath) { - this.filepath = filepath; - } + @Getter + private String dmaapConsumerTopicUrl; - public synchronized void setA1ControllerBaseUrl(String a1ControllerBaseUrl) { - this.a1ControllerBaseUrl = a1ControllerBaseUrl; - } + @Getter + private String dmaapProducerTopicUrl; + + private Map controllerConfigs = new HashMap<>(); - public synchronized void setA1ControllerUsername(String a1ControllerUsername) { - this.a1ControllerUsername = a1ControllerUsername; + public synchronized Collection getRicConfigs() { + return this.ricConfigs.values(); } - public synchronized void setA1ControllerPassword(String a1ControllerPassword) { - this.a1ControllerPassword = a1ControllerPassword; + public WebClientConfig getWebClientConfig() { + return ImmutableWebClientConfig.builder() // + .keyStoreType(this.sslKeyStoreType) // + .keyStorePassword(this.sslKeyStorePassword) // + .keyStore(this.sslKeyStore) // + .keyPassword(this.sslKeyPassword) // + .isTrustStoreUsed(this.sslTrustStoreUsed) // + .trustStore(this.sslTrustStore) // + .trustStorePassword(this.sslTrustStorePassword) // + .build(); } - public synchronized Collection getRicConfigs() { - return this.ricConfigs.values(); + public synchronized ControllerConfig getControllerConfig(String name) throws ServiceException { + ControllerConfig controllerConfig = this.controllerConfigs.get(name); + if (controllerConfig == null) { + throw new ServiceException("Could not find controller config: " + name); + } + return controllerConfig; } - public RicConfig getRic(String ricName) throws ServiceException { - for (RicConfig ricConfig : getRicConfigs()) { - if (ricConfig.name().equals(ricName)) { - return ricConfig; - } + public synchronized RicConfig getRic(String ricName) throws ServiceException { + RicConfig ricConfig = this.ricConfigs.get(ricName); + if (ricConfig == null) { + throw new ServiceException("Could not find ric configuration: " + ricName); } - throw new ServiceException("Could not find ric: " + ricName); + return ricConfig; } public static class RicConfigUpdate { @@ -121,24 +122,25 @@ public class ApplicationConfig { } } - public synchronized Flux setConfiguration(@NotNull Collection ricConfigs, - Properties dmaapPublisherConfig, Properties dmaapConsumerConfig) { + public synchronized Flux setConfiguration( + ApplicationConfigParser.ConfigParserResult parserResult) { Collection modifications = new ArrayList<>(); - this.dmaapPublisherConfig = dmaapPublisherConfig; - this.dmaapConsumerConfig = dmaapConsumerConfig; + this.controllerConfigs = parserResult.controllerConfigs(); + + this.dmaapConsumerTopicUrl = parserResult.dmaapConsumerTopicUrl(); + this.dmaapProducerTopicUrl = parserResult.dmaapProducerTopicUrl(); Map newRicConfigs = new HashMap<>(); - for (RicConfig newConfig : ricConfigs) { + for (RicConfig newConfig : parserResult.ricConfigs()) { RicConfig oldConfig = this.ricConfigs.get(newConfig.name()); + this.ricConfigs.remove(newConfig.name()); if (oldConfig == null) { newRicConfigs.put(newConfig.name(), newConfig); modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED)); - this.ricConfigs.remove(newConfig.name()); } else if (!newConfig.equals(oldConfig)) { modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED)); newRicConfigs.put(newConfig.name(), newConfig); - this.ricConfigs.remove(newConfig.name()); } else { newRicConfigs.put(oldConfig.name(), oldConfig); }